public function executeDelete(sfWebRequest $request) { $request->checkCSRFProtection(); $this->forward404Unless($zone = ZonePeer::retrieveByPk($request->getParameter('id')), sprintf('Object zone does not exist (%s).', $request->getParameter('id'))); $zone->delete(); $this->redirect('zone/index'); }
public function executeNew(sfWebRequest $request) { $this->form = new RoomForm(); $this->checkReferer($request); if ($request->hasParameter('parentZoneId')) { $this->forward404Unless($parentZone = ZonePeer::retrieveByPk($request->getParameter('parentZoneId')), sprintf('Object zone does not exist (%s).', $request->getParameter('parentZoneId'))); $this->form->addParentZone($parentZone); } }
/** * Returns the choices associated to the model. * * @return array An array of choices */ public function getChoices() { $choices = array(); $add_empty = $this->getOption('add_empty'); if ($add_empty === true) { $choices[''] = array('level' => 0, 'label' => __('Root')); } $root_zones = ZonePeer::doSelectRoot(); $current_zone = $this->getOption('current_zone', null); foreach ($root_zones as $root_zone) { $this->addZoneChoice($choices, $root_zone, $current_zone, $add_empty ? 1 : 0); } return $choices; }
public static function getHasRoomCriteria($roomId, $c = null) { if (is_null($c)) { $c = new Criteria(); } if (!is_null($roomId)) { $zones = ZonePeer::doSelectHasRoom($roomId, false); $zones_ids = array(); foreach ($zones as $zone) { $zones_ids[] = $zone->getId(); } $c->add(SubscriptionPeer::ZONE_ID, $zones_ids, Criteria::IN); } return $c; }
/** * Returns the number of related Zone objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Zone objects. * @throws PropelException */ public function countZonesRelatedByParentZone(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(ZonePeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collZonesRelatedByParentZone === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(ZonePeer::PARENT_ZONE, $this->id); $count = ZonePeer::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(ZonePeer::PARENT_ZONE, $this->id); if (!isset($this->lastZoneRelatedByParentZoneCriteria) || !$this->lastZoneRelatedByParentZoneCriteria->equals($criteria)) { $count = ZonePeer::doCount($criteria, $con); } else { $count = count($this->collZonesRelatedByParentZone); } } else { $count = count($this->collZonesRelatedByParentZone); } } return $count; }
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; }
public static function report($users, $usergroups, $activities, $zones, $rooms, $begin_date, $end_date, $c = null) { if (is_null($c)) { $c = new Criteria(); } $begin_date = date('Y-m-d', $begin_date); $end_date = date('Y-m-d', $end_date); $c->addAnd(ReservationPeer::DATE, $begin_date, Criteria::GREATER_EQUAL); $c->addAnd(ReservationPeer::DATE, $end_date, Criteria::LESS_THAN); if (!empty($users)) { $c->addAnd(ReservationPeer::USER_ID, $users, Criteria::IN); } if (!empty($usergroups)) { //print ('Before usergroup'.$c->toString()); //$c->addJoin(ReservationPeer::USER_ID, UsergroupHasUserPeer::USER_ID, Criteria::LEFT_JOIN); //$c->addJoin(ReservationPeer::USER_ID, UsergroupHasChiefPeer::USER_ID, Criteria::LEFT_JOIN); //$critUser = $c->getNewCriterion(UsergroupHasUserPeer::USERGROUP_ID, $usergroups, Criteria::IN); //$critChief = $c->getNewCriterion(UsergroupHasChiefPeer::USERGROUP_ID, $usergroups, Criteria::IN); //$critChief->addOr($critUser); //$c->addAnd($critChief); $c->addAnd(ReservationPeer::USERGROUP_ID, $usergroups, Criteria::IN); //print ('After usergroup'.$c->toString()); } if (!empty($activities)) { $c->addAnd(ReservationPeer::ACTIVITY_ID, $activities, Criteria::IN); } if (is_null($rooms)) { $rooms = array(); } if (!empty($zones)) { // Retrieving all rooms from the zone and adding to the rooms array foreach ($zones as $zone) { //print (' Current zone: '.$zone.'<br>'); $zp = ZonePeer::retrieveByPk($zone); if (!is_null($zp)) { $rms = $zp->getRooms(); if (!is_null($rms) && is_array($rms)) { foreach ($rms as $r) { //print (' Room ID: '.$r->getId().'<br>'); $rooms[] = $r->getId(); } } } } } //print_r ($rooms); if (!empty($rooms) && is_array($rooms) && count($rooms) > 0) { // Retrieve room profile ID from all rooms $roomsProfiles = array(); foreach ($rooms as $room) { //print (' Current room: '.$room.'<br>'); $rpp = RoomprofilePeer::doSelectFromRoom($room); if (!is_null($rpp) && is_array($rpp)) { foreach ($rpp as $prof) { //print (' Room profile: '.$prof->getId().'<br>'); $roomsProfiles[] = $prof->getId(); } } } //print_r ($roomsProfiles); if (!empty($roomsProfiles) && is_array($roomsProfiles) && count($roomsProfiles) > 0) { $c->addAnd(ReservationPeer::ROOMPROFILE_ID, $roomsProfiles, Criteria::IN); } } // These joins are needed for sorting purposes $c->addJoin(ReservationPeer::USER_ID, UserPeer::ID); $c->addJoin(ReservationPeer::ACTIVITY_ID, ActivityPeer::ID); $c->addJoin(ReservationPeer::RESERVATIONREASON_ID, ReservationreasonPeer::ID, Criteria::LEFT_JOIN); $c->addJoin(ReservationPeer::ROOMPROFILE_ID, RoomprofilePeer::ID); $c->addJoin(RoomprofilePeer::ROOM_ID, RoomPeer::ID); $c->addJoin(ReservationPeer::USERGROUP_ID, UsergroupPeer::ID, Criteria::LEFT_JOIN); $c->addGroupByColumn(ReservationPeer::ID); //print ($c->toString().'<br>'); return self::doSelect($c); }
public function getActiveSubscriptionsZones($activityId = null, $roomId = null) { $c = SubscriptionPeer::getActiveCriteria(); $c->addAnd(SubscriptionPeer::CARD_ID, $this->getId(), Criteria::EQUAL); $c->addJoin(SubscriptionPeer::ZONE_ID, ZonePeer::ID); if (!is_null($activityId)) { $c->addAnd(SubscriptionPeer::ACTIVITY_ID, $activityId); } if (!is_null($roomId)) { $c = SubscriptionPeer::getHasRoomCriteria($roomId, $c); } $c->addGroupByColumn(ZonePeer::ID); return ZonePeer::doSelect($c); }
/** * Get the associated Zone object * * @param PropelPDO Optional Connection object. * @return Zone The associated Zone object. * @throws PropelException */ public function getZone(PropelPDO $con = null) { if ($this->aZone === null && $this->zone_id !== null) { $c = new Criteria(ZonePeer::DATABASE_NAME); $c->add(ZonePeer::ID, $this->zone_id); $this->aZone = ZonePeer::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->aZone->addZoneHasRooms($this); */ } return $this->aZone; }
/** * Selects a collection of Subscription objects pre-filled with all related objects except Usergroup. * * @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 Subscription objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptUsergroup(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); } SubscriptionPeer::addSelectColumns($c); $startcol2 = SubscriptionPeer::NUM_COLUMNS - SubscriptionPeer::NUM_LAZY_LOAD_COLUMNS; ActivityPeer::addSelectColumns($c); $startcol3 = $startcol2 + (ActivityPeer::NUM_COLUMNS - ActivityPeer::NUM_LAZY_LOAD_COLUMNS); ZonePeer::addSelectColumns($c); $startcol4 = $startcol3 + (ZonePeer::NUM_COLUMNS - ZonePeer::NUM_LAZY_LOAD_COLUMNS); CardPeer::addSelectColumns($c); $startcol5 = $startcol4 + (CardPeer::NUM_COLUMNS - CardPeer::NUM_LAZY_LOAD_COLUMNS); UserPeer::addSelectColumns($c); $startcol6 = $startcol5 + (UserPeer::NUM_COLUMNS - UserPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(SubscriptionPeer::ACTIVITY_ID), array(ActivityPeer::ID), $join_behavior); $c->addJoin(array(SubscriptionPeer::ZONE_ID), array(ZonePeer::ID), $join_behavior); $c->addJoin(array(SubscriptionPeer::CARD_ID), array(CardPeer::ID), $join_behavior); $c->addJoin(array(SubscriptionPeer::USER_ID), array(UserPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = SubscriptionPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = SubscriptionPeer::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 = SubscriptionPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); SubscriptionPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Activity rows $key2 = ActivityPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ActivityPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = ActivityPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ActivityPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (Subscription) to the collection in $obj2 (Activity) $obj2->addSubscription($obj1); } // if joined row is not null // Add objects for joined Zone rows $key3 = ZonePeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = ZonePeer::getInstanceFromPool($key3); if (!$obj3) { $omClass = ZonePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); ZonePeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (Subscription) to the collection in $obj3 (Zone) $obj3->addSubscription($obj1); } // if joined row is not null // Add objects for joined Card rows $key4 = CardPeer::getPrimaryKeyHashFromRow($row, $startcol4); if ($key4 !== null) { $obj4 = CardPeer::getInstanceFromPool($key4); if (!$obj4) { $omClass = CardPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj4 = new $cls(); $obj4->hydrate($row, $startcol4); CardPeer::addInstanceToPool($obj4, $key4); } // if $obj4 already loaded // Add the $obj1 (Subscription) to the collection in $obj4 (Card) $obj4->addSubscription($obj1); } // if joined row is not null // Add objects for joined User rows $key5 = UserPeer::getPrimaryKeyHashFromRow($row, $startcol5); if ($key5 !== null) { $obj5 = UserPeer::getInstanceFromPool($key5); if (!$obj5) { $omClass = UserPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj5 = new $cls(); $obj5->hydrate($row, $startcol5); UserPeer::addInstanceToPool($obj5, $key5); } // if $obj5 already loaded // Add the $obj1 (Subscription) to the collection in $obj5 (User) $obj5->addSubscription($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * 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(ZonePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(ZonePeer::DATABASE_NAME); $criteria->add(ZonePeer::ID, $pks, Criteria::IN); $objs = ZonePeer::doSelect($criteria, $con); } return $objs; }
public function getRooms($activities = null) { $result = $this->getDirectRooms($activities); $children = ZonePeer::doSelectChildrenZones($this->getId()); foreach ($children as $child) { $result = array_merge($result, $child->getRooms($activities)); } return array_unique($result); }
/** * Selects a collection of ZoneHasRoom objects pre-filled with all related objects except Room. * * @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 ZoneHasRoom objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptRoom(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); } ZoneHasRoomPeer::addSelectColumns($c); $startcol2 = ZoneHasRoomPeer::NUM_COLUMNS - ZoneHasRoomPeer::NUM_LAZY_LOAD_COLUMNS; ZonePeer::addSelectColumns($c); $startcol3 = $startcol2 + (ZonePeer::NUM_COLUMNS - ZonePeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(ZoneHasRoomPeer::ZONE_ID), array(ZonePeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ZoneHasRoomPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ZoneHasRoomPeer::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 = ZoneHasRoomPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); ZoneHasRoomPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Zone rows $key2 = ZonePeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ZonePeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = ZonePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ZonePeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (ZoneHasRoom) to the collection in $obj2 (Zone) $obj2->addZoneHasRoom($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }