<?php
// REFACTOR FROM HOMES TO COMMERCIAL
namespace AppBundle\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\Cache\Simple\FilesystemCache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class CommercialController extends FrontendController
{
public static function HandleContactForm( $contact_object_id = 0, $fields = [] ) {
// Attempt retrieval of the contact object...
$VmCommercialPropertyContact = \Pimcore\Model\DataObject::getById( $contact_object_id );
if( !( $VmCommercialPropertyContact instanceof \Pimcore\Model\DataObject\VmCommercialPropertyContact ) ) {
return 'Error: Invalid Object!';
}
// Check for a valid recipient email...
if( !filter_var( $VmCommercialPropertyContact->getEmail(), FILTER_VALIDATE_EMAIL ) ) {
return 'Error: Misconfigured Email!';
}
// Check to see if any fields were submitted...
if( empty( $fields ) ) {
return 'Error: Empty Fields!';
}
// reCaptcha
$reCaptchaRes = self::post_captcha( $_POST[ 'g-recaptcha-response' ] );
if( !$reCaptchaRes[ 'success'] ) return 'Please be sure to check the security CAPTCHA box.';
// Construct the message body...
$MailText = null;
$MailHtml = null;
foreach( $fields as $field ) {
$MailText .= "\n".$field[ 'label' ].": ".$field[ 'value' ];
$MailHtml .= '<p><strong>'.$field[ 'label' ].':</strong><br/>'.$field[ 'value' ].'</p>';
}
// Compose an email...
$Mail = new \Pimcore\Mail( $VmCommercialPropertyContact->getSubject() );
$Mail->addTo( $VmCommercialPropertyContact->getEmail() );
$Mail->setFrom( 'no-reply@vanmetrecommercial.com', 'Van Metre Commercial (No Reply)' );
$Mail->setReplyTo( 'no-reply@vanmetrecommercial.com', 'Van Metre Commercial (No Reply)' );
$Mail->setBodyText( $MailText );
$Mail->setBodyHtml( $MailHtml );
// Return the result of the mail send method...
if( $Mail->send() ) {
// Try saving a copy of the message in Pimcore...
$ReceiptDir = \Pimcore\Model\DataObject::getByPath( '/_DATA/COMMERCIAL/RECEIPTS/' );
if( $ReceiptDir instanceof \Pimcore\Model\DataObject\Folder ) {
$Receipt = new \Pimcore\Model\DataObject\VmCommercialPropertyContactReceipt();
$Receipt->setKey( date( 'Y-m-d-H-i-s' ) );
$Receipt->setParent( $ReceiptDir );
$Receipt->setMailText( $MailText );
$Receipt->setMailHtml( $MailHtml );
$Receipt->save();
}
// Return a success message...
return 'Success: Mail Sent!';
}
// Return unspecified error...
return 'Error: Unspecified';
}
// Function to handle verification of reCAPTCHA on server side.
private static function post_captcha( $user_response ) {
$fields_string = '';
$fields = array(
'secret' => '6LfTvr0UAAAAAJNI5s0-6CMlzbeKQJyRWxU6qs7K',
'response' => $user_response
);
// Build POST req fields string.
foreach( $fields as $key=>$value ) {
$fields_string .= $key . '=' .$value . '&';
}
$fields_string = rtrim( $fields_string, '&' );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
curl_setopt( $ch, CURLOPT_POST, count( $fields ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields_string );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec( $ch );
curl_close( $ch );
return json_decode( $result, true );
}
private static function GetTypeMapping()
{
// Get all property types...
$listing = new \Pimcore\Model\DataObject\VmCommercialPropertyType\Listing();
$listing->setCondition( 'o_path = ?', [ '/_DATA/COMMERCIAL/TYPES/' ] );
$types = [];
foreach( $listing as $type ) {
$sublisting = new \Pimcore\Model\DataObject\VmCommercialPropertyType\Listing();
$sublisting->setCondition( 'o_parentId = ?', [ $type->getId() ] );
$subtypes = [];
foreach( $sublisting as $subtype ) {
$subtypes[] = [
'id' => $subtype->getId(),
'key' => $subtype->getKey(),
'subtypes' => []
];
}
$types[] = [
'id' => $type->getId(),
'key' => $type->getKey(),
'subtypes' => $subtypes
];
}
return $types;
}
private static function GetCommercialMapping()
{
// Get all of our property objects that are published...
$listing = new \Pimcore\Model\DataObject\VmCommercialProperty\Listing();
$listing->setCondition( 'o_path = ?', [ '/_DATA/COMMERCIAL/PROPERTIES/' ] );
// Create state level keys in the map array...
// foreach( $listing as $property ) $map[ $property->getSearchSlugState() ] = [];
// Create child city keys in the map array...
$map = [];
foreach ( $listing as $property ) {
$state = strtolower( $property->getSearch_slug_state() );
$city = strtolower( $property->getSearch_slug_city() );
$key = $property->getKey();
$name = $property->getName();
$map[ $state ][ $city ][ $key ] = $name;
}
// Alphabetize...
// uksort( $map, function ( $a, $b ) {
// return count( $b ) - count( $a );
// } );
krsort( $map );
foreach ( $map as $i => &$state ) {
ksort( $state );
foreach ( $state as $ii => &$city ) {
asort( $city );
}
}
// Return the map...
return $map;
}
public function CommercialNavigation()
{
// Retrieve Site ID...
if ( \Pimcore\Model\Site::isSiteRequest() ) {
$site = \Pimcore\Model\Site::getCurrentSite();
$root = $site->getRootDocument();
} else {
$root = \Pimcore\Model\Document::getByPath( '/home-commercial/' );
$site = \Pimcore\Tool\Frontend::getSiteForDocument( $root );
}
// State Labels...
$state_label = [ 'dc' => 'District of Columbia'
, 'al' => 'Alabama', 'hi' => 'Hawaii', 'ma' => 'Massachusetts', 'nm' => 'New Mexico', 'sd' => 'South Dakota'
, 'ak' => 'Alaska', 'id' => 'Idaho', 'mi' => 'Michigan', 'ny' => 'New York', 'tn' => 'Tennessee'
, 'az' => 'Arizona', 'il' => 'Illinois', 'mn' => 'Minnesota', 'nc' => 'North Carolina', 'tx' => 'Texas'
, 'ar' => 'Arkansas', 'in' => 'Indiana', 'ms' => 'Mississippi', 'nd' => 'North Dakota', 'ut' => 'Utah'
, 'ca' => 'California', 'ia' => 'Iowa', 'mo' => 'Missouri', 'oh' => 'Ohio', 'vt' => 'Vermont'
, 'co' => 'Colorado', 'ks' => 'Kansas', 'mt' => 'Montana', 'ok' => 'Oklahoma', 'va' => 'Virginia'
, 'ct' => 'Connecticut', 'ky' => 'Kentucky', 'ne' => 'Nebraska', 'or' => 'Oregon', 'wa' => 'Washington'
, 'de' => 'Delaware', 'la' => 'Louisiana', 'nv' => 'Nevada', 'pa' => 'Pennsylvania', 'wv' => 'West Virginia'
, 'fl' => 'Florida', 'me' => 'Maine', 'nh' => 'New Hampshire', 'ri' => 'Rhode Island', 'wi' => 'Wisconsin'
, 'ga' => 'Georgia', 'md' => 'Maryland', 'nj' => 'New Jersey', 'sc' => 'South Carolina', 'wy' => 'Wyoming'
];
// Get the property hierarchy...
$property_map = self::GetCommercialMapping();
// Generate the menu...
$state_menu = null;
foreach ( $property_map as $state => $state_data ) {
$city_menu = null;
foreach ( $state_data as $city => $city_data ) {
$property_menu = null;
foreach ( $city_data as $property => $property_data ) {
$property_url = $this->generateUrl( 'CommProperties S_C_P', [ 'state' => $state, 'city' => $city, 'property' => $property, 'site' => $site->getId() ] );
$property_menu .= '<li><a href="'.$property_url.'">'.$property_data.'</a></li>';
}
if ( !empty( $property_menu ) ) {
$city_url = $this->generateUrl( 'CommProperties S_C', [ 'state' => $state, 'city' => $city, 'site' => $site->getId() ] );
$city_menu .= '<li><a href="'.$city_url.'">'.ucwords( preg_replace( "/[^A-Za-z0-9 ]/", '', $city ) ).'</a><ul>'.$property_menu.'</ul></li>';
}
}
if ( !empty( $city_menu ) ) {
$state_url = $this->generateUrl( 'CommProperties S', [ 'state' => $state, 'site' => $site->getId() ] );
$state_menu .= '<li><a href="'.$state_url.'">'.$state_label[ $state ].'</a><ul>'.$city_menu.'</ul></li>';
}
}
$properties_menu = null;
if ( !empty( $state_menu ) ) {
$properties_menu .= '<ul>'.$state_menu.'</ul>';
}
// $site = \Pimcore\Model\Site::getCurrentSite();
// $root = $site->getRootDocument();
$pages = new \Pimcore\Model\Document\Listing();
$pages->setCondition( 'parentId = ?', [ $root->getId() ] );
$pages->setOrderKey( 'index' );
$pages->setOrder( 'ASC' );
$nav_menu = null
.'<li>'
.'<a href="'.$this->generateUrl( 'CommProperties', [ 'site' => $site->getId() ] ).'">Properties</a>'
.$properties_menu
.'</li>';
foreach ( $pages as $page ) {
if ( !( $page instanceof \Pimcore\Model\Document\Page ) ) continue;
if ( $page->getProperty( 'navigation_exclude' ) ) continue;
$subpages = new \Pimcore\Model\Document\Listing();
$subpages->setCondition( 'parentId = ?', [ $page->getId() ] );
$subpages->setOrderKey( 'index' );
$subpages->setOrder( 'ASC' );
$subnav_menu = null;
foreach ( $subpages as $subpage ) {
if( $subpage->getProperty( 'navigation_exclude' ) ) continue;
if( $subpage instanceof \Pimcore\Model\Document\Page ) {
$subnav_menu .= '<li><a href="'.$subpage->getFullPath().'">'.$subpage->getProperty( 'navigation_name' ).'</a></li>';
}
if( $subpage instanceof \Pimcore\Model\Document\Link ) {
$subnav_menu .= '<li><a href="'.$subpage->getFullPath().'" target="'.$subpage->getProperty( 'navigation_target' ).'">'.$subpage->getProperty( 'navigation_name' ).'</a></li>';
}
}
if ( !empty( $subnav_menu ) ) $subnav_menu = '<ul>'.$subnav_menu.'</ul>';
if( $page instanceof \Pimcore\Model\Document\Page ) {
$nav_menu .= '<li><a href="'.$page->getFullPath().'">'.$page->getProperty( 'navigation_name' ).'</a>'.$subnav_menu.'</li>';
}
if( $page instanceof \Pimcore\Model\Document\Link ) {
$nav_menu .= '<li><a href="'.$page->getFullPath().'" target="'.$page->getProperty( 'navigation_target' ).'">'.$page->getProperty( 'navigation_name' ).'</a>'.$subnav_menu.'</li>';
}
}
if ( !empty( $nav_menu ) ) $nav_menu = '<ul>'.$nav_menu.'</ul>';
return $this->render( ':Includes:commercial-header-view.html.php', [
'menu' => $nav_menu
] );
}
public function PropertiesListAction( Request $request ) {
/*
ROUTES:
CommProperties S_C_P /properties/%state/%city/%property
CommProperties S_C /properties/%state/%city
CommProperties S /properties/%state
CommProperties /properties
*/
if( $request->get( '_route' ) == 'CommProperties S_C' ) {
$map = $this->GetCommercialMapping();
$state = $request->get( 'state' );
$city = $request->get( 'city' );
if( !isset( $map[ $state ][ $city ] ) ) {
throw new NotFoundHttpException( 'Not found' );
}
$results = [];
$Listing = new \Pimcore\Model\DataObject\VmCommercialProperty\Listing();
$Listing->setOrderKey( 'Name' );
$Listing->getOrder( 'ASC' );
foreach( $Listing as $Property ) {
// Check location...
if( $Property->getSearch_slug_state() != $state ) continue;
if( $Property->getSearch_slug_city() != $city ) continue;
// Check types...
$valid_type = true;
if( !empty( $request->get( 'type' ) ) ) {
$valid_type = false;
$type = $request->get( 'type' );
foreach( $Property->getSearch_types() as $item ) {
if( $type == $item->getId() ) $valid_type = true;
}
}
if( !$valid_type ) continue;
// Check squate footage...
$valid_sqft_min = true;
if( $request->get( 'sqft_min' ) ) {
$valid_sqft_min = false;
if( (int)$Property->getSearch_sqft_min() >= (int)$request->get( 'sqft_min' ) ) $valid_sqft_min = true;
if( (int)$Property->getSearch_sqft_max() >= (int)$request->get( 'sqft_min' ) ) $valid_sqft_min = true;
}
$valid_sqft_max = true;
if( $request->get( 'sqft_max' ) ) {
$valid_sqft_max = false;
if( (int)$Property->getSearch_sqft_min() <= (int)$request->get( 'sqft_max' ) ) $valid_sqft_max = true;
if( (int)$Property->getSearch_sqft_max() <= (int)$request->get( 'sqft_max' ) ) $valid_sqft_max = true;
}
if( !$valid_sqft_min && !$valid_sqft_max ) continue;
// Check availability...
$valid_availability = true;
if( $request->get( 'available' ) && $request->get( 'available' ) == 'open' ) {
if( empty( $Property->getSearch_available_units() ) ) $valid_availability = false;
}
if( !$valid_availability ) continue;
// Check category...
$valid_group = true;
if( !empty( $request->get( 'group' ) ) ) {
if( strpos( $request->get( 'group' ), '_' ) !== false ) {
$group = explode( '_', $request->get( 'group' ) );
$ID = (int)$group[ 0 ];
$Index = (int)$group[ 1 ];
} else {
$ID = (int)$request->get( 'group' );
$Index = null;
}
$ValidProperties = [];
foreach( $this->GetGroupMapping() as $item ) {
if( $item[ 'ID' ] != $ID ) continue;
foreach( $item[ 'Listings' ] as $subitem ) {
if( !is_null( $Index ) && $Index != $subitem[ 'Index' ] ) continue;
$subitem_ids = explode( ',', $subitem[ 'Properties' ] );
foreach( $subitem_ids as $subitem_id ) {
$ValidProperties[] = $subitem_id;
}
}
}
$valid_group = in_array( $Property->getId(), $ValidProperties );
}
if( !$valid_group ) continue;
// Add the property...
$results[] = $Property;
}
$seo_name = \Pimcore\File::getValidFilename( 'properties-'.$state.'-'.$city );
$seo = \Pimcore\Model\DataObject\VmCommercialSeo::getByPath( '/_DATA/COMMERCIAL/SEO/'.$seo_name );
return $this->render( ':Commercial:listing.html.php', [
'state' => $state,
'city' => $city,
'seo' => $seo,
'results' => $results
] );
}
if( $request->get( '_route' ) == 'CommProperties S' ) {
$map = $this->GetCommercialMapping();
$state = $request->get( 'state' );
if( !isset( $map[ $state ] ) ) {
throw new NotFoundHttpException( 'Not found' );
}
$results = [];
$Listing = new \Pimcore\Model\DataObject\VmCommercialProperty\Listing();
$Listing->setOrderKey( 'Name' );
$Listing->getOrder( 'ASC' );
foreach( $Listing as $Property ) {
// Check location...
if( $Property->getSearch_slug_state() != $state ) continue;
// Check types...
$valid_type = true;
if( !empty( $request->get( 'type' ) ) ) {
$valid_type = false;
$type = $request->get( 'type' );
foreach( $Property->getSearch_types() as $item ) {
if( $type == $item->getId() ) $valid_type = true;
}
}
if( !$valid_type ) continue;
// Check squate footage...
$valid_sqft_min = true;
if( $request->get( 'sqft_min' ) ) {
$valid_sqft_min = false;
if( (int)$Property->getSearch_sqft_min() >= (int)$request->get( 'sqft_min' ) ) $valid_sqft_min = true;
if( (int)$Property->getSearch_sqft_max() >= (int)$request->get( 'sqft_min' ) ) $valid_sqft_min = true;
}
$valid_sqft_max = true;
if( $request->get( 'sqft_max' ) ) {
$valid_sqft_max = false;
if( (int)$Property->getSearch_sqft_min() <= (int)$request->get( 'sqft_max' ) ) $valid_sqft_max = true;
if( (int)$Property->getSearch_sqft_max() <= (int)$request->get( 'sqft_max' ) ) $valid_sqft_max = true;
}
if( !$valid_sqft_min && !$valid_sqft_max ) continue;
// Check availability...
$valid_availability = true;
if( $request->get( 'available' ) && $request->get( 'available' ) == 'open' ) {
if( empty( $Property->getSearch_available_units() ) ) $valid_availability = false;
}
if( !$valid_availability ) continue;
// Check category...
$valid_group = true;
if( !empty( $request->get( 'group' ) ) ) {
if( strpos( $request->get( 'group' ), '_' ) !== false ) {
$group = explode( '_', $request->get( 'group' ) );
$ID = (int)$group[ 0 ];
$Index = (int)$group[ 1 ];
} else {
$ID = (int)$request->get( 'group' );
$Index = null;
}
$ValidProperties = [];
foreach( $this->GetGroupMapping() as $item ) {
if( $item[ 'ID' ] != $ID ) continue;
foreach( $item[ 'Listings' ] as $subitem ) {
if( !is_null( $Index ) && $Index != $subitem[ 'Index' ] ) continue;
$subitem_ids = explode( ',', $subitem[ 'Properties' ] );
foreach( $subitem_ids as $subitem_id ) {
$ValidProperties[] = $subitem_id;
}
}
}
$valid_group = in_array( $Property->getId(), $ValidProperties );
}
if( !$valid_group ) continue;
// Add the property...
$results[] = $Property;
}
$seo_name = \Pimcore\File::getValidFilename( 'properties-'.$state );
$seo = \Pimcore\Model\DataObject\VmCommercialSeo::getByPath( '/_DATA/COMMERCIAL/SEO/'.$seo_name );
return $this->render( ':Commercial:listing.html.php', [
'state' => $state,
'seo' => $seo,
'results' => $results
] );
}
if( $request->get( '_route' ) == 'CommProperties' ) {
$results = [];
$Listing = new \Pimcore\Model\DataObject\VmCommercialProperty\Listing();
$Listing->setOrderKey( 'Name' );
$Listing->getOrder( 'ASC' );
foreach( $Listing as $Property ) {
// Check types...
$valid_type = true;
if( !empty( $request->get( 'type' ) ) ) {
$valid_type = false;
$type = $request->get( 'type' );
foreach( $Property->getSearch_types() as $item ) {
if( $type == $item->getId() ) $valid_type = true;
}
}
if( !$valid_type ) continue;
// Check squate footage...
$valid_sqft_min = true;
if( $request->get( 'sqft_min' ) ) {
$valid_sqft_min = false;
if( (int)$Property->getSearch_sqft_min() >= (int)$request->get( 'sqft_min' ) ) $valid_sqft_min = true;
if( (int)$Property->getSearch_sqft_max() >= (int)$request->get( 'sqft_min' ) ) $valid_sqft_min = true;
}
$valid_sqft_max = true;
if( $request->get( 'sqft_max' ) ) {
$valid_sqft_max = false;
if( (int)$Property->getSearch_sqft_min() <= (int)$request->get( 'sqft_max' ) ) $valid_sqft_max = true;
if( (int)$Property->getSearch_sqft_max() <= (int)$request->get( 'sqft_max' ) ) $valid_sqft_max = true;
}
if( !$valid_sqft_min && !$valid_sqft_max ) continue;
// Check availability...
$valid_availability = true;
if( $request->get( 'available' ) && $request->get( 'available' ) == 'open' ) {
if( empty( $Property->getSearch_available_units() ) ) $valid_availability = false;
}
if( !$valid_availability ) continue;
// Check category...
$valid_group = true;
if( !empty( $request->get( 'group' ) ) ) {
if( strpos( $request->get( 'group' ), '_' ) !== false ) {
$group = explode( '_', $request->get( 'group' ) );
$ID = (int)$group[ 0 ];
$Index = (int)$group[ 1 ];
} else {
$ID = (int)$request->get( 'group' );
$Index = null;
}
$ValidProperties = [];
foreach( $this->GetGroupMapping() as $item ) {
if( $item[ 'ID' ] != $ID ) continue;
foreach( $item[ 'Listings' ] as $subitem ) {
if( !is_null( $Index ) && $Index != $subitem[ 'Index' ] ) continue;
$subitem_ids = explode( ',', $subitem[ 'Properties' ] );
foreach( $subitem_ids as $subitem_id ) {
$ValidProperties[] = $subitem_id;
}
}
}
$valid_group = in_array( $Property->getId(), $ValidProperties );
}
if( !$valid_group ) continue;
// Add the property...
$results[] = $Property;
}
$seo_name = \Pimcore\File::getValidFilename( 'properties' );
$seo = \Pimcore\Model\DataObject\VmCommercialSeo::getByPath( '/_DATA/COMMERCIAL/SEO/'.$seo_name );
return $this->render( ':Commercial:listing.html.php', [
'seo' => $seo,
'results' => $results
] );
}
}
private function GetPropertySubnav( $property ) {
// Return if not a property...
if( !( $property instanceof \Pimcore\Model\DataObject\VmCommercialProperty ) ) return null;
// The main property page url...
$main_url = $this->generateUrl( 'CommProperties S_C_P', [
'state' => $property->getSearch_slug_state(),
'city' => $property->getSearch_slug_city(),
'property' => $property->getKey()
] );
// Begin building the menu...
$menu = [];
// Add the location link...
if( !$property->getMapHidden() ) {
$menu[] = [ 'href' => $main_url.'#location', 'target' => null, 'text' => 'Location' ];
}
// Add the demographics link...
if( !$property->getStatsHidden() ) {
$menu[] = [ 'href' => $main_url.'#demographics', 'target' => null, 'text' => 'Demographics' ];
}
// Add the site plan link...
if( !$property->getSiteplanHidden() ) {
$menu[] = [ 'href' => $main_url.'#siteplan', 'target' => null, 'text' => 'Site Plan' ];
}
// Add the gallery and tenants links...
if( !$property->getBoxesHidden() ) {
if( $property->getGallery() && $property->getGallery()->isPublished() ) {
$menu[] = [
'href' => $property->getGallery()->getGalleryLink()->getHref(),
'target' => $property->getGallery()->getGalleryLink()->getTarget(),
'text' => $property->getGallery()->getGalleryLink()->getText()
];
}
if( $property->getTenants() && $property->getTenants()->isPublished() ) {
$menu[] = [
'href' => $property->getTenants()->getPortalLink()->getHref(),
'target' => $property->getTenants()->getPortalLink()->getTarget(),
'text' => $property->getTenants()->getPortalLink()->getText()
];
}
}
// Add the contact link...
if( $property->getContact() && $property->getContact()->isPublished() ) {
$menu[] = [
'href' => $this->generateUrl( 'CommProperties S_C_P Contact', [
'state' => $property->getSearch_slug_state(),
'city' => $property->getSearch_slug_city(),
'property' => $property->getKey()
] ),
'target' => null,
'text' => 'Contact'
];
}
// Add the main link and assemble the data...
return [
'Main' => [
'href' => $main_url,
'target' => null,
'text' => $property->getName()
],
'Menu' => $menu
];
}
public function PropertyMainAction( Request $request ) {
// Check property...
$key = \Pimcore\File::getValidFilename( $request->get( 'property' ) );
$property = \Pimcore\Model\DataObject\VmCommercialProperty::getByPath( '/_DATA/COMMERCIAL/PROPERTIES/'.$key );
if( !( $property instanceof \Pimcore\Model\DataObject\VmCommercialProperty ) ) {
throw new NotFoundHttpException( 'Not found' );
}
if( !$property->isPublished() ) {
throw new NotFoundHttpException( 'Not found' );
}
// Check city...
$city = $request->get( 'city' );
if( $property->getSearch_slug_city() != $city ) {
throw new NotFoundHttpException( 'Not found' );
}
// Check state...
$state = $request->get( 'state' );
if( $property->getSearch_slug_state() != $state ) {
throw new NotFoundHttpException( 'Not found' );
}
// Indexes for components...
$ComponentIndex = 0;
// Configure the commercialhero component...
$this->view->commercialhero = [];
if( !$property->getHeroHidden() ) {
$this->view->commercialhero = [
'is_template' => true,
'AreaIndex' => $ComponentIndex,
'AreaID' => 'commercialhero',
'HeroImageDesktop' => $property->getHeroImageDesktop(),
'HeroImageMobile' => $property->getHeroImageMobile(),
'Heading' => $property->getName(),
'Subheading' => $property->getDisplayCity().', '.$property->getDisplayState()
];
$ComponentIndex ++;
}
// Configure the commercialbasicintro component...
$this->view->commercialbasicintro = [];
if( !$property->getIntroHidden() ) {
$this->view->commercialbasicintro = [
'is_template' => true,
'AreaIndex' => $ComponentIndex,
'AreaID' => 'commercialbasicintro',
'IntroText' => $property->getIntroText(),
'IntroBgColor' => $property->getIntroBgColor(),
'IntroButtons' => $property->getIntroButtons()
];
$ComponentIndex ++;
}
// Configure the commercialsidebymap component...
$this->view->commercialsidebymap = [];
if( !$property->getMapHidden() ) {
$this->view->commercialsidebymap = [
'is_template' => true,
'AreaIndex' => $ComponentIndex,
'AreaID' => 'commercialsidebymap',
'PropertyName' => $property->getName(),
'Latitude' => $property->getLatitude(),
'Longitude' => $property->getLongitude(),
'Zoom' => $property->getZoom(),
'Address' => $property->getAddress(),
'Description' => $property->getDescription(),
'GetDirections' => $property->getGetDirections(),
'GetBrochure' => $property->getGetBrochure(),
'ContactData' => $property->getContactData()
];
$ComponentIndex ++;
}
// Configure the commercialstatistics component...
$this->view->commercialstatistics = [];
if( !$property->getStatsHidden() ) {
$this->view->commercialstatistics = [
'is_template' => true,
'AreaIndex' => $ComponentIndex,
'AreaID' => 'commercialstatistics',
'Stats' => $property->getStats()
];
$ComponentIndex ++;
}
// Configure the commercialsiteplan component...
$this->view->commercialsiteplan = [];
if( !$property->getSiteplanHidden() ) {
$this->view->commercialsiteplan = [
'is_template' => true,
'AreaIndex' => $ComponentIndex,
'AreaID' => 'commercialsiteplan',
'ButtonLink' => $property->getButtonLink(),
'Siteplans' => $property->getSiteplans()
];
$ComponentIndex ++;
}
// Configure the commercialboxlinks component...
$this->view->commercialboxlinks = [];
if( !$property->getBoxesHidden() ) {
if( $property->getGallery() && $property->getTenants() ) {
if( $property->getGallery()->isPublished() && $property->getTenants()->isPublished() ) {
$Boxes = [ [
'Image' => $property->getGallery()->getPreviewImage(),
'Link' => [
'href' => $property->getGallery()->getGalleryLink()->getHref(),
'target' => $property->getGallery()->getGalleryLink()->getTarget(),
'text' => $property->getGallery()->getGalleryLink()->getText()
]
],[
'Image' => $property->getTenants()->getPreviewImage(),
'Link' => [
'href' => $property->getTenants()->getPortalLink()->getHref(),
'target' => $property->getTenants()->getPortalLink()->getTarget(),
'text' => $property->getTenants()->getPortalLink()->getText()
]
] ];
$this->view->commercialboxlinks = [
'is_template' => true,
'AreaIndex' => $ComponentIndex,
'AreaID' => 'commercialboxlinks',
'Boxes' => $Boxes
];
$ComponentIndex ++;
}
}
}
// Configure the commercialnearbyproperties component...
$this->view->commercialnearbyproperties = [];
if( !$property->getNearbyHidden() ) {
$this->view->commercialnearbyproperties = [
'is_template' => true,
'AreaIndex' => $ComponentIndex,
'AreaID' => 'commercialnearbyproperties',
'NearbyProperties' => $property->getNearbyProperties()
];
$ComponentIndex ++;
}
// Configure the SEO title and description...
$this->view->SeoTitle = $property->getSeoTitle();
$this->view->SeoDescription = $property->getSeoDescription();
// Configure the property nav template...
$this->view->propertynav = $this->GetPropertySubnav( $property );
}
public function PropertyGalleryAction( Request $request ) {
/*
ROUTES:
CommProperties S_C_P Gallery /properties/%state/%city/%property/gallery
*/
}
public function PropertyTenantsAction( Request $request ) {
/*
ROUTES:
CommProperties S_C_P Tenants /properties/%state/%city/%property/tenants
*/
}
public function PropertyContactAction( Request $request ) {
/*
ROUTES:
CommProperties S_C_P Contact /properties/%state/%city/%property/contact
*/
// Check property...
$key = \Pimcore\File::getValidFilename( $request->get( 'property' ) );
$property = \Pimcore\Model\DataObject\VmCommercialProperty::getByPath( '/_DATA/COMMERCIAL/PROPERTIES/'.$key );
if( !( $property instanceof \Pimcore\Model\DataObject\VmCommercialProperty ) ) {
throw new NotFoundHttpException( 'Not found' );
}
if( !$property->isPublished() ) {
throw new NotFoundHttpException( 'Not found' );
}
// Check city...
$city = $request->get( 'city' );
if( $property->getSearch_slug_city() != $city ) {
throw new NotFoundHttpException( 'Not found' );
}
// Check state...
$state = $request->get( 'state' );
if( $property->getSearch_slug_state() != $state ) {
throw new NotFoundHttpException( 'Not found' );
}
// Check the contact form...
if( !$property->getContact() || !$property->getContact()->isPublished() ) {
throw new NotFoundHttpException( 'Not found' );
}
// Indexes for components...
$ComponentIndex = 0;
// Configure the commercialcontactform component...
$this->view->commercialcontactform = [
'is_template' => true,
'AreaIndex' => $ComponentIndex,
'AreaID' => 'commercialcontactform',
'ContactObject' => $property->getContact()
];
$ComponentIndex ++;
// Configure the SEO title and description...
$this->view->SeoTitle = $property->getContact()->getSeoTitle();
$this->view->SeoDescription = $property->getContact()->getSeoDescription();
// Configure the property nav template...
$this->view->propertynav = $this->GetPropertySubnav( $property );
}
public function GetGroupMapping() {
$GroupMap = [];
$Listing = new \Pimcore\Model\DataObject\VmCommercialGroup\Listing();
$Listing->setOrderKey( 'Name' );
$Listing->setOrder( 'ASC' );
foreach( $Listing as $VmCommercialGroup ) {
$GroupListings = [];
foreach( $VmCommercialGroup->getListings() as $i => $Subgroup ) {
// Start off empty...
$GroupListingProperties = [];
// Iterate over the properties...
foreach( $Subgroup[ 'listing_properties' ]->getData() as $Property ) {
// Skip if it's not a property (because it could be a services object)...
if( !( $Property instanceof \Pimcore\Model\DataObject\VmCommercialProperty ) ) continue;
// Add it...
$GroupListingProperties[] = $Property->getId();
}
// Skip if no properties were listed...
if( empty( $GroupListingProperties ) ) continue;
// Add it...
$GroupListings[] = [
'Index' => $i,
'Title' => $Subgroup[ 'listing_title' ]->getData(),
'Properties' => implode( ',', $GroupListingProperties )
];
}
// Skip if no properties were listed...
if( empty( $GroupListings ) ) continue;
// Add it...
$GroupMap[] = [
'ID' => $VmCommercialGroup->getId(),
'Name' => $VmCommercialGroup->getName(),
'Listings' => $GroupListings
];
}
return $GroupMap;
}
public function searchdataAction( Request $request )
{
/*
ROUTES:
SearchData /searchdata
*/
header( 'Content-Type: application/json' );
die( json_encode( [
'PropertiesBaseUrl' => $this->generateUrl( 'CommProperties', [] ),
'PropertiesMapping' => $this->GetCommercialMapping(),
'GroupMapping' => $this->GetGroupMapping(),
'TypeMapping' => $this->GetTypeMapping()
] ) );
}
public function FavoritesAction( Request $Request ) {
/*
ROUTES:
Favorites: /favorites
*/
$results = [];
if( !empty( $_COOKIE[ 'vmcomm-favorites' ] ) ) {
$favorite_ids = explode( ',', $_COOKIE[ 'vmcomm-favorites' ] );
$Listing = new \Pimcore\Model\DataObject\VmCommercialProperty\Listing();
$Listing->setOrderKey( 'Name' );
$Listing->getOrder( 'ASC' );
foreach( $Listing as $Property ) {
// Check if the id is in our favorites...
if( !in_array( $Property->getId(), $favorite_ids ) ) continue;
// Add property to results...
$results[] = $Property;
}
}
return $this->render( ':Commercial:listing.html.php', [
'route' => $Request->get( '_route' ),
'results' => $results
] );
}
}