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; } }
/** * 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 EventHasList $obj A EventHasList 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 = serialize(array((string) $obj->getIdEvent(), (string) $obj->getIdList())); } // if key === null EventHasListPeer::$instances[$key] = $obj; } }
/** * Filter the query by a related EventHasList object * * @param EventHasList|PropelObjectCollection $eventHasList the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return CustomListsQuery The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterByEventHasList($eventHasList, $comparison = null) { if ($eventHasList instanceof EventHasList) { return $this->addUsingAlias(CustomListsPeer::ID_CUSTOM_LIST, $eventHasList->getIdList(), $comparison); } elseif ($eventHasList instanceof PropelObjectCollection) { return $this->useEventHasListQuery()->filterByPrimaryKeys($eventHasList->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByEventHasList() only accepts arguments of type EventHasList or PropelCollection'); } }
/** * Exclude object from result * * @param EventHasList $eventHasList Object to remove from the list of results * * @return EventHasListQuery The current query, for fluid interface */ public function prune($eventHasList = null) { if ($eventHasList) { $this->addCond('pruneCond0', $this->getAliasedColName(EventHasListPeer::ID_EVENT), $eventHasList->getIdEvent(), Criteria::NOT_EQUAL); $this->addCond('pruneCond1', $this->getAliasedColName(EventHasListPeer::ID_LIST), $eventHasList->getIdList(), Criteria::NOT_EQUAL); $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); } return $this; }