| Server IP : 54.36.91.62 / Your IP : 216.73.217.112 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/amisdesseniors-fr/lemans/components/com_djmediatools/models/ |
Upload File : |
<?php
/**
* @version $Id$
* @package DJ-MediaTools
* @copyright Copyright (C) 2017 DJ-Extensions.com, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: http://dj-extensions.com
* @author email contact@dj-extensions.com
* @developer Szymon Woronowski - szymon.woronowski@design-joomla.eu
*
* DJ-MediaTools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DJ-MediaTools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DJ-MediaTools. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
use Joomla\Utilities\ArrayHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
jimport('joomla.application.component.modellist');
class DJMediatoolsModelCategories extends JModelList
{
private $_categories = null;
private $_category = null;
private $_params = null;
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'id', 'a.id',
'title', 'a.title',
'alias', 'a.alias',
'parent_id', 'a.parent_id', 'parent_title',
'ordering', 'a.ordering',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'published', 'a.published'
);
}
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null)
{
// Initialise variables.
$app = JFactory::getApplication();
$params = $app->getParams('com_djmediatools');
$start = $app->input->getInt('limitstart', 0);
$limit = $app->input->getInt('limit', $params->get('albums_limit', $app->getCfg('list_limit')));
$this->setState('list.start', $start);
$this->setState('list.limit', $limit);
$orderCol = JFactory::getApplication()->input->getCmd('filter_order', 'ordering');
if (!in_array($orderCol, $this->filter_fields)) {
$orderCol = 'ordering';
}
$this->setState('list.ordering', $orderCol);
$listOrder = JFactory::getApplication()->input->getCmd('filter_order_Dir', 'ASC');
if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) {
$listOrder = 'ASC';
}
$this->setState('list.direction', $listOrder);
$id = JFactory::getApplication()->input->get('id');
$this->setState('category.id', intval($id));
$this->setState('filter.published', 1);
}
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('category.id');
$id .= ':' . $this->getState('filter.published');
return parent::getStoreId($id);
}
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'a.*, CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug'
)
);
$query->from('#__djmt_albums AS a');
// Join over the categories.
$query->select('c.title AS parent_title');
$query->join('LEFT', '#__djmt_albums AS c ON c.id = a.parent_id');
// Filter by published state
$published = $this->getState('filter.published');
if (is_numeric($published)) {
$query->where('a.published = ' . (int)$published);
} else if ($published === '') {
$query->where('(a.published = 0 OR a.published = 1)');
}
$query->where('a.visible = 1');
// Filter by category state
$category = $this->getState('category.id');
if (is_numeric($category)) {
$query->where('a.parent_id = ' . (int)$category);
}
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');
$query->order($db->escape($orderCol . ' ' . $orderDirn));
return $query;
}
public function getItems()
{
$id = $this->getState('category.id');
if ($this->_categories === null) $this->_categories = array();
if (!isset($this->_categories[$id])) $this->_categories[$id] = parent::getItems();
return $this->_categories[$id];
}
public function getItem($id = null)
{
if (is_null($id)) {
$id = $this->getState('category.id');
}
if ($this->_category === null) $this->_category = array();
if (!isset($this->_category[$id])) {
$this->_category[$id] = false;
if (isset($id) && $id == 0) {
$this->_category[$id] = 'root';
} else {
// Get a level row instance.
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_djmediatools/tables');
$table = JTable::getInstance('Categories', 'DJMediatoolsTable');
// Attempt to load the row.
if ($table->load($id)) {
// Check published state.
if ($published = $this->getState('filter.published')) {
if ($table->published != $published) {
return $this->_category[$id];
}
}
// Convert the JTable to a clean JObject.
$properties = $table->getProperties(1);
$this->_category[$id] = ArrayHelper::toObject($properties, 'JObject');
$this->_category[$id]->params = new JRegistry($this->_category[$id]->params);
} else if ($error = $table->getError()) {
$this->setError($error);
}
}
}
return $this->_category[$id];
}
function getParams($component = true, $overrideParams = null)
{
// we have to take clear JRegistry object to avoid overriding static component params
$params = new JRegistry;
// global params first
$cparams = JComponentHelper::getParams('com_djmediatools');
$params->merge($cparams);
// override global/menu params with category params
$id = $this->getState('category.id');
$category = $this->getItem($id);
if ($category && $category != 'root') {
$cparams = $category->params;
$params->merge($cparams);
}
$app = JFactory::getApplication();
// override global params with menu params only for component view
if ($component && $app->input->get('option') == 'com_djmediatools' && $app->getMenu()->getActive() != null) {
$menu = $app->getMenu();
// J4 compatibility
if(method_exists($menu->getActive(), 'getParams')) {
$mparams = $menu->getActive()->getParams();
}else {
$mparams = $menu->getActive()->params;
}
//$mparams = clone($mparams);
$params->merge($mparams);
}
if ($overrideParams) {
$params->merge($overrideParams);
}
$preset = $params->get('preset');
if (!empty($preset) && $preset != -1) {
// load preset params
$file = JPath::clean(JPATH_ROOT . '/media/djmediatools/presets/' . $preset . '.json');
if (JFile::exists($file)) {
$presetParams = new JRegistry;
$presetParams->loadString(file_get_contents($file));
$params->merge($presetParams);
}
}
if ($overrideParams) {
$params->merge($overrideParams);
}
// set default values
$params->def('blank', $params->get('blank', JURI::root(true) . '/components/com_djmediatools/assets/images/blank.gif'));
return $params;
}
private function getSortedItems(&$items, $parent = 0, $level = 0)
{
$categories = array();
foreach ($items as $key => $item) {
if (isset($item->level)) {
continue;
}
if ($item->parent_id == $parent) {
$item->key = $key;
$item->level = $level;
$categories[] = $item;
$categories = array_merge($categories, $this->getSortedItems($items, $item->id, $level + 1));
}
}
return $categories;
}
public function getSelectOptions($disable_default = false, $disable_self = false, $self_id = 0, $only_component = false)
{
$this->getState('filter.published');
$this->setState('filter.published', '');
$this->getState('filter.category.id');
$this->setState('filter.category.id', '');
$this->state->set('list.ordering', 'a.ordering');
$this->state->set('list.direction', 'asc');
$this->setState('list.start', 0);
$this->setState('list.limit', 0);
//$only_component = (JFactory::getApplication()->input->get('view')=='item' && JFactory::getApplication()->input->get('option')=='com_djmediatools' ? true : false);
$options = array();
if (!$disable_default) $options[] = JHTML::_('select.option', '0', JText::_('COM_DJMEDIATOOLS_ROOT_CATEGORY'), 'value', 'text');
$cats = $this->getItems();
$items = $this->getSortedItems($cats);
$level = 0;
$disabled = false;
if (!$self_id) $self_id = JFactory::getApplication()->input->getInt('id', null);
foreach ($items as $item) {
$prefix = '';
for ($i = 0; $i < $item->level; $i++) {
$prefix .= ' - ';
}
if ($disable_self) {
if ($disabled && $item->level <= $level) {
$disabled = false;
$disable_self = false;
} else if ($item->id == $self_id) {
$disabled = true;
$level = $item->level;
}
} else if ($only_component && $item->source != 'component') {
$disabled = true;
} else {
$disabled = false;
}
$options[] = JHTML::_('select.option', $item->id, $prefix . $item->title, 'value', 'text', $disabled);
}
return $options;
}
}