src/AppBundle/Controller/CommercialController.php line 629

Open in your IDE?
  1. <?php
  2.     // REFACTOR FROM HOMES TO COMMERCIAL
  3.     namespace AppBundle\Controller;
  4.     use Pimcore\Controller\FrontendController;
  5.     use Symfony\Component\Cache\Simple\FilesystemCache;
  6.     use Symfony\Component\HttpFoundation\Request;
  7.     use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  8.     class CommercialController extends FrontendController
  9.     {
  10.         public static function HandleContactForm$contact_object_id 0$fields = [] ) {
  11.             // Attempt retrieval of the contact object...
  12.             $VmCommercialPropertyContact = \Pimcore\Model\DataObject::getById$contact_object_id );
  13.             if( !( $VmCommercialPropertyContact instanceof \Pimcore\Model\DataObject\VmCommercialPropertyContact ) ) {
  14.                 return 'Error: Invalid Object!';
  15.             }
  16.             // Check for a valid recipient email...
  17.             if( !filter_var$VmCommercialPropertyContact->getEmail(), FILTER_VALIDATE_EMAIL ) ) {
  18.                 return 'Error: Misconfigured Email!';
  19.             }
  20.             // Check to see if any fields were submitted...
  21.             if( empty( $fields ) ) {
  22.                 return 'Error: Empty Fields!';
  23.             }
  24.             // reCaptcha
  25.             $reCaptchaRes self::post_captcha$_POST'g-recaptcha-response' ] );
  26.             if( !$reCaptchaRes'success'] ) return 'Please be sure to check the security CAPTCHA box.';
  27.             // Construct the message body...
  28.             $MailText null;
  29.             $MailHtml null;
  30.             foreach( $fields as $field ) {
  31.                 $MailText .= "\n".$field'label' ].": ".$field'value' ];
  32.                 $MailHtml .= '<p><strong>'.$field'label' ].':</strong><br/>'.$field'value' ].'</p>';
  33.             }
  34.             // Compose an email...
  35.             $Mail = new \Pimcore\Mail$VmCommercialPropertyContact->getSubject() );
  36.             $Mail->addTo$VmCommercialPropertyContact->getEmail() );
  37.             $Mail->setFrom'no-reply@vanmetrecommercial.com''Van Metre Commercial (No Reply)' );
  38.             $Mail->setReplyTo'no-reply@vanmetrecommercial.com''Van Metre Commercial (No Reply)' );
  39.             $Mail->setBodyText$MailText );
  40.             $Mail->setBodyHtml$MailHtml );
  41.             // Return the result of the mail send method...
  42.             if( $Mail->send() ) {
  43.                 // Try saving a copy of the message in Pimcore...
  44.                 $ReceiptDir = \Pimcore\Model\DataObject::getByPath'/_DATA/COMMERCIAL/RECEIPTS/' );
  45.                 if( $ReceiptDir instanceof \Pimcore\Model\DataObject\Folder ) {
  46.                     $Receipt = new \Pimcore\Model\DataObject\VmCommercialPropertyContactReceipt();
  47.                     $Receipt->setKeydate'Y-m-d-H-i-s' ) );
  48.                     $Receipt->setParent$ReceiptDir );
  49.                     $Receipt->setMailText$MailText );
  50.                     $Receipt->setMailHtml$MailHtml );
  51.                     $Receipt->save();
  52.                 }
  53.                 // Return a success message...
  54.                 return 'Success: Mail Sent!';
  55.             }
  56.             // Return unspecified error...
  57.             return 'Error: Unspecified';
  58.         }
  59.         // Function to handle verification of reCAPTCHA on server side.
  60.         private static function post_captcha$user_response ) {
  61.             $fields_string '';
  62.             $fields = array(
  63.                 'secret' => '6LfTvr0UAAAAAJNI5s0-6CMlzbeKQJyRWxU6qs7K',
  64.                 'response' => $user_response
  65.             );
  66.             // Build POST req fields string.
  67.             foreach( $fields as $key=>$value ) {
  68.                 $fields_string .= $key '=' .$value '&';
  69.             }
  70.             $fields_string rtrim$fields_string'&' );
  71.             $ch curl_init();
  72.             curl_setopt$chCURLOPT_URL'https://www.google.com/recaptcha/api/siteverify');
  73.             curl_setopt$chCURLOPT_POSTcount$fields ) );
  74.             curl_setopt$chCURLOPT_POSTFIELDS$fields_string );
  75.             curl_setopt$chCURLOPT_RETURNTRANSFERtrue );
  76.             $result curl_exec$ch );
  77.             curl_close$ch );
  78.             return json_decode$resulttrue );
  79.         }
  80.         private static function GetTypeMapping()
  81.         {
  82.             // Get all property types...
  83.             $listing = new \Pimcore\Model\DataObject\VmCommercialPropertyType\Listing();
  84.             $listing->setCondition'o_path = ?', [ '/_DATA/COMMERCIAL/TYPES/' ] );
  85.             $types = [];
  86.             foreach( $listing as $type ) {
  87.                 $sublisting = new \Pimcore\Model\DataObject\VmCommercialPropertyType\Listing();
  88.                 $sublisting->setCondition'o_parentId = ?', [ $type->getId() ] );
  89.                 $subtypes = [];
  90.                 foreach( $sublisting as $subtype ) {
  91.                     $subtypes[] = [
  92.                         'id' => $subtype->getId(),
  93.                         'key' => $subtype->getKey(),
  94.                         'subtypes' => []
  95.                     ];
  96.                 }
  97.                 $types[] = [
  98.                     'id' => $type->getId(),
  99.                     'key' => $type->getKey(),
  100.                     'subtypes' => $subtypes
  101.                 ];
  102.             }
  103.             return $types;
  104.         }
  105.         private static function GetCommercialMapping()
  106.         {
  107.             
  108.             // Get all of our property objects that are published...
  109.             $listing = new \Pimcore\Model\DataObject\VmCommercialProperty\Listing();
  110.             $listing->setCondition'o_path = ?', [ '/_DATA/COMMERCIAL/PROPERTIES/' ] );
  111.             // Create state level keys in the map array...
  112.             // foreach( $listing as $property ) $map[ $property->getSearchSlugState() ] = [];
  113.             // Create child city keys in the map array...
  114.             $map = [];
  115.             foreach ( $listing as $property ) {
  116.                 $state                          strtolower$property->getSearch_slug_state() );
  117.                 $city                           strtolower$property->getSearch_slug_city() );
  118.                 $key                            $property->getKey();
  119.                 $name                           $property->getName();
  120.                 $map$state ][ $city ][ $key ] = $name;
  121.             }
  122.             // Alphabetize...
  123.             // uksort( $map, function ( $a, $b ) {
  124.             //     return count( $b ) - count( $a );
  125.             // } );
  126.             krsort$map );
  127.             foreach ( $map as $i => &$state ) {
  128.                 ksort$state );
  129.                 foreach ( $state as $ii => &$city ) {
  130.                     asort$city );
  131.                 }
  132.             }
  133.             // Return the map...
  134.             return $map;
  135.         }
  136.         public function CommercialNavigation()
  137.         {
  138.             // Retrieve Site ID...
  139.             if ( \Pimcore\Model\Site::isSiteRequest() ) {
  140.                 $site = \Pimcore\Model\Site::getCurrentSite();
  141.                 $root $site->getRootDocument();
  142.             } else {
  143.                 $root = \Pimcore\Model\Document::getByPath'/home-commercial/' );
  144.                 $site = \Pimcore\Tool\Frontend::getSiteForDocument$root );
  145.             }
  146.             // State Labels...
  147.             $state_label = [ 'dc' => 'District of Columbia'
  148.                 'al' => 'Alabama',     'hi' => 'Hawaii',    'ma' => 'Massachusetts''nm' => 'New Mexico',     'sd' => 'South Dakota'
  149.                 'ak' => 'Alaska',      'id' => 'Idaho',     'mi' => 'Michigan',      'ny' => 'New York',       'tn' => 'Tennessee'
  150.                 'az' => 'Arizona',     'il' => 'Illinois',  'mn' => 'Minnesota',     'nc' => 'North Carolina''tx' => 'Texas'
  151.                 'ar' => 'Arkansas',    'in' => 'Indiana',   'ms' => 'Mississippi',   'nd' => 'North Dakota',   'ut' => 'Utah'
  152.                 'ca' => 'California',  'ia' => 'Iowa',      'mo' => 'Missouri',      'oh' => 'Ohio',           'vt' => 'Vermont'
  153.                 'co' => 'Colorado',    'ks' => 'Kansas',    'mt' => 'Montana',       'ok' => 'Oklahoma',       'va' => 'Virginia'
  154.                 'ct' => 'Connecticut''ky' => 'Kentucky',  'ne' => 'Nebraska',      'or' => 'Oregon',         'wa' => 'Washington'
  155.                 'de' => 'Delaware',    'la' => 'Louisiana''nv' => 'Nevada',        'pa' => 'Pennsylvania',   'wv' => 'West Virginia'
  156.                 'fl' => 'Florida',     'me' => 'Maine',     'nh' => 'New Hampshire''ri' => 'Rhode Island',   'wi' => 'Wisconsin'
  157.                 'ga' => 'Georgia',     'md' => 'Maryland',  'nj' => 'New Jersey',    'sc' => 'South Carolina''wy' => 'Wyoming'
  158.             ];
  159.             // Get the property hierarchy...
  160.             $property_map self::GetCommercialMapping();
  161.             // Generate the menu...
  162.             $state_menu null;
  163.             foreach ( $property_map as $state => $state_data ) {
  164.                 $city_menu null;
  165.                 foreach ( $state_data as $city => $city_data ) {
  166.                     $property_menu null;
  167.                     foreach ( $city_data as $property => $property_data ) {
  168.                         $property_url  $this->generateUrl'CommProperties S_C_P', [ 'state' => $state'city' => $city'property' => $property'site' => $site->getId() ] );
  169.                         $property_menu .= '<li><a href="'.$property_url.'">'.$property_data.'</a></li>';
  170.                     }
  171.                     if ( !empty( $property_menu ) ) {
  172.                         $city_url  $this->generateUrl'CommProperties S_C', [ 'state' => $state'city' => $city'site' => $site->getId() ] );
  173.                         $city_menu .= '<li><a href="'.$city_url.'">'.ucwordspreg_replace"/[^A-Za-z0-9 ]/"''$city ) ).'</a><ul>'.$property_menu.'</ul></li>';
  174.                     }
  175.                 }
  176.                 if ( !empty( $city_menu ) ) {
  177.                     $state_url  $this->generateUrl'CommProperties S', [ 'state' => $state'site' => $site->getId() ] );
  178.                     $state_menu .= '<li><a href="'.$state_url.'">'.$state_label$state ].'</a><ul>'.$city_menu.'</ul></li>';
  179.                 }
  180.             }
  181.             $properties_menu null;
  182.             if ( !empty( $state_menu ) ) {
  183.                 $properties_menu .= '<ul>'.$state_menu.'</ul>';
  184.             }
  185.             // $site = \Pimcore\Model\Site::getCurrentSite();
  186.             // $root = $site->getRootDocument();
  187.             $pages = new \Pimcore\Model\Document\Listing();
  188.             $pages->setCondition'parentId = ?', [ $root->getId() ] );
  189.             $pages->setOrderKey'index' );
  190.             $pages->setOrder'ASC' );
  191.             $nav_menu null
  192.             .'<li>'
  193.                 .'<a href="'.$this->generateUrl'CommProperties', [ 'site' => $site->getId() ] ).'">Properties</a>'
  194.                 .$properties_menu
  195.             .'</li>';
  196.             foreach ( $pages as $page ) {
  197.                 if ( !( $page instanceof \Pimcore\Model\Document\Page ) ) continue;
  198.                 if ( $page->getProperty'navigation_exclude' ) ) continue;
  199.                 $subpages = new \Pimcore\Model\Document\Listing();
  200.                 $subpages->setCondition'parentId = ?', [ $page->getId() ] );
  201.                 $subpages->setOrderKey'index' );
  202.                 $subpages->setOrder'ASC' );
  203.                 $subnav_menu null;
  204.                 foreach ( $subpages as $subpage ) {
  205.                     if( $subpage->getProperty'navigation_exclude' ) ) continue;
  206.                     if( $subpage instanceof \Pimcore\Model\Document\Page ) {
  207.                         $subnav_menu .= '<li><a href="'.$subpage->getFullPath().'">'.$subpage->getProperty'navigation_name' ).'</a></li>';
  208.                     }
  209.                     if( $subpage instanceof \Pimcore\Model\Document\Link ) {
  210.                         $subnav_menu .= '<li><a href="'.$subpage->getFullPath().'" target="'.$subpage->getProperty'navigation_target' ).'">'.$subpage->getProperty'navigation_name' ).'</a></li>';
  211.                     }
  212.                 }
  213.                 if ( !empty( $subnav_menu ) ) $subnav_menu '<ul>'.$subnav_menu.'</ul>';
  214.                 if( $page instanceof \Pimcore\Model\Document\Page ) {
  215.                     $nav_menu .= '<li><a href="'.$page->getFullPath().'">'.$page->getProperty'navigation_name' ).'</a>'.$subnav_menu.'</li>';
  216.                 }
  217.                 if( $page instanceof \Pimcore\Model\Document\Link ) {
  218.                     $nav_menu .= '<li><a href="'.$page->getFullPath().'" target="'.$page->getProperty'navigation_target' ).'">'.$page->getProperty'navigation_name' ).'</a>'.$subnav_menu.'</li>';
  219.                 }
  220.             }
  221.             if ( !empty( $nav_menu ) ) $nav_menu '<ul>'.$nav_menu.'</ul>';
  222.             return $this->render':Includes:commercial-header-view.html.php', [
  223.                 'menu' => $nav_menu
  224.             ] );
  225.         }
  226.         public function PropertiesListActionRequest $request ) {
  227.             /*
  228.             ROUTES:
  229.             CommProperties S_C_P    /properties/%state/%city/%property
  230.             CommProperties S_C        /properties/%state/%city
  231.             CommProperties S        /properties/%state
  232.             CommProperties            /properties
  233.             */
  234.             if( $request->get'_route' ) == 'CommProperties S_C' ) {
  235.                 $map $this->GetCommercialMapping();
  236.                 $state $request->get'state' );
  237.                 $city $request->get'city' );
  238.                 if( !isset( $map$state ][ $city ] ) ) {
  239.                     throw new NotFoundHttpException'Not found' );
  240.                 }
  241.                 $results = [];
  242.                 $Listing = new \Pimcore\Model\DataObject\VmCommercialProperty\Listing();
  243.                 $Listing->setOrderKey'Name' );
  244.                 $Listing->getOrder'ASC' );
  245.                 foreach( $Listing as $Property ) {
  246.                     // Check location...
  247.                     if( $Property->getSearch_slug_state() != $state ) continue;
  248.                     if( $Property->getSearch_slug_city() != $city ) continue;
  249.                     // Check types...
  250.                     $valid_type true;
  251.                     if( !empty( $request->get'type' ) ) ) {
  252.                         $valid_type false;
  253.                         $type $request->get'type' );
  254.                         foreach( $Property->getSearch_types() as $item ) {
  255.                             if( $type == $item->getId() ) $valid_type true;
  256.                         }
  257.                     }
  258.                     if( !$valid_type ) continue;
  259.                     // Check squate footage...
  260.                     $valid_sqft_min true;
  261.                     if( $request->get'sqft_min' ) ) {
  262.                         $valid_sqft_min false;
  263.                         if( (int)$Property->getSearch_sqft_min() >= (int)$request->get'sqft_min' ) ) $valid_sqft_min true;
  264.                         if( (int)$Property->getSearch_sqft_max() >= (int)$request->get'sqft_min' ) ) $valid_sqft_min true;
  265.                     }
  266.                     $valid_sqft_max true;
  267.                     if( $request->get'sqft_max' ) ) {
  268.                         $valid_sqft_max false;
  269.                         if( (int)$Property->getSearch_sqft_min() <= (int)$request->get'sqft_max' ) ) $valid_sqft_max true;
  270.                         if( (int)$Property->getSearch_sqft_max() <= (int)$request->get'sqft_max' ) ) $valid_sqft_max true;
  271.                     }
  272.                     if( !$valid_sqft_min && !$valid_sqft_max ) continue;
  273.                     // Check availability...
  274.                     $valid_availability true;
  275.                     if( $request->get'available' ) && $request->get'available' ) == 'open' ) {
  276.                         if( empty( $Property->getSearch_available_units() ) ) $valid_availability false;
  277.                     }
  278.                     if( !$valid_availability ) continue;
  279.                     // Check category...
  280.                     $valid_group true;
  281.                     if( !empty( $request->get'group' ) ) ) {
  282.                         if( strpos$request->get'group' ), '_' ) !== false ) {
  283.                             $group explode'_'$request->get'group' ) );
  284.                             $ID = (int)$group];
  285.                             $Index = (int)$group];
  286.                         } else {
  287.                             $ID = (int)$request->get'group' );
  288.                             $Index null;
  289.                         }
  290.                         $ValidProperties = [];
  291.                         foreach( $this->GetGroupMapping() as $item ) {
  292.                             if( $item'ID' ] != $ID ) continue;
  293.                             foreach( $item'Listings' ] as $subitem ) {
  294.                                 if( !is_null$Index ) && $Index != $subitem'Index' ] ) continue;
  295.                                 $subitem_ids explode','$subitem'Properties' ] );
  296.                                 foreach( $subitem_ids as $subitem_id ) {
  297.                                     $ValidProperties[] = $subitem_id;
  298.                                 }
  299.                             }
  300.                         }
  301.                         $valid_group in_array$Property->getId(), $ValidProperties );
  302.                     }
  303.                     if( !$valid_group ) continue;
  304.                     // Add the property...
  305.                     $results[] = $Property;
  306.                 }
  307.                 $seo_name = \Pimcore\File::getValidFilename'properties-'.$state.'-'.$city );
  308.                 $seo = \Pimcore\Model\DataObject\VmCommercialSeo::getByPath'/_DATA/COMMERCIAL/SEO/'.$seo_name );
  309.                 return $this->render':Commercial:listing.html.php', [
  310.                     'state'   => $state,
  311.                     'city'    => $city,
  312.                     'seo'     => $seo,
  313.                     'results' => $results
  314.                 ] );
  315.             }
  316.             if( $request->get'_route' ) == 'CommProperties S' ) {
  317.                 $map $this->GetCommercialMapping();
  318.                 $state $request->get'state' );
  319.                 if( !isset( $map$state ] ) ) {
  320.                     throw new NotFoundHttpException'Not found' );
  321.                 }
  322.                 $results = [];
  323.                 $Listing = new \Pimcore\Model\DataObject\VmCommercialProperty\Listing();
  324.                 $Listing->setOrderKey'Name' );
  325.                 $Listing->getOrder'ASC' );
  326.                 foreach( $Listing as $Property ) {
  327.                     // Check location...
  328.                     if( $Property->getSearch_slug_state() != $state ) continue;
  329.                     // Check types...
  330.                     $valid_type true;
  331.                     if( !empty( $request->get'type' ) ) ) {
  332.                         $valid_type false;
  333.                         $type $request->get'type' );
  334.                         foreach( $Property->getSearch_types() as $item ) {
  335.                             if( $type == $item->getId() ) $valid_type true;
  336.                         }
  337.                     }
  338.                     if( !$valid_type ) continue;
  339.                     // Check squate footage...
  340.                     $valid_sqft_min true;
  341.                     if( $request->get'sqft_min' ) ) {
  342.                         $valid_sqft_min false;
  343.                         if( (int)$Property->getSearch_sqft_min() >= (int)$request->get'sqft_min' ) ) $valid_sqft_min true;
  344.                         if( (int)$Property->getSearch_sqft_max() >= (int)$request->get'sqft_min' ) ) $valid_sqft_min true;
  345.                     }
  346.                     $valid_sqft_max true;
  347.                     if( $request->get'sqft_max' ) ) {
  348.                         $valid_sqft_max false;
  349.                         if( (int)$Property->getSearch_sqft_min() <= (int)$request->get'sqft_max' ) ) $valid_sqft_max true;
  350.                         if( (int)$Property->getSearch_sqft_max() <= (int)$request->get'sqft_max' ) ) $valid_sqft_max true;
  351.                     }
  352.                     if( !$valid_sqft_min && !$valid_sqft_max ) continue;
  353.                     // Check availability...
  354.                     $valid_availability true;
  355.                     if( $request->get'available' ) && $request->get'available' ) == 'open' ) {
  356.                         if( empty( $Property->getSearch_available_units() ) ) $valid_availability false;
  357.                     }
  358.                     if( !$valid_availability ) continue;
  359.                     // Check category...
  360.                     $valid_group true;
  361.                     if( !empty( $request->get'group' ) ) ) {
  362.                         if( strpos$request->get'group' ), '_' ) !== false ) {
  363.                             $group explode'_'$request->get'group' ) );
  364.                             $ID = (int)$group];
  365.                             $Index = (int)$group];
  366.                         } else {
  367.                             $ID = (int)$request->get'group' );
  368.                             $Index null;
  369.                         }
  370.                         $ValidProperties = [];
  371.                         foreach( $this->GetGroupMapping() as $item ) {
  372.                             if( $item'ID' ] != $ID ) continue;
  373.                             foreach( $item'Listings' ] as $subitem ) {
  374.                                 if( !is_null$Index ) && $Index != $subitem'Index' ] ) continue;
  375.                                 $subitem_ids explode','$subitem'Properties' ] );
  376.                                 foreach( $subitem_ids as $subitem_id ) {
  377.                                     $ValidProperties[] = $subitem_id;
  378.                                 }
  379.                             }
  380.                         }
  381.                         $valid_group in_array$Property->getId(), $ValidProperties );
  382.                     }
  383.                     if( !$valid_group ) continue;
  384.                     // Add the property...
  385.                     $results[] = $Property;
  386.                 }
  387.                 $seo_name = \Pimcore\File::getValidFilename'properties-'.$state );
  388.                 $seo = \Pimcore\Model\DataObject\VmCommercialSeo::getByPath'/_DATA/COMMERCIAL/SEO/'.$seo_name );
  389.                 return $this->render':Commercial:listing.html.php', [
  390.                     'state'   => $state,
  391.                     'seo'     => $seo,
  392.                     'results' => $results
  393.                 ] );
  394.             }
  395.             if( $request->get'_route' ) == 'CommProperties' ) {
  396.                 $results = [];
  397.                 $Listing = new \Pimcore\Model\DataObject\VmCommercialProperty\Listing();
  398.                 $Listing->setOrderKey'Name' );
  399.                 $Listing->getOrder'ASC' );
  400.                 foreach( $Listing as $Property ) {
  401.                     // Check types...
  402.                     $valid_type true;
  403.                     if( !empty( $request->get'type' ) ) ) {
  404.                         $valid_type false;
  405.                         $type $request->get'type' );
  406.                         foreach( $Property->getSearch_types() as $item ) {
  407.                             if( $type == $item->getId() ) $valid_type true;
  408.                         }
  409.                     }
  410.                     if( !$valid_type ) continue;
  411.                     // Check squate footage...
  412.                     $valid_sqft_min true;
  413.                     if( $request->get'sqft_min' ) ) {
  414.                         $valid_sqft_min false;
  415.                         if( (int)$Property->getSearch_sqft_min() >= (int)$request->get'sqft_min' ) ) $valid_sqft_min true;
  416.                         if( (int)$Property->getSearch_sqft_max() >= (int)$request->get'sqft_min' ) ) $valid_sqft_min true;
  417.                     }
  418.                     $valid_sqft_max true;
  419.                     if( $request->get'sqft_max' ) ) {
  420.                         $valid_sqft_max false;
  421.                         if( (int)$Property->getSearch_sqft_min() <= (int)$request->get'sqft_max' ) ) $valid_sqft_max true;
  422.                         if( (int)$Property->getSearch_sqft_max() <= (int)$request->get'sqft_max' ) ) $valid_sqft_max true;
  423.                     }
  424.                     if( !$valid_sqft_min && !$valid_sqft_max ) continue;
  425.                     // Check availability...
  426.                     $valid_availability true;
  427.                     if( $request->get'available' ) && $request->get'available' ) == 'open' ) {
  428.                         if( empty( $Property->getSearch_available_units() ) ) $valid_availability false;
  429.                     }
  430.                     if( !$valid_availability ) continue;
  431.                     // Check category...
  432.                     $valid_group true;
  433.                     if( !empty( $request->get'group' ) ) ) {
  434.                         if( strpos$request->get'group' ), '_' ) !== false ) {
  435.                             $group explode'_'$request->get'group' ) );
  436.                             $ID = (int)$group];
  437.                             $Index = (int)$group];
  438.                         } else {
  439.                             $ID = (int)$request->get'group' );
  440.                             $Index null;
  441.                         }
  442.                         $ValidProperties = [];
  443.                         foreach( $this->GetGroupMapping() as $item ) {
  444.                             if( $item'ID' ] != $ID ) continue;
  445.                             foreach( $item'Listings' ] as $subitem ) {
  446.                                 if( !is_null$Index ) && $Index != $subitem'Index' ] ) continue;
  447.                                 $subitem_ids explode','$subitem'Properties' ] );
  448.                                 foreach( $subitem_ids as $subitem_id ) {
  449.                                     $ValidProperties[] = $subitem_id;
  450.                                 }
  451.                             }
  452.                         }
  453.                         $valid_group in_array$Property->getId(), $ValidProperties );
  454.                     }
  455.                     if( !$valid_group ) continue;
  456.                     // Add the property...
  457.                     $results[] = $Property;
  458.                 }
  459.                 $seo_name = \Pimcore\File::getValidFilename'properties' );
  460.                 $seo = \Pimcore\Model\DataObject\VmCommercialSeo::getByPath'/_DATA/COMMERCIAL/SEO/'.$seo_name );
  461.                 return $this->render':Commercial:listing.html.php', [
  462.                     'seo'     => $seo,
  463.                     'results' => $results
  464.                 ] );
  465.             }
  466.         }
  467.         private function GetPropertySubnav$property ) {
  468.             // Return if not a property...
  469.             if( !( $property instanceof \Pimcore\Model\DataObject\VmCommercialProperty ) ) return null;
  470.             // The main property page url...
  471.             $main_url $this->generateUrl'CommProperties S_C_P', [
  472.                 'state'    => $property->getSearch_slug_state(),
  473.                 'city'     => $property->getSearch_slug_city(),
  474.                 'property' => $property->getKey()
  475.             ] );
  476.             // Begin building the menu...
  477.             $menu = [];
  478.             // Add the location link...
  479.             if( !$property->getMapHidden() ) {
  480.                 $menu[] = [ 'href' => $main_url.'#location''target' => null'text' => 'Location' ];
  481.             }
  482.             // Add the demographics link...
  483.             if( !$property->getStatsHidden() ) {
  484.                 $menu[] = [ 'href' => $main_url.'#demographics''target' => null'text' => 'Demographics' ];
  485.             }
  486.             // Add the site plan link...
  487.             if( !$property->getSiteplanHidden() ) {
  488.                 $menu[] = [ 'href' => $main_url.'#siteplan''target' => null'text' => 'Site Plan' ];
  489.             }
  490.             // Add the gallery and tenants links...
  491.             if( !$property->getBoxesHidden() ) {
  492.                 if( $property->getGallery() && $property->getGallery()->isPublished() ) {
  493.                     $menu[] = [
  494.                         'href'   => $property->getGallery()->getGalleryLink()->getHref(),
  495.                         'target' => $property->getGallery()->getGalleryLink()->getTarget(),
  496.                         'text'   => $property->getGallery()->getGalleryLink()->getText()
  497.                     ];
  498.                 }
  499.                 if( $property->getTenants() && $property->getTenants()->isPublished() ) {
  500.                     $menu[] = [
  501.                         'href'   => $property->getTenants()->getPortalLink()->getHref(),
  502.                         'target' => $property->getTenants()->getPortalLink()->getTarget(),
  503.                         'text'   => $property->getTenants()->getPortalLink()->getText()
  504.                     ];
  505.                 }
  506.             }
  507.             // Add the contact link...
  508.             if( $property->getContact() && $property->getContact()->isPublished() ) {
  509.                 $menu[] = [
  510.                     'href'   => $this->generateUrl'CommProperties S_C_P Contact', [
  511.                         'state'    => $property->getSearch_slug_state(),
  512.                         'city'     => $property->getSearch_slug_city(),
  513.                         'property' => $property->getKey()
  514.                     ] ),
  515.                     'target' => null,
  516.                     'text'   => 'Contact'
  517.                 ];
  518.             }
  519.             // Add the main link and assemble the data...
  520.             return [
  521.                 'Main' => [
  522.                     'href'   => $main_url,
  523.                     'target' => null,
  524.                     'text'   => $property->getName()
  525.                 ],
  526.                 'Menu' => $menu
  527.             ];
  528.         }
  529.         public function PropertyMainActionRequest $request ) {
  530.             // Check property...
  531.             $key = \Pimcore\File::getValidFilename$request->get'property' ) );
  532.             $property = \Pimcore\Model\DataObject\VmCommercialProperty::getByPath'/_DATA/COMMERCIAL/PROPERTIES/'.$key );
  533.             if( !( $property instanceof \Pimcore\Model\DataObject\VmCommercialProperty ) ) {
  534.                 throw new NotFoundHttpException'Not found' );
  535.             }
  536.             if( !$property->isPublished() ) {
  537.                 throw new NotFoundHttpException'Not found' );
  538.             }
  539.             // Check city...
  540.             $city $request->get'city' );
  541.             if( $property->getSearch_slug_city() != $city ) {
  542.                 throw new NotFoundHttpException'Not found' );
  543.             }
  544.             // Check state...
  545.             $state $request->get'state' );
  546.             if( $property->getSearch_slug_state() != $state ) {
  547.                 throw new NotFoundHttpException'Not found' );
  548.             }
  549.             // Indexes for components...
  550.             $ComponentIndex 0;
  551.             // Configure the commercialhero component...
  552.             $this->view->commercialhero = [];
  553.             if( !$property->getHeroHidden() ) {
  554.                 $this->view->commercialhero = [
  555.                     'is_template'      => true,
  556.                     'AreaIndex'        => $ComponentIndex,
  557.                     'AreaID'           => 'commercialhero',
  558.                     'HeroImageDesktop' => $property->getHeroImageDesktop(),
  559.                     'HeroImageMobile'  => $property->getHeroImageMobile(),
  560.                     'Heading'          => $property->getName(),
  561.                     'Subheading'       => $property->getDisplayCity().', '.$property->getDisplayState()
  562.                 ];
  563.                 $ComponentIndex ++;
  564.             }
  565.             // Configure the commercialbasicintro component...
  566.             $this->view->commercialbasicintro = [];
  567.             if( !$property->getIntroHidden() ) {
  568.                 $this->view->commercialbasicintro = [
  569.                     'is_template'  => true,
  570.                     'AreaIndex'    => $ComponentIndex,
  571.                     'AreaID'       => 'commercialbasicintro',
  572.                     'IntroText'    => $property->getIntroText(),
  573.                     'IntroBgColor' => $property->getIntroBgColor(),
  574.                     'IntroButtons' => $property->getIntroButtons()
  575.                 ];
  576.                 $ComponentIndex ++;
  577.             }
  578.             // Configure the commercialsidebymap component...
  579.             $this->view->commercialsidebymap = [];
  580.             if( !$property->getMapHidden() ) {
  581.                 $this->view->commercialsidebymap = [
  582.                     'is_template'   => true,
  583.                     'AreaIndex'     => $ComponentIndex,
  584.                     'AreaID'        => 'commercialsidebymap',
  585.                     'PropertyName'  => $property->getName(),
  586.                     'Latitude'      => $property->getLatitude(),
  587.                     'Longitude'     => $property->getLongitude(),
  588.                     'Zoom'          => $property->getZoom(),
  589.                     'Address'       => $property->getAddress(),
  590.                     'Description'   => $property->getDescription(),
  591.                     'GetDirections' => $property->getGetDirections(),
  592.                     'GetBrochure'   => $property->getGetBrochure(),
  593.                     'ContactData'   => $property->getContactData()
  594.                 ];
  595.                 $ComponentIndex ++;
  596.             }
  597.             // Configure the commercialstatistics component...
  598.             $this->view->commercialstatistics = [];
  599.             if( !$property->getStatsHidden() ) {
  600.                 $this->view->commercialstatistics = [
  601.                     'is_template' => true,
  602.                     'AreaIndex'   => $ComponentIndex,
  603.                     'AreaID'      => 'commercialstatistics',
  604.                     'Stats'       => $property->getStats()
  605.                 ];
  606.                 $ComponentIndex ++;
  607.             }
  608.             // Configure the commercialsiteplan component...
  609.             $this->view->commercialsiteplan = [];
  610.             if( !$property->getSiteplanHidden() ) {
  611.                 $this->view->commercialsiteplan = [
  612.                     'is_template' => true,
  613.                     'AreaIndex'   => $ComponentIndex,
  614.                     'AreaID'      => 'commercialsiteplan',
  615.                     'ButtonLink'  => $property->getButtonLink(),
  616.                     'Siteplans'   => $property->getSiteplans()
  617.                 ];
  618.                 $ComponentIndex ++;
  619.             }
  620.             // Configure the commercialboxlinks component...
  621.             $this->view->commercialboxlinks = [];
  622.             if( !$property->getBoxesHidden() ) {
  623.                 if( $property->getGallery() && $property->getTenants() ) {
  624.                     if( $property->getGallery()->isPublished() && $property->getTenants()->isPublished() ) {
  625.                         $Boxes = [ [
  626.                             'Image' => $property->getGallery()->getPreviewImage(),
  627.                             'Link'  => [
  628.                                 'href'   => $property->getGallery()->getGalleryLink()->getHref(),
  629.                                 'target' => $property->getGallery()->getGalleryLink()->getTarget(),
  630.                                 'text'   => $property->getGallery()->getGalleryLink()->getText()
  631.                             ]
  632.                         ],[
  633.                             'Image' => $property->getTenants()->getPreviewImage(),
  634.                             'Link' => [
  635.                                 'href'   => $property->getTenants()->getPortalLink()->getHref(),
  636.                                 'target' => $property->getTenants()->getPortalLink()->getTarget(),
  637.                                 'text'   => $property->getTenants()->getPortalLink()->getText()
  638.                             ]
  639.                         ] ];
  640.                         $this->view->commercialboxlinks = [
  641.                             'is_template' => true,
  642.                             'AreaIndex'   => $ComponentIndex,
  643.                             'AreaID'      => 'commercialboxlinks',
  644.                             'Boxes'       => $Boxes
  645.                         ];
  646.                         $ComponentIndex ++;
  647.                     }
  648.                 }
  649.             }
  650.             // Configure the commercialnearbyproperties component...
  651.             $this->view->commercialnearbyproperties = [];
  652.             if( !$property->getNearbyHidden() ) {
  653.                 $this->view->commercialnearbyproperties = [
  654.                     'is_template'      => true,
  655.                     'AreaIndex'        => $ComponentIndex,
  656.                     'AreaID'           => 'commercialnearbyproperties',
  657.                     'NearbyProperties' => $property->getNearbyProperties()
  658.                 ];
  659.                 $ComponentIndex ++;
  660.             }
  661.             // Configure the SEO title and description...
  662.             $this->view->SeoTitle       $property->getSeoTitle();
  663.             $this->view->SeoDescription $property->getSeoDescription();
  664.             // Configure the property nav template...
  665.             $this->view->propertynav $this->GetPropertySubnav$property );
  666.         }
  667.         public function PropertyGalleryActionRequest $request ) {
  668.             /*
  669.             ROUTES:
  670.             CommProperties S_C_P Gallery    /properties/%state/%city/%property/gallery
  671.             */
  672.         }
  673.         public function PropertyTenantsActionRequest $request ) {
  674.             /*
  675.             ROUTES:
  676.             CommProperties S_C_P Tenants    /properties/%state/%city/%property/tenants
  677.             */
  678.         }
  679.         public function PropertyContactActionRequest $request ) {
  680.             /*
  681.             ROUTES:
  682.             CommProperties S_C_P Contact    /properties/%state/%city/%property/contact
  683.             */
  684.             // Check property...
  685.             $key = \Pimcore\File::getValidFilename$request->get'property' ) );
  686.             $property = \Pimcore\Model\DataObject\VmCommercialProperty::getByPath'/_DATA/COMMERCIAL/PROPERTIES/'.$key );
  687.             if( !( $property instanceof \Pimcore\Model\DataObject\VmCommercialProperty ) ) {
  688.                 throw new NotFoundHttpException'Not found' );
  689.             }
  690.             if( !$property->isPublished() ) {
  691.                 throw new NotFoundHttpException'Not found' );
  692.             }
  693.             // Check city...
  694.             $city $request->get'city' );
  695.             if( $property->getSearch_slug_city() != $city ) {
  696.                 throw new NotFoundHttpException'Not found' );
  697.             }
  698.             // Check state...
  699.             $state $request->get'state' );
  700.             if( $property->getSearch_slug_state() != $state ) {
  701.                 throw new NotFoundHttpException'Not found' );
  702.             }
  703.             // Check the contact form...
  704.             if( !$property->getContact() || !$property->getContact()->isPublished() ) {
  705.                 throw new NotFoundHttpException'Not found' );
  706.             }
  707.             // Indexes for components...
  708.             $ComponentIndex 0;
  709.             // Configure the commercialcontactform component...
  710.             $this->view->commercialcontactform = [
  711.                 'is_template'   => true,
  712.                 'AreaIndex'     => $ComponentIndex,
  713.                 'AreaID'        => 'commercialcontactform',
  714.                 'ContactObject' => $property->getContact()
  715.             ];
  716.             $ComponentIndex ++;
  717.             // Configure the SEO title and description...
  718.             $this->view->SeoTitle       $property->getContact()->getSeoTitle();
  719.             $this->view->SeoDescription $property->getContact()->getSeoDescription();
  720.             // Configure the property nav template...
  721.             $this->view->propertynav $this->GetPropertySubnav$property );
  722.         }
  723.         public function GetGroupMapping() {
  724.             $GroupMap = [];
  725.             $Listing = new \Pimcore\Model\DataObject\VmCommercialGroup\Listing();
  726.             $Listing->setOrderKey'Name' );
  727.             $Listing->setOrder'ASC' );
  728.             foreach( $Listing as $VmCommercialGroup ) {
  729.                 $GroupListings = [];
  730.                 foreach( $VmCommercialGroup->getListings() as $i => $Subgroup ) {
  731.                     // Start off empty...
  732.                     $GroupListingProperties = [];
  733.                     // Iterate over the properties...
  734.                     foreach( $Subgroup'listing_properties' ]->getData() as $Property ) {
  735.                         // Skip if it's not a property (because it could be a services object)...
  736.                         if( !( $Property instanceof \Pimcore\Model\DataObject\VmCommercialProperty ) ) continue;
  737.                         // Add it...
  738.                         $GroupListingProperties[] = $Property->getId();
  739.                     }
  740.                     // Skip if no properties were listed...
  741.                     if( empty( $GroupListingProperties ) ) continue;
  742.                     // Add it...
  743.                     $GroupListings[] = [
  744.                         'Index'      => $i,
  745.                         'Title'      => $Subgroup'listing_title' ]->getData(),
  746.                         'Properties' => implode','$GroupListingProperties )
  747.                     ];
  748.                 }
  749.                 // Skip if no properties were listed...
  750.                 if( empty( $GroupListings ) ) continue;
  751.                 // Add it...
  752.                 $GroupMap[] = [
  753.                     'ID'       => $VmCommercialGroup->getId(),
  754.                     'Name'     => $VmCommercialGroup->getName(),
  755.                     'Listings' => $GroupListings
  756.                 ];
  757.             }
  758.             return $GroupMap;
  759.         }
  760.         public function searchdataActionRequest $request )
  761.         {
  762.             /*
  763.             ROUTES:
  764.             SearchData                /searchdata
  765.             */
  766.             header'Content-Type: application/json' );
  767.             die( json_encode( [
  768.                 'PropertiesBaseUrl' => $this->generateUrl'CommProperties', [] ),
  769.                 'PropertiesMapping' => $this->GetCommercialMapping(),
  770.                 'GroupMapping'      => $this->GetGroupMapping(),
  771.                 'TypeMapping'       => $this->GetTypeMapping()
  772.             ] ) );
  773.         }
  774.         public function FavoritesActionRequest $Request ) {
  775.             /*
  776.             ROUTES:
  777.             Favorites:                /favorites
  778.             */
  779.             $results = [];
  780.             if( !empty( $_COOKIE'vmcomm-favorites' ] ) ) {
  781.                 $favorite_ids explode','$_COOKIE'vmcomm-favorites' ] );
  782.                 $Listing = new \Pimcore\Model\DataObject\VmCommercialProperty\Listing();
  783.                 $Listing->setOrderKey'Name' );
  784.                 $Listing->getOrder'ASC' );
  785.                 foreach( $Listing as $Property ) {
  786.                     // Check if the id is in our favorites...
  787.                     if( !in_array$Property->getId(), $favorite_ids ) ) continue;
  788.                     // Add property to results...
  789.                     $results[] = $Property;
  790.                 }
  791.             }
  792.             return $this->render':Commercial:listing.html.php', [
  793.                 'route'   => $Request->get'_route' ),
  794.                 'results' => $results
  795.             ] );
  796.         }
  797.     }