From d52c711b939f77fa8e930ed954c27752e6af8edd Mon Sep 17 00:00:00 2001 From: Cody Reichert Date: Fri, 15 Nov 2019 10:39:46 -0600 Subject: [PATCH 1/2] Support openhouses on multi-vendor accounts --- src/simply-rets-api-helper.php | 10 ++++++---- src/simply-rets-openhouses.php | 35 +++++++++++++++++++++++----------- src/simply-rets-shortcode.php | 13 ++++++++++--- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/simply-rets-api-helper.php b/src/simply-rets-api-helper.php index bf281fa..d72ffcf 100644 --- a/src/simply-rets-api-helper.php +++ b/src/simply-rets-api-helper.php @@ -21,11 +21,13 @@ public static function retrieveRetsListings( $params, $settings = NULL ) { } public static function retrieveOpenHousesResults($params, $settings = NULL) { - $request_url = SimplyRetsApiHelper::srRequestUrlBuilder($params, "openhouses"); - $response = SimplyRetsApiHelper::srApiRequest($request_url); - $response_markup = SimplyRetsOpenHouses::openHousesSearchResults($response); + $api_url = SimplyRetsApiHelper::srRequestUrlBuilder($params, "openhouses"); + $api_response = SimplyRetsApiHelper::srApiRequest($api_url); - return $response_markup; + return SimplyRetsOpenHouses::openHousesSearchResults( + $api_response, + $settings + ); } public static function retrieveListingDetails( $listing_id ) { diff --git a/src/simply-rets-openhouses.php b/src/simply-rets-openhouses.php index 33fa817..2c409a8 100644 --- a/src/simply-rets-openhouses.php +++ b/src/simply-rets-openhouses.php @@ -17,10 +17,13 @@ class SimplyRetsOpenHouses { * Return an empty array if no openhouses exist. */ public static function getOpenHousesByListingId($listing_id) { - $response = SimplyRetsApiHelper::makeApiRequest( - array("listingId" => $listing_id, "startdate" => date("Y-m-d")), - "openhouses" - ); + $params = array_filter([ + "listingId" => $listing_id, + "startdate" => date("Y-m-d"), + "vendor" => get_query_var("sr_vendor", NULL) + ]); + + $response = SimplyRetsApiHelper::makeApiRequest($params, "openhouses"); return $response["response"]; } @@ -55,7 +58,7 @@ public static function getOpenHouseDateTimes($openhouse) { /** * Generate markup /openhouses search response. */ - public static function openHousesSearchResults($search_response) { + public static function openHousesSearchResults($search_response, $settings) { $res = $search_response["response"]; $pag = $search_response["pagination"]; @@ -78,8 +81,12 @@ public static function openHousesSearchResults($search_response) { } else { + // Generate markup for each open house result foreach($res as $idx=>$oh) { - $markup .= SimplyRetsOpenHouses::openHouseSearchResultMarkup($oh); + $markup .= SimplyRetsOpenHouses::openHouseSearchResultMarkup( + $oh, + $settings + ); } $markup .= <<listing; $full_address = SrUtils::buildFullAddressString($listing); - $details_link = SrUtils::buildDetailsLink($listing); $list_price_fmtd = '$' . number_format($listing->listPrice); $listing_id = $listing->listingId; + // Photo markup and styles $dummy = plugins_url( 'assets/img/defprop.jpg', __FILE__ ); $main_photo = !empty($listing->photos) ? $listing->photos[0] : $dummy; $photo_style = "background-image:url('$main_photo');background-size:cover;"; + // Agent/office compliance markup $listing_office = $listing->office->name; $listing_agent = $listing->agent->firstName . ' ' . $listing->agent->lastName; $compliance_markup = SrUtils::mkListingSummaryCompliance( @@ -114,10 +122,15 @@ public static function openHouseSearchResultMarkup($openhouse) { $listing_agent ); - $openhouse_times = SimplyRetsOpenHouses::getOpenHouseDateTimes( - $openhouse - ); + // Listing details page link + $link_settings = array_key_exists("vendor", $settings) ? array( + "sr_vendor" => $settings["vendor"] + ) : array(); + + $details_link = SrUtils::buildDetailsLink($listing, $link_settings); + // Open house times + $openhouse_times = SimplyRetsOpenHouses::getOpenHouseDateTimes($openhouse); $day = $openhouse_times["day"]; $time = $openhouse_times["time"]; diff --git a/src/simply-rets-shortcode.php b/src/simply-rets-shortcode.php index 883cc41..187ac82 100644 --- a/src/simply-rets-shortcode.php +++ b/src/simply-rets-shortcode.php @@ -194,6 +194,7 @@ public static function sr_int_map_search($atts) { public static function sr_openhouses_shortcode($atts = array()) { $param_str = "?"; + $settings = array(); // Build a query string from the options provided on the short-code if (is_array($atts)) { @@ -202,12 +203,18 @@ public static function sr_openhouses_shortcode($atts = array()) { $val = trim($v); $param_str .= "{$param}={$val}&"; } + + // Pass certain settings through as an array + if ($param === "vendor") { + $settings["vendor"] = $value; + } } } - $content = SimplyRetsApiHelper::retrieveOpenHousesResults($param_str); - - return $content; + return SimplyRetsApiHelper::retrieveOpenHousesResults( + $param_str, + $settings + ); } From 5f7a9d5313b9b7222d3eeaba31d3cfefbe5335f1 Mon Sep 17 00:00:00 2001 From: Cody Reichert Date: Fri, 15 Nov 2019 10:51:06 -0600 Subject: [PATCH 2/2] Show all upcoming openhouses - don't limit to 4 --- src/assets/css/simply-rets-client.css | 1 + src/simply-rets-api-helper.php | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/assets/css/simply-rets-client.css b/src/assets/css/simply-rets-client.css index dac8a47..e5614b1 100644 --- a/src/assets/css/simply-rets-client.css +++ b/src/assets/css/simply-rets-client.css @@ -338,6 +338,7 @@ the class or the id, depending on what you need. .sr-listing-openhouses-banner-item { display: inline-block; width: 25%; + padding-bottom: 5px; } /* diff --git a/src/simply-rets-api-helper.php b/src/simply-rets-api-helper.php index d72ffcf..f0ef62c 100644 --- a/src/simply-rets-api-helper.php +++ b/src/simply-rets-api-helper.php @@ -1043,9 +1043,7 @@ public static function srResidentialDetailsGenerator( $listing ) { ); $upcoming_openhouses = count($openhouses); - $next_openhouses = $upcoming_openhouses > 0 - ? array_slice($openhouses, 0, 4) - : NULL; + $next_openhouses = $upcoming_openhouses > 0 ? $openhouses : NULL; $next_openhouses_banner = ""; if ($next_openhouses) {