Ejemplo n.º 1
0
 public function getAllReservationsCount($reservation_id = null)
 {
     $c = ReservationPeer::getPeriodCriteria(strtotime($this->getStart()), strtotime($this->getStop()));
     $c->addAnd(ReservationPeer::ACTIVITY_ID, $this->getActivityId(), Criteria::EQUAL);
     if (!is_null($this->getUserId())) {
         $c->addAnd(ReservationPeer::USER_ID, $this->getUserId(), Criteria::EQUAL);
     }
     if (!is_null($this->getCardId())) {
         $c->addAnd(ReservationPeer::CARD_ID, $this->getCardId(), Criteria::EQUAL);
     }
     if (!is_null($reservation_id)) {
         $c->addAnd(ReservationPeer::ID, $reservation_id, Criteria::NOT_EQUAL);
     }
     $c->clearSelectColumns();
     $c->addSelectColumn('SUM(' . ReservationPeer::DURATION . ')');
     $stmt = ReservationPeer::doSelectStmt($c);
     $row = $stmt->fetch(PDO::FETCH_NUM);
     return $row[0];
 }
Ejemplo n.º 2
0
 public static function getOccupancy($zone, $activities, $begin_date, $end_date)
 {
     $begin_date_str = date('Y-m-d', $begin_date);
     $end_date_str = date('Y-m-d', $end_date);
     /*print('Begin date: '.$begin_date_str.'<br>');
     		print('End date: '.$end_date_str.'<br>');*/
     if (!is_null($zone)) {
         $zone = ZonePeer::retrieveByPk($zone);
         //print('Zone is not null: '.$zone.' - Getting rooms....'.'<br>');
         $rooms = $zone->getRooms($activities);
     } else {
         //print('Zone is null !'.'<br>');
         $c = new Criteria();
         if (!empty($activities)) {
             $c->addJoin(RoomHasActivityPeer::ROOM_ID, RoomPeer::ID);
             $c->addAnd(RoomHasActivityPeer::ACTIVITY_ID, $activities, Criteria::IN);
         }
         $rooms = RoomPeer::doSelect($c);
     }
     /*print('All Rooms To Check:'.'<br>');
     		print_r ($rooms);
     		print('<br>');*/
     $report = array();
     foreach ($rooms as $room) {
         // Occupancy
         //print('Processing room: '.$room.'<br>');
         $c = new Criteria();
         $c->addJoin(ReservationPeer::ROOMPROFILE_ID, RoomprofilePeer::ID);
         $c->addJoin(RoomprofilePeer::ROOM_ID, RoomPeer::ID);
         $c->add(RoomPeer::ID, $room->getId(), Criteria::EQUAL);
         $c->addAnd(ReservationPeer::DATE, $begin_date_str, Criteria::GREATER_EQUAL);
         $c->addAnd(ReservationPeer::DATE, $end_date_str, Criteria::LESS_THAN);
         // We only keep finished reservation ?
         //$c->addAnd(ReservationPeer::STATUS, Reservation::BLOCKED, Criteria::EQUAL);
         if (!empty($activities)) {
             $c->addAnd(ReservationPeer::ACTIVITY_ID, $activities, Criteria::IN);
         }
         $c->clearSelectColumns();
         $c->addSelectColumn('SUM(' . ReservationPeer::DURATION . ')');
         $c->setLimit(1);
         //print ('SQL Command: '.$c->toString().'<br>');
         $stmt = ReservationPeer::doSelectStmt($c);
         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
             $occupancy_time = $row[0];
         }
         //print('Ocupancy time: '.$occupancy_time.'<br>');
         $total_time = 0;
         // Total time => Total number of opening hours in minutes during the begin and end date
         for ($date = $begin_date; $date < $end_date; $date = strtotime('+1 day', $date)) {
             $total_time += $room->getOpeningDuration(date('N', $date) - 1);
         }
         //print('Total door opening duration: '.$total_time.'<br>');
         if ($total_time <= 0) {
             continue;
         }
         // Results
         $report[$room->getId()] = array('room' => $room, 'occupancy_time' => $occupancy_time, 'total_time' => $total_time, 'ratio' => $total_time > 0 ? $occupancy_time / $total_time : null);
     }
     /*print('Final report:'.'<br>');
     		print_r ($report);
     		print('<br>');*/
     return $report;
 }
Ejemplo n.º 3
0
 public function countMinutesPerWeek($activityId, $roomId, $tst, $reservation_id = null)
 {
     $c = ReservationPeer::getWeekCriteria($tst);
     $c->addAnd(ReservationPeer::CARD_ID, $this->getId(), Criteria::EQUAL);
     $c->addAnd(ReservationPeer::ACTIVITY_ID, $activityId, Criteria::EQUAL);
     $zones = $this->getActiveSubscriptionsZones($activityId, $roomId);
     $rooms = ZonePeer::getRooms($zones);
     $rooms_ids = array();
     foreach ($rooms as $room) {
         $rooms_ids[] = $room->getId();
     }
     $c->addJoin(ReservationPeer::ROOMPROFILE_ID, RoomprofilePeer::ID);
     $c->addAnd(RoomprofilePeer::ROOM_ID, $rooms_ids, Criteria::IN);
     if (!is_null($reservation_id)) {
         $c->addand(ReservationPeer::ID, $reservation_id, Criteria::NOT_EQUAL);
     }
     $c->clearSelectColumns();
     $c->addSelectColumn('SUM(' . ReservationPeer::DURATION . ')');
     $c->setLimit(1);
     $stmt = ReservationPeer::doSelectStmt($c);
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         return $row[0];
     }
     return 0;
 }
Ejemplo n.º 4
0
 /**
  * Method to do selects.
  *
  * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
  * @param      PropelPDO $con
  * @return     array Array of selected Objects
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelect(Criteria $criteria, PropelPDO $con = null)
 {
     return ReservationPeer::populateObjects(ReservationPeer::doSelectStmt($criteria, $con));
 }
Ejemplo n.º 5
0
 /**
  * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
  *
  * This will only work if the object has been saved and has a valid primary key set.
  *
  * @param      boolean $deep (optional) Whether to also de-associated any related objects.
  * @param      PropelPDO $con (optional) The PropelPDO connection to use.
  * @return     void
  * @throws     PropelException - if this object is deleted, unsaved or doesn't have pk match in db
  */
 public function reload($deep = false, PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("Cannot reload a deleted object.");
     }
     if ($this->isNew()) {
         throw new PropelException("Cannot reload an unsaved object.");
     }
     if ($con === null) {
         $con = Propel::getConnection(ReservationPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     // We don't need to alter the object instance pool; we're just modifying this instance
     // already in the pool.
     $stmt = ReservationPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
     $row = $stmt->fetch(PDO::FETCH_NUM);
     $stmt->closeCursor();
     if (!$row) {
         throw new PropelException('Cannot find matching row in the database to reload object values.');
     }
     $this->hydrate($row, 0, true);
     // rehydrate
     if ($deep) {
         // also de-associate any related objects?
         $this->aRoomprofile = null;
         $this->aActivity = null;
         $this->aReservationreason = null;
         $this->aUsergroup = null;
         $this->aCard = null;
         $this->aUser = null;
         $this->aReservationRelatedByReservationparentId = null;
         $this->collReservationsRelatedByReservationparentId = null;
         $this->lastReservationRelatedByReservationparentIdCriteria = null;
         $this->collReservationOtherMemberss = null;
         $this->lastReservationOtherMembersCriteria = null;
     }
     // if (deep)
 }