162 lines
3.9 KiB
PHP
162 lines
3.9 KiB
PHP
<?php
|
|
include_once dirname(__FILE__).'/../../classes/CmsComments.php';
|
|
|
|
class AdminCmsCommentsController extends ModuleAdminController {
|
|
|
|
public function __construct() {
|
|
$this->table = 'cms_comments';
|
|
$this->className = 'CmsComments';
|
|
$this->identifier = 'id_comment';
|
|
$this->bootstrap = TRUE;
|
|
$this->context = Context::getContext();
|
|
|
|
parent::__construct();
|
|
|
|
$this->actions = array('edit','delete');
|
|
$this->bulk_actions = array(
|
|
'delete' => array(
|
|
'text' => $this->l('Supprimer la sélection'),
|
|
'confirm' => $this->l('Êtes vous sur de vouloir supprimer les commentaires ?')),
|
|
'actionPublished' => array(
|
|
'text' => $this->l('Publier la sélection'),
|
|
'confirm' => $this->l('Êtes vous sur de vouloir publier les commentaires ?')),
|
|
);
|
|
|
|
|
|
$this->fields_list = array(
|
|
'id_comment' => array(
|
|
'title' => 'ID',
|
|
'width' => 25
|
|
),
|
|
'id_element' => array(
|
|
'title' => $this->module->l('ID CMS'),
|
|
'width' => 45,
|
|
),
|
|
'name' => array(
|
|
'title' => $this->module->l('Nom'),
|
|
'width' => 45,
|
|
),
|
|
'email' => array(
|
|
'title' => $this->module->l('Email'),
|
|
'width' => 45,
|
|
),
|
|
'comments' => array(
|
|
'title' => $this->module->l('Commentaire'),
|
|
'width' => 45,
|
|
'callback' => 'formatComment',
|
|
),
|
|
'date_add' => array(
|
|
'title' => $this->module->l('Date'),
|
|
'width' => 45,
|
|
'type' => 'date',
|
|
),
|
|
'published' => array(
|
|
'title' => $this->l('Active'),
|
|
'active' => 'status',
|
|
'type' => 'bool',
|
|
'class' => 'fixed-width-xs',
|
|
'align' => 'center',
|
|
'ajax' => true,
|
|
'orderby' => false
|
|
)
|
|
);
|
|
}
|
|
|
|
public function processbulkactionPublished() {
|
|
foreach ($this->boxes as $key => $box) {
|
|
$comment = new CmsComments($box);
|
|
$comment->published = 1;
|
|
$comment->save();
|
|
}
|
|
$this->redirect_after = self::$currentIndex.'&conf=4&token='.$this->token;
|
|
}
|
|
|
|
public function formatComment($data, $obj) {
|
|
return substr($data, 0, 150) . '...';
|
|
}
|
|
|
|
public function ajaxProcessstatuscmsComments() {
|
|
if (!$id_comment = (int)Tools::getValue('id_comment'))
|
|
die(Tools::jsonEncode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the status'))));
|
|
else
|
|
{
|
|
$comments = new CmsComments((int)$id_comment);
|
|
if (Validate::isLoadedObject($comments))
|
|
{
|
|
$comments->published = $comments->published == 1 ? 0 : 1;
|
|
$comments->save() ?
|
|
die(Tools::jsonEncode(array('success' => true, 'text' => $this->l('The status has been updated successfully')))) :
|
|
die(Tools::jsonEncode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the status'))));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function renderForm() {
|
|
if (!($obj = $this->loadObject(TRUE)))
|
|
return;
|
|
|
|
$this->fields_form = array(
|
|
'tinymce' => TRUE,
|
|
'legend' => array(
|
|
'title' => $this->className,
|
|
),
|
|
'submit' => array(
|
|
'name' => 'submitCMSPSComments',
|
|
'title' => $this->l('Save'),
|
|
),
|
|
'input' => array(
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Nom'),
|
|
'name' => 'name',
|
|
'required' => TRUE,
|
|
'size' => 114,
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Email'),
|
|
'name' => 'email',
|
|
'required' => TRUE,
|
|
'size' => 114,
|
|
),
|
|
array(
|
|
'type' => 'textarea',
|
|
'label' => $this->l('Commentaire'),
|
|
'name' => 'comments',
|
|
'cols' => 100,
|
|
'rows' => 6,
|
|
),
|
|
array(
|
|
'type' => 'date',
|
|
'label' => $this->l('Date ajout'),
|
|
'name' => 'date_add'
|
|
),
|
|
array(
|
|
'type' => 'switch',
|
|
'label' => $this->l('Publié'),
|
|
'name' => 'published',
|
|
'required' => false,
|
|
'is_bool' => true,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'active_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Enabled')
|
|
),
|
|
array(
|
|
'id' => 'active_off',
|
|
'value' => 0,
|
|
'label' => $this->l('Disabled')
|
|
)
|
|
)
|
|
),
|
|
)
|
|
);
|
|
|
|
|
|
return parent::renderForm();
|
|
}
|
|
|
|
|
|
}
|