entityAmount view, lists, filter adjusted, where/order
authorLaury GvR <laury@gaslightmedia.com>
Mon, 24 Sep 2018 21:09:17 +0000 (17:09 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Mon, 24 Sep 2018 21:09:17 +0000 (17:09 -0400)
- Entity amount views added
- Using 'url' instead of 'resultUrl' for the list anchors
- Implemented Bad Location data list
- Implemented Pending Member Profiles
- Changed model to respect ORDER BY, and do proper counts
- Commented code, removed unneeded comments, fixed spacing

models/admin/newDashboard/index.php
setup/adminHooks.php
views/admin/newDashboard/components/entityAmount.html
views/admin/newDashboard/components/list.html

index a527180..57cf222 100644 (file)
@@ -198,50 +198,47 @@ class GlmMembersAdmin_newDashboard_index extends GlmDataMembers
             $haveInfoRecords = true;
         }
 
-        // Not sure how to make the 'callback' use $this-> or this could get pulled out
-        // function orderSort ($a, $b) { return (strcmp ($a['order'],$b['order']));    }
-
-        // In case we want to treat the widget data before sending it to the viewfile.
-        // May be able to avoid sending the (huge) Config array to the view
+        // Create a set of useful data for each registered plugin that has a filter
+        //  Use that filter to retrieve table information, then run query for each 'list' field.
         foreach ( $this->config[ 'addOns' ] as $a ) {
             if ( has_filter( $a['slug'] . "-dashboard-widget") ) {
-                //var_dump($a);
                 $addons[$a['slug']]['name'] = $a['short_name'];
                 $addons[$a['slug']]['slug'] = $a['slug'];
-                $addons[$a['slug']]['index'] = $a['index'];
+                // $addons[$a['slug']]['index'] = $a['index'];
+                // echo $a['index'];
                 $addons[$a['slug']]['widgetData'] = apply_filters($a['slug'] . "-dashboard-widget", "");
                 $addons[$a['slug']]['widgetData'] = $this->queryWidgetLists($addons[$a['slug']]['widgetData']);
 
                 // Sort the component list based on the 'order'
                 uasort($addons[$a['slug']]['widgetData']['components'], array($this, 'orderSort') ) ;
             } else {
-                echo "<br>" . $a['slug'] .  " has no filter called " . $a['slug'] . "-dashboard-widget";
+                // For testing
+                //  echo "<br>" . $a['slug'] .  " has no filter called " . $a['slug'] . "-dashboard-widget";
             }
         }
 
         // Compile template data.
         $templateData = array(
-            'lockedToMember'     => $lockedToMember,
-            'member'             => $actionData,
-            'showArchived'       => $showArchived,
-            'statusTypeNumbers'  => $this->config['status_numb'],
-            'memberID'           => $memberID,
-            'haveInfoRecords'    => $haveInfoRecords,
-            'memberInfoRecords'  => $memberInfoRecords,
-            'clickThroughCounts' => $clickThroughCounts,
-            'detailViewCounts'   => $detailViewCounts,
-            'statusPending'      => $this->config['status_numb']['Pending'],
-            //'widgetData'         => $addons['widgetData'],
-            'addons'            => $addons,
+            'lockedToMember'        => $lockedToMember,
+            'member'                => $actionData,
+            'showArchived'          => $showArchived,
+            'statusTypeNumbers'     => $this->config['status_numb'],
+            'memberID'              => $memberID,
+            'haveInfoRecords'       => $haveInfoRecords,
+            'memberInfoRecords'     => $memberInfoRecords,
+            'clickThroughCounts'    => $clickThroughCounts,
+            'detailViewCounts'      => $detailViewCounts,
+            'statusPending'         => $this->config['status_numb']['Pending'],
+            'addons'                => $addons,
         );
 
         // Return status, suggested view, and data to controller.
         return array(
-            'status'           => $success,
-            'menuItemRedirect' => false,
-            'modelRedirect'    => false,
-            'view'             => 'admin/newDashboard/index.html',
-            'data'             => $templateData
+            'status'            => $success,
+            'menuItemRedirect'  => false,
+            'modelRedirect'     => false,
+            'view'              => 'admin/newDashboard/index.html',
+            'data'              => $templateData
         );
 
     }
@@ -251,16 +248,21 @@ class GlmMembersAdmin_newDashboard_index extends GlmDataMembers
     public function queryWidgetLists( &$widgetData = false ) {
         
         foreach ( $widgetData['components'] as &$widgetComponent ) {
+            $where = " TRUE ";
+            $order = "";
+            $limit = "5";
+            if ( isset($widgetComponent['where']) && $widgetComponent['where'] !== "" ) {
+                $where .= " AND " . $widgetComponent['where'];
+            }
+            if ( isset($widgetComponent['orderBy']) && $widgetComponent['orderBy'] !== "" ) {
+                $order .= " ORDER BY " . $widgetComponent['orderBy'];
+            }
 
             if ( $widgetComponent['template'] == 'list' && isset($widgetComponent['fields']) && isset($widgetComponent['table']) ) {
-                
-                if ( isset($widgetComponent['where']) && $widgetComponent['where'] !== "" ) {
-                    $where = $widgetComponent['where'];
-                } else {
-                    $where = " TRUE ";
-                }
-                
-                $resultsQuery = "SELECT " . $widgetComponent['fields'] . " FROM " . $widgetComponent['table'] . " WHERE " . $where . " LIMIT 5;";
+                $table = $widgetComponent['table'];
+                $fields = $widgetComponent['fields'];
+                $resultsQuery = "SELECT " . $fields . " FROM " . $table . " WHERE" .  $where . $order . " LIMIT " . $limit . ";";
+                //echo "<br>" .$resultsQuery;
                 $widgetComponent['sql'] = $resultsQuery;
                 $widgetComponent['listItems'] = $this->wpdb->get_results($resultsQuery);
 
@@ -271,14 +273,18 @@ class GlmMembersAdmin_newDashboard_index extends GlmDataMembers
                             // in url vs config array reference to ref_type (e.g. member vs Member, and member vs members)
                             $listItem->ref_type = strtolower($this->config['ref_type'][$listItem->ref_type]);
                         }
-                        if ( isset($listItem->expire_date)) {
-                            
-                        }
                     }
                 }
+                // $countQuery = "SELECT COUNT(" . $widgetComponent['entityID'] . ") FROM " . $widgetComponent['table'] . " WHERE " . $where . ";";
+                // $widgetComponent['count'] = $this->wpdb->get_var($countQuery);
+
+            } 
+            if ( isset($widgetComponent['table']) && ($widgetComponent['template'] == 'list' || $widgetComponent['template'] == 'entityAmount') ) {
+                $table = $widgetComponent['table'];
                 $countQuery = "SELECT COUNT(id) FROM " . $widgetComponent['table'] . " WHERE " . $where . ";";
+                //echo "<br>" .$countQuery;
                 $widgetComponent['count'] = $this->wpdb->get_var($countQuery);
-
+                //echo "<pre>" . var_dump($widgetComponent['count']) . "</pre>";
             }
         }
         return $widgetData;
index 8cf7b54..2177b3e 100644 (file)
@@ -409,7 +409,7 @@ add_filter(
     function ( $member = null ) {
         $membersIndexPage = GLM_MEMBERS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-members';
         $memberIndexPage = GLM_MEMBERS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-member';
-        $membersTable = GLM_MEMBERS_PLUGIN_PREFIX . "members";
+        $membersTable = GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info";
         $membersEditPage = GLM_MEMBERS_PLUGIN_ADMIN_MENU_URL_BASE.'member&glm_action=memberInfo';
 
         /*
@@ -454,6 +454,7 @@ add_filter(
                 ],
                 [
                     'id'       => 'entityAmount',
+                    'title'    => 'Number of ' . $this->config['terms']['term_member_plur_cap'],
                     'order'    => 1,
                     'template' => 'entityAmount',
                     'table'    => $membersTable,
@@ -471,27 +472,27 @@ add_filter(
                 ],
                 [
                     'id'        => 'pending', 
-                    'title'     => "Pending Members",
-                    'slug'      => "pending-members",
+                    'title'     => "Pending Member Profiles",
+                    'slug'      => "pending-member-profiles",
                     'order'     => 3,
                     'template'  => 'list',
-                    'entityID'  => 'id',
+                    'entityID'  => 'memberInfo',
                     'table'     => $membersTable,
-                    'fields'    => "id, title, ref_type, ref_dest",
+                    'fields'    => "id, reference_name as title, member as ref_dest, '10' as ref_type, status",
                     'where'     => 'status='.$this->config['status_numb']['Pending'],
-                    'resultUrl' => $membersIndexPage,
+                    'url'       => $membersEditPage,
                 ],
                 [
-                    'id'        => 'active',
-                    'title'     => "Bad Locaction Data",
+                    'id'        => 'bad-location-data',
+                    'title'     => "Bad Location Data",
                     'slug'      => "bad-location-data",
                     'order'     => 4,
                     'template'  => 'list',
-                    'entityID'  => 'id',
+                    'entityID'  => 'memberInfo',
                     'table'     => $membersTable,
-                    'fields'    => "id, title, ref_type, ref_dest",
-                    'where'     => 'status='.$this->config['status_numb']['Active'],
-                    'resultUrl' => $membersIndexPage,
+                    'fields'    => "id, reference_name as title, member as ref_dest, '10' as ref_type, status",
+                    'where'     => "has_no_map_data='1'",
+                    'url'       => $membersEditPage,
                 ],
             ]
         ];
index d980c07..a44ddcd 100644 (file)
@@ -1 +1,9 @@
-entityAmount
\ No newline at end of file
+<div class="{$component}-list list-header"> {if $component.title}{$component.title}:{/if} 
+    {if $component.url}
+        <a href="{$component.url}"></a>
+            <pre>{$component.count}</pre>
+        </a>
+    {else}
+        <span>{$component.count}</span>
+    {/if}
+</div>
\ No newline at end of file
index 991315b..0e50699 100644 (file)
@@ -3,7 +3,7 @@
 {foreach $component['listItems'] as $listItem}
     {if isset($listItem)}
         <li class="collection-item" style="line-height: 1;padding : 5px 15px;">
-            <a href='{$component.resultUrl}{if isset($listItem->ref_dest) && isset($listItem->ref_type)}&{$listItem->ref_type}={$listItem->ref_dest}{/if}&{$component.entityID}={$listItem->id}'>
+            <a href='{$component.url}{if isset($listItem->ref_dest) && isset($listItem->ref_type)}&{$listItem->ref_type}={$listItem->ref_dest}{/if}&{$component.entityID}={$listItem->id}'>
                 {$listItem->title}{if isset($listItem->expire_date)} - expired: {date( "m/d/Y", strtotime($listItem->expire_date))}{/if}
             </a>
         </li>