Lists & filter fixed, use fieldsMap, links fixed
authorLaury GvR <laury@gaslightmedia.com>
Tue, 2 Oct 2018 16:17:14 +0000 (12:17 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Tue, 2 Oct 2018 16:17:14 +0000 (12:17 -0400)
Every list now passes a fields map to ensure the field values its
result produces correspond to the expected field names in the
widget component templates. For example, the list.html component
template expects an entity 'name', but packaging plugin passes this
as 'title' - with the map, they are matched.

getList for the lists now use custom fields array to allow this.

Quicklinks, count, and list entity & ref_dest links are now working.

models/admin/events/list.php
setup/adminHooks.php

index 4b77c35..ae828bb 100644 (file)
@@ -641,8 +641,6 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
 
             case 'list':
             default:
-
-
                 $where = 'true';
 
                 // If we have a back request then go through the PHP_SESSION
index 5001af7..b830060 100644 (file)
@@ -251,10 +251,36 @@ add_action( 'init', function(){
 add_filter(
     GLM_MEMBERS_EVENTS_PLUGIN_SLUG .'-dashboard-widget',
     function ( $member = null ) {
+        require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataEvents.php';
+        $Events = new GlmDataEvents($this->wpdb, $this->config);
+
+        // Set default values for using getList() later, where the custom set of fields below will be used.
+        $where = '';
+        $order = '';
+        $fieldVals = true;
+        $idField = 'id';
+        $start = false;
+        $limit = false;
+    
+        // Save the current fields array and make a copy. Will be restored before the return.
+        $fSave = $Events->fields;
+    
+        // Remove what we don't want from the copy and get the list
+        $Events->fields = array(
+            'id'            => $fSave['id'],
+            'name'          => $fSave['name'],
+            'name_slug'     => $fSave['name_slug'],
+            'ref_type'      => $fSave['ref_type'],
+            'ref_dest'      => $fSave['ref_dest'],
+            'ref_dest_id'   => $fSave['ref_dest_id'],
+            'status'        => $fSave['status'],
+        );
+    
         $eventsIndexPage    = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-events-index&glm_action=edit';
         $eventsTable        = GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events";
         $eventsEditPage     = GLM_MEMBERS_PLUGIN_ADMIN_MENU_URL_BASE.'events-index&glm_action=list&option=edit';
         $eventsListPage     = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-events-list';
+        $eventsRefLink      = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-member&glm_action=index';
         $content            = [
             'title'         => 'Events',
             'components'    => [
@@ -303,8 +329,8 @@ add_filter(
                     'title'     => 'Number of Events',
                     'order'     => 1,
                     'template'  => 'entityAmount',
-                    'table'     => $eventsTable,
                     'url'       => $eventsIndexPage . "&option=search",
+                    'result'    => $Events->getStats(),
                 ],
                 [
                     'id'        => 'textSearch', 
@@ -324,21 +350,33 @@ add_filter(
                     'resultUrl' => $eventsListPage.'&event=',
                 ],
                 [
-                    'id'        => 'pending',
-                    'title'     => "Pending Events",
-                    'slug'      => "pending-events",
-                    'order'     => 3,
-                    'template'  => 'list',
-                    'entityID'  => 'eventID',
-                    'table'     => $eventsTable,
-                    'fields'    => "id, name as title, ref_dest, ref_type, status",
-                    'where'     => 'status='.$this->config['status_numb']['Pending'] . '',
-                    'resultUrl' => $eventsEditPage,
+                    'id'            => 'pending-events', 
+                    'title'         => 'Pending Events',
+                    'slug'          => 'pending-events',
+                    'order'         => 3,
+                    'template'      => 'list',
+                    'entityID'      => 'event',
+                    'defaultRefType'=> 'member',
+                    'refLink'       => $eventsRefLink,
+                    'url'           => $eventsEditPage,
+                    'result'        => $Events->getList("status=".$Events->config['status_numb']['Pending'], $order, $fieldVals, $idField, $start, $limit),
+                    'count'         => $Events->getStats("status=".$Events->config['status_numb']['Pending'], $order, $fieldVals, $idField, $start, $limit),
+                    'fieldMap'      => [
+                        'id'            => 'id',
+                        'ref_dest_name' => 'ref_dest',
+                        'name'          => 'name',
+                        'ref_type'      => 'ref_type',
+                        'ref_dest_id'   => 'ref_dest_id',
+                        'status'        => 'status'
+                    ],
                 ],
             ]
         ];
 
-         return $content;
+        // Restore the fields list
+        $Events->fields = $fSave;
+
+        return $content;
     },
     13,
     1