Exemple #1
0
 /**
  * Returns all unit ids that are passed criteria option
  *
  * @param RM_Unit_Search_Criteria $criteria
  * @return array, false
  */
 function getAdvancedSearchUnitIDs(RM_Unit_Search_Criteria $criteria)
 {
     if (!$criteria->categories || count($criteria->categories) == 0) {
         return false;
     }
     $model = new RM_UnitCategories();
     $units = $model->getByCategories($criteria->categories);
     $unitIDs = array();
     foreach ($units as $row) {
         $unitIDs[] = $row->unit_id;
     }
     //we need to add code to support Group Module
     //we need to include every unit ID of a groups that main unit in group assigned to a category
     if (class_exists('RM_Groups')) {
         $groupUnitIDs = array();
         $groupsModel = new RM_Groups();
         $unitsModel = new RM_Units();
         foreach ($unitIDs as $unitID) {
             $unit = $unitsModel->get($unitID);
             if ($groupsModel->isMain($unit)) {
                 $units = $groupsModel->getGroupUnitsByMain($unit);
                 foreach ($units as $unit) {
                     $groupUnitIDs[] = $unit->getId();
                 }
             }
         }
         $unitIDs = array_merge($unitIDs, $groupUnitIDs);
         $unitIDs = array_unique($unitIDs);
     }
     return $unitIDs;
 }
Exemple #2
0
 public function updateJsonAction()
 {
     $unit = $this->_getParam('edit_unit');
     $unit['color'] = ltrim($this->_getParam('color'), "#");
     $dao = new RM_Units();
     // update the unit record
     $dao->updateUnit($unit);
     if (isset($unit['group_id'])) {
         // make sure that sub units are converted to the same unit type
         if (class_exists(RM_Groups)) {
             $groups = new RM_Groups();
             // get the unit object
             $unitObject = $dao->get($unit['id'], null, array('description', 'summary'));
             if (!$groups->isMain($unitObject)) {
                 // if it's not a main unit, then update the unit to the same unit type as the main unit
                 $allGroupedUnits = $groups->getGroupUnitsByMain($unitObject);
                 // find the main unit id...
                 foreach ($allGroupedUnits as $groupUnit) {
                     if ($groups->isMain($groupUnit)) {
                         $mainUnitID = $groupUnit->id;
                     }
                 }
                 // get the main unit object
                 $mainUnitObject = $dao->get($mainUnitID, null, array('description', 'summary'));
                 // get the type for the main unit
                 $rmUnitTypes = new RM_UnitTypes();
                 $typeInfo = $rmUnitTypes->getByUnit($mainUnitObject)->toArray();
                 // update the subunit to the same type
                 $unit['type_id'] = (int) $typeInfo['id'];
                 $dao->updateUnit($unit);
             }
         }
     }
     return array('data' => array('success' => true, 'msg' => ''));
 }
Exemple #3
0
 /**
  * Quantity Check, this returns the number of available units
  *
  * @param none
  * @return json
  */
 function quantitycheckJsonAction()
 {
     $unitID = $this->_getParam('unit_id', null);
     $startdate = $this->_getParam('startdate');
     $enddate = $this->_getParam('enddate');
     $qty = $this->_getParam('quantity', 1);
     $unitModel = new RM_Units();
     $language = RM_Environment::getInstance()->getLocale();
     $availableSubUnits = array();
     $mainFound = false;
     $masterUnit = $unitModel->get($unitID, $language);
     $data = array();
     $data['start_datetime'] = new RM_Date(strtotime($startdate));
     $data['end_datetime'] = new RM_Date(strtotime($enddate));
     $data->adults = $this->_getParam('adults', 1);
     $data->children = $this->_getParam('children', 0);
     $data->infants = $this->_getParam('infants', 0);
     $data->otherinfo = $this->_getParam("otherInfo", array());
     $criteria = new RM_Unit_Search_Criteria($data);
     $groupsModel = new RM_Groups();
     $AllavailableSubUnits = $masterUnit->getAllSubUnits($criteria, $masterUnit);
     foreach ($AllavailableSubUnits as $subunit) {
         if ($subunit->getGroupId() === $masterUnit->getGroupId()) {
             if ($groupsModel->isMain($subunit)) {
                 // if it's the main unit set a flag
                 $mainFound = true;
             }
             $availableSubUnits[] = $subunit;
         }
     }
     if (count($availableSubUnits) < $qty) {
         $availableSubUnits[] = $masterUnit;
     }
     $qtyAvailable = count($availableSubUnits);
     // if the main unit was not found add one to the quantity
     // total as the main unit + the sub unit is available.
     if (!$mainFound) {
         $qtyAvailable += 1;
     }
     return array('data' => array('success' => true, "qty" => $qtyAvailable));
 }
Exemple #4
0
 public function insertNewReservation($user, $unitDetails, $inprogres = 0, $confirmed = 1, $bookingRef = null)
 {
     //1. add information into rm_reservation
     if ($user->id) {
         $userID = $user->id;
     } else {
         // at this point the user does not exist in ResMania let's add it...
         $userData = array();
         foreach ($user as $key => $value) {
             if ($key == 'name') {
                 $nameArray = explode(" ", $value);
                 $userData['first_name'] = $nameArray[0];
                 $userData['last_name'] = $nameArray[1] . " " . $nameArray[2];
             }
             $userData[$key] = $value;
         }
         $userData['group_id'] = 0;
         unset($userData['id']);
         $rmUsers = new RM_Users();
         $userID = $rmUsers->insert($userData);
     }
     $reservation = $this->createRow();
     $reservation->user_id = $userID;
     $reservation->confirmed = $confirmed;
     $reservation->in_progress = $inprogres;
     // this will hide the reservation until we have completed the process
     if ($bookingRef !== null) {
         $reservation->id = $bookingRef;
     }
     $reservation->creation_datetime = date(RM_Config::MYSQL_DATEFORMAT);
     //current server datetime
     $reservationID = $reservation->save();
     //2. add information into rm_reservation_details
     $detailsModel = new RM_ReservationDetails();
     $priceSystem = RM_Environment::getInstance()->getPriceSystem();
     foreach ($unitDetails as $unitDetail) {
         $detail = $detailsModel->createRow();
         $selectedUnit = $unitDetail->getUnit();
         // get the master unit
         if (class_exists("RM_Groups")) {
             $groupsObject = new RM_Groups();
             $isMaster = $groupsObject->isMain($selectedUnit);
             if (!$isMaster) {
                 $unitModel = new RM_Units();
                 $group = $groupsObject->getByUnit($selectedUnit);
                 if ($group != null) {
                     try {
                         $groupID = $group->main_unit_id;
                         $selectedUnit = $unitModel->get($groupID, RM_Environment::getInstance()->getLocale());
                     } catch (Exception $e) {
                     }
                 }
             }
         }
         $information = new RM_Prices_Information($selectedUnit, $unitDetail->getPeriod(), $unitDetail->getPersons(), $unitDetail->getOtherInfo());
         try {
             $detail->total_price = $priceSystem->getTotalUnitPrice($information);
         } catch (Exception $e) {
             $detail->total_price = 0;
         }
         $detail->reservation_id = $reservationID;
         $detail->unit_id = $unitDetail->getUnit()->getId();
         $detail->start_datetime = $unitDetail->getPeriod()->getStart()->toMySQL();
         $detail->end_datetime = $unitDetail->getPeriod()->getEnd()->toMySQL();
         $detail->adults = $unitDetail->getPersons()->getAdults() == 0 ? 1 : $unitDetail->getPersons()->getAdults();
         $detail->children = $unitDetail->getPersons()->getChildren();
         $detail->infants = $unitDetail->getPersons()->getInfants();
         // process other information (this allows the price system to manage
         // other data i.e: board_types for the hospitality price module
         $otherInfo = $unitDetail->getOtherInfo();
         if ($otherInfo) {
             foreach ($otherInfo as $key => $value) {
                 $detail->{$key} = $value;
             }
         }
         $detail->save();
         $this->_insertDetailExtraData($unitDetail, $detail);
     }
     return $reservationID;
 }