src/Controller/Services/SchemaorgController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Services;
  3. use App\AppBundle;
  4. use Pimcore\Controller\Configuration\ResponseHeader;
  5. use Pimcore\Controller\FrontendController;
  6. use Pimcore\Model\Asset;
  7. use SaintElmos\BaseBundle\Services\ImageResponsive;
  8. use SaintElmos\BaseBundle\Templating\Helper\FrontendHelper;
  9. use SaintElmos\BaseBundle\Utils\SETConf;
  10. use SaintElmos\BaseBundle\Controller\BaseController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use \Pimcore\Model\DataObject;
  13. class SchemaorgController extends FrontendController
  14. {
  15.     public function jsonAction(Request $request,\Pimcore\Config\Config $websiteConfig)
  16.     {
  17.         //if ($this->editmode){
  18.         //    $this->document->setProperty('snippet_exclude', 'bool', 'true')->save();
  19.         //}
  20.        // echo "<pre>";print_r($this->document->getParent()); 
  21.        $pimObject $this->document->getEditable("business_workingDaysAndHours_objectGeolocationFolder");
  22.         $alias "";
  23.         $openingHoursSpecification = [];
  24.         $weiter false;
  25.         if(!empty($pimObject)){
  26.             $objectPath = (string) $pimObject;
  27.             $objectAlias DataObject::getByPath(trim($objectPath));
  28.             
  29.             
  30.             if(!empty($objectAlias)){
  31.                 $alias AppBundle::getValue($objectAlias'getAlias');
  32.                 
  33.             }
  34.             $oID $pimObject->getId();
  35.             $weiter true;
  36.             
  37.         }
  38.         if(!empty($alias))
  39.         {
  40.             $oID $alias->getId();
  41.             $weiter true;
  42.              
  43.         }
  44.         if($weiter)
  45.         {
  46.             if ($oID)
  47.             {
  48.                 $new_object DataObject::getById($oID);
  49.                 $days = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
  50.                 $timepattern "/^[0-9]{1}[0-9]{1}:[0-5]{1}[0-9]{1}-[0-9]{1}[0-9]{1}:[0-5]{1}[0-9]{1}/";
  51.                 $open_per_day = [];
  52.                 //..get these values from the fields in Database for "this" store
  53.                 $open_per_day[0] = AppBundle::getValue($new_object'getMonday'); // object_localized_data_15.monday
  54.                 $open_per_day[1] = AppBundle::getValue($new_object'getTuesday'); // object_localized_data_15.tuesday
  55.                 $open_per_day[2] = AppBundle::getValue($new_object'getWednesday'); // object_localized_data_15.wednesday
  56.                 $open_per_day[3] = AppBundle::getValue($new_object'getThursday'); // object_localized_data_15.thursday
  57.                 $open_per_day[4] = AppBundle::getValue($new_object'getFriday'); // object_localized_data_15.friday
  58.                 $open_per_day[5] = AppBundle::getValue($new_object'getSaturday'); // object_localized_data_15.saturday
  59.                 $open_per_day[6] = AppBundle::getValue($new_object'getSunday'); // object_localized_data_15.sunday
  60.                 // put "ALL" times in "one" array
  61.                 $times = [];
  62.                 foreach ($open_per_day as $index => $value) {
  63.                     $val explode("|",$value);
  64.                     foreach ($val as $v) {
  65.                         $v str_replace('–''-'$v);
  66.                         if (preg_match($timepatterntrim($v))) {
  67.                             if(count($times)) {
  68.                                 $is_day_added false;
  69.                                 foreach ($times as $t_index => $t) {
  70.                                     if($t['openHours'] == $v) {
  71.                                         $times[$t_index]['days'][] = $days[$index];
  72.                                         $is_day_added true;
  73.                                     }
  74.                                 }
  75.                                 if($is_day_added === false) {
  76.                                     $times[] = [
  77.                                         "days" => [$days[$index]],
  78.                                         "openHours" => $v
  79.                                     ];
  80.                                 }
  81.                             } else {
  82.                                 $times[] = [
  83.                                     "days" => [$days[$index]],
  84.                                     "openHours" => $v
  85.                                 ];
  86.                             }
  87.                         }
  88.                     }
  89.                 }
  90.                 $openingHoursSpecificationArray = [];
  91.                 // Iterate through each element in the $openingHoursArray
  92.                 foreach ($times as $index => $entry) {
  93.                     $object = [];
  94.                     $object['@type'] = 'OpeningHoursSpecification';
  95.                     foreach ($entry['days'] as $day) {
  96.                         $object['dayOfWeek'][] = $day;
  97.                     }
  98.                     $times explode("-"$entry['openHours']);
  99.                     $object['opens'] = $times[0];
  100.                     $object['closes'] = $times[1];
  101.                     $openingHoursSpecificationArray[] = $object;
  102.                 }
  103.                 $openingHoursSpecification $openingHoursSpecificationArray;
  104.             }
  105.         }
  106.         $parentAction explode("::",$this->document->getParent()->getController()); 
  107.         $parentAction str_replace("Action","",$parentAction[1]);
  108.         
  109.         return $this->renderTemplate("services/Schemaorg/strukturierte-daten.html.twig", ["parentAction" => $parentAction"openingHoursSpecification" => $openingHoursSpecification]);    
  110.     }
  111. }