Skip to content

Commit

Permalink
Support openhouses on multi-vendor accounts (#148)
Browse files Browse the repository at this point in the history
Support openhouses on multi-vendor accounts
  • Loading branch information
CodyReichert committed Nov 15, 2019
2 parents 57c2363 + 5f7a9d5 commit 4f0b8c2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/assets/css/simply-rets-client.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand Down
14 changes: 7 additions & 7 deletions src/simply-rets-api-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -1041,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) {
Expand Down
35 changes: 24 additions & 11 deletions src/simply-rets-openhouses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
}
Expand Down Expand Up @@ -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"];

Expand All @@ -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 .= <<<HTML
Expand All @@ -96,28 +103,34 @@ public static function openHousesSearchResults($search_response) {
/**
* Generate markup for a single open house search result
*/
public static function openHouseSearchResultMarkup($openhouse) {
public static function openHouseSearchResultMarkup($openhouse, $settings) {
$listing = $openhouse->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(
$listing_office,
$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"];

Expand Down
13 changes: 10 additions & 3 deletions src/simply-rets-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
);
}


Expand Down

0 comments on commit 4f0b8c2

Please sign in to comment.