public function executeDelete(sfWebRequest $request) { $request->checkCSRFProtection(); $this->forward404Unless($closeperiod = CloseperiodPeer::retrieveByPk($request->getParameter('id')), sprintf('Object closeperiod does not exist (%s).', $request->getParameter('id'))); $roomId = $closeperiod->getRoomId(); $closeperiod->delete(); $this->redirect('closeperiod/index?roomId=' . $roomId); }
public function doClean($values) { if (is_null($values)) { $values = array(); } if (!is_array($values)) { throw new InvalidArgumentException('You must pass an array parameter to the clean() method'); } if (is_null($values['start']) || is_null($values['stop'])) { $valid = true; } else { $valid = !CloseperiodPeer::overlaps($values['id'], $values['start'], $values['stop'], $values['Room_id']); } if (!$valid) { $error = new sfValidatorError($this, 'invalid', array()); if ($this->getOption('throw_global_error')) { throw $error; } throw new sfValidatorErrorSchema($this, array('start' => $error)); } return $values; }
public static function getGantt($room_list, $activityId, $person, $timestamp) { $now = time(); $room_id_list = PropelLogic::getIdList($room_list); // Get the day start $dayStart = ReservationPeer::getDayStart($timestamp); // We get all the reservations for the current room list in the week containing the given timestamp. $c = ReservationPeer::getDayCriteria($timestamp); $c->addJoin(ReservationPeer::ROOMPROFILE_ID, RoomprofilePeer::ID); $c->addAnd(RoomprofilePeer::ROOM_ID, $room_id_list, Criteria::IN); $c->addAscendingOrderByColumn(ReservationPeer::DATE); $reservations = ReservationPeer::doSelect($c); // We get all the day periods for the current room list. $dayOfWeek = date('N', $timestamp) - 1; $c = new Criteria(); $c->addAnd(DayperiodPeer::ROOM_ID, $room_id_list, Criteria::IN); $c->addAnd(DayperiodPeer::DAY_OF_WEEK, $dayOfWeek, Criteria::EQUAL); $c->addAscendingOrderByColumn(DayperiodPeer::START); $dayPeriods = DayperiodPeer::doSelect($c); // We get all the close periods for the current room list. $c = CloseperiodPeer::getDayCriteria($timestamp); $c->addAnd(CloseperiodPeer::ROOM_ID, $room_id_list, Criteria::IN); $c->addAscendingOrderByColumn(CloseperiodPeer::START); $c->addAscendingOrderByColumn(CloseperiodPeer::STOP); $closePeriods = CloseperiodPeer::doSelect($c); // We build the availability array $startIndex = 48; $stopIndex = 0; $result = array(); foreach ($room_list as $room) { $room_id = $room->getId(); $result[$room_id] = array(); $result[$room_id]['room'] = $room; for ($i = 0; $i < 48; ++$i) { $result[$room_id][$i] = array(); $tst = strtotime(date('Y-m-d H:i:s', $dayStart) . ' + ' . $i * 30 . ' minute'); $value = RoomPeer::COMPLETE; foreach ($dayPeriods as $dayPeriod) { if ($dayPeriod->getRoomId() == $room_id) { if ($dayPeriod->matchTimestamp($tst)) { if ($startIndex > $i) { $startIndex = $i; } if ($stopIndex <= $i) { $stopIndex = $i + 1; } $value = RoomPeer::FREE; break; } } } foreach ($closePeriods as $closePeriod) { if ($closePeriod->getRoomId() == $room_id) { if ($closePeriod->matchTimestamp($tst)) { $value = RoomPeer::COMPLETE; break; } } if (strtotime($closePeriod->getStart()) > $tst) { break; } } if ($value != RoomPeer::COMPLETE) { if ($tst < $now) { $value = RoomPeer::PAST; } else { $maximumTimestamp = $person->getMaximumDate($activityId, $room_id); if ($maximumTimestamp <= $tst || !$person->hasSubscription($activityId, $room_id, $tst)) { $value = RoomPeer::TOOFAR; } else { foreach ($reservations as $reservation) { if ($reservation->getRoomprofile()->getRoomId() == $room_id) { if ($reservation->matchTimestamp($tst)) { $value = RoomPeer::COMPLETE; break; } } if (strtotime($reservation->getDate()) > $tst) { break; } } } } } $result[$room_id][$i]['value'] = $value; $result[$room_id][$i]['timestamp'] = $tst; $result[$room_id][$i]['room'] = $room; $result['timestamps'][$i] = $tst; } } $result['startIndex'] = $startIndex; $result['stopIndex'] = $stopIndex; return $result; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = CloseperiodPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setStart($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setStop($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setRoomId($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setReason($arr[$keys[4]]); } }
public static function checkCloseperiods($start, $stop, $roomId) { $starttime = strtotime($start); $stoptime = strtotime($stop); if ($starttime >= $stoptime) { //throw new Exception('Start time cannot be superior or equal to stop time.'); return false; } $c = CloseperiodPeer::getFromRoomCriteria($roomId); $c->addAnd(CloseperiodPeer::STOP, $start, Criteria::GREATER_THAN); $c->addAnd(CloseperiodPeer::START, $stop, Criteria::LESS_THAN); return CloseperiodPeer::doCount($c) == 0; }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = RoomPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related Closeperiod objects $c = new Criteria(CloseperiodPeer::DATABASE_NAME); $c->add(CloseperiodPeer::ROOM_ID, $obj->getId()); $affectedRows += CloseperiodPeer::doDelete($c, $con); // delete related Dayperiod objects $c = new Criteria(DayperiodPeer::DATABASE_NAME); $c->add(DayperiodPeer::ROOM_ID, $obj->getId()); $affectedRows += DayperiodPeer::doDelete($c, $con); // delete related Roomprofile objects $c = new Criteria(RoomprofilePeer::DATABASE_NAME); $c->add(RoomprofilePeer::ROOM_ID, $obj->getId()); $affectedRows += RoomprofilePeer::doDelete($c, $con); // delete related RoomHasActivity objects $c = new Criteria(RoomHasActivityPeer::DATABASE_NAME); $c->add(RoomHasActivityPeer::ROOM_ID, $obj->getId()); $affectedRows += RoomHasActivityPeer::doDelete($c, $con); // delete related RoomHasEnergyaction objects $c = new Criteria(RoomHasEnergyactionPeer::DATABASE_NAME); $c->add(RoomHasEnergyactionPeer::ROOM_ID, $obj->getId()); $affectedRows += RoomHasEnergyactionPeer::doDelete($c, $con); // delete related RoomHasFeaturevalue objects $c = new Criteria(RoomHasFeaturevaluePeer::DATABASE_NAME); $c->add(RoomHasFeaturevaluePeer::ROOM_ID, $obj->getId()); $affectedRows += RoomHasFeaturevaluePeer::doDelete($c, $con); // delete related ZoneHasRoom objects $c = new Criteria(ZoneHasRoomPeer::DATABASE_NAME); $c->add(ZoneHasRoomPeer::ROOM_ID, $obj->getId()); $affectedRows += ZoneHasRoomPeer::doDelete($c, $con); } return $affectedRows; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(CloseperiodPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(CloseperiodPeer::DATABASE_NAME); $criteria->add(CloseperiodPeer::ID, $pks, Criteria::IN); $objs = CloseperiodPeer::doSelect($criteria, $con); } return $objs; }
/** * Returns the number of related Closeperiod objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Closeperiod objects. * @throws PropelException */ public function countCloseperiods(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(RoomPeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collCloseperiods === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(CloseperiodPeer::ROOM_ID, $this->id); $count = CloseperiodPeer::doCount($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return count of the collection. $criteria->add(CloseperiodPeer::ROOM_ID, $this->id); if (!isset($this->lastCloseperiodCriteria) || !$this->lastCloseperiodCriteria->equals($criteria)) { $count = CloseperiodPeer::doCount($criteria, $con); } else { $count = count($this->collCloseperiods); } } else { $count = count($this->collCloseperiods); } } return $count; }