public static function GetRoom() { $c = new Criteria(); $c->add(RoomPeer::STATUS, Constant::RECORD_STATUS_ACTIVE); $rooms = RoomPeer::doSelect($c); return $rooms; }
public function executeCreate(sfWebRequest $request) { $this->forward404Unless($request->isMethod('post')); $this->forward404Unless($this->room = RoomPeer::retrieveByPk($request->getParameter('roomId')), sprintf('Object room does not exist (%s).', $request->getParameter('roomId'))); $this->form = new RoomprofileForm(); $this->processForm($request, $this->form); $this->form->setDefaultRoom($this->room); $this->setTemplate('new'); }
public function executeCreate(sfWebRequest $request) { $this->forward404Unless($request->isMethod('post')); $this->forward404Unless($this->room = RoomPeer::retrieveByPk($request->getParameter('roomId')), sprintf('Object room does not exist (%s).', $request->getParameter('roomId'))); $this->form = new DayperiodForm(); $day = $request->getParameter('day'); if (!is_null($day)) { $this->form->setDefaultWeekDay($day); } $this->processForm($request, $this->form); $this->form->setDefaultRoom($this->room); $this->setTemplate('new'); }
public function executeDelete(sfWebRequest $request) { $room = RoomPeer::retrieveByPk(Utility::DecryptQueryString($request->getParameter('id'))); if ($room) { $room->setStatus(Constant::RECORD_STATUS_DELETED); if ($room->save()) { $this->getUser()->setFlash('SUCCESS_MESSAGE', Constant::RECORD_STATUS_DELETED_SUCCESSFULLY); } else { $this->getUser()->setFlash('ERROR_MESSAGE', Constant::DB_ERROR); } } else { $this->getUser()->setFlash('ERROR_MESSAGE', Constant::INVALID_REQUEST); } $this->redirect('Room/list'); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->form = new OccupancyForm(array(), array(), false); $formName = $this->form->getName(); $this->getUser()->syncParameters($this, 'occupancy', 'index', array($formName), $request); $this->occupancy_list = array(); $this->filtered = false; if (!is_null($this->{$formName})) { $this->filtered = true; $this->form->bind($this->{$formName}, $request->getFiles($formName)); if ($this->form->isValid()) { $this->occupancy_list = RoomPeer::getOccupancy($this->form->getValue('zone'), $this->form->getValue('activities'), strtotime($this->form->getValue('begin_date')), strtotime($this->form->getValue('end_date'))); } } }
public function canAccessRoom($roomId, $activityId = null) { $zones = $this->getActiveSubscriptionsZones($activityId); foreach ($zones as $zone) { if ($zone->hasRoom($roomId)) { if (RoomPeer::isRoomActive($roomId)) { return true; } } } return false; }
/** * 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(RoomPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(RoomPeer::DATABASE_NAME); $criteria->add(RoomPeer::ID, $pks, Criteria::IN); $objs = RoomPeer::doSelect($criteria, $con); } return $objs; }
public function executeSendDeleteMessage(sfWebRequest $request) { $this->forward404Unless($this->user = UserPeer::retrieveByPk($request->getParameter('userId')), sprintf('Object user does not exist (%s).', $request->getParameter('userId'))); $this->forward404Unless($this->room = RoomPeer::retrieveByPk($request->getParameter('roomId')), sprintf('Object room does not exist (%s).', $request->getParameter('roomId'))); $this->forward404Unless($this->activity = ActivityPeer::retrieveByPk($this->getUser()->getAttribute('activityId')), sprintf('Object activity does not exist (%s).', $this->getUser()->getAttribute('activityId'))); $sender = $this->getUser()->getTemposUser(); $this->form = new MessageForm(); $this->form->setRecipient($this->user); $this->form->setSender($sender); }
public function getOpeningDuration($dayOfWeek = null) { return RoomPeer::getOpeningDuration($this->getId(), $dayOfWeek); }
/** * This function performs the validation work for complex object models. * * In addition to checking the current object, all related objects will * also be validated. If all pass then <code>true</code> is returned; otherwise * an aggreagated array of ValidationFailed objects will be returned. * * @param array $columns Array of column names to validate. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise. */ protected function doValidate($columns = null) { if (!$this->alreadyInValidation) { $this->alreadyInValidation = true; $retval = null; $failureMap = array(); // We call the validate method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aUser !== null) { if (!$this->aUser->validate($columns)) { $failureMap = array_merge($failureMap, $this->aUser->getValidationFailures()); } } if (($retval = RoomPeer::doValidate($this, $columns)) !== true) { $failureMap = array_merge($failureMap, $retval); } if ($this->collProductions !== null) { foreach ($this->collProductions as $referrerFK) { if (!$referrerFK->validate($columns)) { $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures()); } } } if ($this->collPermissions !== null) { foreach ($this->collPermissions as $referrerFK) { if (!$referrerFK->validate($columns)) { $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures()); } } } $this->alreadyInValidation = false; } return !empty($failureMap) ? $failureMap : true; }
/** * 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 = RoomPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setTitle($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setDescription($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setPrice($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setStatus($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setCreatedAt($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setUpdatedAt($arr[$keys[6]]); } }
} } else { ?> <?php foreach ($zones as $zone) { ?> <?php if ($zone->getDirectRoomsCount($activity->getId(), RoomPeer::getActiveCriteria()) > 0) { ?> <h3><?php echo $zone->getName(); ?> </h3> <ul class="blocklist"> <?php foreach ($zone->getDirectRooms($activity->getId(), RoomPeer::getActiveCriteria()) as $room) { ?> <?php $features_array = $room->getValuedFeaturesArray(); ?> <?php echo block_item($room->getName(), array(color_square($activity->getColor()), definition_list(array(__('Capacity') => $room->getCapacity(), __('Address') => $room->getAddress())), definition_list($features_array), link_to(__('Select'), 'reservation/index?roomId=' . $room->getId()))); ?> <?php } ?> </ul> <?php } ?>
/** * Selects a collection of Permission objects pre-filled with all related objects except User. * * @return array Array of Permission objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptUser(Criteria $c, $con = null) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } PermissionPeer::addSelectColumns($c); $startcol2 = PermissionPeer::NUM_COLUMNS - PermissionPeer::NUM_LAZY_LOAD_COLUMNS + 1; RoomPeer::addSelectColumns($c); $startcol3 = $startcol2 + RoomPeer::NUM_COLUMNS; $c->addJoin(PermissionPeer::ROOM_ID, RoomPeer::ROOM_ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = PermissionPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = RoomPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getRoom(); //CHECKME if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addPermission($obj1); break; } } if ($newObject) { $obj2->initPermissions(); $obj2->addPermission($obj1); } $results[] = $obj1; } return $results; }
/** * Selects a collection of RoomHasFeaturevalue objects pre-filled with all related objects except Featurevalue. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of RoomHasFeaturevalue objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptFeaturevalue(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } RoomHasFeaturevaluePeer::addSelectColumns($c); $startcol2 = RoomHasFeaturevaluePeer::NUM_COLUMNS - RoomHasFeaturevaluePeer::NUM_LAZY_LOAD_COLUMNS; RoomPeer::addSelectColumns($c); $startcol3 = $startcol2 + (RoomPeer::NUM_COLUMNS - RoomPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(RoomHasFeaturevaluePeer::ROOM_ID), array(RoomPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = RoomHasFeaturevaluePeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = RoomHasFeaturevaluePeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $omClass = RoomHasFeaturevaluePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); RoomHasFeaturevaluePeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Room rows $key2 = RoomPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = RoomPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = RoomPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); RoomPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (RoomHasFeaturevalue) to the collection in $obj2 (Room) $obj2->addRoomHasFeaturevalue($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Description : Retrieve a room from data base by code * * @param String $roomCode : code of a room * @return : Room object */ public function getRoomByCode($roomCode) { try { $criteria = new Criteria(); $criteria->add(RoomPeer::CODE, $roomCode); return RoomPeer::doSelectOne($criteria); } catch (Exception $e) { return null; } }
public function getDirectRooms($activities = null, $c = null) { if (is_null($c)) { $c = new Criteria(); } $c->addAnd(ZoneHasRoomPeer::ZONE_ID, $this->getId(), Criteria::EQUAL); if (!empty($activities)) { if (!is_array($activities)) { $activities = array($activities); } $c->addJoin(RoomHasActivityPeer::ROOM_ID, ZoneHasRoomPeer::ROOM_ID); $c->addAnd(RoomHasActivityPeer::ACTIVITY_ID, $activities, Criteria::IN); } $c->addJoin(RoomPeer::ID, ZoneHasRoomPeer::ROOM_ID, Criteria::LEFT_JOIN); $c->addAscendingOrderByColumn(RoomPeer::NAME); return RoomPeer::doSelect($c); }
/** * Get the associated Room object * * @param Connection Optional Connection object. * @return Room The associated Room object. * @throws PropelException */ public function getRoom($con = null) { // include the related Peer class include_once 'src/model/whiteboard/om/BaseRoomPeer.php'; if ($this->aRoom === null && $this->room_id !== null) { $this->aRoom = RoomPeer::retrieveByPK($this->room_id, $con); /* The following can be used instead of the line above to guarantee the related object contains a reference to this object, but this level of coupling may be undesirable in many circumstances. As it can lead to a db query with many results that may never be used. $obj = RoomPeer::retrieveByPK($this->room_id, $con); $obj->addRooms($this); */ } return $this->aRoom; }
/** * 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 = RoomPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCapacity($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setAddress($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setDescription($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setIsActive($arr[$keys[5]]); } }
protected function processCopyForm(sfWebRequest $request, sfForm $form, Room $room) { $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $this->forward404Unless($copyRoom = RoomPeer::retrieveByPk($form->getValue('copyRoom_id')), sprintf('Object room does not exist (%s).', $form->getValue('copyRoom_id'))); if ($copyRoom->getId() != $room->getId()) { $room->copyDayperiodsFromRoom($copyRoom); $room->save(); } $this->redirect('dayperiod/index?roomId=' . $room->getId()); } }
protected static function getMonthAvailability($room_id_list, $activityId, $person, $timestamp) { $now = time(); // Get the month limits $monthStart = ReservationPeer::getMonthStart($timestamp); $monthStop = ReservationPeer::getMonthStop($timestamp); $tst = $monthStart; // We get all the reservations for the current room list in the month containing the given timestamp. $c = ReservationPeer::getMonthCriteria($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. $c = new Criteria(); $c->addAnd(DayperiodPeer::ROOM_ID, $room_id_list, Criteria::IN); $c->addAscendingOrderByColumn(DayperiodPeer::DAY_OF_WEEK); $c->addAscendingOrderByColumn(DayperiodPeer::START); $c->addGroupByColumn(DayperiodPeer::ROOM_ID); $c->addGroupByColumn(DayperiodPeer::DAY_OF_WEEK); $dayPeriods = DayperiodPeer::doSelect($c); // We get all the close periods for the current room list. $c = CloseperiodPeer::getMonthCriteria($timestamp); $c->addAnd(CloseperiodPeer::ROOM_ID, $room_id_list, Criteria::IN); $c->addAscendingOrderByColumn(CloseperiodPeer::START); $c->addAscendingOrderByColumn(CloseperiodPeer::STOP); $closePeriods = CloseperiodPeer::doSelect($c); // Days off $dayOff = array(); for ($i = 0; $i < 7; ++$i) { $dayOff[$i] = 0; } foreach ($dayPeriods as $dayPeriod) { ++$dayOff[$dayPeriod->getDayOfWeek()]; } // Opening duration $roomsDurations = array(); for ($dayOfWeek = 0; $dayOfWeek < 7; ++$dayOfWeek) { $roomsDurations[$dayOfWeek] = array(); foreach ($room_id_list as $room_id) { $roomsDurations[$dayOfWeek][$room_id] = RoomPeer::getOpeningDuration($room_id, $dayOfWeek); } } $roomsDuration = array(); // Result $result = array(); for ($i = 1; $tst < $monthStop; ++$i) { $roomsId = $room_id_list; $dayOfWeek = date('N', $tst) - 1; $roomsDuration = $roomsDurations[$dayOfWeek]; if ($dayOff[$dayOfWeek] == 0) { $value = RoomPeer::COMPLETE; $roomsId = array(); } else { $value = RoomPeer::FREE; foreach ($closePeriods as $closePeriod) { if ($closePeriod->matchFullDayTimestamp($tst)) { $roomsDuration[$closePeriod->getRoomId()] = 0; } elseif ($closePeriod->matchDayTimestamp($tst)) { $roomsDuration[$closePeriod->getRoomId()] -= $closePeriod->getDayCloseDuration($tst); $value = RoomPeer::OCCUPIED; } } if (strtotime(date('Y-m-d', $now)) > $tst) { $value = RoomPeer::PAST; } else { $cnt = 0; foreach ($room_id_list as $roomId) { $maximumTimestamp = $person->getMaximumDate($activityId, $roomId); if ($maximumTimestamp <= $tst || !$person->hasSubscription($activityId, $roomId, $tst)) { ++$cnt; unset($roomsId[array_search($roomId, $roomsId)]); } } if ($cnt == count($room_id_list)) { $value = RoomPeer::TOOFAR; } else { if ($dayOff[$dayOfWeek] < count($room_id_list)) { $value = RoomPeer::OCCUPIED; } foreach ($reservations as $reservation) { if (!$reservation->isOld()) { if ($reservation->matchDayTimestamp($tst)) { $roomsDuration[$reservation->getRoomprofile()->getRoomId()] -= $reservation->getDuration($tst); $value = RoomPeer::OCCUPIED; } elseif (strtotime($reservation->getDate() . ' - 1 day') > $tst) { break; } } } $cnt = 0; foreach ($room_id_list as $room_id) { if ($roomsDuration[$room_id] < 60) { ++$cnt; unset($roomsId[array_search($room_id, $roomsId)]); } } if ($cnt < count($room_id_list)) { if ($cnt > 0) { $value = RoomPeer::OCCUPIED; } } else { $value = RoomPeer::COMPLETE; $roomsId = array(); } } } } $result[$i] = array(); $result[$i]['value'] = $value; $result[$i]['timestamp'] = $tst; $result[$i]['rooms'] = $roomsId; $tst = strtotime(date('Y-m-d', $monthStart) . ' + ' . $i . ' day'); } return $result; }
public function executeSearchRoomProcess(sfWebRequest $request) { $this->forward404Unless($request->isMethod('post')); $this->handleZoneParameters($request); $this->form = new RoomSearchForm($this->activity); $this->form->setIsActive(true); $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName())); if ($this->form->isValid()) { $this->rooms = RoomPeer::searchRooms($this->activity->getId(), $this->form->getValue('is_active'), $this->form->getValue('namePattern'), $this->form->getValue('capacity'), $this->form->getValue('addressPattern'), $this->form->getValue('descriptionPattern'), $this->form->getFeaturesFieldsValues()); $this->rooms = $this->person->filterAccessibleRooms($this->rooms); $this->setTemplate('roomIndex'); } else { $this->setTemplate('searchRoom'); } }
/** * Get the associated Room object * * @param PropelPDO Optional Connection object. * @return Room The associated Room object. * @throws PropelException */ public function getRoom(PropelPDO $con = null) { if ($this->aRoom === null && $this->room_id !== null) { $c = new Criteria(RoomPeer::DATABASE_NAME); $c->add(RoomPeer::ID, $this->room_id); $this->aRoom = RoomPeer::doSelectOne($c, $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->aRoom->addRoomHasFeaturevalues($this); */ } return $this->aRoom; }
/** * Returns the number of related Rooms. * * @param Criteria $criteria * @param boolean $distinct * @param Connection $con * @throws PropelException */ public function countRooms($criteria = null, $distinct = false, $con = null) { // include the Peer class include_once 'src/model/whiteboard/om/BaseRoomPeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } $criteria->add(RoomPeer::USER_ID, $this->getUserId()); return RoomPeer::doCount($criteria, $distinct, $con); }