| 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/plats-individuels/lyon/administrator/components/com_djcatalog2/models/ |
Upload File : |
<?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.
defined('_JEXEC') or die;
class Djcatalog2ModelCombination extends JModelAdmin
{
protected $text_prefix = 'COM_DJCATALOG2';
public function __construct($config = array())
{
parent::__construct($config);
}
public function getTable($type = 'Combinations', $prefix = 'Djcatalog2Table', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
public function getForm($data = array(), $loadData = true)
{
// Initialise variables.
$app = JFactory::getApplication();
// Get the form.
$form = $this->loadForm('com_djcatalog2.combination', 'combination', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
return $form;
}
protected function loadFormData()
{
$data = JFactory::getApplication()->getUserState('com_djcatalog2.edit.combination.data', array());
if (empty($data)) {
$data = (array) $this->getItem();
}
if ($data['id']) {
// Load options
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select(['f.field_id', 'f.value'])
->from($db->quoteName('#__djc2_items_combinations_fields', 'f'))
->where('f.combination_id = ' . $data['id']);
$db->setQuery($query);
$fieldsValues = $db->loadObjectList();
$data['fields'] = [];
foreach ($fieldsValues as $fieldsValue) {
$data['fields'][$fieldsValue->field_id] = $fieldsValue->value;
}
}
if (!$data['item_id']) {
$app = JFactory::getApplication();
$parent = $app->getUserStateFromRequest('com_djcatalog2.items.filter.parent', 'filter_parent', 0);
$data['item_id'] = $parent;
}
return $data;
}
protected function getReorderConditions($table = null)
{
$condition = array();
return $condition;
}
public function delete(&$pks)
{
return parent::delete($pks);
}
/**
* Method to test whether a record can be deleted.
*
* @param object $record A record object.
*
* @return boolean True if allowed to delete the record. Defaults to the permission for the component.
*
* @since 1.6
*/
protected function canDelete($record)
{
return JFactory::getUser()->authorise('core.delete', $this->option) || JFactory::getUser()->authorise('djcatalog2.admin.catalogue', $this->option);
}
/**
* Method to test whether a record can have its state changed.
*
* @param object $record A record object.
*
* @return boolean True if allowed to change the state of the record. Defaults to the permission for the component.
*
* @since 1.6
*/
protected function canEditState($record)
{
return JFactory::getUser()->authorise('core.edit.state', $this->option) || JFactory::getUser()->authorise('djcatalog2.admin.catalogue', $this->option);
}
protected function preprocessForm(JForm $form, $data, $group = 'helloworld')
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$app = JFactory::getApplication();
$parent = $app->getUserStateFromRequest('com_djcatalog2.items.filter.parent', 'filter_parent', 0);
$itemModel = JModelLegacy::getInstance('Item', 'Djcatalog2Model', array('ignore_request' => true));
$item = $itemModel->getItem($parent);
if (isset($item->language)) {
$query
->select(['f.*'])
->from($db->quoteName('#__djc2_items_extra_fields', 'f'))
->where('f.cart_variant = 1')
->where('(f.language = ' . $db->quote('*') . ' OR f.language = ' . $db->quote($item->language) . ')')
->order('f.ordering');
$db->setQuery($query);
$extraFields = $db->loadObjectList('id');
$ids = array_keys($extraFields);
// Get options
$query = $db->getQuery(true);
$query
->select(['o.id', 'o.value', 'o.field_id'])
->from($db->quoteName('#__djc2_items_extra_fields_options', 'o'))
->where('o.field_id IN (' . implode(',', $ids) . ')');
$db->setQuery($query);
$options = $db->loadObjectList();
foreach ($options as $option) {
if (isset($extraFields[$option->field_id])) {
$extraFields[$option->field_id]->options[$option->id] = $option;
}
}
$query = $db->getQuery(true);
$query
->select('DISTINCT v.field_id')
->from($db->quoteName('#__djc2_items_combinations_fields', 'v'))
->join('INNER', $db->quoteName('#__djc2_items_combinations', 'c') . ' ON c.id = v.combination_id')
->where('c.item_id = ' . (int) $parent);
$db->setQuery($query);
$assignedFields = $db->loadColumn();
$addform = new SimpleXMLElement('<form />');
$fields = $addform->addChild('fields');
$fields->addAttribute('name', 'fields');
$fieldset = $fields->addChild('fieldset');
$fieldset->addAttribute('name', 'fields');
foreach ($extraFields as $extraField) {
$field = $fieldset->addChild('field');
$field->addAttribute('name', $extraField->id);
$field->addAttribute('type', 'list');
$field->addAttribute('label', $extraField->name);
if(in_array($extraField->id, $assignedFields)) {
$field->addAttribute('required', true);
}
$opt = $field->addChild('option', JText::_('COM_DJCATALOG2_SELECT_VALUE'));
foreach ($extraField->options as $optionId => $option) {
$opt = $field->addChild('option', $option->value);
$opt->addAttribute('value', $option->id);
}
}
$form->load($addform, false);
}
parent::preprocessForm($form, $data, $group);
}
}