Created
December 12, 2017 11:10
-
-
Save cyberlex404/ec06f9f182ab47049a209c29ed46862e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Drupal\braslavskie_bat\Controller; | |
| use Drupal\braslavskie_bat\BatFullCalendarEvents; | |
| use Drupal\Core\Controller\ControllerBase; | |
| use Drupal\Core\Url; | |
| use Drupal\housing_rooms\Entity\HousingRoomInterface; | |
| use Symfony\Component\DependencyInjection\ContainerInterface; | |
| use Drupal\Core\Entity\EntityTypeManager; | |
| use Drupal\Core\Logger\LoggerChannel; | |
| use Symfony\Component\HttpFoundation\JsonResponse; | |
| use Symfony\Component\HttpFoundation\RedirectResponse; | |
| use Symfony\Component\HttpFoundation\Request; | |
| use Drupal\Core\Datetime\DrupalDateTime; | |
| /** | |
| * Class FullCalendar. | |
| */ | |
| class FullCalendar extends ControllerBase { | |
| /** | |
| * Drupal\Core\Entity\EntityTypeManager definition. | |
| * | |
| * @var \Drupal\Core\Entity\EntityTypeManager | |
| */ | |
| protected $entityTypeManager; | |
| /** | |
| * Drupal\Core\Logger\LoggerChannel definition. | |
| * | |
| * @var \Drupal\Core\Logger\LoggerChannel | |
| */ | |
| protected $loggerChannelDefault; | |
| /** | |
| * @var \Drupal\braslavskie_bat\BatFullCalendarEvents | |
| */ | |
| protected $batEvents; | |
| /** | |
| * Constructs a new FullCalendar object. | |
| */ | |
| public function __construct(EntityTypeManager $entity_type_manager, LoggerChannel $logger_channel_default, BatFullCalendarEvents $batEvents) { | |
| $this->entityTypeManager = $entity_type_manager; | |
| $this->loggerChannelDefault = $logger_channel_default; | |
| $this->batEvents = $batEvents; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public static function create(ContainerInterface $container) { | |
| return new static( | |
| $container->get('entity_type.manager'), | |
| $container->get('logger.channel.default'), | |
| $container->get('braslavskie_bat.full_calendar_events') | |
| ); | |
| } | |
| /** | |
| * Предоставляет данные о событиях календаря номера для публичного клендаря бронирования. | |
| * | |
| * @return \Symfony\Component\HttpFoundation\Response | |
| * Return Hello string. | |
| */ | |
| public function room(HousingRoomInterface $housing_room, Request $request) { | |
| $response = new JsonResponse(); | |
| /* | |
| if (!$request->request->has('room') | |
| || !$request->request->has('start') | |
| || !$request->request->has('end')) { | |
| $response = new RedirectResponse(Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString()); | |
| return $response; | |
| } | |
| */ | |
| $roomId = $request->request->get('room'); | |
| if ($housing_room->id() !== $roomId) { | |
| $data['error'] = 'error'; | |
| } | |
| $start = $request->request->get('start'); | |
| $end = $request->request->get('end'); | |
| if (!$request->request->has('start')) { | |
| $start = '2017-11-11'; | |
| } | |
| if (!$request->request->has('end')) { | |
| $end = '2018-02-11'; | |
| } | |
| $eventStart = DrupalDateTime::createFromFormat('Y-m-d', $start); | |
| $eventEnd = DrupalDateTime::createFromFormat('Y-m-d', $end); | |
| $id = $housing_room->id(); | |
| $this->loggerChannelDefault->debug("Load start: $start end: $end room: $id"); | |
| $data = $this->batEvents->events($housing_room, $eventStart, $eventEnd); | |
| /* | |
| $data = [ | |
| //'data' => $data, | |
| 'ip' => $request->getClientIp(), | |
| 'query' => $request->query->all(), | |
| 'post' => $request->request->all(), | |
| 'start' => $eventStart->format('Y-d-m H:i'), | |
| 'end' => $eventEnd->format('Y-d-m H:i'), | |
| ]; | |
| */ | |
| $response->setData($data); | |
| return $response; | |
| } | |
| /** | |
| * Метод предоставляет данные для построения календаря на странице редактора | |
| * | |
| * @param \Drupal\housing_rooms\Entity\HousingRoomInterface $housing_room | |
| * @param \Symfony\Component\HttpFoundation\Request $request | |
| */ | |
| public function roomBoard(HousingRoomInterface $housing_room, Request $request) { | |
| $response = new JsonResponse(); | |
| return $this->room($housing_room, $request); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment