Add ability to send parameters into the route to determine which addons to use
authorLaury GvR <laury@gaslightmedia.com>
Tue, 30 Jul 2019 16:15:38 +0000 (12:15 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Tue, 30 Jul 2019 16:15:38 +0000 (12:15 -0400)
setup/routes/dashboard.php

index 87f71bc..847848b 100644 (file)
  * @link     http://dev.gaslightmedia.com/
  */
 
-/**
- * Require the Contact Data Class.
- */
-require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php';
-
-require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataEvents.php';
-
 /**
  * Documentation for Wordpress API and adding custom endpoints.
  * https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
@@ -96,10 +89,15 @@ class GLMA_Dashboard_Rest_Controller
                             //$summary[] = $addon;
                         //}
 
+                        $parameters = $request->get_params();
+                        $summary['parameters'] = $parameters;
+                        $addons= explode(",", $parameters['addons'] );
+                        $summary['addons'] = $addons;
 
-                        if ( defined("GLM_MEMBERS_EVENTS_PLUGIN_PATH") ) {
+                        $config = array();
 
-                            $config = array();
+                        if ( in_array( 'events', $addons ) && defined("GLM_MEMBERS_EVENTS_PLUGIN_PATH") ) {
+                            require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataEvents.php';
                             
                             $events_summary = $this->get_events_summary( $config );
                             $summary['events'] = $events_summary;
@@ -107,17 +105,19 @@ class GLMA_Dashboard_Rest_Controller
                             $config['today'] = true;
                             $events_today = $this->get_events_summary( $config );
                             $summary['events_today'] = $events_today;
+                            
                         }
                         if ( defined("GLM_MEMBERS_EVENTS_PLUGIN_PATH") ) {
                         }
-                        if ( defined("GLM_MEMBERS_COUPONS_PLUGIN_PATH") ) {
-                            $summary['coupons'] = $this->get_coupons_summary();
+                        if ( in_array( 'coupons', $addons ) && defined("GLM_MEMBERS_COUPONS_PLUGIN_PATH") ) {
+                            $summary['coupons'] = $this->get_coupons_summary( $config );
                         }
-                        if ( defined("GLM_MEMBERS_PACKAGING_PLUGIN_PATH") ) {
-                            $summary['packaging'] =  $this->get_packages_summary();
+                        if ( in_array( 'packaging', $addons ) && defined("GLM_MEMBERS_PACKAGING_PLUGIN_PATH") ) {
+                            $summary['packaging'] =  $this->get_packaging_summary( $config );
                         }
 
-                        if ( defined("GLM_MEMBERS_PLUGIN_PATH") ) {
+                        if ( in_array( 'members', $addons ) && defined("GLM_MEMBERS_PLUGIN_PATH") ) {
+                            require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php';
                             // Cannot think of a reason to use members on home screen
                             //$members = $this->get_members_summary();
                             //$summary['members'] = $members;
@@ -125,6 +125,10 @@ class GLMA_Dashboard_Rest_Controller
 
                         return rest_ensure_response( get_object_vars ( (object) $summary ) );
                     },
+
+                    'args' => array(
+                        'eventsfeatured' => false
+                    )
                 )
             )
         );
@@ -176,7 +180,7 @@ class GLMA_Dashboard_Rest_Controller
     }
     
     // Get members
-    public function get_members_summary() {
+    public function get_members_summary( $config ) {
         $fields = "id, name, member_slug";
         $table = GLM_MEMBERS_PLUGIN_DB_PREFIX."members";
         $where = 
@@ -227,7 +231,7 @@ class GLMA_Dashboard_Rest_Controller
     }
 
     // Get coupons
-    public function get_coupons_summary() {
+    public function get_coupons_summary( $config ) {
         $fields = "id, name, name_slug, descr, image, start_date, end_date, expire";
         $table = GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."coupons";
         $where = "status IN (".$this->config['status_numb']['Active'].")
@@ -244,7 +248,7 @@ class GLMA_Dashboard_Rest_Controller
     }
     
     // Get packages
-    public function get_packages_summary() {
+    public function get_packaging_summary( $config ) {
         $fields = "id, title, package_slug, short_descr, image, start_date, end_date, expire_date";
         $table = GLM_MEMBERS_PACKAGING_PLUGIN_DB_PREFIX."packages";
         $where = "status IN (".$this->config['status_numb']['Active'].")