public function editCyclicalEventAction($id) { $cyclicalEvent = CyclicalEventsQuery::create()->findPk($id); $userId = $this->getUser()->getId(); if (!$cyclicalEvent instanceof CyclicalEvents || $cyclicalEvent->getIdUser() !== $userId) { return $this->redirectToRoute('cyclical_events'); } $request = $this->getRequest(); $translator = $this->get('translator'); $weight = $cyclicalEvent->getCyclicalEventWeight(); $title = $translator->trans('Edytuj zdarzenie'); $chooseText = $translator->trans('-- Wybierz --'); $listsChoice = CustomListsQuery::getAllListsChoice($userId, $chooseText); $form = $this->createForm(new CyclicalEventType($translator), $cyclicalEvent); $form->handleRequest($request); if ($form->isValid()) { $data = $form->getData(); if (!$this->validateLists($data)) { return $this->redirectToRoute('cyclical_events'); } $cyclicalEvent->save(); return $this->redirectToList(); } return $this->render('OrganizerBundle:CyclicalEvents:form.html.twig', array('form' => $form->createView(), 'title' => $title, 'weight' => $weight, 'listsChoice' => $listsChoice)); }
public function viewAction($id) { $customList = CustomListsQuery::create()->findPk($id); $userId = $this->getUser()->getId(); $request = $this->getRequest(); if (!$customList instanceof CustomLists || $customList->getIdUser() !== $userId) { return $this->redirectToList(); } //Delete request if ($request->request->has('deletedListId')) { $listId = $request->request->get('deletedListId'); $list = CustomListsQuery::create()->findPk($listId); if ($list instanceof CustomLists) { $list->delete(); return new JsonResponse(true); } } return $this->render('OrganizerBundle:CustomLists:view.html.twig', array('list' => $customList)); }
public function validateList($idList) { //Protection from accessing another user lists $userId = $this->getUser()->getId(); $list = CustomListsQuery::create()->findPk($idList); if (!$list instanceof CustomLists || $list->getIdUser() != $userId) { return false; } return true; }
/** * 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(CustomListsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = CustomListsQuery::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; } }
/** * Returns a new CustomListsQuery object. * * @param string $modelAlias The alias of a model in the query * @param CustomListsQuery|Criteria $criteria Optional Criteria to build the query from * * @return CustomListsQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof CustomListsQuery) { return $criteria; } $query = new CustomListsQuery(null, null, $modelAlias); if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * Gets the number of CustomLists objects related by a many-to-many relationship * to the current object by way of the cyclical_event_has_list cross-reference table. * * @param Criteria $criteria Optional query object to filter the query * @param boolean $distinct Set to true to force count distinct * @param PropelPDO $con Optional connection object * * @return int the number of related CustomLists objects */ public function countCustomListss($criteria = null, $distinct = false, PropelPDO $con = null) { if (null === $this->collCustomListss || null !== $criteria) { if ($this->isNew() && null === $this->collCustomListss) { return 0; } else { $query = CustomListsQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByCyclicalEvents($this)->count($con); } } else { return count($this->collCustomListss); } }
/** * Get the associated CustomLists object * * @param PropelPDO $con Optional Connection object. * @param $doQuery Executes a query to get the object if required * @return CustomLists The associated CustomLists object. * @throws PropelException */ public function getCustomLists(PropelPDO $con = null, $doQuery = true) { if ($this->aCustomLists === null && $this->custom_list !== null && $doQuery) { $this->aCustomLists = CustomListsQuery::create()->findPk($this->custom_list, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aCustomLists->addCustomListElements($this); */ } return $this->aCustomLists; }