maxImageBytes = (Configuration::get('PS_LIMIT_UPLOAD_IMAGE_VALUE') * 1000000);
$this->table = 'guide_category';
$this->className = 'GuideCategory';
$this->lang = true;
$this->edit = true;
$this->delete = true;
$this->view = true;
$this->fieldsDisplay = array(
'id_guide_category' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 30
),
'name' => array(
'title' => $this->l('Title'),
'width' => 100
),
'description' => array(
'title' => $this->l('Description'),
'width' => 500,
'maxlength' => 90,
'orderby' => false
),
'position' => array(
'title' => $this->l('Position'),
'width' => 40,
'filter_key' => 'position',
'align' => 'center',
'position' => 'position'
),
'active' => array(
'title' => $this->l('Displayed'),
'active' => 'status',
'align' => 'center',
'type' => 'bool',
'orderby' => false
)
);
if (isset($_GET['delete'.$this->table])) {
self::$current_category = new GuideCategory(
(int)(Tools::getValue('id_guide_category_parent', 0))
);
}
else {
self::$current_category = new GuideCategory(
(int)(
Tools::getValue('id_guide_category',
Tools::getValue('id_guide_category_parent', 0))
)
);
}
$this->_select = 'position ';
$this->_filter = 'AND a.`id_parent` = '.(int)(self::$current_category->id);
$this->_orderBy = 'position';
$this->_orderWay = 'DESC';
$this->identifiersDnd['id_guide_category'] = 'id_guide_category';
parent::__construct();
}
public static function getCurrentCategory()
{
return self::$current_category;
}
public function displayForm($token = NULL)
{
global $currentIndex, $cookie, $smarty;
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
$langs = Language::getLanguages(false);
$form = new FormBuilder('AdminGuideCategories', $this->table, 'id_guide_category', 'Add');
$this->fieldsForm = array(
'id_parent' => array(
'title' => $this->l('Catégorie parent'),
'type' => 'select',
'options_raw' => GuideCategory::findCategoriesTree($cookie->id_lang, $obj->id),
'options_map' => ['id_guide_category', 'name', 'level'],
'empty_option' => ['value'=>'0', 'label'=>$this->l('No parent category')],
'initial_value' => $obj->id_parent?$obj->id_parent:self::$current_category->id
),
'id_category_family' => array(
'title' => $this->l('Famille'),
'type' => 'select',
'options_raw' => GuideCategory::findFamiliesTree($cookie->id_lang),
'options_map' => ['id_category_family', 'name', 'level'],
'initial_value' => $obj->id_category_family
),
'name' => array(
'title' => $this->l('Title'),
'type' => 'text',
'required' => true,
'translatable' => true,
'attrs' => [
'onkeyup' => 'copy2friendlyURL();'
]
),
'description' => array(
'title' => $this->l('Description'),
'type' => 'textarea',
'translatable' => true,
),
'image' => array(
'title' => $this->l('Image'),
'type' => 'file',
'file_attrs' => [
'max_bytes' => $this->maxImageBytes,
'allowed_format' => 'JPEG',
'html_file' => "img",
'path' => $obj->getImageFileUrl().'?rand='.time()
]
),
'active' => array(
'title' => $this->l('Displayed'),
'type' => 'yesno',
'required' => true,
),
'link_rewrite' => array(
'title' => $this->l('Simplified URL'),
'type' => 'text',
'required' => true,
),
'meta_title' => array(
'title' => $this->l('Title (META)'),
'type' => 'text',
'translatable' => true,
),
'meta_description' => array(
'title' => $this->l('Description (META)'),
'type' => 'textarea',
'translatable' => true,
),
);
$form->setTitle($this->l('Purchase guide category'));
$form->setFields($this->fieldsForm);
$form->enableSubmitAndBackToParent();
$form->setSubmitButton($this->l('Save'));
$form->display($smarty, $langs, $obj);
$currentIndex .= '&id_guide_category='.($obj->id?$obj->id_parent:self::$current_category->id);
}
public function displayTop()
{
global $currentIndex, $cookie;
$clean_currentIndex = $currentIndex;
$parent_category = 0;
if (Validate::isLoadedObject(self::$current_category)) {
$parent_category = new GuideCategory(self::$current_category->id_parent);
if (Validate::isLoadedObject($parent_category)) {
echo ' '.$this->l('back to').' '.$parent_category->name[$cookie->id_lang].'
';
}
else {
echo ' '.$this->l('back').'
';
}
echo $this->l('Current category').' : '.self::$current_category->name[$cookie->id_lang].'
';
}
}
public function displayList()
{
global $currentIndex;
$this->displayTop();
if ($this->edit AND (!isset($this->noAdd) OR !$this->noAdd))
echo '
'.$this->l('Add new').'
';
// Append when we get a syntax error in SQL query
if ($this->_list === false)
{
$this->displayWarning($this->l('Bad SQL query'));
return false;
}
// Display list header (filtering, pagination and column names)
$this->displayListHeader();
if (!sizeof($this->_list))
echo '