From: Laury GvR Date: Fri, 13 Jan 2017 22:07:27 +0000 (-0500) Subject: Fixed alpha list for contact list display X-Git-Tag: v1.0.19^2~11 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=5339f11e73023759885989c441a4ab1271615ba2;p=WP-Plugins%2Fglm-member-db-contacts.git Fixed alpha list for contact list display Alpha list was producing errors on the contact list due to wrong code in the model and shortcodes.php, thinking alpha was undefined. --- diff --git a/classes/data/dataContacts.php b/classes/data/dataContacts.php index 6d3b63d..fcac99f 100644 --- a/classes/data/dataContacts.php +++ b/classes/data/dataContacts.php @@ -479,6 +479,43 @@ class GlmDataContacts extends GlmDataAbstract return $r; } + + + /* + * Get Alpha list of first characters in member name + * for those members that have active info. + * + * @param string $where Where clause + * Note the table refernces M and I. + * @param string $selected Optional selected alpha character + * + * @return object Class object + * + */ + public function getAlphaList($where = '', $selected = '') + { + + + $sql = " + SELECT DISTINCT LEFT(T.lname, 1) AS alpha + FROM ".GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX. "contacts T + WHERE T.active = true + $where + ORDER BY alpha + ;"; + + $alphaData = $this->wpdb->get_results($sql, ARRAY_A); + + // Set selected + foreach ($alphaData as $k=>$v) { + $alphaData[$k]['default'] = ($v['alpha'] == $selected); + } + + return $alphaData; + + } + + /* * Get the contact's "Permissions" (contact_role) * diff --git a/models/front/contacts/list.php b/models/front/contacts/list.php index 7fc8898..85d6a16 100644 --- a/models/front/contacts/list.php +++ b/models/front/contacts/list.php @@ -14,9 +14,6 @@ */ // Translation table for [glm-contacts-list] "show" options to configuration parameters -$GLOBALS['showOpts'] = array( - -); // Load Contacts data abstract require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataContacts.php'; @@ -104,43 +101,34 @@ class GlmMembersFront_contacts_list extends GlmDataContacts public function modelAction ($actionData = false) { - $view = 'index.html'; - $option = 'list'; - $fromMemberMenu = false; - $loggedInMember = false; - $refType = false; - $refTypeName = false; - $haveMember = false; + $view = 'index.html'; + $option = 'list'; + $haveMember = false; $this->memberID = false; - $memberData = false; - $memberName = false; - $membersList = false; - $contactsList = false; - $haveContacts = false; - $contactID = false; - $contactInfo = false; - $newContactEmailExists = false; - $newContactUsernameExists = false; - $misMatchedWpUsers = false; - $newContactCreated = false; - $usingExistingWPContact = false; - $usernameChangedToWP = false; - $contactUpdated = false; + $memberData = false; + $memberName = false; + $membersList = false; + $contactsList = false; + $haveContacts = false; + $contactID = false; + $contactInfo = false; $filterArchived = false; - $filterText = false; - $countySearch = false; - $countyList = array(); - $haveCounties = false; - $haveFilter = false; - $userDeleted = false; - $wpUserDeleted = false; + $filterText = false; + $countySearch = false; + $countyList = array(); + $haveCounties = false; + $haveFilter = false; $contactMembers = array(); - $order = false; + $order = false; + + $textSearch = ''; + $blankStart = false; + $membersFound = false; - $numbContacts = false; + // Paging Parameters + $paging = true; $numbDisplayed = false; $lastDisplayed = false; - $paging = true; $prevStart = false; $nextStart = false; $start = 1; @@ -157,6 +145,18 @@ class GlmMembersFront_contacts_list extends GlmDataContacts 'delete', 'list' ); + + + if (isset($_REQUEST['textSearch'])) { + $actionData['request']['text-search'] = $_REQUEST['textSearch']; + } + if (isset($_REQUEST['alpha'])) { + $actionData['request']['alpha'] = $_REQUEST['alpha']; + } + // 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 this is a logged in member user, then show their contacts only if (isset($this->config['loggedInUser']['contactUser'])) { @@ -177,26 +177,7 @@ class GlmMembersFront_contacts_list extends GlmDataContacts } } - - // If we're coming from the Member Contacts Menu/Tab - if (defined('GLM_MEMBERS_CONTACTS_MEMBER_MENU')) { - - $fromMemberMenu = true; - - // Check if we've received member ID - if (isset($_REQUEST['member'])) { - - // Clean up the member ID and store it in wordpress option - $this->memberID = $_REQUEST['member']-0; - update_option('glmMembersDatabaseMemberID', $this->memberID); - - // Otherwise check if a member is stored in wordpress option - } else { - $this->memberID = get_option('glmMembersDatabaseMemberID', false); - } - - } - + // Load members data class require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'; $this->Members = new GlmDataMembers($this->wpdb, $this->config); @@ -216,7 +197,7 @@ class GlmMembersFront_contacts_list extends GlmDataContacts $option = 'list'; $where = ' TRUE '; - + // Only list member contacts for the selected member if ($haveMember) { $where .= " AND ref_type = ".$this->config['ref_type_numb']['Member'].' AND ref_dest = '.$this->memberID; @@ -247,22 +228,47 @@ class GlmMembersFront_contacts_list extends GlmDataContacts // Get the total number of contacts listed $numbContacts = $this->getStats($where); + // If the number of events is less than a page, don't do paging if ($numbContacts <= $limit) { $paging = false; } // Setting $paging to false until we figure it out for contacts - $paging = false; + //$paging = false; // Get full list of names matching this where clause for search box $namesList = $this->getIdName($where); + + $contactsList = $this->getList($where, $order, true, 'id',$start, $limit); + + // If doing alpha list + $alphaList = false; + $alphaWhere = ''; + if ($this->config['settings']['list_show_search_alpha']) { + + $alphaSelected = false; + + // Check for alpha selected + if ($actionData['request']['alpha'] && strlen($actionData['request']['alpha']) == 1) { + $alphaSelected = strtoupper($actionData['request']['alpha']); + $alphaWhere .= " AND T.lname LIKE '$alphaSelected%'"; + } + + // Get full list for all other filters, but not filtered by alpha (that would be silly) + $alphaList = $this->getAlphaList(' AND '.$where, $alphaSelected); + + } + + $order = "lname, fname"; + // Get list of contacts + // Check if we're doing paging if (isset($_REQUEST['pageSelect'])) { // If request is for Next - if ($_REQUEST['pageSelect'][0] == 'N') { + if ($_REQUEST['pageSelect'] == 'Next') { $newStart = $_REQUEST['nextStart'] - 0; // Otherwise it must be Previous @@ -274,10 +280,43 @@ class GlmMembersFront_contacts_list extends GlmDataContacts $start = $newStart; } } - $order = "lname, fname"; - // Get list of contacts - $contactsList = $this->getList($where, $order); + + $list = $contactsList['list']; + + // If we're not paging, then force $start and $limit to false to data abstract returns everything. + $resultParam = 'listResult'; + if (!$paging) { + $start = false; + $limit = false; + $resultParam = 'list'; + } + + // Get stats for the current selection + $contactsFound = $this->getStats(str_replace('T.', '', $where)); + + // Get stats for number of members found matching current selection criteria (includes alpha selection) + $filteredContactsFound = $this->getStats(str_replace('T.', '', $where.$alphaWhere)); + + // Get member list sorted as specified + switch ($this->config['settings']['list_order_list']) { + + // Pseudo-Random list order + case $this->config['sort_order_numb']['Pseudo-Random']: + ${$resultParam} = $this->getList($where.$alphaWhere, 'pseudo-random', true, 'id', $start, $limit); + break; + + // Default is alpha-numeric list order + default: + case $this->config['sort_order_numb']['Alpha-Numeric']: + ${$resultParam} = $this->getList($where.$alphaWhere, $order, true, 'id', $start, $limit); + break; + + } + if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) { + glmMembersFront::addNotice($list, 'DataBlock', 'Member Data'); + } + if ($contactsList != false) { if ($paging) { //Get paging results @@ -306,16 +345,6 @@ class GlmMembersFront_contacts_list extends GlmDataContacts if ($countyList[0]) { $haveCounties = true; } -// -// -// -// $r = array( -// 'contactRole' => $contactRole, -// 'wpRole' => $this->config['contact_role_wordpress'][$contactRole] -// ); -// -// return $r; - // If the option is "edit" don't let lower-level users assign privileges above the user's pay grade if (($option == 'edit' || $option == 'create') && $this->config['loggedInUser']['contactUser']) { @@ -326,45 +355,34 @@ class GlmMembersFront_contacts_list extends GlmDataContacts } } - - // Compile template data $templateData = array( 'option' => $option, - 'loggedInMember' => $loggedInMember, - 'fromMemberMenu' => $fromMemberMenu, 'haveMember' => $haveMember, 'memberID' => $this->memberID, 'memberData' => $memberData, 'memberName' => $memberName, 'membersList' => $membersList, - 'refType' => $refType, - 'refTypeName' => $refTypeName, 'haveContacts' => $haveContacts, - 'contactsList' => $contactsList, + 'contactsList' => $list, 'numbContacts' => $numbContacts, 'contactID' => $contactID, 'contactInfo' => $contactInfo, - 'newContactEmailExists' => $newContactEmailExists, - 'newContactUsernameExists' => $newContactUsernameExists, - 'misMatchedWpUsers' => $misMatchedWpUsers, - 'usernameChangedToWP' => $usernameChangedToWP, - 'newContactCreated' => $newContactCreated, - 'usingExistingWPContact' => $usingExistingWPContact, - 'contactUpdated' => $contactUpdated, 'filterArchived' => $filterArchived, 'filterText' => $filterText, 'countyList' => $countyList, 'haveCounties' => $haveCounties, 'countySearch' => $countySearch, 'haveFilter' => $haveFilter, - 'userDeleted' => $userDeleted, - 'wpUserDeleted' => $wpUserDeleted, 'contactMembers' => $contactMembers, - + 'alphaList' => $alphaList, + 'alphaSelected' => $alphaSelected, + 'contactsFound' => $contactsFound, + 'filteredContactsFound' => $filteredContactsFound, 'numbDisplayed' => $numbDisplayed, 'lastDisplayed' => $lastDisplayed, + 'textSearch' => $textSearch, 'paging' => $paging, 'prevStart' => $prevStart, 'nextStart' => $nextStart, diff --git a/setup/shortcodes.php b/setup/shortcodes.php index 7fbfc24..dbb41dd 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -104,6 +104,7 @@ $glmMembersContactsShortcodes = array( 'member' => false, 'template' => false, 'limit' => null, + 'alpha' => false, ) ), ); diff --git a/views/front/contacts/list.html b/views/front/contacts/list.html index cd38cda..029c5b1 100644 --- a/views/front/contacts/list.html +++ b/views/front/contacts/list.html @@ -46,8 +46,27 @@ and open the template in the editor. {if $paging} - {/if} + {/if} + + {if $settings.list_show_search_alpha} + + {/if} + + {if $paging} + +
+ Previous page + Next page +
+ showing {$start} through {$lastDisplayed} of {$filteredContactsFound} + {/if} + {if $haveContacts} {foreach $contactsList as $contact}
@@ -94,70 +113,7 @@ and open the template in the editor. {/if} - - - - - {include file='front/footer.html'}