/**
  * Resets all references to other model objects or collections of model objects.
  *
  * This method is a user-space workaround for PHP's inability to garbage collect
  * objects with circular references (even in PHP 5.3). This is currently necessary
  * when using Propel in certain daemon or large-volume/high-memory operations.
  *
  * @param boolean $deep Whether to also clear the references on all referrer objects.
  */
 public function clearAllReferences($deep = false)
 {
     if ($deep && !$this->alreadyInClearAllReferencesDeep) {
         $this->alreadyInClearAllReferencesDeep = true;
         if ($this->aEvents instanceof Persistent) {
             $this->aEvents->clearAllReferences($deep);
         }
         if ($this->aCustomLists instanceof Persistent) {
             $this->aCustomLists->clearAllReferences($deep);
         }
         $this->alreadyInClearAllReferencesDeep = false;
     }
     // if ($deep)
     $this->aEvents = null;
     $this->aCustomLists = null;
 }
 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));
 }
 /**
  * @param	Events $events The events object to add.
  */
 protected function doAddEvents(Events $events)
 {
     // set the back reference to this object directly as using provided method either results
     // in endless loop or in multiple relations
     if (!$events->getCustomListss()->contains($this)) {
         $eventHasList = new EventHasList();
         $eventHasList->setEvents($events);
         $this->addEventHasList($eventHasList);
         $foreignCollection = $events->getCustomListss();
         $foreignCollection[] = $this;
     }
 }
 /**
  * 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;
 }
示例#5
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;
     }
 }
 /**
  * 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');
     }
 }