2017-08-01 19:41:36 +02:00

69 lines
2.5 KiB
PHP

<?php
class ConfiguratorOptGroup extends ObjectModel
{
public $id_configurator_opt_group;
public $type;
public $reference;
public $name;
public $description;
public $separator;
public static $definition = array(
'table' => 'configurator_opt_group',
'primary' => 'id_configurator_opt_group',
'multilang' => true,
'fields' => array(
'type' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => true),
'reference' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => true),
/* Lang fields */
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => '', 'required' => false),
'separator' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => '', 'required' => false),
),
'associations' => array(
'options' => array('type' => self::HAS_MANY, 'field' => 'id_configurator_opt_group', 'object' => 'ConfiguratorOpt', 'association' => 'configurator_opt'),
),
);
public function getConfiguratorOptName()
{
$id_lang = (int)Context::getContext()->language->id;
return $this->name[$id_lang];
}
public static function getAll()
{
$id_lang = (int)Context::getContext()->language->id;
$opts = Db::getInstance()->executeS('
SELECT cog.*, cogl.`name`
FROM `'._DB_PREFIX_.'configurator_opt_group` cog, `'._DB_PREFIX_.'configurator_opt_group_lang` cogl
WHERE cog.`id_configurator_opt_group` = cogl.`id_configurator_opt_group` AND cogl.`id_lang` = '.(int)$id_lang);
return $opts;
}
public function delete()
{
// Supprimer les Opt associés
}
public static function getValues($id_configurator_opt_group)
{
$id_lang = (int)Context::getContext()->language->id;
$sql = 'SELECT co.*, col.`name`
FROM `'._DB_PREFIX_.'configurator_opt` co
LEFT JOIN `'._DB_PREFIX_.'configurator_opt_lang` col ON co.`id_configurator_opt` = col.`id_configurator_opt`
WHERE co.`id_configurator_opt_group` = '.(int)$id_configurator_opt_group.' AND col.`id_lang` = '.(int)$id_lang;
$result = Db::getInstance()->executeS($sql);
return $result;
}
}