/** * Returns a new EventHasListQuery object. * * @param string $modelAlias The alias of a model in the query * @param EventHasListQuery|Criteria $criteria Optional Criteria to build the query from * * @return EventHasListQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof EventHasListQuery) { return $criteria; } $query = new EventHasListQuery(null, null, $modelAlias); if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
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)); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this CustomLists is new, it will return * an empty collection; or if this CustomLists has previously * been saved, it will retrieve related EventHasLists from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in CustomLists. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelObjectCollection|EventHasList[] List of EventHasList objects */ public function getEventHasListsJoinEvents($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = EventHasListQuery::create(null, $criteria); $query->joinWith('Events', $join_behavior); return $this->getEventHasLists($query, $con); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(EventHasListPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = EventHasListQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }