Added admin dashboard widget
authorChuck Scott <cscott@gaslightmedia.com>
Wed, 25 Mar 2015 16:42:46 +0000 (12:42 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Wed, 25 Mar 2015 16:42:46 +0000 (12:42 -0400)
classes/data/dataMembers.php
controllers/admin.php
defines.php
models/admin/dashboardWidget/index.php [new file with mode: 0644]
views/admin/dashboardWidget/index.html [new file with mode: 0644]

index 39a5656..e9389c0 100644 (file)
@@ -185,6 +185,27 @@ class GlmDataMembers extends GlmDataAbstract {
                }
 
        }
+
+       /*
+        * Get a simple members list - Name and ID only
+        *
+        * @return array Array of Name and ID for all members
+        * @access public
+        */
+       public function getSimpleMembersList()
+       {
+
+           $memberList = $this->wpdb->get_results(
+            "
+            SELECT id, name
+              FROM ".$this->table."
+            ;",
+               ARRAY_A
+        );
+
+           return $memberList;
+       }
+
 }
 
 ?>
\ No newline at end of file
index a0583ba..b9f2aad 100644 (file)
@@ -26,6 +26,9 @@
  */
 $GLOBALS['glmMembersAdminValidActions'] = array(
 
+        'dashboardWidget' => array(
+                'index'
+        ),
         'members' => array(
                 'index', // member list
                 'list',
@@ -203,6 +206,14 @@ class glmMembersAdmin extends GlmPluginSupport
                         'glmMembersAdminScripts'
                 ));
 
+        // Add dashboard widget
+        add_action( 'wp_dashboard_setup',
+                array(
+                        $this,
+                        'glmMembersAdminDashboardWidget'
+
+                ));
+
     }
 
     /**
@@ -320,6 +331,40 @@ class glmMembersAdmin extends GlmPluginSupport
 
     }
 
+    /**
+     * Add Admin Dashboard Widget
+     *
+     * This method is called by an add_action() hook setup in the contructor.
+     *
+     * (no prameters)
+     *
+     * @return void
+     * @access public
+     */
+    public function glmMembersAdminDashboardWidget ()
+    {
+
+        wp_add_dashboard_widget(
+                'glm_members_admin_dashboard_widget',
+                'Member DB Summary',
+                array(
+                        $this,
+                        'glmMembersAdminDashboardContent'
+                )
+        );
+
+    }
+
+    /**
+     * Admin dashboard widget content
+     *
+     * (no prameters)
+     *
+     * @return void
+     * @access public
+     */
+
+
     /*
      * Menu item specific "Callback" methods
      *
@@ -333,6 +378,12 @@ class glmMembersAdmin extends GlmPluginSupport
      *
      */
 
+    // Dashboard Widget
+    public function glmMembersAdminDashboardContent ()
+    {
+        $this->controller('dashboardWidget');
+    }
+
     // Main Plugin Menu Item
     public function glmMembersAdminMenuMembers ()
     {
@@ -628,9 +679,10 @@ class glmMembersAdmin extends GlmPluginSupport
 
         // Add standard template parameters
         $smarty->templateAssign ( 'adminDebug', GLM_MEMBERS_PLUGIN_ADMIN_DEBUG);
+        $smarty->templateAssign ( 'adminURL', GLM_MEMBERS_PLUGIN_ADMIN_URL);
         $smarty->templateAssign ( 'baseURL', GLM_MEMBERS_PLUGIN_BASE_URL);
         $smarty->templateAssign ( 'thisURL', GLM_MEMBERS_PLUGIN_CURRENT_URL );
-        $smarty->templateAssign ( 'thisPage', $_REQUEST['page']);
+        $smarty->templateAssign ( 'thisPage', (isset($_REQUEST['page']) ? $_REQUEST['page']: '') );
         $smarty->templateAssign ( 'glmPluginName', GLM_MEMBERS_PLUGIN_NAME );
         $smarty->templateAssign ( 'glmPluginMediaURL', GLM_MEMBERS_PLUGIN_MEDIA_URL );
         $smarty->templateAssign ( 'thisYear', date ( 'Y' ) );
index 8879abd..f89b042 100644 (file)
@@ -27,13 +27,15 @@ define('GLM_MEMBERS_PLUGIN_VERSION', 0.1);
 define('GLM_MEMBERS_PLUGIN_DB_VERSION', 0.1);
 
 // URLs
+$adminURL = admin_url('admin.php');
+define('GLM_MEMBERS_PLUGIN_ADMIN_URL', $adminURL);
 define('GLM_MEMBERS_PLUGIN_URL', plugin_dir_url(__FILE__));
-
 $pageUri = explode('?', $_SERVER['REQUEST_URI']);               // Bust this up to access URL path and script name only
 define('GLM_MEMBERS_PLUGIN_BASE_URL', WP_PLUGIN_URL.'/'.GLM_MEMBERS_PLUGIN_DIR);
 define('GLM_MEMBERS_PLUGIN_CURRENT_URL', $pageProtocol.'://'.$_SERVER['SERVER_NAME'].$pageUri[0]);
 define('GLM_MEMBERS_PLUGIN_MEDIA_URL', WP_CONTENT_URL.'/plugins/'.GLM_MEMBERS_PLUGIN_DIR.'/media');
 
+
 // Directories
 define('GLM_MEMBERS_PLUGIN_PATH', dirname(__FILE__));
 define('GLM_MEMBERS_PLUGIN_DB_SCRIPTS', dirname(__FILE__).'/misc/databaseScripts');
diff --git a/models/admin/dashboardWidget/index.php b/models/admin/dashboardWidget/index.php
new file mode 100644 (file)
index 0000000..3aec7c4
--- /dev/null
@@ -0,0 +1,171 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin Members Dashboard
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+// Load Members data abstract
+require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php');
+
+/*
+ * This class performs the work for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_dashboardWidget_index extends GlmDataMembers
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for members data class
+        parent::__construct(false, false);
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This method does the work for this model and returns any resulting data
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * 'view'
+     *
+     * A suggested view name that the contoller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     */
+    public function modelAction ($actionData = false)
+    {
+
+        $success = true;
+
+        // Get stats on the current list of members
+        $stats = $this->getStats();
+
+        // Get simple member list
+        $membersList = $this->getSimpleMembersList();
+
+        // Check for required Member Types
+        require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberTypes.php');
+        $MemberTypes = new GlmDataMemberTypes($this->wpdb, $this->config);
+        $memberTypesStats = $MemberTypes->getStats();
+        $haveMemberTypes = ($memberTypesStats > 0);
+
+        // Check for required Categories
+        require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php');
+        $Categories = new GlmDataCategories($this->wpdb, $this->config);
+        $categoriesStats = $Categories->getStats();
+        $haveCategories = ($categoriesStats > 0);
+
+        // Check for required Regions
+        require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataRegions.php');
+        $Regions = new GlmDataRegions($this->wpdb, $this->config);
+        $regionsStats = $Regions->getStats();
+        $haveRegions = ($regionsStats > 0);
+
+        // Check for required Accommodation Types
+        require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataAccommodationTypes.php');
+        $AccommodationTypes = new GlmDataAccommodationTypes($this->wpdb, $this->config);
+        $accommodationTypesStats = $AccommodationTypes->getStats();
+        $haveAccommodationTypes = ($accommodationTypesStats > 0);
+
+        // Get number of member information records with pending updates
+        require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php');
+        $MemberInfo = new GlmDataMemberInfo($this->wpdb, $this->config);
+        $membersPending = $MemberInfo->getStats('status = '.$this->config['status_numb']['Pending']);
+
+        // If there's members with pending information, list them
+        $pendingList = false;
+        if ($membersPending > 0) {
+            $pendingList = $MemberInfo->getList('status = '.$this->config['status_numb']['Pending']);
+        }
+
+        // Compile template data
+        $templateData = array(
+            'numbMembers' => $stats,
+            'membersList' => $membersList,
+            'membersPending' => $membersPending,
+            'haveMemberTypes' => $haveMemberTypes,
+            'haveCategories' => $haveCategories,
+            'haveRegions' => $haveRegions,
+            'haveAccommodationTypes' => $haveAccommodationTypes,
+            'pendingList' => $pendingList
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status' => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect' => false,
+            'view' => 'admin/dashboardWidget/index.html',
+            'data' => $templateData
+        );
+
+    }
+
+
+}
+
+?>
\ No newline at end of file
diff --git a/views/admin/dashboardWidget/index.html b/views/admin/dashboardWidget/index.html
new file mode 100644 (file)
index 0000000..3e4b740
--- /dev/null
@@ -0,0 +1,91 @@
+    <table class="glm-admin-table">
+    
+{if $membersList}
+        <tr>
+            <th>Members</th>
+            <td>
+                <select id="glmMembersList" class="glm-right">
+                    <option value=""></option>
+    {foreach $membersList as $m}
+                    <option value="{$m.id}">{$m.name}</option>
+    {/foreach}                
+                </select>
+            </td>
+        </tr>
+{/if}
+{if !$haveMemberTypes}
+        <tr>
+            <th class="glm-error">No Member Types</th>
+            <td><a href="{$adminURL}?page=glm-members-admin-menu-configure&glm_action=memberTypes" class="glm-right">Add</a></td>
+        </tr>
+{/if}                
+{if !$haveCategories}
+        <tr>
+            <th><span class="glm-error">No Member Categories</span></th>
+            <td><a href="{$adminURL}?page=glm-members-admin-menu-configure&glm_action=categories" class="glm-right">Add</a></td>
+        </tr>
+{/if}                
+{if !$haveRegions}
+        <tr>
+            <th><span class="glm-error">No Regions</span></th>
+            <td><a href="{$adminURL}?page=glm-members-admin-menu-configure&glm_action=regions" class="glm-right">Add</a></td>
+        </tr>
+{/if}                
+{if !$haveAccommodationTypes}
+        <tr>
+            <th><span class="glm-error">No Accommodation Types</span></th>
+            <td><a href="{$adminURL}?page=glm-members-admin-menu-configure&glm_action=accommodationTypes" class="glm-right">Add</a></td>
+        </tr>
+{/if}                
+{if $numbMembers == 0}
+        <tr>
+           <th> <span class="glm-error">No Members</span></th>
+            <td><a href="{$adminURL}?page=glm-members-admin-menu-member&glm_action=index&member_id=" class="glm-right">Add a Member</a></td>
+        </tr>
+{/if}                
+        <tr><th>Number of Members Listed: </th><td><a href="{$adminURL}?page=glm-members-admin-menu-members-list" class="glm-right">List Members</a><span class="glm-left">{$numbMembers}</span></td></tr>
+    </table>
+    
+{if $membersPending}
+    <hr>
+    <h4><span  class="glm-error">Pending Member Information</span></h4>
+    
+    <table class="wp-list-table widefat fixed posts glm-admin-table"">
+        <thead>
+            <tr>
+                <th>Member Name</th>
+                <th>Reference Name</th>
+            </tr>
+        </thead>
+        <tbody>
+    {assign var="i" value="0"}
+    {foreach $pendingList as $p}
+        {if $i++ is odd by 1} 
+            <tr>
+        {else}
+            <tr class="alternate">
+        {/if}
+                <td>
+                    <a href="{$adminURL}?page=glm-members-admin-menu-member&glm_action=memberInfo&member={$p.member_pointer}&id={$p.id}}">{$p.member}</a>
+                </td>
+                <td>
+                    {$p.reference_name}
+                </td>
+            </tr>
+    {/foreach}
+        </tbody>
+    </table>
+{/if}
+
+{if $membersList}
+    <script type="text/javascript">
+        jQuery(document).ready(function($) {
+
+            $('#glmMembersList').change( function() {
+                window.location.replace("{$adminURL}?page=glm-members-admin-menu-member&glm_action=index&member=" + $(this).find('option:selected').val() );
+            });
+               
+               
+        });
+    </script>
+{/if}
\ No newline at end of file