Esempio n. 1
0
 /**
  * Check if unit is flexible available in the period: at least one available day in given period.
  *
  * @param RM_Unit_Row $unit
  * @param RM_Reservation_Period $reservationPeriod
  * @return bool
  */
 public function isFlexibleAvailable(RM_Unit_Row $unit, RM_Reservation_Period $reservationPeriod)
 {
     $days = $reservationPeriod->getDays();
     foreach ($days as $day) {
         $end = clone $day->addDay(1);
         $currentReservationPeriod = new RM_Reservation_Period($day, $end);
         if ($this->isAvailableUnitbyDate($unit, $currentReservationPeriod)) {
             return true;
         }
     }
     return false;
 }
 public function getganttJsonAction()
 {
     $ids = explode(",", $this->_getParam('ids'));
     // id's of units
     $startdatetime = new RM_Date(strtotime($this->_getParam('start_datetime', date(RM_Config::MYSQL_DATEFORMAT_SHORT))));
     $enddatetime = new RM_Date(strtotime($this->_getParam('end_datetime', date(RM_Config::MYSQL_DATEFORMAT_SHORT))));
     // 1 get all the days between the start and end period
     $RM_PeriodObj = new RM_Reservation_Period($startdatetime, $enddatetime);
     $days = $RM_PeriodObj->getDays();
     $numberofDays = count($days);
     // 2 cycle through each unit specified and check if the date is reserved or not
     $unitModel = new RM_Units();
     $reservationModel = new RM_Reservations();
     $daycount = 0;
     $unitcount = 0;
     $colspan = 0;
     $dateInfo = array();
     $monthInfo = array();
     $years = new stdClass();
     $years->startyear = $days[0]->toString("Y");
     // set the start year
     foreach ($ids as $id) {
         $unit = $unitModel->get($id);
         $unitInfo = new stdClass();
         $unitInfo->id = $id;
         $unitInfo->unitname = $unit->name;
         $reservationData = array();
         foreach ($days as $day) {
             $dayInfo = new stdClass();
             $dayInfo->id = $id;
             $dayInfo->date = $day->toString(RM_Config::MYSQL_DATEFORMAT_SHORT);
             $dayInfo->reserved = $reservationModel->fetchAllByUnitDate($id, $day->toString(RM_Config::MYSQL_DATEFORMAT_SHORT))->count();
             $reservationData[] = $dayInfo;
             // this holds each of the reservation status for each cell.
             if ($unitcount == 0) {
                 // this information is only collected on the first pass of this loop
                 $dates = new stdClass();
                 $months = new stdClass();
                 $dates->day = $day->toString("d");
                 if (!$lastMonth) {
                     $lastMonth = $day->toString("F");
                     //set the starting value
                 }
                 $months->month = $lastMonth;
                 $months->colspan = $colspan + 1;
                 if ($day->toString("F") != $lastMonth || $daycount >= $numberofDays - 1) {
                     $colspan = 0;
                     $monthInfo[] = clone $months;
                 } else {
                     $colspan++;
                 }
                 $lastMonth = $day->toString("F");
                 $dateInfo[] = $dates;
             }
             $years->endyear = $day->toString("Y");
             $daycount++;
             // this will count to the same value as $numberofDays
         }
         $unitcount++;
         // this will increment for each unit
         $unitInfo->days = $reservationData;
         $unitData[] = $unitInfo;
         // this is a holding array based on each unit.
     }
     // set the years colspan... the years are just rendered twice start and end years at the top of th page.
     // or once if there is only one year
     if ($years->endyear == $years->startyear) {
         $years->colspan = $numberofDays;
     } else {
         $years->colspan = $numberofDays / 2;
     }
     $json = "{\n            years: " . Zend_Json::encode($years) . ",\n            months: " . Zend_Json::encode($monthInfo) . ",\n            days: " . Zend_Json::encode($dateInfo) . ",\n            data: " . Zend_Json::encode($unitData) . "\n        }";
     return array('data' => $json, 'encoded' => true);
 }
Esempio n. 3
0
 /**
  * Returns unit that are not that have a min stay on this period more than this period
  * or don't have a prices at all for this period
  * 
  * @param RM_Reservation_Period $period
  * @return array array with unit ids
  */
 public function getByMinPeriod(RM_Reservation_Period $period)
 {
     $days = $period->getDays();
     $persons = new RM_Reservation_Persons(array("adults" => 1, "children" => 0, "infants" => 0));
     $length = count($days);
     $unitIDs = array();
     foreach ($days as $day) {
         $unitIDs[] = $this->_getByMinPeriod($day, $persons, $length);
     }
     if (count($unitIDs) == 0) {
         return array();
     }
     $result = $unitIDs[0];
     for ($i = 1; $i < count($unitIDs); $i++) {
         if (count($unitIDs[$i]) == 0) {
             return array();
         }
         $result = array_intersect($result, $unitIDs[$i]);
     }
     return $result;
 }