Ejemplo n.º 1
0
 public function viewAction($eventId = null)
 {
     if ($eventId != null) {
         //Enable quick event preview
         if (!$this->validateEvent($eventId)) {
             return $this->redirectToRoute('calendar_view');
         }
         $event = EventsQuery::create()->findPk($eventId);
         $eventDate = $event->getEventDate();
     } else {
         $eventDate = null;
     }
     $request = $this->getRequest();
     $user = $this->getUser();
     $userId = $user->getId();
     $translator = $this->get('translator');
     if ($request->request->has('listsFromEvent')) {
         //Load event's lists
         $eventId = $request->request->get('listsFromEvent');
         if (!$this->validateEvent($eventId)) {
             return new JsonResponse('{}');
         }
         $event = EventsQuery::create()->findPk($eventId);
         $eventsList = $event->getCustomListss();
         //Prevent circular reference
         $serializer = SerializerBuilder::create()->build();
         $jsonContent = $serializer->serialize($eventsList, 'json');
         return new JsonResponse($jsonContent);
     }
     if ($request->request->has('chosenDate')) {
         //Get all events from a chosen day
         $userId = $this->getUser()->getId();
         $chosenDate = $request->request->get('chosenDate');
         $events = EventsQuery::create()->filterByIdUser($userId)->orderByEventOrder()->findByEventDate($chosenDate);
         $cyclicalEvents = EventsUtil::getCyclicalEvents($userId, $chosenDate);
         //Load cyclical events too
         $arr = array($events, $cyclicalEvents);
         $serializer = SerializerBuilder::create()->build();
         $jsonContent = $serializer->serialize($arr, 'json');
         return new JsonResponse($jsonContent);
     }
     if ($request->request->has('eventId')) {
         //Save event
         //Get all variables
         $eventId = $request->request->get('eventId');
         $chosenDate = $request->request->get('chosenDay');
         $title = $request->request->get('title');
         $content = $request->request->get('content');
         $weight = $request->request->get('weight');
         $order = $request->request->get('order');
         if ($eventId == null) {
             $event = new Events();
         } else {
             if (!$this->validateEvent($eventId)) {
                 return new JsonResponse('{}');
             }
             $event = EventsQuery::create()->findPk($eventId);
         }
         $event->setIdUser($userId);
         $event->setEventName($title)->setEventDescription($content)->setEventWeight($weight)->setEventDate($chosenDate)->setEventOrder($order);
         $event->save();
         return new JsonResponse($event->getIdEvent());
     }
     if ($request->request->has('deletedEventId')) {
         //Delete event
         $deletedEventId = $request->request->get('deletedEventId');
         if (!$this->validateEvent($deletedEventId)) {
             return new JsonResponse('{}');
         }
         $event = EventsQuery::create()->findPk($deletedEventId);
         $event->delete();
     }
     if ($request->request->has('addListToEventList')) {
         //Add list to event
         $addListToEventList = $request->request->get('addListToEventList');
         $addListToEventEvent = $request->request->get('addListToEventEvent');
         if (!$this->validateEvent($addListToEventEvent) || !$this->validateList($addListToEventList)) {
             return new JsonResponse('{}');
         }
         $eventhasList = new EventHasList();
         $eventhasList->setIdEvent($addListToEventEvent)->setIdList($addListToEventList)->save();
     }
     if ($request->request->has('removeListId')) {
         //Remove list from event
         $removeListId = $request->request->get('removeListId');
         $removeListEvent = $request->request->get('removeListEvent');
         if (!$this->validateEvent($removeListEvent) || !$this->validateList($removeListId)) {
             //Return empty response if there is something wrong with the event
             return new JsonResponse('{}');
         }
         //Get a proper row from the junction table
         $eventhasList = EventHasListQuery::create()->where('event_has_list.id_event =' . $removeListEvent . ' AND ' . 'event_has_list.id_list = ' . $removeListId);
         $eventhasList->delete();
     }
     if ($request->request->has('getListElements')) {
         //Get elements of the list assigned to event
         $listId = $request->request->get('getListElements');
         if (!$this->validateList($listId)) {
             return new JsonResponse('{}');
         }
         $listElements = CustomListsQuery::create()->findPk($listId)->getCustomListElements();
         $serializer = SerializerBuilder::create()->build();
         $jsonContent = $serializer->serialize($listElements, 'json');
         return new JsonResponse($jsonContent);
     }
     if ($request->request->has('chosenCyclicalEvent')) {
         //Load cyclical event as a template to new event
         $chosenCyclicalEventId = $request->request->get('chosenCyclicalEvent');
         if (!$this->validateCyclicalEvent($chosenCyclicalEventId)) {
             //Security purpose
             return new JsonResponse('{}');
         }
         $chosenDate = $request->request->get('cyclicalChosenDate');
         $chosenCyclicalEvent = CyclicalEventsQuery::create()->findPk($chosenCyclicalEventId);
         //Create and save event
         $newEvent = new Events();
         $newEvent->setEventName($chosenCyclicalEvent->getCyclicalEventName())->setEventDescription($chosenCyclicalEvent->getCyclicalEventDescription())->setEventWeight($chosenCyclicalEvent->getCyclicalEventWeight())->setEventDate($chosenDate)->setIdUser($userId);
         $newEvent->save();
         //Save event's custom lists
         foreach ($chosenCyclicalEvent->getCustomListss() as $list) {
             $eventHasList = new EventHasList();
             $eventHasList->setIdEvent($newEvent->getIdEvent())->setIdList($list->getIdCustomList());
             $eventHasList->save();
         }
         $response = array($chosenCyclicalEvent, $newEvent->getIdEvent());
         $serializer = SerializerBuilder::create()->build();
         $jsonContent = $serializer->serialize($response, 'json');
         return new JsonResponse($jsonContent);
     }
     //Perform a list selection
     $chooseText = $translator->trans('-- Wybierz --');
     $listsChoice = CustomListsQuery::getAllListsChoice($userId, $chooseText);
     $cyclicalEventsChoice = CyclicalEventsQuery::getAllEventsChoice($userId, $chooseText);
     return $this->render('OrganizerBundle:Calendar:view.html.twig', array('listsChoice' => $listsChoice, 'cyclicalEventsChoice' => $cyclicalEventsChoice, 'eventId' => $eventId, 'eventDate' => $eventDate));
 }
Ejemplo n.º 2
0
 /**
  * Exclude object from result
  *
  * @param   Events $events Object to remove from the list of results
  *
  * @return EventsQuery The current query, for fluid interface
  */
 public function prune($events = null)
 {
     if ($events) {
         $this->addUsingAlias(EventsPeer::ID_EVENT, $events->getIdEvent(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
 /**
  * Filter the query by a related Events object
  *
  * @param   Events|PropelObjectCollection $events The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return                 EventHasListQuery The current query, for fluid interface
  * @throws PropelException - if the provided filter is invalid.
  */
 public function filterByEvents($events, $comparison = null)
 {
     if ($events instanceof Events) {
         return $this->addUsingAlias(EventHasListPeer::ID_EVENT, $events->getIdEvent(), $comparison);
     } elseif ($events instanceof PropelObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(EventHasListPeer::ID_EVENT, $events->toKeyValue('PrimaryKey', 'IdEvent'), $comparison);
     } else {
         throw new PropelException('filterByEvents() only accepts arguments of type Events or PropelCollection');
     }
 }
Ejemplo n.º 4
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param Events $obj A Events object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getIdEvent();
         }
         // if key === null
         EventsPeer::$instances[$key] = $obj;
     }
 }
Ejemplo n.º 5
0
 /**
  * Declares an association between this object and a Events object.
  *
  * @param                  Events $v
  * @return EventHasList The current object (for fluent API support)
  * @throws PropelException
  */
 public function setEvents(Events $v = null)
 {
     if ($v === null) {
         $this->setIdEvent(NULL);
     } else {
         $this->setIdEvent($v->getIdEvent());
     }
     $this->aEvents = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Events object, it will not be re-added.
     if ($v !== null) {
         $v->addEventHasList($this);
     }
     return $this;
 }