Skip to content

Commit

Permalink
Fix option filters not working in pagination
Browse files Browse the repository at this point in the history
This fixes an issue where some option filters like `map_position` and
`grid_view` are dropped when using the pagination links.
  • Loading branch information
CodyReichert committed Feb 28, 2024
1 parent 3e0ce66 commit 0e6ecad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/simply-rets-api-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SimplyRetsApiHelper {
public static function retrieveRetsListings( $params, $settings = NULL ) {
$request_url = SimplyRetsApiHelper::srRequestUrlBuilder( $params );
$request_response = SimplyRetsApiHelper::srApiRequest( $request_url );
$response_markup = SimplyRetsApiHelper::srResidentialResultsGenerator($request_response, $settings, $params);
$response_markup = SimplyRetsApiHelper::srResidentialResultsGenerator($request_response, $settings);

return $response_markup;
}
Expand Down Expand Up @@ -356,7 +356,7 @@ public static function srPaginationParser($headers) {
*/
foreach( $pag_links as $key=>$link ) {
$link_parts = parse_url( $link );
$no_prefix = array('offset', 'limit', 'type', 'water', 'grid_view');
$no_prefix = array('offset', 'limit', 'type', 'water', 'grid_view', "show_map");

$query_part = !empty($link_parts['query']) ? $link_parts['query'] : NULL;
$output = SrUtils::proper_parse_str($query_part);
Expand Down Expand Up @@ -1371,7 +1371,7 @@ public static function resultDataColumnMarkup($val, $name, $reverse=false, $id="
}


public static function srResidentialResultsGenerator($request_response, $settings, $params = array()) {
public static function srResidentialResultsGenerator($request_response, $settings) {
$cont = "";
$pagination = $request_response['pagination'];
$lastUpdate = $request_response['lastUpdate'];
Expand All @@ -1391,7 +1391,7 @@ public static function srResidentialResultsGenerator($request_response, $setting

/** Build pagination links HTML **/
$page_count = count($response);
$limit = isset($params['limit']) ? $params['limit'] : 20;
$limit = isset($settings['limit']) ? $settings['limit'] : 20;
$pag = SrUtils::buildPaginationLinks( $pagination );
$prev_link = $pag['prev'];
$next_link = $page_count < $limit ? "" : $pag['next'];
Expand Down
6 changes: 5 additions & 1 deletion src/simply-rets-post-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public static function srQueryVarsInit( $vars ) {
$vars[] = "sr_vendor";
// settings
$vars[] = "sr_map_position";
$vars[] = "show_map";
$vars[] = "grid_view";
return $vars;
}
Expand Down Expand Up @@ -619,7 +620,8 @@ public static function srPostDefaultContent( $content ) {
/** multi mls */
$vendor = get_query_var('sr_vendor', '');
/** Settings */
$grid_view = get_query_var("grid_view", FALSE);
$grid_view = get_query_var("grid_view", false);
$show_map = get_query_var("show_map", true);
$map_position = get_query_var('sr_map_position',
get_option('sr_search_map_position'));

Expand Down Expand Up @@ -932,12 +934,14 @@ public static function srPostDefaultContent( $content ) {
way to get them back on the other side right now.
*/
"grid_view" => $grid_view,
"show_map" => $show_map,
"map_position" => $map_position
);

$settings = array(
"limit" => $limit,
"map_position" => $map_position,
"show_map" => $show_map,
"grid_view" => $grid_view
);

Expand Down
11 changes: 5 additions & 6 deletions src/simply-rets-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public static function parseShortcodeAttributes($atts, $setting_atts = array())
// Parse settings, don't add them to the API query
if (array_key_exists($param, $setting_atts)) {
$attributes["settings"][$param] = $value;
continue;
}

$values = explode(";", $value);
Expand All @@ -250,11 +249,6 @@ public static function parseShortcodeAttributes($atts, $setting_atts = array())
}

$attributes["params"][$name] = count($values) > 1 ? $values : $value;

// Add vendor to params and settings
if ($param === "vendor") {
$attributes["settings"]["vendor"] = $value;
}
}

return $attributes;
Expand Down Expand Up @@ -282,6 +276,8 @@ public static function sr_residential_shortcode($atts = array ()) {
"map_position" => get_option('sr_search_map_position', 'map_above'),
"show_map" => "true",
"grid_view" => false,
"vendor" => "",
"limit" => 20
);

$data = SrShortcodes::parseShortcodeAttributes($atts, $setting_atts);
Expand Down Expand Up @@ -348,6 +344,7 @@ public static function sr_search_form_shortcode( $atts ) {

/** Settings */
$grid_view = isset($atts["grid_view"]) ? $atts["grid_view"] : FALSE;
$show_map = isset($atts["show_map"]) ? $atts["show_map"] : TRUE;

/** User Facing Parameters */
$minbeds = array_key_exists('minbeds', $atts) ? $atts['minbeds'] : '';
Expand Down Expand Up @@ -593,6 +590,7 @@ public static function sr_search_form_shortcode( $atts ) {
<input type="hidden" name="sr_ownership" value="<?php echo $ownership; ?>" />
<input type="hidden" name="sr_salesagent" value="<?php echo $salesAgent; ?>" />
<input type="hidden" name="grid_view" value="<?php echo $grid_view; ?>" />
<input type="hidden" name="show_map" value="<?php echo $show_map; ?>" />

<div>
<button class="btn button submit btn-submit" style="display:inline-block;">Search</button>
Expand Down Expand Up @@ -690,6 +688,7 @@ public static function sr_search_form_shortcode( $atts ) {
<input type="hidden" name="limit" value="<?php echo $limit; ?>" />
<input type="hidden" name="status" value="<?php echo $adv_status; ?>" />
<input type="hidden" name="grid_view" value="<?php echo $grid_view; ?>" />
<input type="hidden" name="show_map" value="<?php echo $show_map; ?>" />
<input
type="hidden"
name="sr_specialListingConditions"
Expand Down

0 comments on commit 0e6ecad

Please sign in to comment.