Lists & filter fixed, use fieldsMap, links fixed
authorLaury GvR <laury@gaslightmedia.com>
Tue, 2 Oct 2018 16:18:14 +0000 (12:18 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Tue, 2 Oct 2018 16:18:41 +0000 (12:18 -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.

setup/adminHooks.php

index beb9a77..6de9c3e 100644 (file)
@@ -47,10 +47,39 @@ add_filter('glm-member-db-admin-management-hooksHelp', function($content) {
 add_filter(
     GLM_MEMBERS_PACKAGING_PLUGIN_SLUG .'-dashboard-widget',
     function ( $member = null ) {
-        $packagingIndexPage = GLM_MEMBERS_PACKAGING_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-packaging-index&glm_action=index';
-        $packagesTable = GLM_MEMBERS_PACKAGING_PLUGIN_DB_PREFIX . "packages";
-        $packagingMemberEditPage = GLM_MEMBERS_PLUGIN_ADMIN_MENU_URL_BASE.'member&glm_action=packaging&option=edit';
-        $packagingEditPage = GLM_MEMBERS_PLUGIN_ADMIN_MENU_URL_BASE.'member&glm_action=packaging&option=edit';
+        require_once GLM_MEMBERS_PACKAGING_PLUGIN_CLASS_PATH.'/data/dataPackages.php';
+        $Packages = new GlmDataPackages($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
+        $fSave = $Packages->fields;
+    
+        // Remove what we don't want from the copy and get the list
+        $Packages->fields = array(
+            'id'            => $fSave['id'],
+            'title'         => $fSave['title'],
+            'status'        => $fSave['status'],
+            'ref_dest'      => $fSave['ref_dest'],
+            'ref_dest_name' => $fSave['ref_dest_name'],
+            'ref_type'      => $fSave['ref_type'],
+            'expire_date'   => $fSave['expire_date'],
+        );
+        $widgetResult = $Packages->getList("status=".$Packages->config['status_numb']['Pending'], $order, $fieldVals, $idField, $start, $limit);
+
+        // echo "<br><pre>" . var_dump($widgetResult) . "</pre><br>";
+    
+        $packagingIndexPage         = GLM_MEMBERS_PACKAGING_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-packaging-index&glm_action=index';
+        $packagesTable              = GLM_MEMBERS_PACKAGING_PLUGIN_DB_PREFIX . "packages";
+        $packagingMemberEditPage    = GLM_MEMBERS_PLUGIN_ADMIN_MENU_URL_BASE . 'member&glm_action=packaging&option=edit';
+        $packagingEditPage          = GLM_MEMBERS_PLUGIN_ADMIN_MENU_URL_BASE . 'member&glm_action=packaging&option=edit';
+        $packagingRefLink           = GLM_MEMBERS_PACKAGING_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-member&glm_action=index';
 
         /*
         * For list components: pass ref_type and ref_dest as part of the 'fields' string if you want to
@@ -97,8 +126,8 @@ add_filter(
                     'title'    => 'Number of Packages',
                     'order'    => 1,
                     'template' => 'entityAmount',
-                    'table'    => $packagesTable,
                     'url'      => $packagingIndexPage . "&option=search",
+                    'result'   => $Packages->getStats(),
                 ],
                 [
                     'id'        => 'textSearch',
@@ -110,18 +139,6 @@ add_filter(
                     'where'     => 'title',
                     'resultUrl' => $packagingIndexPage . "&option=edit&packageID=",
                 ],
-                // [
-                //     'id'        => 'active',
-                //     'title'     => "Active Packages",
-                //     'slug'      => "active-packages",
-                //     'order'     => 3,
-                //     'template'  => 'list',
-                //     'entityID'  => 'packageID',
-                //     'table'     => $packagesTable,
-                //     'fields'    => "id, title, ref_type, ref_dest",
-                //     'where'     => 'status='.$this->config['status_numb']['Active'],
-                //     'resultUrl' => $packagingEditPage,
-                // ],
                 [
                     'id'        => 'pending', 
                     'title'     => "Pending Packages",
@@ -129,10 +146,19 @@ add_filter(
                     'order'     => 4,
                     'template'  => 'list',
                     'entityID'  => 'packageID',
-                    'table'     => $packagesTable,
-                    'fields'    => "id, title, ref_type, ref_dest",
-                    'where'     => 'status='.$this->config['status_numb']['Pending'],
-                    'url'       => $packagingEditPage,
+                    'refLink'   => $packagingRefLink,
+                    'url'       => $packagingIndexPage . "&option=search",
+                    'result'    => $Packages->getList("status=".$Packages->config['status_numb']['Pending'], $order, $fieldVals, $idField, $start, $limit),
+                    'count'     => $Packages->getStats("status=".$Packages->config['status_numb']['Pending'], $order, $fieldVals, $idField, $start, $limit),
+                    'fieldMap'  => [
+                        'id'            => 'id',
+                        'name'          => 'title',
+                        'status'        => 'status',
+                        'ref_dest_id'   => 'ref_dest',
+                        'ref_dest_name' => 'ref_dest_name',
+                        'ref_type'      => 'ref_type',
+                        'expire_date'   => 'expire_date'
+                    ],
                 ],
                 [
                     'id'        => 'expired',
@@ -141,16 +167,27 @@ add_filter(
                     'order'     => 5,
                     'template'  => 'list',
                     'entityID'  => 'packageID',
-                    'table'     => $packagesTable,
-                    'fields'    => "id, title, ref_type, ref_dest, expire_date",
-                    'where'     => 'expire_date < NOW()',
-                    'orderBy'   => 'expire_date DESC',
-                    'url'       => $packagingEditPage,
+                    'refLink'   => $packagingRefLink,
+                    'url'       => $packagingIndexPage . "&option=search",
+                    'result'    => $Packages->getList("expire_date < NOW()", "expire_date DESC", $fieldVals, $idField, $start, $limit),
+                    'count'     => $Packages->getStats("expire_date < NOW()", "expire_date DESC", $fieldVals, $idField, $start, $limit),
+                    'fieldMap'  => [
+                        'id'            => 'id',
+                        'name'          => 'title',
+                        'status'        => 'status',
+                        'ref_dest_id'   => 'ref_dest',
+                        'ref_dest_name' => 'ref_dest_name',
+                        'ref_type'      => 'ref_type',
+                        'expire_date'   => 'expire_date'
+                    ],
                 ],
             ]
         ];
+        
+        // Restore the fields list
+        $Packages->fields = $fSave;
 
-         return $content;
+        return $content;
     },
     13,
     1