src/Controller/CalenderController.php line 161

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Carbon\Carbon;
  4. use Pimcore\Model\DataObject\Day;
  5. use Pimcore\Model\DataObject\Month;
  6. use Pimcore\Translation\Translator;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. class CalenderController extends BaseController
  10. {
  11.     /**
  12.      *
  13.      * @param Request $request
  14.      * @param Translator $translator
  15.      *
  16.      * @return Response
  17.      *
  18.      * @throws \Exception
  19.      */
  20.     public function defaultAction(Request $request)
  21.     {
  22.         $calender = [];
  23.         $HisCalender = [];
  24.         $year Carbon::now()->format('Y');
  25.         $monthList Month::getList();
  26.         $monthList->setCondition("`o_path` = '/Kalender/" $year "/'");
  27.         $monthList->setOrderKey('o_key');
  28.         $monthList->setOrder("asc");
  29.         $thisMonth Carbon::now()->format('m');
  30.         foreach ($monthList as $month) {
  31.             if ($month->getKey() >= $thisMonth) {
  32.                 if ($month->getChildren()) {
  33.                     $days = [];
  34.                     foreach ($month->getChildren() as $day) {
  35.                         /** @var $day Day */
  36.                         if ($month->getKey() === $day->getDatum()?->format('m')) {
  37.                             $days[] = $this->getDayData($day);
  38.                         } else {
  39.                             $days = [];
  40.                         }
  41.                     }
  42.                     usort($days, static function ($a$b) {
  43.                         return strtotime($a['Datum']) - strtotime($b['Datum']);
  44.                     });
  45.                     $calender[] = [
  46.                         'month' => $month->getMaand_name(),
  47.                         'days' => $days,
  48.                     ];
  49.                 } else {
  50.                     $calender[] = [
  51.                         'month' => $month->getMaand_name()
  52.                     ];
  53.                 }
  54.             } else if ($month->getChildren()) {
  55.                 $Hisdays = [];
  56.                 foreach ($month->getChildren() as $day) {
  57.                     /** @var $day Day */
  58.                     if ($month->getKey() === $day->getDatum()?->format('m')) {
  59.                         $Hisdays[] = $this->getDayData($day);
  60.                     } else {
  61.                         $Hisdays = [];
  62.                     }
  63.                 }
  64.                 usort($Hisdays, static function ($a$b) {
  65.                     return strtotime($a['Datum']) - strtotime($b['Datum']);
  66.                 });
  67.                 $HisCalender[] = [
  68.                     'month' => $month->getMaand_name(),
  69.                     'days' => $Hisdays,
  70.                 ];
  71.             } else {
  72.                 $HisCalender[] = [
  73.                     'month' => $month->getMaand_name()
  74.                 ];
  75.             }
  76.         }
  77.         return $this->render('calender/overview.html.twig', [
  78.             'calender' => $calender,
  79.             'HisCalender' => $HisCalender,
  80.             'year' => $year,
  81.         ]);
  82.     }
  83.     public function defaultNextYearAction(Request $request)
  84.     {
  85.         $calender = [];
  86.         $HisCalender = [];
  87.         $year Carbon::now()->addYear()->format('Y');
  88.         $monthList Month::getList();
  89.         $monthList->setCondition("`o_path` = '/Kalender/" $year "/'");
  90.         $monthList->setOrderKey('o_key');
  91.         $monthList->setOrder("asc");
  92.         $thisMonth 0;
  93.         foreach ($monthList as $month) {
  94.             if ($month->getKey() >= $thisMonth) {
  95.                 if ($month->getChildren()) {
  96.                     $days = [];
  97.                     foreach ($month->getChildren() as $day) {
  98.                         /** @var $day Day */
  99.                         if ($month->getKey() === $day->getDatum()?->format('m')) {
  100.                             $days[] = $this->getDayData($day);
  101.                         } else {
  102.                             $days = [];
  103.                         }
  104.                     }
  105.                     usort($days, static function ($a$b) {
  106.                         return strtotime($a['Datum']) - strtotime($b['Datum']);
  107.                     });
  108.                     $calender[] = [
  109.                         'month' => $month->getMaand_name(),
  110.                         'days' => $days,
  111.                     ];
  112.                 } else {
  113.                     $calender[] = [
  114.                         'month' => $month->getMaand_name()
  115.                     ];
  116.                 }
  117.             } else if ($month->getChildren()) {
  118.                 $Hisdays = [];
  119.                 foreach ($month->getChildren() as $day) {
  120.                     if ($month->getKey() === $day->getDatum()?->format('m')) {
  121.                         $Hisdays[] = $this->getDayData($day);
  122.                     } else {
  123.                         $Hisdays = [];
  124.                     }
  125.                 }
  126.                 usort($Hisdays, static function ($a$b) {
  127.                     return strtotime($a['Datum']) - strtotime($b['Datum']);
  128.                 });
  129.                 $HisCalender[] = [
  130.                     'month' => $month->getMaand_name(),
  131.                     'days' => $Hisdays,
  132.                 ];
  133.             } else {
  134.                 $HisCalender[] = [
  135.                     'month' => $month->getMaand_name()
  136.                 ];
  137.             }
  138.         }
  139.         return $this->render('calender/overview.html.twig', [
  140.             'calender' => $calender,
  141.             'HisCalender' => $HisCalender,
  142.             'year' => $year,
  143.         ]);
  144.     }
  145.     private function getDayData($day): array
  146.     {
  147.         /** @var $day Day */
  148.         return [
  149.             "dayinfo" => $day->getDate_info(),
  150.             "start_u" => $day->getBegin_Tijd(),
  151.             "eind_u" => $day->getEind_Tijd(),
  152.             "Datum" => $day->getDatum(),
  153.             "Datum_description" => $day->getDate_description(),
  154.             "Place" => $day->getPlace_date(),
  155.         ];
  156.     }
  157. }