From: Anthony Talarico Date: Thu, 25 Oct 2018 11:54:36 +0000 (-0400) Subject: adding ajax model, testing the connection, adding model and view for new management... X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=db99ea0a0c4bb92c849ee47a812bb5a40800a525;p=WP-Plugins%2Fglm-member-db.git adding ajax model, testing the connection, adding model and view for new management dashboard --- diff --git a/models/admin/ajax/adminSearch.php b/models/admin/ajax/adminSearch.php new file mode 100644 index 00000000..dc6b0576 --- /dev/null +++ b/models/admin/ajax/adminSearch.php @@ -0,0 +1,89 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +/** + * + * This class exports the currently selected members list + * to a printable HTML file, to a CSV file, or otherwise. + */ +class GlmMembersAdmin_ajax_adminSearch +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /** + * Constructor + * + * This constructor 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; + + //parent::__construct(false, false); + + } + + /** + * Perform Model Action + * + * This modelAction takes an AJAX image upload and stores the image in the + * media/images directory of the plugin. + * + * This model action does not return, it simply does it's work then calls die(); + * + * @param $actionData + * + * Echos JSON string as response and does not return + */ + public function modelAction ($actionData = false) + { + global $wpdb; + $status = $this->config['status_numb']['Active']; + if( isset( $_REQUEST['table'] ) ){ + + } + + $return = array( + 'searchData' => 'test' // Where our events list will go + ); + + header('Content-type:application/json;charset=utf-8', true); + echo json_encode($return); + wp_die(); + } +} diff --git a/models/admin/manageMembers/manage.php b/models/admin/manageMembers/manage.php new file mode 100644 index 00000000..25dc34a2 --- /dev/null +++ b/models/admin/manageMembers/manage.php @@ -0,0 +1,413 @@ + + * @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_manageMembers_manage 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 to setup table and fields array + * + * Since this class is extending GlmDataMembers, it does not need to pass + * $wpdb and $config to it in the constructor. + */ + 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) + { + + $where = ' true '; + $alphaWhere = ' true '; + $catSearchSelected = false; + $catSelectedString = ""; + $mTypeSelected = ''; + $catSelected = ''; + $catsToUse = ''; + $filterPending = false; + $filterArchived = false; + $filterFeatured = false; + $haveFilter = false; + $numbDisplayed = false; + $lastDisplayed = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; // Set to the number of listings per page + $namesList = false; + $enable_members = $this->config['settings']['enable_members']; + $textSearch = false; + + // Save all query parameters + if ( isset( $_REQUEST['glm_action'] ) && $_REQUEST['glm_action'] == 'list' ) { + $_SESSION['member_saved_search'] = $_REQUEST; + } else if ( !isset( $_REQUEST['glm_action'] ) + && (!isset( $_REQUEST['back_to_search'] ) || !filter_var( $_REQUEST['back_to_search'], FILTER_VALIDATE_BOOLEAN )) + ) { + unset( $_SESSION['member_saved_search'] ); + } + // Check for back to search flag + if ( isset( $_REQUEST['back_to_search'] ) + && filter_var( $_REQUEST['back_to_search'], FILTER_VALIDATE_BOOLEAN ) + && isset( $_SESSION['member_saved_search'] ) + ) { + $_REQUEST = $_SESSION['member_saved_search']; + } + // Check if this is a request to show archived members + if (isset($_REQUEST['filterArchived'])) { + $where .= " AND access = ".$this->config['access_numb']['Archived']; + $filterArchived = true; + $haveFilter = true; + + // If not, don't show them + } else { + $where .= " AND access != ".$this->config['access_numb']['Archived']; + } + + // Check for a text search + if (isset($_REQUEST['text_search']) && trim($_REQUEST['text_search']) != '') { + + // $textSearch = addslashes(filter_input(INPUT_POST, 'text_search', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); + $textSearch = addslashes(filter_var($_REQUEST['text_search'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); + $where .= " AND T.id in ( + SELECT DISTINCT(id) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members + WHERE name like '%$textSearch%' + )"; + + } + + // Get a list of categories for filtering + require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php'; + $Categories = new GlmDataCategories($this->wpdb, $this->config); + $categories = $Categories->getListSortedParentChild(false); + + // If we have categories, add "selected" element default false; + if (is_array($categories)) { + reset($categories); + while (list($k, $v) = each($categories)) { + $categories[$k]['selected'] = false; + } + } + + // Get a list of member_types for filtering + require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberTypes.php'; + $MemberTypes = new GlmDataMemberTypes( $this->wpdb, $this->config ); + $member_types = $MemberTypes->getList(); + + // Check if there is a member_type filter + if ( isset( $_REQUEST['filterMemberTypes'] ) && $memberTypeFilter = filter_var( $_REQUEST['filterMemberTypes'], FILTER_VALIDATE_INT ) ) { + $where .= " AND T.member_type = $memberTypeFilter "; + $mTypeSelected = $memberTypeFilter; + } + + // Check if there is a category filter (multi-select) + if (isset($_REQUEST['categorySearch']) && $_REQUEST['categorySearch'] > 0) { + $catsToUse = explode(',',$_REQUEST['categorySearch']); + } + if (isset($_REQUEST['filterCategories']) && count($_REQUEST['filterCategories']) > 0) { + $catsToUse = $_REQUEST['filterCategories']; + } + + if ($catsToUse && $catsToUse !== '') { + $cats = ''; + $catsSep = ''; + + // For each selected category + foreach($catsToUse as $c) { + $cats .= $catsSep.$c; + $catsSep = ','; + $categories[$c]['selected'] = true; + } + + $where .= " AND T.id in ( + SELECT DISTINCT(I.member) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info I, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info M, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories C + WHERE I.id = M.member_info + AND I.status != " . $this->config['status_numb']['Archived'] ." + AND ( + M.category in ($cats) + OR (C.parent in ($cats) AND M.category = C.id) + ) + )"; + $catSelectedString = $cats; + } + + // Check for "Pending Only + if (isset($_REQUEST['filterPending'])) { + + // Refine search only to members with pending Info data + $where .= " AND ( + SELECT COUNT(id) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info I + WHERE I.status = ".$this->config['status_numb']['Pending']." + AND I.member = T.id + )"; + + $filterPending = true; + $haveFilter = true; + } + + // Check for "Featured Only + if (isset($_REQUEST['filterFeatured'])) { + + // Refine search only to members with pending Info data + $where .= " AND ( + SELECT COUNT(id) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members I + WHERE I.featured = 1 + AND I.id = T.id + + )"; + $filterFeatured = true; + $haveFilter = true; + } + + // If doing alpha list + if (isset($_REQUEST['alpha'])) { + $actionData['request']['alpha'] = $_REQUEST['alpha']; + } + + $alphaList = false; + $alphaWhere = ''; + + $alphaSelected = false; + + // If user clicked a page request then we need to check the savedAlpha value + if (isset($_REQUEST['savedAlpha']) && isset($_REQUEST['pageSelect'])) { + $actionData['request']['alpha'] = $_REQUEST['savedAlpha']; + } + + if ($actionData['request']['alpha'] && strlen($actionData['request']['alpha']) == 1) { + $alphaSelected = strtoupper($actionData['request']['alpha']); + $alphaWhere .= " AND T.name LIKE '$alphaSelected%'"; + } + + // Get full list for all other filters, but not filtered by alpha (that would be silly) + $alphaList = $this->getAlphaList(' AND '.$where, $alphaSelected); + + $whereParts = apply_filters('glm-member-db-admin-search-query', $where, 'glm-member-db'); + if ( is_array( $whereParts ) && count( $whereParts ) > 0 ) { + $where .= ' AND '.implode(" AND ", $whereParts); + $whereSep = ' AND '; + } + + // Get count of members listed + $memberCount = $this->getStats($where); + + // If the number of members is less than a page, don't do paging + if ($memberCount <= $limit) { + $paging = false; + } + + // Get full list of names matching this where clause for search box + $namesList = $this->getIdName($where); + + // Check if we're doing paging + if (isset($_REQUEST['pageSelect'])) { + + // If request is for Next + if ($_REQUEST['pageSelect'][0] == 'N') { + $newStart = $_REQUEST['nextStart'] - 0; + + // Otherwise it must be Previous + } else { + $newStart = $_REQUEST['prevStart'] - 0; + } + + if ($newStart > 0) { + $start = $newStart; + } + } + + // echo '
$where: ' . print_r( $where, true ) . '
'; + + // Get stats for number of members found matching current selection criteria (includes alpha selection) + $filteredMembersFound = $this->getStats(str_replace('T.', '', $where.$alphaWhere)); + + // Get a current list of members + $listResult = $this->getSimpleMembersList($where.$alphaWhere, 'name', true, 'id', $start, $limit); + + // Get paging results + $numbDisplayed = $listResult['returned']; + $lastDisplayed = $listResult['last']; + if ($start == 1) { + $prevStart = false; + } else { + $prevStart = $start - $limit; + if ($start < 1) { + $start = 1; + } + } + if ($listResult['returned'] == $limit) { + $nextStart = $start + $limit; + } + + // since we're doing paging, we have to break out just the member data + $list = $listResult['list']; + unset($listResult); + + // If we have list entries - even if it's an empty list + $success = true; + $haveMembers = false; + if ($list !== false) { + + $success = true; + + // If we have any entries + if (count($list) > 0) { + $haveMembers = true; + } + } + + // Determine if current user can add, edit, delete member data +// $canEdit = current_user_can('glm_members_edit'); + + // Add a url for each member + if ( isset( $list) && is_array( $list ) ) { + foreach ($list as $member) { + $list[$member['id']]['member_slug'] = sanitize_title($member['name']); + } + } + + // Create current month/date string to pre-populate the Month/Year field for + $monthYear = date('F Y'); + + // Update the textSearch for output into the form. + $textSearch = str_replace("\'", "'", $textSearch ); + $textSearch = str_replace('\\"', '"', $textSearch ); + $textSearch = str_replace('\\', '', $textSearch ); + + // Compile template data + $templateData = array( + 'monthYear' => $monthYear, + 'enable_members' => $enable_members, + 'haveMembers' => $haveMembers, + 'members' => $list, + 'memberCount' => $memberCount, + 'categories' => $categories, + 'member_types' => $member_types, + 'haveFilter' => $haveFilter, + 'filterArchived' => $filterArchived, + 'filterFeatured' => $filterFeatured, + 'filterPending' => $filterPending, + 'catSelected' => $catSelected, + 'catSearchSelected' => $catSelectedString, + 'mTypeSelected' => $mTypeSelected, + 'alphaList' => $alphaList, + 'alphaSelected' => $alphaSelected, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start, + 'limit' => $limit, + 'namesList' => $namesList, + 'textSearch' => $textSearch + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/manageMembers/manage.html', + 'data' => $templateData + ); + + } + +} + +?> diff --git a/setup/adminMenus.php b/setup/adminMenus.php index 171381c3..87443cab 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -75,12 +75,21 @@ if (current_user_can('glm_members_members')) { add_submenu_page( $mainMenuSlug, $this->config['terms']['term_admin_menu_members'].' Members', - $this->config['terms']['term_admin_menu_members'], + $this->config['terms']['term_admin_menu_newMembers'], 'glm_members_member', 'glm-members-admin-menu-members', function() {$this->controller('members', 'index');} ); + add_submenu_page( + $mainMenuSlug, + $this->config['terms']['term_admin_menu_members'].'New Members', + 'Manage Members', + 'glm_members_member', + 'glm-members-admin-menu-members-manage', + function() {$this->controller('manageMembers', 'manage');} + ); + // Add a submenu for the "Member" section add_submenu_page( $mainMenuSlug, diff --git a/setup/validActions.php b/setup/validActions.php index c67c1373..5df37f1e 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -46,6 +46,10 @@ $glmMembersValidActions = array( 'fileLibraryUpdate' => 'glm-member-db', 'glmCron' => 'glm-member-db', 'glmTextSearch' => 'glm-member-db', + 'adminSearch' => 'glm-member-db', + ), + 'manageMembers' => array( + 'manage' => 'glm-member-db' ), 'dashboard' => array( 'index' => 'glm-member-db', diff --git a/views/admin/manageMembers/manage.html b/views/admin/manageMembers/manage.html new file mode 100644 index 00000000..d4f17f3d --- /dev/null +++ b/views/admin/manageMembers/manage.html @@ -0,0 +1,33 @@ + +
+ test +
+ \ No newline at end of file