コード例 #1
0
ファイル: Closeperiod.php プロジェクト: jfesquet/tempos
 public function getDayCloseDuration($tst)
 {
     $start = strtotime($this->getStart());
     $stop = strtotime($this->getStop());
     $dayStart = mktime(0, 0, 0, date('m', $tst), date('d', $tst), date('Y', $tst));
     $dayStop = mktime(0, 0, 0, date('m', $tst), date('d', $tst) + 1, date('Y', $tst));
     if ($start < $dayStart) {
         $start = $dayStart;
     }
     if ($stop > $dayStop) {
         $stop = $dayStop;
     }
     $dayOfWeek = date('N', $tst) - 1;
     $c = DayperiodPeer::getFromRoomCriteria($this->getRoomId());
     $c->addAnd(DayperiodPeer::DAY_OF_WEEK, $dayOfWeek, Criteria::EQUAL);
     $dayperiods = DayperiodPeer::doSelect($c);
     if (count($dayperiods) > 0) {
         $result = 0;
         foreach ($dayperiods as $dayperiod) {
             $result += $dayperiod->getDurationIn($start, $stop, $dayStart);
         }
         return $result;
     } else {
         return 0;
     }
 }
コード例 #2
0
 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 = !DayperiodPeer::overlaps($values['id'], $values['start'], $values['stop'], $values['day_of_week'], $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;
 }
コード例 #3
0
ファイル: BaseDayperiod.php プロジェクト: jfesquet/tempos
 /**
  * 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 = DayperiodPeer::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->setDayOfWeek($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setRoomId($arr[$keys[4]]);
     }
 }
コード例 #4
0
ファイル: RoomPeer.php プロジェクト: jfesquet/tempos
 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;
 }
コード例 #5
0
ファイル: ReservationPeer.php プロジェクト: jfesquet/tempos
 public static function checkDayperiods($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 = DayperiodPeer::getFromRoomCriteria($roomId);
     $c->addAnd(DayperiodPeer::DAY_OF_WEEK, self::getWeekDaysFromInterval($starttime, $stoptime), Criteria::IN);
     $dayperiods = DayperiodPeer::doSelect($c);
     while ($starttime < $stoptime) {
         // Check if the start matches one dayperiod
         $tst = null;
         foreach ($dayperiods as $index => $dayperiod) {
             if ($dayperiod->matchTimestamp($starttime)) {
                 $tst = $dayperiod->getStopTimestamp($starttime);
                 unset($dayperiods[$index]);
                 break;
             }
         }
         if (is_null($tst)) {
             return false;
         }
         $starttime = $tst;
     }
     return true;
 }
コード例 #6
0
ファイル: BaseRoomPeer.php プロジェクト: jfesquet/tempos
 /**
  * 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;
 }
コード例 #7
0
ファイル: BaseDayperiodPeer.php プロジェクト: jfesquet/tempos
 /**
  * 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(DayperiodPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(DayperiodPeer::DATABASE_NAME);
         $criteria->add(DayperiodPeer::ID, $pks, Criteria::IN);
         $objs = DayperiodPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
コード例 #8
0
ファイル: actions.class.php プロジェクト: jfesquet/tempos
 public function executeRepeatWeek(sfWebRequest $request)
 {
     $this->forward404Unless($dayperiod = DayperiodPeer::retrieveByPk($request->getParameter('id')), sprintf('Object dayperiod does not exist (%s).', $request->getParameter('id')));
     $dayperiod->repeatWeek();
     $this->redirect('dayperiod/index?roomId=' . $dayperiod->getRoomId());
 }
コード例 #9
0
ファイル: Dayperiod.php プロジェクト: jfesquet/tempos
 protected function getOverlappingDayperiodsCriteria()
 {
     return DayperiodPeer::getOverlappingDayperiodsCriteria($this->getId(), $this->getStart(), $this->getStop(), $this->getDayOfWeek(), $this->getRoomId());
 }
コード例 #10
0
ファイル: BaseRoom.php プロジェクト: jfesquet/tempos
 /**
  * Returns the number of related Dayperiod objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related Dayperiod objects.
  * @throws     PropelException
  */
 public function countDayperiods(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->collDayperiods === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(DayperiodPeer::ROOM_ID, $this->id);
             $count = DayperiodPeer::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(DayperiodPeer::ROOM_ID, $this->id);
             if (!isset($this->lastDayperiodCriteria) || !$this->lastDayperiodCriteria->equals($criteria)) {
                 $count = DayperiodPeer::doCount($criteria, $con);
             } else {
                 $count = count($this->collDayperiods);
             }
         } else {
             $count = count($this->collDayperiods);
         }
     }
     return $count;
 }