File manager - Edit - /home/verseaumee/ptitsanes/plugins/solidres/experience/components/com_solidres/models/experiences.php
Back
<?php /** ------------------------------------------------------------------------ SOLIDRES - Accommodation booking extension for Joomla ------------------------------------------------------------------------ * @author Solidres Team <contact@solidres.com> * @website https://www.solidres.com * @copyright Copyright (C) 2013 - 2019 Solidres. All Rights Reserved. * @license GNU General Public License version 3, or later ------------------------------------------------------------------------ */ defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; use Joomla\Registry\Registry; class SolidresModelExperiences extends JModelList { protected function populateState($ordering = 'a.ordering', $direction = 'ASC') { $app = JFactory::getApplication('site'); $menu = $app->getMenu()->getActive(); if ($menu) { $params = $menu->params; } else { $params = new Registry; } $this->setState('params', $params); $categories = (array) $params->get('categories', array()); if ($cats = $app->input->getString('cat')) { $categories = explode('|', $cats); } $this->setState('filter.cat', $categories); $countryId = $params->get('country_id', ''); $this->setState('filter.country_id', $countryId); $city = $params->get('city', ''); $this->setState('filter.city', $city); $baseLocation = $app->input->getString('base_location', $params->get('base_location', '')); $this->setState('filter.base_location', $baseLocation); $endLocation = $app->input->getString('end_location', $params->get('end_location', '')); $this->setState('filter.end_location', $endLocation); $tempRange = array(); if ($ranges = $app->input->getString('range')) { foreach (explode('|', $ranges) as $range) { if (!empty($range)) { if (strpos($range, '-') !== false) { $tempRange[] = $range; } } } } $this->setState('filter.range', $tempRange); $owners = array(); foreach (explode('|', $app->input->getString('owner', '')) as $partnerId) { if (is_numeric($partnerId)) { $owners[] = (int) $partnerId; } } $this->setState('filter.owner', $owners); $trans = array(); foreach (explode('|', $app->input->getString('tran', '')) as $tranId) { if (is_numeric($tranId)) { $trans[] = (int) $tranId; } } $this->setState('filter.tran', $trans); $fromDay = null; $toDay = null; $fromHour = null; $toHour = null; foreach (explode('|', $app->input->getString('day', '')) as $day) { $day = explode('-', $day, 2); if (count($day) == 2) { if (null === $fromDay || $fromDay > (int) $day[0]) { $fromDay = (int) $day[0]; } if (null === $toDay || $toDay < (int) $day[1]) { $toDay = (int) $day[1]; } } } foreach (explode('|', $app->input->getString('hour', '')) as $hour) { $hour = explode('-', $hour, 2); if (count($hour) == 2) { if (null === $fromHour || $fromHour > (int) $hour[0]) { $fromHour = (int) $hour[0]; } if (null === $toHour || $toHour < (int) $hour[1]) { $toHour = (int) $hour[1]; } } } $this->setState('filter.from_day', $fromDay); $this->setState('filter.to_day', $toDay); $this->setState('filter.from_hour', $fromHour); $this->setState('filter.to_hour', $toHour); parent::populateState($ordering, $direction); $reviews = array(); foreach (explode('|', $app->input->getString('review', '')) as $review) { if (trim($review) !== '') { $reviews[] = trim($review); } } $paramOrdering = $params->get('ordering', 'name_asc'); list($pOrdering, $pDirection) = explode('_', $paramOrdering); $ordering = strtolower($app->input->get('ordering', '')); $direction = strtolower($app->input->get('direction', '')); if (empty($ordering)) { $ordering = $pOrdering; } if (empty($direction)) { $direction = isset($pDirection) ? $pDirection : 'asc'; } if (in_array($direction, array('asc', 'desc'), true)) { $this->setState('list.direction', $direction); } if (in_array($ordering, array('ordering', 'name', 'review', 'distance'), true)) { if ($ordering == 'review' && SRPlugin::isEnabled('feedback')) { $ordering = 'reviewScore'; $this->setState('list.direction', 'desc'); } elseif ($ordering == 'name') { $ordering = 'a.name'; } elseif ($ordering == 'ordering') { $ordering = 'a.ordering'; } else { $ordering = 'assetTable.distance_from_city_centre'; } $this->setState('list.ordering', $ordering); } if ($distance = $app->input->getString('distance', '')) { if (strpos($distance, '-') !== false) { $this->setState('filter.distance', $distance); } } $this->setState('filter.review', array_unique($reviews)); $fromDate = $app->input->getString('fromDate', ''); $toDate = $app->input->getString('toDate', ''); if (!empty($fromDate) && !empty($toDate)) { $this->setState('filter.from_date', $fromDate); $this->setState('filter.to_date', $toDate); } $filterTag = $app->input->get('filter_tag'); if ($tag = $app->input->get->get('tag', '', 'string')) { $db = $this->getDbo(); $tags = []; foreach (explode('|', $tag) as $tagAlias) { if (empty($tagAlias)) { continue; } $query = $db->getQuery(true) ->select('a.id') ->from($db->quoteName('#__tags', 'a')) ->where('a.lft > 0 AND a.published = 1 AND a.alias = ' . $db->quote($tagAlias)); $db->setQuery($query); if ($tagId = $db->loadResult()) { $tags[] = (int) $tagId; } } if ($tags) { $filterTag = $tags; } } $this->setState('filter.tag', $filterTag); $this->setState('filter.language', JLanguageMultilang::isEnabled()); } protected function getStoreId($id = '') { $id .= ':' . $this->getState('filter.country_id'); $id .= ':' . $this->getState('filter.city'); $id .= ':' . $this->getState('filter.base_location'); $id .= ':' . $this->getState('filter.end_location'); $id .= ':' . $this->getState('filter.from_day'); $id .= ':' . $this->getState('filter.to_day'); $id .= ':' . $this->getState('filter.from_hour'); $id .= ':' . $this->getState('filter.to_hour'); $id .= ':' . $this->getState('filter.distance'); $id .= ':' . $this->getState('filter.from_date'); $id .= ':' . $this->getState('filter.to_date'); $id .= ':' . join(':', $this->getState('filter.cat', array())); $id .= ':' . join(':', $this->getState('filter.owner', array())); $id .= ':' . join(':', $this->getState('filter.tran', array())); $id .= ':' . join(':', $this->getState('filter.review', array())); $id .= ':' . join(':', $this->getState('filter.range')); $id .= ':' . serialize($this->getState('filter.tag')); return parent::getStoreId($id); } protected function getListQuery() { $db = $this->getDbo(); $query = $db->getQuery(true); $query->select( $this->getState('list.select', 'DISTINCT a.id') ); $query->from($db->qn('#__sr_experiences', 'a')) ->where('a.state = 1'); $categories = (array) $this->getState('filter.cat'); if (!empty($categories)) { $query->innerJoin($db->qn('#__sr_experience_category_xref', 'cx') . ' ON cx.experience_id = a.id'); $query->where('cx.category_id IN (' . join(',', ArrayHelper::toInteger($categories)) . ')'); } $trans = (array) $this->getState('filter.tran'); if (!empty($trans)) { $query->innerJoin($db->qn('#__sr_experience_transportation_xref', 'tx') . ' ON tx.experience_id = a.id'); $query->where('tx.transportation_id IN (' . join(',', ArrayHelper::toInteger($trans)) . ')'); } $owners = (array) $this->getState('filter.owner'); if (!empty($owners)) { $query->where('a.partner_id IN (' . join(',', ArrayHelper::toInteger($owners)) . ')'); } $countryId = (int) $this->getState('filter.country_id'); if ($countryId > 0) { $query->where('a.country_id = ' . $countryId); } $city = trim($this->getState('filter.city')); if (!empty($city)) { $query ->innerJoin($db->qn('#__sr_countries', 'c') . ' ON c.id = a.country_id') ->where('(a.base_location LIKE ' . $db->q($city . '%') . ' OR c.name LIKE ' . $db->q($city . '%') . ')'); } $ranges = $this->getState('filter.range'); if (!empty($ranges)) { $orWhere = array(); foreach ($ranges as $range) { $parts = explode('-', $range, 2); if (count($parts) == 2) { $min = (float) $parts[0]; $max = (float) $parts[1]; if ($min > 0.00 && $max > 0.00) { $orWhere[] = '(a.pricing_base BETWEEN ' . $min . ' AND ' . $max . ')'; } elseif ($min > 0.00) { $orWhere[] = 'a.pricing_base >= ' . $min; } elseif ($max > 0.00) { $orWhere[] = 'a.pricing_base <= ' . $max; } } } if (count($orWhere)) { $query->where('(' . join(' OR ', $orWhere) . ')'); } } $fromDay = (int) $this->getState('filter.from_day', 0); $toDay = (int) $this->getState('filter.to_day', 0); $fromHour = (int) $this->getState('filter.from_hour', 0); $toHour = (int) $this->getState('filter.to_hour', 0); $durationWhere = array(); if ($fromDay > 0 && $toDay > 0) { $durationWhere[] = '(a.duration_unit = 1 AND a.duration BETWEEN ' . $fromDay . ' AND ' . $toDay . ')'; } if ($fromHour > 0 && $toHour > 0) { $durationWhere[] = '(a.duration_unit = 0 AND a.duration BETWEEN ' . $fromHour . ' AND ' . $toHour . ')'; } if (count($durationWhere)) { $query->where('(' . join(' OR ', $durationWhere) . ')'); } $langTag = JFactory::getLanguage()->getTag(); $languages = JLanguageHelper::getLanguages('lang_code'); $langId = isset($languages[$langTag]) ? (int) $languages[$langTag]->lang_id : 0; $params = JComponentHelper::getParams('com_solidres'); $isTranslate = $params->get('enable_multilingual_mode') && $langId > 0 && JComponentHelper::isEnabled('com_falang') && $langTag != JComponentHelper::getParams('com_languages')->get('site', 'en-GB'); $baseLocation = $this->getState('filter.base_location'); $endLocation = $this->getState('filter.end_location'); if (!empty($baseLocation) || !empty($endLocation)) { if (!empty($baseLocation)) { if ($isTranslate) { $query->leftJoin($db->qn('#__falang_content', 'fa1') . ' ON fa1.reference_table = ' . $db->q('sr_experiences') . ' AND fa1.reference_field = ' . $db->q('base_location') . ' AND fa1.reference_id = a.id AND fa1.language_id = ' . $langId) ->where('fa1.value LIKE ' . $db->q('%' . $baseLocation . '%')); } else { $query->where('a.base_location LIKE ' . $db->q('%' . $baseLocation . '%')); } } if (!empty($endLocation)) { if ($isTranslate) { $query->leftJoin($db->qn('#__falang_content', 'fa2') . ' ON fa2.reference_table = ' . $db->q('sr_experiences') . ' AND fa2.reference_field = ' . $db->q('end_location') . ' AND fa2.reference_id = a.id AND fa2.language_id = ' . $langId) ->where('fa2.value LIKE ' . $db->q('%' . $endLocation . '%')); } else { $query->where('a.end_location LIKE ' . $db->q('%' . $endLocation . '%')); } } } if (SRPlugin::isEnabled('feedback')) { $reviews = $this->getState('filter.review', array()); $subQuery = $db->getQuery(true) ->select('AVG(a2.score)') ->from($db->qn('#__sr_feedback_scores', 'a2')) ->innerJoin($db->qn('#__sr_feedbacks', 'a3') . ' ON a3.id = a2.feedback_id') ->leftJoin($db->qn('#__sr_experience_reservations', 'a4') . ' ON a4.id = a3.reservation_id') ->where('a3.state = 1 AND a3.scope = 1 AND (a4.experience_id = a.id OR a3.item_id = a.id)') ->group('a.id'); $query->select('(' . $subQuery->__toString() . ') AS reviewScore'); if ($reviews) { settype($reviews, 'array'); $minScore = null; foreach ($reviews as $review) { if (strpos($review, '-') !== false) { $parts = explode('-', $review, 2); $min = (float) $parts[0]; if (null === $minScore || $min > $minScore) { $minScore = $min; } } } $query->having('reviewScore >= ' . $minScore); } } $query->leftJoin($db->qn('#__sr_experience_asset_xref', 'acdXref') . ' ON acdXref.experience_id = a.id') ->leftJoin($db->qn('#__sr_reservation_assets', 'assetTable') . ' ON assetTable.id = acdXref.reservation_asset_id'); if ($distance = $this->getState('filter.distance', '')) { $distance = preg_replace('/[^0-9\-\.]/', '', $distance); if (strpos($distance, '-') !== false) { list($from, $to) = explode('-', $distance, 2); $from = floatval($from); $to = floatval($to); if ($from > 0.00 || $to > 0.00) { $query->where('assetTable.distance_from_city_centre BETWEEN ' . $from . ' AND ' . $to); } } } $fromDate = $this->getState('filter.from_date'); $toDate = $this->getState('filter.to_date'); if (!empty($fromDate) && !empty($toDate)) { try { $fromDate = $db->q(JFactory::getDate($fromDate)->toSql()); $toDate = $db->q(JFactory::getDate($toDate)->toSql()); $query->leftJoin($db->qn('#__sr_experience_date_xref', 'dateXref') . ' ON dateXref.experience_id = a.id') ->where('dateXref.date BETWEEN ' . $fromDate . ' AND ' . $toDate); } catch (Exception $e) { } } // Filter by language if ($this->getState('filter.language')) { $query->where('a.language IN (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); } // Filter by a single or group of tags. $hasTag = false; $tagId = $this->getState('filter.tag'); if (is_numeric($tagId)) { $hasTag = true; $query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId); } elseif (is_array($tagId)) { $tagId = Joomla\Utilities\ArrayHelper::toInteger($tagId); $tagId = implode(',', $tagId); if (!empty($tagId)) { $hasTag = true; $query->where($db->quoteName('tagmap.tag_id') . ' IN (' . $tagId . ')'); } } if ($hasTag) { $query->join('LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap') . ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') . ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_solidres.experience') ); } $ordering = $this->getState('list.ordering', 'a.ordering'); $direction = $this->getState('list.direction', 'ASC'); $query->order($db->escape($ordering) . ' ' . $db->escape($direction)); return $query; } public function getItems() { $app = JFactory::getApplication(); $items = parent::getItems(); if (!$items) { $app->setUserState('com_solidres.experience.filterData', []); return $items; } $config = JComponentHelper::getParams('com_solidres'); $days = preg_split('/\r\n|\n|,/', trim($config->get('duration_days', ''))); $hours = preg_split('/\r\n|\n|,/', trim($config->get('duration_hours', ''))); $review = SRPlugin::isEnabled('feedback'); $filterData = [ 'cat' => [], 'owner' => [], 'tran' => [], 'review' => [], 'range' => [], 'day' => [], 'hour' => [], 'tag' => [], ]; $reviewRanges = []; $priceRanges = []; if ($review) { foreach (PlgSolidresFeedback::getReviewRange() as $range => $text) { $parts = explode('-', $range, 2); $reviewRanges[$range] = (float) $parts[0]; $filterData['review'][$range] = 0; } } $currentCurrencyId = $app->input->cookie->get('solidres_currency', 0, 'int'); if (!$currentCurrencyId) { $currentCurrencyId = JComponentHelper::getParams('com_solidres')->get('default_currency_id', 0); } $db = $this->getDbo(); $query = $db->getQuery(true) ->select('a.filter_range') ->from($db->qn('#__sr_currencies', 'a')) ->where('a.id = ' . (int) $currentCurrencyId); $db->setQuery($query); if ($result = $db->loadResult()) { $prices = preg_split('/\r\n|\n/', trim($result)); foreach ($prices as $price) { $range = str_ireplace('plus', '0', trim($price)); $parts = explode('-', $range, 2); if (count($parts) === 2) { $priceRanges[$range] = array((float) $parts[0], (float) $parts[1]); $filterData['range'][$range] = 0; } } } foreach ($items as &$item) { if ($review) { $app->triggerEvent('onSolidresFeedbackPrepare', array('com_solidres.experience', $item)); } $reviewCount = isset($item->reviewCount) ? $item->reviewCount : 0; $reviewScores = isset($item->reviewScores) ? $item->reviewScores : null; $reviewComment = isset($item->reviewComment) ? $item->reviewComment : null; $reviewWidget = isset($item->reviewWidget) ? $item->reviewWidget : null; $item = SRExperienceHelper::getItem($item->id); $item->reviewScores = $reviewScores; $item->reviewComment = $reviewComment; $item->reviewCount = $reviewCount; $item->reviewWidget = $reviewWidget; if (!empty($item->categories)) { foreach ($item->categories as $category) { $cat = (int) $category->id; if (isset($filterData['cat'][$cat])) { $filterData['cat'][$cat]++; } else { $filterData['cat'][$cat] = 1; } } } if (!empty($item->transportations)) { foreach ($item->transportations as $transportation) { $tran = (int) $transportation->id; if (isset($filterData['tran'][$tran])) { $filterData['tran'][$tran]++; } else { $filterData['tran'][$tran] = 1; } } } $owner = (int) $item->partner_id; if ($owner) { if (isset($filterData['owner'][$owner])) { $filterData['owner'][$owner]++; } else { $filterData['owner'][$owner] = 1; } } if (!empty($item->reviewScores)) { $reviewScores = (float) $item->reviewScores; foreach ($reviewRanges as $range => $minScore) { if ($reviewScores >= $minScore) { $filterData['review'][$range]++; } } } $price = (float) $item->pricing_base; foreach ($priceRanges as $range => $prices) { if ($price >= $prices[0] && ($prices[1] < 0.01 || $price <= $prices[1])) { $filterData['range'][$range]++; } } $duration = (float) $item->duration; $vars = $item->duration_unit ? $days : $hours; $filterVar = $item->duration_unit ? 'day' : 'hour'; foreach ($vars as $var) { $parts = explode('-', trim($var), 2); if ($duration >= (float) $parts[0] && $duration <= $parts[1]) { if (isset($filterData[$filterVar][$var])) { $filterData[$filterVar][$var]++; } else { $filterData[$filterVar][$var] = 1; } } } if ($tags = $this->getItemTags($item->id)) { foreach ($tags as $tagAlias) { if (isset($filterData['tag'][$tagAlias])) { $filterData['tag'][$tagAlias]++; } else { $filterData['tag'][$tagAlias] = 1; } } } } $app->setUserState('com_solidres.experience.filterData', $filterData); return $items; } public function getItemTags($pk) { static $tags = []; $pk = (int) $pk; if (!array_key_exists($pk, $tags)) { $db = \JFactory::getDbo(); $query = $db->getQuery(true) ->select('DISTINCT t.alias') ->from($db->quoteName('#__tags', 't')) ->join('INNER', $db->quoteName('#__contentitem_tag_map', 'm') . ' ON ' . $db->quoteName('m.tag_id') . ' = ' . $db->quoteName('t.id') . ' AND ' . $db->quoteName('m.type_alias') . ' = ' . $db->quote('com_solidres.experience') . ' AND ' . $db->quoteName('m.content_item_id') . ' = ' . $pk) ->order('t.lft ASC'); $db->setQuery($query); $tags[$pk] = $db->loadColumn(); } return $tags[$pk]; } }
| ver. 1.4 |
Github
|
.
| PHP 8.5.7 | Generation time: 0 |
proxy
|
phpinfo
|
Settings