/** * NBA FUNCTIONALITY * Count total results from member/user search for pagination & efficiency * * @param array $search_vals Current search parameters, either submitted or default * @param array $division_states List of abbreviated states in searched division * * @since 1.0.0 */ function nba_total_results($search_vals, $division_states) { //-- EXISTING SEARCH KEYS --// if ($search_vals['search_key'] && $_SESSION['nba']['search_key']) { // If the existing search keys don't match, the form was probably submitted, // so we need to do a new search for total_results. if ($_SESSION['nba']['search_key'] != $search_vals['search_key']) { $_SESSION['nba']['total_results'] = count(nba_do_member_directory_search($search_vals, $division_states)); // Update the session search key to the newly submitted "hidden input" // search key $_SESSION['nba']['search_key'] = $search_vals['search_key']; } } else { if (!$search_vals['search_key'] && !$_SESSION['nba']['search_key']) { } else { $_SESSION['nba']['total_results'] = count(nba_do_member_directory_search($search_vals, $division_states)); // In the case that there was a submitted search key, but not an already // existing session key, set the session key to the submitted key. if ($search_vals['search_key']) { $_SESSION['nba']['search_key'] = $search_vals['search_key']; } } } // else //-- FOR TESTING --// // unset( $_SESSION['nba']['search_key'] ); // unset( $_SESSION['nba']['total_results'] ); // d( $_SESSION ); }
/** * NBA Member Directory * * @author Jordan Pakrosnis */ function nba_do_member_directory() { //=============================// // CONFIG SEARCH VALS & META // //=============================// $search_vals = nba_get_search_vals(); //======================================================// // DIVISIONS, DIVISION STATES, TEACHING LEVELS CONFIG // //======================================================// //-- GET DIVISIONS --// // Needed for checking chair $divisions = nba_get_divisions(); //-- STATE OR DIVISION CHAIR? --// if ($divisions['current_user']['state_chair'] || $divisions['current_user']['division_chair']) { $is_chair = true; } else { $is_chair = false; } //-- SELECTED DIVISION STATES --// // Get if searching by division is enabled & searched & form is submitted if ($search_vals['do_search'] && $search_vals['division_name'] != 'all' && $search_vals['division_name'] != 'disabled') { $division_states = array(); // foreach in the searched division's states as State Chair ID foreach ($divisions[$search_vals['division_name']]['states'] as $state => $chair) { $division_states[] = nba_format_state($state, 'abbr'); } } else { $division_states = ''; } // if division_name isn't default //-- TEACHING LEVELS --// $teaching_levels = array('none' => 'None', 'elementary' => 'Elementary', 'middle-school' => 'Middle School', 'junior-high-school' => 'Junior High School', 'high-school' => 'High School', 'college-university' => 'College / University', 'community' => 'Community', 'military' => 'Military', 'other' => 'Other'); //=======================================// // COUNT TOTAL USERS (SESSION CONTROL) // //=======================================// nba_total_results($search_vals, $division_states); //-- WRAPPER --// echo '<section class="nba-member-directory clearfix">'; //-- INIT PAGINATION --// if ($search_vals['do_search']) { $pagination = nba_get_pagination($search_vals, $division_states); } //===============// // SEARCH FORM // //===============// nba_member_directory_search_form($search_vals, $divisions, $teaching_levels, $is_chair); if ($search_vals['do_search']) { //======================================// // GET & DISPLAY RESULTS & PAGINATION // //======================================// $results = nba_do_member_directory_search($search_vals, $division_states, $pagination['users_per_page'], $pagination['offset']); //-- RESULTS FOUND --// if ($results) { nba_display_member_directory_results($results, $divisions, $teaching_levels); nba_do_pagination($pagination); } else { echo '<div class="directory-none-found">'; echo '<h3>There are no members that match your search.</h3>'; echo '<div>'; // .directory-none-found } // None Found } // if do_search // Close Wrapper echo '</section>'; }