public static function reportTime($activities, $rooms, $begin_date, $end_date, $begin_hour, $end_hour, $periodicity, $number, $c = null) { if (is_null($c)) { $c = new Criteria(); } /*print '<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>'; $l = ReservationPEER::doSelect($c); foreach ($l as $t) { $tab_res = $t->getReservationsRelatedByReservationparentId(); print 'ID : '.$t->getId().'<br/>'; print 'DT : '.$t->getDate().'<br/>'; print 'AC : '.$t->getActivity().'<br/>'; print 'CT : '.$t->countReservationsRelatedByReservationparentId().'<br/>'; print 'RP : '.$t->getReservationRelatedByReservationparentId().'<br/>'; print 'RF : '.$tab_res[0].'<br/><br/>'; }*/ $begin_date = date('Y-m-d', $begin_date); $end_date = date('Y-m-d', $end_date); // Tableaux contenant les heures de début et fin $begin_hour = date('H:i', $begin_hour); $tab_begin_hour = explode(":", $begin_hour); $end_hour = date('H:i', $end_hour); $tab_end_hour = explode(":", $end_hour); // Heure pour dates curseurs $cursor_date = strtotime("{$begin_date} + {$tab_begin_hour['0']} hours + {$tab_begin_hour['1']} minutes"); if ($end_hour <= $begin_hour) { $end_cursor = strtotime("{$begin_date} + {$tab_end_hour['0']} hours + {$tab_end_hour['1']} minutes + 1 day"); if ($begin_date == $end_date || $begin_hour == '00:00' && $begin_hour == $end_hour) { $end_date = strtotime("{$end_date} + {$tab_end_hour['0']} hours + {$tab_end_hour['1']} minutes + 1 day"); } else { $end_date = strtotime("{$end_date} + {$tab_end_hour['0']} hours + {$tab_end_hour['1']} minutes"); } } else { $end_cursor = strtotime("{$begin_date} + {$tab_end_hour['0']} hours + {$tab_end_hour['1']} minutes"); $end_date = strtotime("{$end_date} + {$tab_end_hour['0']} hours + {$tab_end_hour['1']} minutes"); } // print "DATE : ".date('Y-m-d H:i:s', $cursor_date)." - ".date('Y-m-d H:i:s', $end_cursor)."<br/>"; // print "DATE : ".date('Y-m-d H:i:s', strtotime($begin_date))." - ".date('Y-m-d H:i:s', $end_date)."<br/>"; // Définition du pas switch ($periodicity) { case 'dayly': $period = 'day'; break; case 'weekly': $period = 'week'; break; case 'monthly': $period = 'month'; break; case 'annual': $period = 'year'; break; default: $period = 'day'; break; } $count = 0; $crit = null; while ($end_cursor <= $end_date) { $count++; // print "DATE $count => cursor_date : ".date('Y-m-d H:i:s', $cursor_date)." - end_cursor : ".date('Y-m-d H:i:s', $end_cursor)." - end_date : ". date('Y-m-d H:i:s', $end_date)."<br/>"; // Requête Criteria $crit1 = $c->getNewCriterion(ReservationPeer::DATE, $cursor_date, Criteria::GREATER_EQUAL); $crit2 = $c->getNewCriterion(ReservationPeer::DATE, strtotime(date('Y-m-d H:i:s')), Criteria::GREATER_EQUAL); $crit3 = $c->getNewCriterion(ReservationPeer::DATE, "DATE_ADD(" . ReservationPeer::DATE . ", INTERVAL " . ReservationPeer::DURATION . " MINUTE) <= '" . date('Y-m-d H:i:s', $end_cursor) . "'", Criteria::CUSTOM); $crit1->addAnd($crit2); $crit1->addAnd($crit3); if ($count > 1) { $crit->addOr($crit1); } else { $crit = $crit1; } $cursor_date = strtotime(date('Y-m-d H:i:s', $cursor_date) . ' + ' . $number . ' ' . $period); $end_cursor = strtotime(date('Y-m-d H:i:s', $end_cursor) . ' + ' . $number . ' ' . $period); } $c->add($crit); if (!empty($activities)) { $c->addAnd(ReservationPeer::ACTIVITY_ID, $activities, Criteria::IN); } if (is_null($rooms)) { $rooms = array(); } 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::ACTIVITY_ID, ActivityPeer::ID); $c->addJoin(ReservationPeer::ROOMPROFILE_ID, RoomprofilePeer::ID); $c->addJoin(RoomprofilePeer::ROOM_ID, RoomPeer::ID); $c->addGroupByColumn(ReservationPeer::ID); // print ($c->toString().'<br>'); return self::doSelect($c); }
public function executeIndex(sfWebRequest $request) { $this->forward404Unless($this->room = RoomPeer::retrieveByPk($request->getParameter('roomId')), sprintf('Object room does not exist (%s).', $request->getParameter('roomId'))); $this->roomprofile_list = RoomprofilePeer::doSelectFromRoom($this->room->getId()); }