/** * Returns intersection with current period * * @param RM_Reservation_Period $period * @return void */ function getIntersection(RM_Reservation_Period $period) { if ($this->getEnd()->compare($period->getStart()) < 0) { return null; } if ($this->getStart()->compare($period->getEnd()) > 0) { return null; } $startDate = clone $this->getStart(); if ($startDate->compare($period->getStart()) < 0) { $startDate = clone $period->getStart(); } $endDate = clone $this->getEnd(); if ($endDate->compare($period->getEnd()) > 0) { $endDate = clone $period->getEnd(); } return new RM_Reservation_Period($startDate, $endDate); }
protected function _init() { $this->_period = RM_Reservation_Period::getDefault(); if ($this->_criteria->start_datetime && $this->_criteria->end_datetime) { $this->_isDefaultPeriod = false; $this->_period = new RM_Reservation_Period(new RM_Date(strtotime($this->_criteria->start_datetime)), new RM_Date(strtotime($this->_criteria->end_datetime))); } $this->_persons = new RM_Reservation_Persons(array("adults" => $this->_criteria->adults, "children" => $this->_criteria->children, "infants" => $this->_criteria->infants)); $config = new RM_Config(); $this->_showPriceWithTax = (bool) $config->getValue('rm_config_prices_with_tax'); if ($this->_showPriceWithTax) { $this->_taxSystem = RM_Environment::getInstance()->getTaxSystem(); } }
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); }
/** * Return how many reservations start (only starts) * in input reservation period * * @param RM_Unit_Row $unit * @param RM_Reservation_Period $period * @return int */ public function getReservationCount(RM_Unit_Row $unit, RM_Reservation_Period $period) { $sql = "\r\n SELECT\r\n *\r\n FROM\r\n rm_reservation_details\r\n WHERE\r\n (\r\n UNIX_TIMESTAMP(start_datetime)<=UNIX_TIMESTAMP('" . $period->getEnd()->toMySQL() . "')\r\n AND\r\n UNIX_TIMESTAMP(start_datetime)>=UNIX_TIMESTAMP('" . $period->getStart()->toMySQL() . "')\r\n )\r\n AND\r\n unit_id = '" . $unit->getId() . "'"; $value = $this->_getBySQL($sql)->count(); return $value; }
/** * This checks if a unit/units is available for the selected dates/time * * @param RM_Reservation_Period $reservationPeriod The selected date/time periods * @param RM_Unit_Row $unitObject the unit object * @return Zend_Db_Table_Rowset containing only reserved units ids */ private function _isAvailable(RM_Reservation_Period $reservationPeriod, RM_Unit_Row $unit = null) { $sql = "SELECT\r\n rd.unit_id as id\r\n FROM\r\n rm_reservations AS r\r\n LEFT OUTER JOIN\r\n rm_reservation_details rd ON rd.reservation_id=r.id\r\n WHERE\r\n ((\r\n UNIX_TIMESTAMP(rd.start_datetime)<UNIX_TIMESTAMP('" . $reservationPeriod->getEnd()->toMySQL() . "')\r\n AND\r\n UNIX_TIMESTAMP(rd.start_datetime)>=UNIX_TIMESTAMP('" . $reservationPeriod->getStart()->toMySQL() . "')\r\n ) OR (\r\n UNIX_TIMESTAMP(rd.end_datetime)>UNIX_TIMESTAMP('" . $reservationPeriod->getStart()->toMySQL() . "')\r\n AND\r\n UNIX_TIMESTAMP(rd.end_datetime)<=UNIX_TIMESTAMP('" . $reservationPeriod->getEnd()->toMySQL() . "')\r\n ) OR (\r\n UNIX_TIMESTAMP(rd.start_datetime)<=UNIX_TIMESTAMP('" . $reservationPeriod->getStart()->toMySQL() . "')\r\n AND\r\n UNIX_TIMESTAMP(rd.end_datetime)>=UNIX_TIMESTAMP('" . $reservationPeriod->getEnd()->toMySQL() . "')\r\n ))\r\n AND\r\n r.confirmed = '1'\r\n "; if ($unit !== null) { $unitID = $unit->getId(); $sql .= "AND\r\n rd.unit_id = '{$unitID}'\r\n "; } return $this->_getBySQL($sql); }
/** * Get all current prices for a unit. * * @param $unit RM_Unit_Row * @return Zend_Db_Table_Rowset with results */ public function getCurrent($unit) { $period = RM_Reservation_Period::getDefault(); // we use default period $sql = "\n \t\tSELECT\n \t\t\t*\n \t\tFROM\n \t\t\t{$this->_name}\n \t\tWHERE\n \t\t\tunit_id='{$unit->id}'\n \t\t\tAND UNIX_TIMESTAMP(end_datetime) >= UNIX_TIMESTAMP('" . $period->getStart()->toMySQL() . "')\n AND UNIX_TIMESTAMP(start_datetime) <= UNIX_TIMESTAMP('" . $period->getEnd()->toMySQL() . "')\n "; return $this->_getBySQL($sql); }