public static function getCyclicalEvents($userId, $date, $minimalWeight = null) { $convertedDate = date(strtotime($date)); $dateDay = date("d", $convertedDate); //Get a numeric representation of the day of the week $dateWeek = date("w", $convertedDate); $dateMonth = intval(date("m", $convertedDate)) - 1; //adjust to app numeration $query = '( cyclical_events.cyclical_event_week_day = ' . $dateWeek . ' OR (cyclical_events.cyclical_event_month IS NULL AND cyclical_events.cyclical_event_day = ' . $dateDay . ')' . ' OR (cyclical_events.cyclical_event_month =' . $dateMonth . ' AND cyclical_events.cyclical_event_day = ' . $dateDay . ') )'; if ($minimalWeight !== null) { $query .= ' AND cyclical_events.cyclical_event_weight >= ' . $minimalWeight; } $allCyclicalThisDay = CyclicalEventsQuery::create()->where($query)->orderByCyclicalEventDay('asc')->orderByCyclicalEventWeekDay('asc')->filterByIdUser($userId)->find(); return $allCyclicalThisDay; }
public function viewAction($id) { $cyclicalEvent = CyclicalEventsQuery::create()->findPk($id); $userId = $this->getUser()->getId(); $request = $this->getRequest(); if (!$cyclicalEvent instanceof CyclicalEvents || $cyclicalEvent->getIdUser() !== $userId) { return $this->redirectToRoute('cyclical_events'); } if ($request->request->has('deletedEventId')) { $eventId = $request->request->get('deletedEventId'); $event = CyclicalEventsQuery::create()->findPk($eventId); if ($event instanceof CyclicalEvents) { $event->delete(); return new JsonResponse(true); } } return $this->render('OrganizerBundle:CyclicalEvents:view.html.twig', array('cyclicalEvent' => $cyclicalEvent)); }
public function validateCyclicalEvent($idCyclicalEvent) { //Protection from accessing another user lists $userId = $this->getUser()->getId(); $cyclicalEvent = CyclicalEventsQuery::create()->findPk($idCyclicalEvent); if (!$cyclicalEvent instanceof CyclicalEvents || $cyclicalEvent->getIdUser() != $userId) { return false; } return true; }
/** * Returns a new CyclicalEventsQuery object. * * @param string $modelAlias The alias of a model in the query * @param CyclicalEventsQuery|Criteria $criteria Optional Criteria to build the query from * * @return CyclicalEventsQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof CyclicalEventsQuery) { return $criteria; } $query = new CyclicalEventsQuery(null, null, $modelAlias); if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * Gets the number of CyclicalEvents 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 CyclicalEvents objects */ public function countCyclicalEventss($criteria = null, $distinct = false, PropelPDO $con = null) { if (null === $this->collCyclicalEventss || null !== $criteria) { if ($this->isNew() && null === $this->collCyclicalEventss) { return 0; } else { $query = CyclicalEventsQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByCustomLists($this)->count($con); } } else { return count($this->collCyclicalEventss); } }
/** * 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(CyclicalEventsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = CyclicalEventsQuery::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; } }