2017-07-26 10:47:30 +02:00

183 lines
4.3 KiB
PHP

<?php
include_once dirname(__FILE__).'/../../classes/AdvSiteReview.php';
class AdminAdvSiteReviewsController extends ModuleAdminController {
public function __construct() {
$this->table = 'advsitereviews';
$this->className = 'AdvSiteReview';
$this->identifier = 'id_comment';
$this->lang = true;
$this->deleted = false;
$this->bootstrap = true;
$this->position_identifier = 'id_comment';
$this->_defaultOrderBy = 'position';
parent::__construct();
$this->actions = array('edit', 'delete');
$this->fields_list = array(
'id_comment' => array(
'title' => 'ID',
'width' => 25
),
'firstname' => array(
'title' => $this->module->l('Prénom'),
),
'lastname' => array(
'title' => $this->module->l('Nom'),
),
'rank' => array(
'title' => $this->module->l('Note'),
),
'content' => array(
'title' => $this->module->l('Contenu'),
'width' => 45,
),
'position' => array(
'title' => $this->l('Position'),
'position' => 'position',
'filter_key' => 'a!position'
),
'active' => array(
'title' => $this->l('Validé'),
'active' => 'status',
'type' => 'bool',
'align' => 'center',
'orderby' => false
)
);
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL){
$this->_join .= 'JOIN `'._DB_PREFIX_.'advsitereviews_shop` as ashop ON a.`id_comment` = ashop.`id_comment` AND ashop.`id_shop` IN ('.implode(', ', Shop::getContextListShopID()).') ';
$this->_group .= 'GROUP BY ashop.`id_comment`';
}
}
public function renderView() {
return $this->renderList();
}
public function renderForm() {
$this->fields_form = array(
'tinymce' => TRUE,
'legend' => array(
'title' => $this->className,
),
'submit' => array(
'name' => 'submitAdvSlider',
'title' => $this->l('Save'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Prénom'),
'name' => 'firstname',
'lang' => TRUE,
),
array(
'type' => 'text',
'label' => $this->l('Nom'),
'name' => 'lastname',
'lang' => TRUE,
),
array(
'type' => 'text',
'label' => $this->l('Note'),
'name' => 'rank',
),
array(
'type' => 'text',
'label' => $this->module->l('Titre'),
'name' => 'title',
'lang' => TRUE,
),
array(
'type' => 'text',
'label' => $this->module->l('Lieu'),
'name' => 'place',
'lang' => TRUE,
),
array(
'type' => 'text',
'label' => $this->module->l('Date'),
'name' => 'date',
'lang' => TRUE,
),
array(
'type' => 'textarea',
'label' => $this->l('Contenu'),
'name' => 'content',
'autoload_rte' => TRUE,
'lang' => TRUE
),
array(
'type' => 'switch',
'label' => $this->l('Validé ?'),
'name' => 'active',
'required' => FALSE,
'is_bool' => TRUE,
'default' => 1,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
),
array(
'type' => 'shop',
'label' => $this->l('Shop'),
'form_group_class' => 'fieldhide input_association',
'name' => 'checkBoxShopAsso_advsitereviews'
)
)
);
return parent::renderForm();
}
public function ajaxProcessUpdatePositions()
{
$way = (int)(Tools::getValue('way'));
$id = (int)(Tools::getValue('id'));
$positions = Tools::getValue('review');
$obj = 'advsitereviews';
if (is_array($positions)){
foreach ($positions as $position => $value)
{
$pos = explode('_', $value);
if (isset($pos[2]) && (int)$pos[2] === $id)
{
$menu_obj = new AdvSiteReview((int)$pos[2]);
if (Validate::isLoadedObject($menu_obj))
if (isset($position) && $menu_obj->updatePosition($way, $position))
{
echo 'ok position '.(int)$position.' for '.$obj.' '.(int)$pos[2]."\r\n";
}
else
echo '{"hasError" : true, "errors" : "Can not update '.$obj.' '.(int)$id.' to position '.(int)$position.' "}';
else
echo '{"hasError" : true, "errors" : "This '.$obj.' ('.(int)$id.') cannot be loaded"}';
break;
}
}
}
}
}