Esempio n. 1
0
 /**
  * Returns all unit objects by it's type
  *
  * @param object    $criteria this object contains the specification for the
  * search.
  * @return Zend_Db_Table_Rowset All units objects
  */
 public function getAll(RM_Unit_Search_Criteria $criteria)
 {
     $fieldsNames = array();
     $fieldsNames[] = 'rm_units.*';
     $languageFieldsNames = array();
     $languageFieldsNames[] = 'rm_unit_language_details.*';
     if ($criteria->offset === null) {
         $criteria->offset = 0;
     }
     $sql = "\r\n            SELECT\r\n                " . implode(',', $fieldsNames);
     if (count($languageFieldsNames) > 0) {
         $sql .= ", " . implode(',', $languageFieldsNames);
     }
     if (!$criteria->language) {
         $criteria->language = RM_Environment::getInstance()->getLocale();
     }
     $sql .= "\r\n            FROM\r\n                rm_units\r\n            INNER JOIN\r\n                rm_unit_language_details ON\r\n                rm_units.id = rm_unit_language_details.unit_id";
     $sql .= "\r\n            AND rm_unit_language_details.iso = '{$criteria->language}'\r\n                WHERE 1=1 ";
     if ($criteria->type) {
         $sql .= " AND type_id = '" . $criteria->type->id . "' ";
     }
     // this gets the units that are unavailable so these are excluded from the results
     if ($criteria->start_datetime && $criteria->end_datetime) {
         $reservationPeriod = new RM_Reservation_Period(new RM_Date(strtotime($criteria->start_datetime)), new RM_Date(strtotime($criteria->end_datetime)));
         if ($criteria->flexible) {
             //My dates are flexible: every unit with at least one day available should we shown
             $availableUnitIDs = $this->getFlexibleAvailable($reservationPeriod);
             if (count($availableUnitIDs) == 0) {
                 $sql .= " AND 1=0 ";
                 //This will returns 0 rows
                 return $this->_getBySQL($sql);
             } else {
                 $sql .= "\r\n                        AND rm_units.id IN (" . implode(',', $availableUnitIDs) . ")\r\n                    ";
             }
         } else {
             $reservedUnits = $this->getReservedUnits($reservationPeriod)->toArray();
             $unitsWithAvailbilityCheckDisabled = RM_Environment::getInstance()->getPriceSystem()->getUnitWithAvailabiltyCheckDisabled();
             if (count($reservedUnits) > 0) {
                 $reservedUnits = array_diff($reservedUnits, $unitsWithAvailbilityCheckDisabled);
             }
             if (count($reservedUnits) > 0) {
                 $reservedUnitIDs = array();
                 foreach ($reservedUnits as $unit) {
                     if ($unit['id']) {
                         $reservedUnitIDs[] = $unit['id'];
                     }
                 }
                 $reservedUnitsCSV = implode(',', $reservedUnitIDs);
                 if ($reservedUnitsCSV != "," && $reservedUnitsCSV != "") {
                     $sql .= "\r\n                            AND rm_units.id NOT IN (" . $reservedUnitsCSV . ")\r\n                        ";
                 }
             }
             //we need to check min period length
             $manager = RM_Prices_Manager::getInstance();
             $minPeriodNotUnitIDs = $manager->getByMinPeriod($reservationPeriod);
             if (count($minPeriodNotUnitIDs) > 0) {
                 $minPeriodNotUnitIDsCSV = implode(',', $minPeriodNotUnitIDs);
                 if ($minPeriodNotUnitIDsCSV != "," && $minPeriodNotUnitIDsCSV != "") {
                     $sql .= "\r\n                            AND rm_units.id NOT IN (" . $minPeriodNotUnitIDsCSV . ")\r\n                        ";
                 }
             }
         }
     }
     if ($criteria->image == 1) {
         $unitIDsWithImages = $this->getWithImages();
         if (count($unitIDsWithImages) == 0) {
             $sql .= " AND 1=0 ";
             //This will returns 0 rows
             return $this->_getBySQL($sql);
         } else {
             $sql .= "\r\n                    AND rm_units.id IN (" . implode(',', $unitIDsWithImages) . ")\r\n                ";
         }
     }
     //3. prices: from - to
     if ((int) $criteria->prices_from != 0 || (int) $criteria->prices_to != 99999999) {
         if ($criteria->prices_from || $criteria->prices_to) {
             if ($criteria->start_datetime && $criteria->end_datetime) {
                 $reservationPeriod = new RM_Reservation_Period(new RM_Date(strtotime($criteria->start_datetime)), new RM_Date(strtotime($criteria->end_datetime)));
             } else {
                 $reservationPeriod = null;
             }
             $priceRangeUnitIDs = RM_Environment::getInstance()->getPriceSystem()->getByPriceRange($criteria->prices_from, $criteria->prices_to, $reservationPeriod);
             if (count($priceRangeUnitIDs) == 0) {
                 $sql .= " AND 1=0 ";
                 //This will returns 0 rows
                 return $this->_getBySQL($sql);
             } else {
                 $sql .= "\r\n                        AND rm_units.id IN (" . implode(',', $priceRangeUnitIDs) . ")\r\n                    ";
             }
         }
     }
     //4. check all plugins and modules to extend advanced search
     $model = new RM_Modules();
     $modules = $model->getAllEnabled();
     foreach ($modules as $module) {
         if ($module instanceof RM_Search_Advanced_Interface) {
             $unitIDs = $module->getAdvancedSearchUnitIDs($criteria);
             if ($unitIDs !== false) {
                 if (count($unitIDs) == 0) {
                     $sql .= " AND 1=0 ";
                     //This will returns 0 rows
                     return $this->_getBySQL($sql);
                 } elseif (count($unitIDs) > 0) {
                     $sql .= "\r\n                            -- added by modules: " . $module->name . "\r\n                            AND rm_units.id IN (" . implode(',', $unitIDs) . ")\r\n                        ";
                 }
             }
         }
     }
     $pluginModel = new RM_Plugins();
     $plugins = $pluginModel->getAllEnabled();
     foreach ($plugins as $plugin) {
         if ($plugin instanceof RM_Search_Advanced_Interface) {
             $unitIDs = $plugin->getAdvancedSearchUnitIDs($criteria);
             if ($unitIDs !== false) {
                 if (count($unitIDs) == 0) {
                     $sql .= " AND 1=0 ";
                     //This will returns 0 rows
                     return $this->_getBySQL($sql);
                 } elseif (count($unitIDs) > 0) {
                     $sql .= "\r\n                            -- added by modules: " . $plugin->name . "\r\n                            AND rm_units.id IN (" . implode(',', $unitIDs) . ")\r\n                        ";
                 }
             }
         }
     }
     if ($criteria->publishedOnly === true) {
         $sql .= " AND rm_units.published='1'";
     }
     if (count($criteria->filters) > 0) {
         $filterConditions = array();
         foreach ($criteria->filters as $filter) {
             $filterConditions = array_merge($filterConditions, $this->_getConditions($filter));
         }
         $filterSQL = implode(" AND ", $filterConditions);
         $sql .= " AND " . $filterSQL;
     }
     if ($criteria->order !== null) {
         if ($criteria->order == 'random') {
             $sessionID = session_id();
             $random = hexdec($sessionID[0]);
             $sql .= " ORDER BY RAND(" . $random . ") ";
         } elseif ($criteria->order != 'price') {
             $sql .= " ORDER BY {$criteria->order} ";
         }
     }
     if ($criteria->count !== null) {
         $sql .= " LIMIT {$criteria->offset}, {$criteria->count} ";
     }
     return $this->_getBySQL($sql);
 }
Esempio n. 2
0
 private function _getModules()
 {
     $model = new RM_Modules();
     $modules = $model->getAllEnabled();
     $result = array();
     foreach ($modules as $module) {
         $node = $module->getNode();
         if ($node !== null) {
             $result[] = $node;
         }
     }
     return $result;
 }