From: Chuck Scott Date: Wed, 25 Mar 2015 16:42:46 +0000 (-0400) Subject: Added admin dashboard widget X-Git-Tag: v1.0.0~40 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=1caaf62f186f6d5c41aa419933d4c52fe5ca344d;p=WP-Plugins%2Fglm-member-db.git Added admin dashboard widget --- diff --git a/classes/data/dataMembers.php b/classes/data/dataMembers.php index 39a56560..e9389c0c 100644 --- a/classes/data/dataMembers.php +++ b/classes/data/dataMembers.php @@ -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 diff --git a/controllers/admin.php b/controllers/admin.php index a0583baf..b9f2aadf 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -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' ) ); diff --git a/defines.php b/defines.php index 8879abd3..f89b042e 100644 --- a/defines.php +++ b/defines.php @@ -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 index 00000000..3aec7c43 --- /dev/null +++ b/models/admin/dashboardWidget/index.php @@ -0,0 +1,171 @@ + + * @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 index 00000000..3e4b740b --- /dev/null +++ b/views/admin/dashboardWidget/index.html @@ -0,0 +1,91 @@ + + +{if $membersList} + + + + +{/if} +{if !$haveMemberTypes} + + + + +{/if} +{if !$haveCategories} + + + + +{/if} +{if !$haveRegions} + + + + +{/if} +{if !$haveAccommodationTypes} + + + + +{/if} +{if $numbMembers == 0} + + + + +{/if} + +
Members + +
No Member TypesAdd
No Member CategoriesAdd
No RegionsAdd
No Accommodation TypesAdd
No MembersAdd a Member
Number of Members Listed: List Members{$numbMembers}
+ +{if $membersPending} +
+

Pending Member Information

+ + + + + + + + + + {assign var="i" value="0"} + {foreach $pendingList as $p} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + {/foreach} + +
Member NameReference Name
+ {$p.member} + + {$p.reference_name} +
+{/if} + +{if $membersList} + +{/if} \ No newline at end of file