Your IP : 216.73.216.240


Current Path : /home/juvelize/www/modules/mod_ic_event_list/src/Helper/
Upload File :
Current File : /home/juvelize/www/modules/mod_ic_event_list/src/Helper/EventsHelper.php

<?php
/**
 *----------------------------------------------------------------------------
 * iCagenda     Events Management Extension for Joomla!
 *      PRO     Module iC Event List
 *----------------------------------------------------------------------------
 * @version     3.3.0 2024-02-25
 *
 * @package     iCagendaPro.Site
 * @subpackage  mod_ic_event_list
 * @link        https://www.icagenda.com
 *
 * @author      Cyril Rezé
 * @copyright   (c) 2012-2024 Cyril Rezé / iCagenda. All rights reserved.
 * @license     GNU General Public License version 3 or later; see LICENSE.txt
 *
 * @since       3.2
 *----------------------------------------------------------------------------
*/

namespace WebiC\Module\EventList\Site\Helper;

\defined('_JEXEC') or die;

use iCutilities\Thumb\Thumb as icagendaThumb;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Uri\Uri;
use Joomla\Registry\Registry;
use WebiC\Component\iCagenda\Site\Model\EventsModel;

/**
 * Helper for mod_ic_event_list
 *
 * @since  3.2
 */
class EventsHelper
{
	/**
	 * Retrieve list of banners
	 *
	 * @param   Registry        $params  The module parameters
	 * @param   BannersModel    $model   The model
	 * @param   CMSApplication  $app     The application
	 *
	 * @return  mixed
	 */
	public static function getList(Registry $params, EventsModel $model, CMSApplication $app)
	{
		$config = ComponentHelper::getParams('com_icagenda');

		// Set application parameters in model
		$app       = Factory::getApplication();
		$appParams = $app->getParams();
		$model->setState('params', $appParams);

		// Set the filters based on the module params
		$model->setState('filter.state', 1);

		// DateTime (Upcoming) filter
		$filter_by_date = $params->get('filter_by_date');

		if (isset($filter_by_date))
		{
			$upcoming = $params->get('filter_by_date', '1');
		}
		else
		{
			$upcoming = $params->get('time', '1'); // old setting (removed since 3.4.0-rc)

			if ($upcoming == '4') $upcoming = '5'; // convert old 'All' setting
			if ($upcoming == '3') $upcoming = '4'; // convert old 'today' setting
			if ($upcoming == '2') $upcoming = '3'; // convert old 'future' setting
			if ($upcoming == '0') $upcoming = '2'; // convert old 'past' setting
		}

		$model->setState('filter.upcoming', (int) $upcoming);

		// Set state for module params (Filter by features...)
		$model->setState('filter.mod_params', $params);

		// Display all dates filter
		$datesDisplay = $params->get('datesDisplay', $config->get('datesDisplay', 1));

		$model->setState('filter.all_dates', $datesDisplay);

		// Category filter
		$model->setState('filter.category_id', $params->get('mcatid', 'all'));

		// Access filter
		$model->setState('filter.access', 'e.access');

		// Filter by language
		$model->setState('filter.language',$app->getLanguageFilter());

		// Set number of events (processed in mod_ic_event_list.php)
//		$model->setState('list.start', 0);
//		$model->setState('list.limit', (int) $params->get('count', 5));

		// Set ordering
		$model->setState('list.ordering', 'e.next');

		// Set direction
		$orderby = ($params->get('orderby', '2') == 2) ? 'ASC' : 'DESC';

		$model->setState('list.direction', $orderby);

		// Retrieve Content
		$events = $model->getItems();

		return $events;
	}

	/**
	 * Get Thumbnail
	 *
	 * @since 3.0
	 */
	public static function getThumbnail($image, $thumb_generator)
	{
		// START iCthumb
		$img   = HTMLHelper::cleanImageURL($image);
		$image = $img->url;

		// Set if run iCthumb
		if ($image && ($thumb_generator == 1)) {
			// Generate xsmall thumb if not exist
			$thumb_img = icagendaThumb::sizeXSmall($image);
		} elseif ($image && ($thumb_generator == 0)) {
			$thumb_img = icagendaThumb::sizeOriginal($image);
		} else {
			return false;
		}

		$baseURL = Uri::base();
		$thumb_img = ltrim($thumb_img, '/');

		return $baseURL . $thumb_img;
	}
}