示例#1
0
 /**
  * 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);
 }
示例#2
0
 /**
  * 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;
 }
示例#3
0
 /**
  * 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);
 }
示例#4
0
 /**
  * This method will returns all prices that is in date range with daily price in range
  *
  * @param float $from
  * @param float $to
  * @param RM_Reservation_Period $period
  * @return Zend_Db_Table_Rowset_Abstract
  */
 public function getByPriceRange($from, $to, $period = null)
 {
     $sql = "\n    \t\tSELECT\n    \t\t\t*\n    \t\tFROM\n    \t\t\t{$this->_name}\n    \t\tWHERE\n                weekday_price >= {$from} AND weekday_price <= {$to}\n        ";
     if ($period !== null) {
         $sql .= " AND\n                ((\n                    UNIX_TIMESTAMP(start_datetime)<UNIX_TIMESTAMP('" . $period->getEnd()->toMySQL() . "')\n                        AND\n                    UNIX_TIMESTAMP(end_datetime)>=UNIX_TIMESTAMP('" . $period->getEnd()->toMySQL() . "')\n                ) OR (\n                    UNIX_TIMESTAMP(start_datetime)>UNIX_TIMESTAMP('" . $period->getStart()->toMySQL() . "')\n                        AND\n                    UNIX_TIMESTAMP(end_datetime)<=UNIX_TIMESTAMP('" . $period->getStart()->toMySQL() . "')\n                ) OR (\n                    UNIX_TIMESTAMP(start_datetime)>UNIX_TIMESTAMP('" . $period->getStart()->toMySQL() . "')\n                        AND\n                    UNIX_TIMESTAMP(end_datetime)<=UNIX_TIMESTAMP('" . $period->getEnd()->toMySQL() . "')\n                ))\n            ";
     }
     return $this->_getBySQL($sql);
 }