From: Anthony Talarico Date: Mon, 13 Mar 2017 17:00:30 +0000 (-0400) Subject: adding pagination to the search results, changing the layout of the initial search X-Git-Tag: v1.0.0^2~29 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=f8aa6c62e44e06338e7c4480134acc023c3b56fd;p=WP-Plugins%2Fglm-member-db-obits.git adding pagination to the search results, changing the layout of the initial search page --- diff --git a/css/front.css b/css/front.css index 391503d..d3b4c95 100644 --- a/css/front.css +++ b/css/front.css @@ -100,30 +100,66 @@ } .search-container .results-limit-container { margin-bottom: 20px; + text-align: center; +} +.search-container .results-limit-container input:nth-child(2){ + margin-left: 20px; +} +input.sidebar-criteria{ + margin-left: 10px; } .detail-record{ padding: 5px 0px; - } .detail-label{ font-weight: bold; - padding: 2px 0; + padding: 2px 10px; } .detail-value{ - padding: 2px 0; - + padding: 2px 0; } .detail-header{ font-size: 24px; padding: 5px 0px; margin-bottom: 15px; text-align: center; -} -.detail-wrapper{ - } .record-row:nth-child(even){ background-color: #eeeeee; } - +.expand-collapse{ + display: inline-block; + float:right; + color: #1d3961; +} +.expand-collapse:focus{ + color: #1d3961; +} +.search-container .not-wrapper{ + margin-top: 7px; +} +.search-input input, .search-input select{ + max-width: 320px; +} +.search-input select{ +/* max-width: 222px;*/ +} +.search-container .not-input{ + margin-top: 10px; +} +.logic-input{ + max-width: 125px; +} +.search-container .search-btn-container{ + margin: 0 auto; + width: 120px; + margin-top: 20px; +} +.footable-filter{ + max-width: 250px; + float: left !important; +} +.glm-alpha-link, .detail-link{ + color: #1d3961; +} \ No newline at end of file diff --git a/models/front/obits/search.php b/models/front/obits/search.php index feedc16..8ac6f55 100644 --- a/models/front/obits/search.php +++ b/models/front/obits/search.php @@ -97,26 +97,51 @@ class GlmMembersFront_obits_search extends GlmDataObits $view = 'search'; $sql = "SELECT * FROM $this->table"; -// $sql_where = "SELECT * FROM $this->table WHERE "; $year_ranges = new glmObitSupportFunctions($this->wpdb, $this->config); $birth_death_range = array('birth' => $year_ranges->getObitYearRange(BIRTH_YEAR_START), 'death' => $year_ranges->getObitYearRange(DEATH_YEAR_START)); $logic_dropdown = array('Contains' => 'LIKE' ,'Starts With' => 'LIKE%','Equals' => '=', 'More than' => '>', 'Less than' => '<'); - $per_page = isset( $_REQUEST['results-limit']) ? (int)filter_var( $_REQUEST['results-limit'], FILTER_SANITIZE_STRING) : 20; - + $per_page = isset( $_REQUEST['results-limit']) ? (int)filter_var( $_REQUEST['results-limit'], FILTER_SANITIZE_STRING) : 50; +// echo "PER PAGE:" . $per_page; + $form_data = $_POST; + + // build array of potential search fields , will be used in the paging urls + $form_fields = array( + 'last' => filter_var($form_data['last_name'],FILTER_SANITIZE_STRING), + 'first' => filter_var($form_data['first_mid'],FILTER_SANITIZE_STRING), + 'b_yr' => filter_var($form_data['b_year'],FILTER_SANITIZE_STRING), + 'b_range' => filter_var($form_data['b_yr_range'],FILTER_SANITIZE_STRING), + 'd_yr' => filter_var($form_data['d_year'],FILTER_SANITIZE_STRING), + 'd_range' => filter_var($form_data['d_yr_range'],FILTER_SANITIZE_STRING), + 'spouse' => filter_var($form_data['spouse_partner'],FILTER_SANITIZE_STRING), + 'maiden' => filter_var($form_data['maiden_other'],FILTER_SANITIZE_STRING) + ); + $get_fields = array( + 'last_name' => filter_var($_GET['last'],FILTER_SANITIZE_STRING), + 'first_mid' => filter_var($_GET['first'],FILTER_SANITIZE_STRING), + 'b_year' => filter_var($_GET['b_yr'],FILTER_SANITIZE_STRING), + 'b_yr_range' => filter_var($_GET['b_range'],FILTER_SANITIZE_STRING), + 'd_year' => filter_var($_GET['d_yr'],FILTER_SANITIZE_STRING), + 'd_yr_range' => filter_var($_GET['d_range'],FILTER_SANITIZE_STRING), + 'spouse_partner' => filter_var($_GET['spouse'],FILTER_SANITIZE_STRING), + 'maiden_other' => filter_var($_GET['maiden'],FILTER_SANITIZE_STRING) + ); + // get the alpha key if ( isset( $_REQUEST['alpha'] ) ){ $alpha_key = filter_var( $_REQUEST['alpha'], FILTER_SANITIZE_STRING ); } + // create the any condition or all conditions query logic if( isset( $_REQUEST['conditions'] ) && $_REQUEST['conditions'][0] == 'any'){ $clause = ' OR '; } else if ( isset( $_REQUEST['conditions'] ) && $_REQUEST['conditions'][0] == 'all') { $clause = ' AND '; } + // separate the search fields from the logic ('not', 'contains, 'equals') etc. foreach($form_data as $key=>$value){ if (isset($value) && $value !== ''){ if( $value !== 'Search' && $key !== 'conditions' && $key !== 'results-limit'){ @@ -127,9 +152,28 @@ class GlmMembersFront_obits_search extends GlmDataObits $search_options[$key] = $value; } } + } else { + // populate an array for each empty search value + $empty_values[] = 'void'; } } - + + // check to see if the GET query params search array is empty + foreach($get_fields as $key=>$val){ + if( $val !== '' && isset($val)){ + $get_values[$key] = $val; + } + } + + + // check to see if there are 8 empty values, if there are, there are no search values + if(count($empty_values) === 8){ + $empty_search = 'true'; + } else { + $empty_search = 'false'; + } + + // build the initial sql query based on the search fields populated foreach($search_fields as $field => $f){ foreach($search_options as $option => $o){ @@ -156,18 +200,24 @@ class GlmMembersFront_obits_search extends GlmDataObits } $search = implode($clause, $search_fields); - -// $sql = "SELECT * FROM $this->table" . -// ( empty($search) ? " ORDER BY last_name ASC LIMIT 100" : " WHERE $search ORDER BY last_name ASC LIMIT 100"); - - if( empty($search) && empty( $alpha_key) ){ + + // check the GET variables for sql queries with paging + if( empty( $search ) && empty( $alpha_key) && empty($get_values) ){ $where = ""; } else if( !empty( $alpha_key ) ) { $where = "last_name LIKE '$alpha_key%'"; - } else { + + } else if( !empty( $get_values ) ){ + foreach($get_values as $key=>$value){ + if($value !== ''){ + $where .= "$key LIKE '%$value%' AND "; + } + } + $where = substr($where, 0, -5); + }else { $where = $search; } - + if (isset($_REQUEST['pageSelect'])) { // If request is for Next @@ -185,7 +235,8 @@ class GlmMembersFront_obits_search extends GlmDataObits } $obits = $this->getList($where, 'last_name', $fieldVals = true, $idField = 'id', $start, $per_page); - +// echo '
', print_r($obits), '
'; + $returned = $obits['returned']; // Get paging results $numbDisplayed = $obits['returned']; @@ -202,9 +253,13 @@ class GlmMembersFront_obits_search extends GlmDataObits if ($obits['returned'] == $per_page) { $nextStart = $start + $per_page; } -// print_r($obits['list']); + + if( empty( $where ) ){ + $get_rows = "SELECT COUNT(*) FROM $this->table"; + } else { + $get_rows = "SELECT COUNT(*) FROM $this->table WHERE $where"; + } - $get_rows = "SELECT COUNT(*) FROM $this->table"; $rows = $this->wpdb->get_results($get_rows, 'ARRAY_A'); @@ -231,14 +286,13 @@ class GlmMembersFront_obits_search extends GlmDataObits if( isset($_REQUEST['searchButton']) || isset( $_REQUEST['pageSelect'] ) || isset($_REQUEST['alpha'] ) ){ $view = 'searchResults'; } - + // Compile template data $templateData = array( 'birth_death_range' => $birth_death_range, 'sql' => $sql, 'obits' => $obits['list'], 'logic' => $logic_dropdown, - 'pages' => $pages, 'per_page' => $per_page, 'numbDisplayed' => $numbDisplayed, 'lastDisplayed' => $lastDisplayed, @@ -248,8 +302,12 @@ class GlmMembersFront_obits_search extends GlmDataObits 'start' => $start, 'limit' => $per_page, 'total' => $total_records, + 'returned' => $returned, 'alphaList' => $alphaList, - 'alpha_key' => $alpha_key + 'alpha_key' => $alpha_key, + 'search' => $form_fields, + 'get_params' => $get_fields, + 'empty_search' => $empty_search ); // Return status, any suggested view, and any data to controller diff --git a/views/front/obits/search.html b/views/front/obits/search.html index c2b913f..7899375 100644 --- a/views/front/obits/search.html +++ b/views/front/obits/search.html @@ -5,97 +5,90 @@
All Conditions Any Condition - - -
-
+
Last Name:
-
+
-
+
-
- +
+
-
+
First Name & Middle:
-
+ +
-
+
-
- +
+
-
+
Birth Year:
-
+ +
-
+
-
- +
+
-
+
Birth Year Range:
-
+ +
-
+
-
+
-
+
-
- +
+
-
+
Death Year Range:
-
+ +
-
+
-
+
-
+
-
- +
+
-
+
Spouse / Partner Name:
-
- +
+
-
+
-
- +
+
- - +
+ +
diff --git a/views/front/obits/searchResults.html b/views/front/obits/searchResults.html index c91ecb2..fc16138 100644 --- a/views/front/obits/searchResults.html +++ b/views/front/obits/searchResults.html @@ -1,266 +1,264 @@