src/Controller/CalendarController.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\CalendarRepository;
  4. use App\Repository\DataRepository;
  5. use App\Repository\IndemaUsersRepository;
  6. use FOS\RestBundle\Controller\AbstractFOSRestController;
  7. use FOS\RestBundle\Request\ParamFetcher;
  8. use FOS\RestBundle\View\View;
  9. use FOS\RestBundle\Controller\Annotations as Rest;
  10. use Symfony\Component\HttpFoundation\Response;
  11. class CalendarController extends AbstractFOSRestController
  12. {
  13.     /**
  14.      * @var DataRepository
  15.      */
  16.     private $dataRepository;
  17.     /**
  18.      * @var CalendarRepository
  19.      */
  20.     private $calendarRepository;
  21.     /**
  22.      * @var IndemaUsersRepository
  23.      */
  24.     private $usersRepository;
  25.     /**
  26.      * DataController constructor.
  27.      * @param DataRepository $dataRepository
  28.      * @param CalendarRepository $calendarRepository
  29.      * @param IndemaUsersRepository $usersRepository
  30.      */
  31.     function __construct(DataRepository $dataRepositoryCalendarRepository $calendarRepositoryIndemaUsersRepository $usersRepository) {
  32.         $this->dataRepository $dataRepository;
  33.         $this->calendarRepository $calendarRepository;
  34.         $this->usersRepository $usersRepository;
  35.     }
  36.     /**
  37.      * @Rest\Get("/calendar", name="calendar_index")
  38.      */
  39.     public function index(): View
  40.     {
  41.         return $this->view(['results' => 'controller loaded'],Response::HTTP_OK);
  42.     }
  43.     /**
  44.      * @Rest\Get("/calendar/cron", name="calendar_cron")
  45.      */
  46.     public function cronAction(): View
  47.     {
  48.         $this->calendarRepository->cronActions();
  49.         return $this->view(['results' => 'cron loaded'],Response::HTTP_OK);
  50.     }
  51.     /**
  52.      * @Rest\Get("/calendar/dates/{uid}/{args}", name="calendar_dates", defaults={"uid"=0,"args"=""})
  53.      */
  54.     public function calendarDatesAction(int $uidstring $args): View
  55.     {
  56.         $defaultCalenderArgs = ['calendar' => 'userCalendar''uid' => 0];
  57.         $args = ['start' => date('Y-m-d 00:00:00'$_GET['start']),
  58.             'end' => date('Y-m-d 23:59:59'$_GET['end']),
  59.             'filter' => $_GET['filter'] ?? [],
  60.             'viewgroup' => $_GET['viewgroup'] ?? 'single',
  61.             'userType' => $_GET['ut'] ?? 'none',
  62.             'uid' => $_GET['u'] ?? 0,
  63.         ];
  64.         if(isset($_GET['filter']['calenderEventData'] ) && !empty($_GET['filter']['calenderEventData'])) {
  65.             $tmp explode('-'$_GET['filter']['calenderEventData']);
  66.             if(in_array($tmp[0], ['project']))
  67.                 $defaultCalenderArgs = ['calendar' => $tmp[0], 'uid' => $tmp[1]];
  68.         }
  69.         switch($defaultCalenderArgs['calendar']) {
  70.             case 'project':
  71.                 $events $this->calendarRepository->loadProjectCalendarData($defaultCalenderArgs['uid'], $args);
  72.                 $businessHours = [];
  73.                 break;
  74.             default:
  75.                 $events $this->calendarRepository->loadCalendarData($uid$args);
  76.                 $businessHours $this->calendarRepository->getUserBusinessHours($uid$args);
  77.                 break;
  78.         }
  79.         return $this->view(['events' => $events'businessHours' => $businessHours],Response::HTTP_OK);
  80.     }
  81.     /**
  82.      * @Rest\Post("/calender/date/update", name="calendar_date_update")
  83.      * @Rest\RequestParam(name="data", description="form data", nullable=false)
  84.      * @param ParamFetcher $paramFetcher
  85.      * @return View
  86.      */
  87.     public function calendarUpdateAction(ParamFetcher $paramFetcher): View
  88.     {
  89.         $data $paramFetcher->get('data');
  90.         if(is_string($data))
  91.             parse_str($data$data);
  92.         if(isset($data['object_data']) && $data['object_data']['mainTable'] == 'calendar_dates' && isset($data['acceptInvitation'])) {
  93.             $this->calendarRepository->updateInvitationStatus($data);
  94.             // echo 'SPECIAL';die();
  95.         } elseif(isset($data['object_data']) && $data['object_data']['mainTable'] == 'calendar_dates') {
  96.             $this->calendarRepository->updateData($data);
  97.         } else {
  98.             $tmp $data['object_data'];
  99.             $tmp['start'] = $data['main_data']['start'];
  100.             $tmp['end'] = $data['main_data']['end'] ?? $data['main_data']['start'];
  101.             $tmp['gmDate'] = false;
  102.             $this->calendarRepository->updateDateRangeData($tmp);
  103.         }
  104.         return $this->view(['data' => $data],Response::HTTP_OK);
  105.     }
  106.     /**
  107.      * @Rest\Post("/calender/date/updatedaterange", name="calendar_date_update_range")
  108.      * @Rest\RequestParam(name="data", description="form data", nullable=false)
  109.      * @param ParamFetcher $paramFetcher
  110.      * @return View
  111.      */
  112.     public function calendarUpdateDateRangeAction(ParamFetcher $paramFetcher): View
  113.     {
  114.         $data $paramFetcher->get('data');
  115.         if(is_string($data))
  116.             parse_str($data$data);
  117.         $data['gmDate'] = true;
  118.         $this->calendarRepository->updateDateRangeData($data);
  119.         return $this->view(['data' => $data],Response::HTTP_OK);
  120.     }
  121.     /**
  122.      * @Rest\Post("/calender/addicaldata", name="calendar_addicaldata")
  123.      * @Rest\RequestParam(name="data", description="form data", nullable=false)
  124.      * @param ParamFetcher $paramFetcher
  125.      * @return View
  126.      */
  127.     public function ticketAddImageAction(ParamFetcher $paramFetcher): View
  128.     {
  129.         $data $paramFetcher->get('data');
  130.         if(isset($_POST['ref_uid']) && $_POST['ref_uid'] > 0)
  131.             $this->calendarRepository->iCalImport(['ref_table' => isset($_POST['ref_table']) && !empty($_POST['ref_table']) ? $_POST['ref_table'] : 'users''ref_uid' => $_POST['ref_uid']]);
  132.         return $this->view(['status' => 'success'],Response::HTTP_CREATED);
  133.     }
  134. }