AnonSec Shell
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/administrator/components/com_djcatalog2/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/coopiak/amisdesseniors-fr/administrator/components/com_djcatalog2/models/combinations.php
<?php
/**
 * @package DJ-Catalog2
 * @copyright Copyright (C) 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
 *
 */

// no direct access
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\ListModel;

defined('_JEXEC') or die;

jimport('joomla.application.component.modellist');

class Djcatalog2ModelCombinations extends ListModel
{
    public function __construct($config = array())
    {
        if (empty($config['filter_fields'])) {
            $config['filter_fields'] = array(
                'i.name', 'name',
                'c.sku',
                'c.price',
                'c.stock',
                'c.ordering'
            );
        }

        parent::__construct($config);
    }

    protected function populateState($ordering = null, $direction = null)
    {
        // Initialise variables.
        $app = Factory::getApplication();
        $session = Factory::getSession();

        $parent = $this->getUserStateFromRequest($this->context . '.filter.parent', 'filter_parent', 0);
        $this->setState('filter.parent', $parent);

        // List state information.
        parent::populateState('i.name', 'asc');

        // If there's a forced language then define that filter for the query where clause
        if (!empty($forcedLanguage)) {
            $this->setState('filter.language', $forcedLanguage);
        }
    }

    protected function getStoreId($id = '')
    {
        // Compile the store id.

        return parent::getStoreId($id);
    }

    public function getItems()
    {
        $items = parent::getItems();
        $store = $this->getStoreId();
        $this->bindImages($store);
        $this->bindAttributes($store);


        return $items;
    }


    protected function _getList($query, $limitstart = 0, $limit = 0)
    {
        $this->_db->setQuery($query, $limitstart, $limit);
        $result = $this->_db->loadObjectList('id');

        return $result;
    }

    protected function getListQuery()
    {
        $parent = $this->getState('filter.parent');

        if (!$parent) {
            throw new Exception(Text::_('COM_DJCATALOG2_PARENT_REQUIRED'), 403);
        }

        $db = Factory::getDbo();
        $query = $db->getQuery(true);

        $query
            ->select([
                'i.name',
                'c.id',
                'c.sku',
                'c.gtin',
                'c.price',
                'c.stock',
                'c.item_id',
                'c.ordering'
            ])
            ->from($db->quoteName('#__djc2_items', 'i'))
            ->join('INNER', $db->quoteName('#__djc2_items_combinations', 'c') . ' ON c.item_id =  i.id')
            ->where('i.id = ' . (int)$parent);

        // Add the list ordering clause.
        $orderCol = $this->state->get('list.ordering', 'i.name');
        $orderDirn = $this->state->get('list.direction', 'asc');
        if ($orderCol == 'a.ordering' || $orderCol == 'category_name') {
            $orderCol = 'c.name ' . $orderDirn . ', a.ordering';
        }


        $query->order($db->escape($orderCol . ' ' . $orderDirn));
        return $query;
    }

    function bindAttributes($store)
    {
        if (!empty($this->cache[$store])) {
            $ids = array_keys($this->cache[$store]);
            if (empty($ids)) {
                return;
            }

            $db = Factory::getDbo();

            $query = $db->getQuery(true);
            $query
                ->select([
                    'f.name',
                    'fo.value',
                    'fv.combination_id'
                ])
                ->from($db->quoteName('#__djc2_items_extra_fields', 'f'))
                ->join('INNER', $db->quoteName('#__djc2_items_combinations_fields', 'fv') . ' ON fv.field_id = f.id')
                ->join('INNER', $db->quoteName('#__djc2_items_extra_fields_options', 'fo') . ' ON fv.value = fo.id')
                ->where('fv.combination_id IN (' . implode(',', $ids) . ')');
            //->where('fo.value <> ' . $db->quote('-'));

            $db->setQuery($query);
            $attributes = $db->loadObjectList();
            foreach ($attributes as $attribute) {
                if (isset($this->cache[$store][$attribute->combination_id])) {
                    $this->cache[$store][$attribute->combination_id]->attributes[] = $attribute;
                }
            }
        }
    }

    function bindImages($store)
    {
        if (!empty($this->cache[$store])) {
            $ids = array_keys($this->cache[$store]);
            if (empty($ids)) {
                return;
            }
            $db = Factory::getDbo();

            $query = $db->getQuery(true);
            $query->select('i.id, img.fullname as item_image, img.caption AS image_caption, img.path AS image_path, img.fullpath AS image_fullpath');
            $query->from('#__djc2_items_combinations as i');
            $query->join('inner', '#__djc2_images as img on img.id=(select id from #__djc2_images where type=\'combination\' and item_id=i.id order by ordering asc limit 1)');
            $query->where('i.id IN (' . implode(',', $ids) . ')');
            $db->setQuery($query);
            $image_list = $db->loadObjectList('id');

            foreach ($this->cache[$store] as $k => $row) {
                $this->cache[$store][$k]->item_image = isset($image_list[$row->id]) ? $image_list[$row->id]->item_image : null;
                $this->cache[$store][$k]->image_caption = isset($image_list[$row->id]) ? $image_list[$row->id]->image_caption : null;
                $this->cache[$store][$k]->image_path = isset($image_list[$row->id]) ? $image_list[$row->id]->image_path : null;
                $this->cache[$store][$k]->image_fullpath = isset($image_list[$row->id]) ? $image_list[$row->id]->image_fullpath : null;
            }
        }
    }

    protected function prepareTable($table)
    {
        // Reorder the records within the category so the new record is first
        if (empty($table->id)) {
            $table->reorder('catid = ' . (int)$table->catid);
        }
    }

    public function getExtraFieldGroups()
    {
        $db = Factory::getDbo();
        $query = $db->getQuery(true);

        $query
            ->select([
                'g.name',
                'g.label',
                'g.id'
            ])
            ->from($db->quoteName('#__djc2_items_extra_fields_groups', 'g'))
            ->order('g.ordering');

        $db->setQuery($query);
        return $db->loadObjectList();


    }

    public function getCombinationFields()
    {
        $parent = $this->getState('filter.parent');

        if (!$parent) {
            throw new Exception(Text::_('COM_DJCATALOG2_PARENT_REQUIRED'), 403);
        }




        $db = Factory::getDbo();
        $query = $db->getQuery(true);

        // Get parent product language
        $query
            ->select('language')
            ->from($db->quoteName('#__djc2_items', 'i'))
            ->where('i.id = ' . (int) $parent);
        $db->setQuery($query);
        $productLanguage = $db->loadResult();



        $query = $db->getQuery(true);


        $query
            ->select([
                'f.*'
            ])
            ->from($db->quoteName('#__djc2_items_extra_fields', 'f'))
            ->order('f.ordering')
            ->where('(f.language = ' . $db->quote('*') . ' OR f.language = ' . $db->quote($productLanguage) . ')')
            ->where('f.cart_variant = 1');

        $db->setQuery($query);
        $fields = $db->loadObjectList('id');
        $groups = [];

        if (count($fields)) {
            // Bind options
            $ids = array_keys($fields);
            $query = $db->getQuery(true);

            $query
                ->select([
                    'o.field_id',
                    'o.id',
                    'o.value'
                ])
                ->from($db->quoteName('#__djc2_items_extra_fields_options', 'o'))
                ->where('o.field_id IN (' . implode(',', $ids) . ')')
                ->order('o.ordering ASC');
            $db->setQuery($query);
            $options = $db->loadObjectList();
            foreach ($options as $option) {
                if (isset($fields[$option->field_id])) {
                    $fields[$option->field_id]->options[] = HTMLHelper::_('select.option', $option->id, $option->value, 'value', 'text');
                }
            }

        }

        foreach ($fields as $field) {
            $groups[$field->group_id][] = $field;
        }


        return $groups;
    }
}

Anon7 - 2022
AnonSec Team