Skip to content

Instantly share code, notes, and snippets.

@Jaballadares
Created June 12, 2017 22:28
Show Gist options
  • Save Jaballadares/712e5b02a9d56be027d7ca8ab8b1ca0e to your computer and use it in GitHub Desktop.
Save Jaballadares/712e5b02a9d56be027d7ca8ab8b1ca0e to your computer and use it in GitHub Desktop.
Home Junction Listing Results Snippet
<?php
use \hji\ResponsiveIDX\ResponsiveIDX;
/**
* Begin template logic
*
* All $listing properties can be accessed directly as
* $listing->propertyName
* To view All Available Properties of the $listing object
* do: var_dump($listing->data);
*/
// Generate main details snippet based on values availability
$fieldsSnippet = null; // HTML snippet for each field output
$emptyRows = null; // Compensate details snippet height with empty rows for missing data
$i=0;
// $mainDetailsHashmap is a default array of listing object properties
// to display in search results snippet.
// Can be amended via ridx_results_snippet_hashmap filter.
$fieldsSnippet .= "<div class='table-list full-width'>
<div class='cell'>
<div class='info-row amenities'>
<p>";
$listPrice = null;
$propertyType = null;
foreach ($mainDetailsHashmap as $fieldName)
{
$fieldValue = $listing->$fieldName;
// Custom output for some fields
switch($fieldName)
{
// Combine full and half baths in a single row
case 'baths_total':
$fieldValue = $listing->baths_total;
break;
// A few markets support listing price range
// in such case we render it
case 'listPrice':
if ($listing->listPriceRange_low && $listing->listPriceRange_high)
{
$fieldValue = $listing->listPriceRange_low . ' - ' . $listing->listPriceRange_high;
}
$listPrice = $fieldValue;
break;
case 'propertyType':
$propertyType = $fieldValue;
break;
}
if(!in_array($fieldName, ['id', 'status', 'propertyType', 'listPrice'])){
$i++;
// Determine odd/even rows for easy styling
$oddEven = (0 == $i % 2) ? 'even' : 'odd';
// Generate HTML snippet markup
if ($fieldValue != null)
{
$fieldsSnippet .= <<<HTML
<span class="amenities-span {$fieldName}"><strong></strong>{$listing->getFieldLabel($fieldName)}</strong>: {$fieldValue}</span>
HTML;
}
else
// Empty row markup
{
$emptyRows .= '<div class="empty-field idx-row ' . $oddEven . '">&nbsp;</div>' . "\n";
}
}
}
$fieldsSnippet .= "</p>
</div>
</div>
</div>";
// Concatenate field snippets with empty rows
$mainDetailsSnippet = $fieldsSnippet . $emptyRows;
/*
* Begin HTML Rendering
*/
?>
<div class="idx-result-snippet clearfix" <?php echo (isset($htmlDataAttributes)) ? implode(' ', $htmlDataAttributes) : null;?>">
<div class="idx-result-snippet-wrapper">
<!-- listing title used to be here -->
<div class="photo-wrap ratio--4-3 spinnerbg item-thumb">
<?php
// Render main details snippet - reference field labels php file to change labels for amenities
echo "<div class='price hide-on-list'><span class='item-price'>" . $listPrice . "</div></span>"; //Render price - removed <br> at end of span
?>
<div class="listing-flags">
<?php
// Check if open house is scheduled
if($listing->get('openHouse_date'))
{
?>
<div class="open_house_flag">
<span>Open House</span>
</div>
<?php
}
// Check if listing is off the Market
if ($listing->offMarket)
{
?>
<div class="off_market_flag">
<span>Off Market</span>
</div>
<?php
}
// Check if listing is new
// Off market listings return false at this time.
if ($listing->daysOnHJI !== false && $listing->daysOnHJI <= 3)
{
?>
<!--<div class="new_listing_flag">-->
<span class="label-featured label label-success">New</span>
<!--</div>-->
<?php
}
?>
<div class="label-wrap label-right hide-on-list">
<span class="label-status label-status-23 label label-default">For Sale</span>
</div>
<a class="ratio--content hover-effect" href="<?php echo $listing->getPageUrl(); ?>" title="<?php echo esc_attr($listing->getTitleTag()); ?>">
<?php
$imageSource = ($listing->getMainPhoto()) ? $listing->getMainPhoto() : $listing->getPhotoNA();
// Removed onload="this.className='main-photo';"
// onload="var t=this;setTimeout(function(){ t.className='main-photo'; }, 1000);"
// from <img> tag
?>
<img data-init="imgcentering" data-ratio="4:3" class="main-photo" data-src="<?php echo $imageSource; ?>" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==" onerror="this.src='<?php echo $listing->getPhotoNA(); ?>'" alt="<?php echo $listing->getAltTag();?>">
</a>
<?php
// Check for Thumbnail MLS Logo Compliance
if ($complianceLogo = $listing->getThumbnailLogo())
{
?>
<span class="idx-small-logo"><?php echo $complianceLogo;?></span>
<?php
}
?>
</div><!-- .listing-flags -->
<?php
if (function_exists('hji_user_favorite_toggle'))
{
echo hji_user_favorite_toggle($listing);
}
?>
</div><!-- .photo-wrap -->
<div class="main-details">
<div class="row">
<div class="col-sm-12">
<div class="label-wrap hide-on-grid">
<span class="label-status label-status-23 label label-default">For Sale</span>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 hide-on-grid" style="width: 50%;">
<h4 class="listing-title" style="text-align: left">
<a href="<?php echo $listing->getPageUrl(); ?>" title="<?php echo esc_attr($listing->getTitleTag());?>">
<?php
// Render address in 2 lines:
// Street
// City, State Zip
$addressLines = $listing->getAddressLines();
if (!$addressLines)
{
// Compensate the space with empty elements if address is not set
?>
<span class="address-line1 hji-not-disclosed" style="color: #9b9b9b;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 265px;">Address not disclosed</span>
<span class="address-line2">&nbsp;</span>
<?php
}
else
{
?>
<span class="address-line1"><?php echo $addressLines[0]; ?>, <?php echo $addressLines[1]; ?></span>
<!-- <span class="address-line2"><?php echo $addressLines[1]; ?></span> -->
<?php
}
?>
</a>
</h4>
</div>
<div class="col-sm-12 hide-on-list">
<h4 class="listing-title" style="text-align: left">
<a href="<?php echo $listing->getPageUrl(); ?>" title="<?php echo esc_attr($listing->getTitleTag());?>">
<?php
// Render address in 2 lines:
// Street
// City, State Zip
$addressLines = $listing->getAddressLines();
if (!$addressLines)
{
// Compensate the space with empty elements if address is not set
?>
<span class="address-line1 hji-not-disclosed" style="color: #9b9b9b;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 265px;">Address not disclosed</span>
<span class="address-line2">&nbsp;</span>
<?php
}
else
{
?>
<span class="address-line1"><?php echo $addressLines[0]; ?>, <?php echo $addressLines[1]; ?></span>
<!--<span class="address-line2"><?php echo $addressLines[1]; ?></span>-->
<?php
}
?>
</a>
</h4>
</div>
<div class="col-sm-6 hide-on-grid" style="width: 50%;text-align: right;padding-right: 36px;">
<?php echo "<span class='item-price'>" . $listPrice . "</span>"; //Render price - removed <br> at end of span ?>
</div>
</div>
<strong><?php echo $propertyType ?></strong>
<?php
// Render main details snippet
// echo "<strong>" . $listPrice . "</strong><br>"; //Render price
echo $mainDetailsSnippet;
// Check if call to action listing details button is defined in the settings
if ($button_listing_details)
{
?>
<div class="call2action-btn">
<a class="btn btn-primary idx_call2action" href="<?php echo $listing->getPageUrl(); ?>" title="Click to view detailed home information."><?php echo $button_listing_details;?></a>
</div>
<?php
}
?>
</div><!-- .main-details -->
</div><!-- .idx-result-snippet-wrapper -->
</div><!-- .idx-result-snippet -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment