From: Laury GvR Date: Wed, 19 Sep 2018 13:36:54 +0000 (-0400) Subject: Menu Dashboard, apply widget filter, new views/model X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=bba5b00c36586d49016a7e1b197f19352d719185;p=WP-Plugins%2Fglm-member-db.git Menu Dashboard, apply widget filter, new views/model - Added header and index view files for the new dashboard - Added index model for the new dashboard - Added valid actions for the new dashboard - Adjusted admin menus to treat Dashboard as the parent in all cases, and made Dashboard the default destination - Applying filter if it exists for each plugin based on its slug with -dashboard-widget suffix. - Some test echo both in members/index.php model, and the newDashboard model. --- diff --git a/models/admin/members/index.php b/models/admin/members/index.php index b0468fff..dd592186 100644 --- a/models/admin/members/index.php +++ b/models/admin/members/index.php @@ -167,7 +167,8 @@ class GlmMembersAdmin_members_index extends GlmDataMembers } // In case we want to treat the widget data before sending it to the viewfile. - // May be able to avoid sending Config to the view + // May be able to avoid sending the (huge) Config array to the view + echo "IN THE WRONG FILE"; foreach ( $this->config[ 'addOns' ] as $a ) { //$widgetData[] = apply_filters($a['slug'] . "-dashboard-widget"); $widgetData[] = $a['slug']; diff --git a/models/admin/newDashboard/index.php b/models/admin/newDashboard/index.php new file mode 100644 index 00000000..8c5b7b6e --- /dev/null +++ b/models/admin/newDashboard/index.php @@ -0,0 +1,218 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'; + +/** + * Dashboard Class Model + * + * Each Add-On can have one or more dashboards. + */ + +class GlmMembersAdmin_newDashboard_index extends GlmDataMembers +{ + /** + * Word Press 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 successful 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 controller 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; + $text = 'text'; + $haveInfoRecords = false; + $memberInfoRecords = false; + $noActive = false; + $showArchived = false; + $memberID = 0; + $clickThroughCounts = array('day' => 0, 'week' => 0, 'month' => 0); + $detailViewCounts = array('day' => 0, 'week' => 0, 'month' => 0); + + // Check if there's a logged in user who is locked to their own entity. + $lockedToMember = apply_filters( 'glm_members_locked_to_member_id', false ); + $memberID = $lockedToMember; + + // Get the current date, first date of this week, and first date of this month + $today = date('Y-m-d'); + $thisWeek = date('Y-m-d', strtotime('-'.date('w').' days')); + $thisMonth = date('Y-m-d', strtotime('-'.(date('j')-1).' days')); + + $clickThroughCounts = $this->wpdb->get_row(" + SELECT COALESCE (( + SELECT clicks + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."clickthrough_stats + WHERE member = $memberID + AND stat_type = 1 + AND stat_date = '$today' + ), 0) AS day, + COALESCE (( + SELECT clicks + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."clickthrough_stats + WHERE member = $memberID + AND stat_type = 2 + AND stat_date = '$thisWeek' + ), 0) AS week, + COALESCE (( + SELECT clicks + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."clickthrough_stats + WHERE member = $memberID + AND stat_type = 3 + AND stat_date = '$thisMonth' + ), 0) AS month + ", ARRAY_A); + + $detailViewCounts = $this->wpdb->get_row(" + SELECT COALESCE (( + SELECT clicks + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_detail_stats + WHERE member = $memberID + AND stat_type = 1 + AND stat_date = '$today' + ), 0) AS day, + COALESCE (( + SELECT clicks + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_detail_stats + WHERE member = $memberID + AND stat_type = 2 + AND stat_date = '$thisWeek' + ), 0) AS week, + COALESCE (( + SELECT clicks + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_detail_stats + WHERE member = $memberID + AND stat_type = 3 + AND stat_date = '$thisMonth' + ), 0) AS month + ", ARRAY_A); + + // Setup the data Abstract class for member info. + require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberInfo.php'; + $MemberInfo = new GlmDataMemberInfo($this->wpdb, $this->config); + $hideArchived = " && T.status != ".$this->config['status_numb']['Archived']; + $memberInfoRecords = $MemberInfo->getList( "T.member = $memberID" . $hideArchived, 'T.status' ); + + // Check if there's any member information records. + if (is_array($memberInfoRecords) && count($memberInfoRecords) > 0) { + $haveInfoRecords = true; + } + + // 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 + foreach ( $this->config[ 'addOns' ] as $a ) { + if ( has_filter( $a['slug'] . "-dashboard-widget") ) { + $widgetData[] = apply_filters($a['slug'] . "-dashboard-widget"); + } else { + echo "
" . $a['slug'] . " has no filter called " . $a['slug'] . "-dashboard-widget"; + //$widgetData[] = $a['slug']; + } + + } + + + // 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' => $widgetData, + ); + + // Return status, suggested view, and data to controller. + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/newDashboard/index.html', + 'data' => $templateData + ); + + } + +} diff --git a/setup/adminMenus.php b/setup/adminMenus.php index 91458b74..1705956d 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -17,7 +17,7 @@ * Added menus or sub-menus examples * * add_submenu_page( - * 'glm-members-admin-menu-members', // Parent slug + * 'glm-members-admin-menu-dashboard', // Parent slug * 'Sample', // Page title * 'Sample', // Menu Title * 'glm_members_edit', // Capability required @@ -33,17 +33,17 @@ // If user can manage all members, then show "Members" menu item if (current_user_can('glm_members_members')) { - $mainMenuSlug = 'glm-members-admin-menu-members'; + $mainMenuSlug = 'glm-members-admin-menu-dashboard'; $enable_members = $this->config['settings']['enable_members']; // Add a sub-submenu for the "Member" "List" page if ( $enable_members ) { add_menu_page( - $this->config['terms']['term_admin_menu_members'], + 'Dashboard', 'GLM Associate', 'glm_members_main_menu', - 'glm-members-admin-menu-members', + 'glm-members-admin-menu-dashboard', function() {}, GLM_MEMBERS_PLUGIN_ASSETS_URL.'/flame.png', '3.100' @@ -51,21 +51,21 @@ if (current_user_can('glm_members_members')) { // Add a sub-submenu for the "Member" "List" page add_submenu_page( - 'glm-members-admin-menu-members', + 'glm-members-admin-menu-dashboard', $this->config['terms']['term_admin_menu_member_list'], - $this->config['terms']['term_admin_menu_members'], + Dashboard, 'glm_members_main_menu', - 'glm-members-admin-menu-members', - function() {$this->controller('members', 'index');} + 'glm-members-admin-menu-dashboard', + function() {$this->controller('newDashboard', 'index');} ); // Add a sub-submenu for the "Member" "List" page add_submenu_page( - 'glm-members-admin-menu-members', + 'glm-members-admin-menu-dashboard', $this->config['terms']['term_admin_menu_member_list'], '    List', 'glm_members_main_menu', - 'glm-members-admin-menu-members-list', + 'glm-members-admin-menu-dashboard-list', function() {$this->controller('members', 'list');} ); @@ -80,10 +80,10 @@ if (current_user_can('glm_members_members')) { ); } else { add_menu_page( - $this->config['terms']['term_admin_menu_members'], + Dashboard, 'GLM Associate', 'glm_members_main_menu', - 'glm-members-admin-menu-members', + 'glm-members-admin-menu-dashboard', function() {}, GLM_MEMBERS_PLUGIN_ASSETS_URL.'/flame.png', '3.100' @@ -91,12 +91,12 @@ if (current_user_can('glm_members_members')) { // Add a sub-submenu for the "Member" "List" page add_submenu_page( - 'glm-members-admin-menu-members', + 'glm-members-admin-menu-dashboard', 'Dashboard', 'Dashboard', 'glm_members_main_menu', - 'glm-members-admin-menu-members', - function() {$this->controller('members', 'index');} + 'glm-members-admin-menu-dashboard', + function() {$this->controller('newDashboard', 'index');} ); } @@ -107,7 +107,7 @@ if (current_user_can('glm_members_members')) { $mainMenuSlug = 'glm-members-admin-menu-member'; add_menu_page( - $this->config['terms']['term_admin_menu_members'], + Dashboard, 'GLM Associate', 'glm_members_main_menu', 'glm-members-admin-menu-member', @@ -132,7 +132,7 @@ if (current_user_can('glm_members_members')) { // Add a submenu for the "Files" if ($this->config['settings']['file_library']) { add_submenu_page( - 'glm-members-admin-menu-members', + 'glm-members-admin-menu-dashboard', 'Files Library', 'Files Library', 'glm_members_settings', @@ -143,7 +143,7 @@ if ($this->config['settings']['file_library']) { // Add a submenu for the "Settings" section add_submenu_page( - 'glm-members-admin-menu-members', + 'glm-members-admin-menu-dashboard', 'Settings', 'Settings', 'glm_members_settings', @@ -153,7 +153,7 @@ add_submenu_page( // Add a submenu for the "Management" section add_submenu_page( - 'glm-members-admin-menu-members', + 'glm-members-admin-menu-dashboard', 'Member DB Management', 'Management', 'glm_members_management', @@ -164,7 +164,7 @@ add_submenu_page( // Add a submenu for the "Import" section global $glm_import_sub_page; $glm_import_sub_page = add_submenu_page( - 'glm-members-admin-menu-members', + 'glm-members-admin-menu-dashboard', 'Import', 'Import', 'glm_members_management', @@ -174,7 +174,7 @@ $glm_import_sub_page = add_submenu_page( // Add a submenu for the "Shortcode Reference" section add_submenu_page( - 'glm-members-admin-menu-members', + 'glm-members-admin-menu-dashboard', 'Shortcode Reference', 'Shortcodes', 'glm_members_shortcodes', diff --git a/setup/validActions.php b/setup/validActions.php index c9d93a05..831bd1b8 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -53,6 +53,9 @@ $glmMembersValidActions = array( 'dashboardWidget' => array( 'index' => 'glm-member-db' ), + 'newDashboard' => array ( + 'index' => 'glm-member-db' + ), 'fileLibrary' => array( 'index' => 'glm-member-db' ), diff --git a/views/admin/members/header.html b/views/admin/members/header.html index 3ba661e3..31ca525e 100644 --- a/views/admin/members/header.html +++ b/views/admin/members/header.html @@ -1,28 +1,3 @@ - -
-

GLM Associate Dashboard

-
-
-
-
- {foreach $widgetData as $w} - {include file='admin/members/summaryWidget.html'} - {/foreach} - -
-
-
-
-
- - - -
{if $enable_members}

All {$terms.term_member_plur_cap}

diff --git a/views/admin/newDashboard/header.html b/views/admin/newDashboard/header.html new file mode 100644 index 00000000..dcca9412 --- /dev/null +++ b/views/admin/newDashboard/header.html @@ -0,0 +1,5 @@ +
+

GLM AssociateDashboard

+
+ + \ No newline at end of file diff --git a/views/admin/newDashboard/index.html b/views/admin/newDashboard/index.html new file mode 100644 index 00000000..75723cd3 --- /dev/null +++ b/views/admin/newDashboard/index.html @@ -0,0 +1,24 @@ +{include file='admin/members/header.html'} +
+

GLM Associate Dashboard

+
+
+
+
+ {foreach $widgetData as $w} + {include file='admin/members/summaryWidget.html'} + {/foreach} + +
+
+
+
+
+ +NewDashboard! +{include file='admin/footer.html'} \ No newline at end of file