/** * Validate information from reservation manager object, 'cause we are on the final step * before payment process. * * @param Zend_Request_Interface $request * @return bool */ function validate($request) { $this->_request = $request; $valid = true; $state = $this->_form->getState(); foreach ($state as $column) { foreach ($column as $panel) { if (in_array($panel->id, $this->_neeedToBeValidatedPanelsIDs)) { $methodName = '_' . $panel->id . '_validate'; $valid &= $this->{$methodName}(); } } } $manager = RM_Reservation_Manager::getInstance(); $savedDetails = $manager->getAllDetails(); $unitModel = new RM_Units(); foreach ($savedDetails as $details) { $valid &= $unitModel->isAvailableUnitbyDate($details->getUnit(), $details->getPeriod()); } return $valid; }
function setdatecriteriaJsonAction() { $this->_withoutView(); $unitID = $this->_getParam('unit_id', null); $unitModel = new RM_Units(); $unit = $unitModel->get($unitID, RM_Environment::getInstance()->getLocale(), array("summary", "description")); if ($unit == null) { return array('data' => array('success' => false, 'error' => $this->_translate->_('User.DatePicker', 'SelectedUnitDoesNotExists'))); } //TODO: we need to check dates for null $startdate = $this->_getParam('startdate', null); $enddate = $this->_getParam('enddate', null); $quantity = (int) $this->_getParam('qty', 1); //TODO: we need to check dates for rigth format to parse them into objects //check if start date is after end date $startDateObject = new RM_Date(strtotime($startdate)); $endDateObject = new RM_Date(strtotime($enddate)); if ($endDateObject->isEarlier($startDateObject)) { return array('data' => array('success' => false, 'error' => $this->_translate->_('User.DatePicker', 'StartAfterEnd'))); } // check if the dates are available... $period = new RM_Reservation_Period($startDateObject, $endDateObject); $adults = $this->_getParam("adults", 1); $children = $this->_getParam("children", 0); $infants = $this->_getParam("infants", 0); $persons = new RM_Reservation_Persons(array("adults" => $adults, "children" => $children, "infants" => $infants)); // get otherinfo - this is non-standard price system information. $otherinfo = Zend_Json::decode($this->_getParam("otherinfo", "{}")); // while we don't need the price here, getTotalUnitPrice will also check the // period selected is valid. $information = new RM_Prices_Information($unit, $period, $persons, $otherinfo); $priceSystem = RM_Environment::getInstance()->getPriceSystem(); try { $calculatedTotalPrice = $priceSystem->getTotalUnitPrice($information); } catch (RM_Exception $e) { return array('data' => array('success' => false, 'error' => $e->getMessage())); } // get the default start/end times... $startArray = explode(" ", $startdate); $endArray = explode(" ", $enddate); $realPriceSystem = $priceSystem->getRealPriceSystem($unit); $configObjectName = "RM_Unit" . $realPriceSystem->name . "Config"; // ie: RM_UnitDailyPricesConfig $priceConfigObject = new $configObjectName(); $recreatePeriod = false; // if the start time is null or 00:00:00 load the default price system times if (!isset($startArray[1]) || $startArray[1] === "" || $startArray[1] === "00:00:00") { try { // placed in a try so that if the price module returns an exception for default_end_time it does not crash this $defaultStartTime = $priceConfigObject->fetchValueByUnit($unitID, 'default_start_time'); $startdate = $startArray[0] . " " . $defaultStartTime; $startDateObject = new RM_Date(strtotime($startdate)); $recreatePeriod = true; } catch (Exception $e) { } } // if the end time is null or 00:00:00 load the default price system times if (!isset($endArray[1]) || $endArray[1] === "" || $endArray[1] === "23:30:00") { try { // placed in a try so that if the price module returns an exception for default_end_time it does not crash this $defaultEndTime = $priceConfigObject->fetchValueByUnit($unitID, 'default_end_time'); $enddate = $endArray[0] . " " . $defaultEndTime; $endDateObject = new RM_Date(strtotime($enddate)); $recreatePeriod = true; } catch (Exception $e) { } } // if the times have been added re-create the period object with the times... if ($recreatePeriod) { $period = new RM_Reservation_Period($startDateObject, $endDateObject); } // get the unit setting for the setting availablity_check // this could fail if the price system doesn't have this setting so it is wrapped in a try try { $availabilityCheck = $priceConfigObject->fetchValueByUnit($unitID, 'availablity_check'); } catch (Exception $e) { $availabilityCheck = "1"; } // check availability if ($availabilityCheck == "1") { $isAvailable = $unitModel->isAvailableUnitbyDate($unit, $period); if (!$isAvailable) { return array('data' => array('success' => false, 'error' => $this->_translate->_('User.DatePicker', 'ReselectDates'))); } } $data = array(); $data['start_datetime'] = $startdate; $data['end_datetime'] = $enddate; $data['adults'] = $adults; $data['children'] = $children; $data['infants'] = $infants; $data['otherinfo'] = $otherinfo; $data['quantity'] = $quantity; $criteria = new RM_Unit_Search_Criteria($data); $criteria->publishedOnly = true; RM_Reservation_Manager::getInstance()->resetCriteria()->setCriteria($criteria); // handle groups $isGroup = $unit->isGroup(); $groupID = $unit->getGroupId(); // if this is a group we need to get an available unit from the 'pool' if ($isGroup) { // get available sub units $AllavailableSubUnits = $unit->getAllSubUnits($criteria, $unit); foreach ($AllavailableSubUnits as $subunit) { if ($subunit->getGroupId() === $unit->getGroupId()) { $availableSubUnits[] = $subunit; } } // set a temporary session variable this is used in the groups row class $_SESSION["returnAllUnits"] = true; $units = array(); $subunits = array(); $selectedCount = 0; // if there is a unit available take the first one from the returned units... foreach ($availableSubUnits as $potentialUnit) { if ($selectedCount >= $quantity) { break; } $details = new RM_Reservation_Details($potentialUnit, $period, $persons, $otherinfo); RM_Reservation_Manager::getInstance()->addDetails($details); $selectedCount += 1; } // if the number of units saved to the reservation are not equal to the quantity also add the master unit if ($selectedCount < $quantity) { // add the master unit also $details = new RM_Reservation_Details($unit, $period, $persons, $otherinfo); RM_Reservation_Manager::getInstance()->addDetails($details); } } else { $details = new RM_Reservation_Details($unit, $period, $persons); RM_Reservation_Manager::getInstance()->addDetails($details); } // remove the temporary session variable unset($_SESSION["returnAllUnits"]); return array('data' => array('success' => true)); }
function _validatePeriod() { if ($this->_request->getParam('rm_calendar_dates', null) != null) { // get the dates from the calendar selection $datesString = $this->_request->getParam('rm_calendar_dates'); $dates = explode(',', $datesString); if (is_array($dates) == false || count($dates) == 0) { $this->_errors[] = 'PeriodSelectionIsWrong'; return false; } $startDateMySQL = $dates[0]; $endDateMySQL = $dates[count($dates) - 1]; } else { // get the saved criteria this is from the search module etc. $criteria = RM_Reservation_Manager::getInstance()->getCriteria(); if ($criteria == null) { $this->_errors[] = 'DatesNotSelected'; return false; } $startDateMySQL = $criteria->start_datetime; $endDateMySQL = $criteria->end_datetime; } if ($startDateMySQL == null) { $this->_errors[] = 'StartDateNotSelected'; return false; } if ($endDateMySQL == null) { $this->_errors[] = 'EndDateNotSelected'; return false; } $period = new RM_Reservation_Period(new RM_Date(strtotime($startDateMySQL)), new RM_Date(strtotime($endDateMySQL))); $unitModel = new RM_Units(); $unit = $unitModel->find($this->_request->getParam('unit_id', null))->current(); if ($unit == null) { $this->_errors[] = 'SelectedUnitDoesNotExists'; return false; } return $unitModel->isAvailableUnitbyDate($unit, $period); }