From: Anthony Talarico Date: Thu, 25 Oct 2018 18:05:21 +0000 (-0400) Subject: adding admin search model X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=a13a70241b80781a4e42d21a89e9d66ef4bc285f;p=WP-Plugins%2Fglm-member-db.git adding admin search model --- diff --git a/models/admin/adminSearch/index.php b/models/admin/adminSearch/index.php new file mode 100644 index 00000000..ba4b501d --- /dev/null +++ b/models/admin/adminSearch/index.php @@ -0,0 +1,184 @@ +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); + + // Enqueue Materialize + wp_register_script( + 'materialize', + GLM_MEMBERS_PLUGIN_URL . 'js/materialize/materialize.min.js', + array( + 'jquery' + ), + GLM_MEMBERS_PLUGIN_VERSION + ); + wp_register_script( + 'autoComplete', + GLM_MEMBERS_PLUGIN_URL . 'js/materialize/autoComplete.min.js', + array( + 'jquery' + ), + GLM_MEMBERS_PLUGIN_VERSION + ); + wp_enqueue_script('materialize', false, array('jquery'), false, true); + wp_enqueue_script('autoComplete', false, array('jquery'), false, true); + wp_enqueue_style('materialize-css', GLM_MEMBERS_PLUGIN_URL . 'css/materialize.min.css'); + wp_enqueue_style('autoComplete', GLM_MEMBERS_PLUGIN_URL . 'css/autoComplete.css'); + wp_enqueue_style('admin-css', GLM_MEMBERS_PLUGIN_URL . 'css/glma-admin-sass.css'); + wp_enqueue_style('css-icons', "https://fonts.googleapis.com/icon?family=Material+Icons"); + + // 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')); + + + // 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") ) { + $addons[$a['slug']]['name'] = $a['short_name']; + $addons[$a['slug']]['slug'] = $a['slug']; + $addons[$a['slug']]['widgetData'] = apply_filters($a['slug'] . "-dashboard-search", ""); + // Sort the component list based on the 'order' + uasort($addons[$a['slug']]['widgetData']['components'], array($this, 'orderSort') ) ; + + } + } + + // Compile template data. + $templateData = array( + 'lockedToMember' => $lockedToMember, + 'member' => $actionData, + 'showArchived' => $showArchived, + 'statusTypeNumbers' => $this->config['status_numb'], + 'memberID' => $memberID, + 'haveInfoRecords' => $haveInfoRecords, + 'memberInfoRecords' => $memberInfoRecords, + 'statusPending' => $this->config['status_numb']['Pending'], + 'addons' => $addons, + 'baseUrl' => GLM_MEMBERS_PLUGIN_URL + ); + + // Return status, suggested view, and data to controller. + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/newDashboard/index.html', + 'data' => $templateData + ); + + } + + public function orderSort ($a, $b) { return (strcmp ($a['order'],$b['order'])); } +} diff --git a/models/admin/newDashboard/index.php b/models/admin/newDashboard/index.php index 512f3af5..df1939bf 100644 --- a/models/admin/newDashboard/index.php +++ b/models/admin/newDashboard/index.php @@ -135,9 +135,17 @@ class GlmMembersAdmin_newDashboard_index extends GlmDataMembers if ( has_filter( $a['slug'] . "-dashboard-widget") ) { $addons[$a['slug']]['name'] = $a['short_name']; $addons[$a['slug']]['slug'] = $a['slug']; + // $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 { + // For testing + // echo "
" . $a['slug'] . " has no filter called " . $a['slug'] . "-dashboard-widget"; } } diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 2b774732..1183b9ed 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -624,7 +624,7 @@ add_filter( $content = [ 'title' => 'Members', - 'widgetButtons' => [ + 'listButtons' => [ [ 'id' => 'add-member', 'content' => 'Add', @@ -637,39 +637,12 @@ add_filter( 'id' => 'export-button', 'content' => 'Export', 'url' => '#', - 'classes' => 'btn-small widget-export-btn waves-effect waves-light btn modal-trigger', + 'classes' => 'btn-small waves-effect waves-light btn modal-trigger', 'styles' => '', 'data' => 'membersExportModal' ], ], 'components' => [ - [ - 'id' => 'quickLinks', - 'order' => -1, - 'template' => 'quickLinks', - 'quickLinks' => [ - 'dashboard' => [ - 'content' => 'Dashboard', - 'url' => $membersIndexPage . "&option=dashboard", - ], - 'search' => [ - 'content' => 'Advanced Search', - 'url' => $membersIndexPage . "&option=search", - ], - 'settings' => [ - 'content' => 'Settings', - 'url' => $membersSettingsPage, - ] - ], - ], - [ - 'id' => 'entityAmount', - 'title' => 'Number of ' . $this->config['terms']['term_member_plur_cap'], - 'order' => 1, - 'template' => 'entityAmount', - 'url' => $membersIndexPage . "&option=search", - 'result' => $MemberInfo->getStats(), - ], [ 'id' => 'membersExportModal', 'template' => 'modal', @@ -687,48 +660,46 @@ add_filter( 'resultUrl' => $memberIndexPage . "&glm_action=index&member=", ], [ - 'id' => 'pending-' . $this->config['terms']['term_member_cap'] . '-profiles', - 'title' => 'Pending ' . $this->config['terms']['term_member_cap'] . ' Profiles', - 'slug' => 'pending-' . $this->config['terms']['term_member'] . '-profiles', - 'order' => 3, - 'template' => 'list', - 'entityID' => 'memberInfo', - 'defaultRefType'=> 'member', - 'refLink' => $membersRefLink, - 'url' => $membersEditPage, - 'countUrl' => $membersIndexPage . '&glm_action=list&filterPending=true', - 'result' => $MemberInfo->getList('status='.$MemberInfo->config['status_numb']['Pending'], $order, $fieldVals, $idField, $start, $limit), - 'count' => $MemberInfo->getStats('status='.$MemberInfo->config['status_numb']['Pending']), - 'fieldMap' => [ - 'ID' => 'id', - 'name' => 'reference_name', - 'status' => 'status', - 'refDestID' => 'member_pointer', - 'refDestName' => 'member', - //'ref_type' => 'ref_type', // membersInfo has no ref_type field yet - ], + 'id' => 'dateSearch', + 'order' => 3, + 'fromDate' => 'fromDate', + 'toDate' => 'toDate', + 'template' => 'dateSearch', + 'entityID' => 'members', + 'defaultFromDate' => date('m/d/Y'), + 'resultUrl' => $eventsListPage.'&event=', ], [ - 'id' => 'bad-location-data', - 'title' => "Bad Location Data", - 'slug' => "bad-location-data", - 'order' => 4, - 'template' => 'list', - 'entityID' => 'memberInfo', - 'defaultRefType'=> 'member', - 'refLink' => $membersRefLink, - 'url' => $membersEditPage, - 'countUrl' => $membersIndexPage . '&glm_action=list&filterBadLocation=true', - 'result' => $MemberInfo->getList("has_no_map_data='1'", $order, $fieldVals, $idField, $start, $limit), - 'count' => $MemberInfo->getStats("has_no_map_data='1'"), - 'fieldMap' => [ - 'ID' => 'id', - 'name' => 'reference_name', - 'status' => 'status', - 'refDestID' => 'member_pointer', - 'refDestName' => 'member', - //'ref_type' => 'ref_type', // membersInfo has no ref_type field yet - ], + 'id' => 'categorySearch', + 'order' => 4, + 'categories' => ['cat 1', 'cat 2', 'cat 3'], + 'template' => 'category', + 'entityID' => 'members', + 'defaultFromDate' => date('m/d/Y'), + ], + [ + 'id' => 'memberTypeSearch', + 'order' => 5, + 'template' => 'dropdown', + 'entityID' => 'members', + 'defaultFromDate' => date('m/d/Y'), + 'resultUrl' => $eventsListPage.'&event=', + ], + [ + 'id' => 'archiveSearch', + 'order' => 6, + 'template' => 'checkbox', + 'entityID' => 'members', + 'defaultFromDate' => date('m/d/Y'), + 'resultUrl' => $eventsListPage.'&event=', + ], + [ + 'id' => 'featuredSearch', + 'order' => 7, + 'template' => 'checkbox', + 'entityID' => 'event', + 'defaultFromDate' => date('m/d/Y'), + 'resultUrl' => $eventsListPage.'&event=', ], ] ];