441 lines
21 KiB
PHP
441 lines
21 KiB
PHP
<?php
|
||
|
||
include_once(_PS_MODULE_DIR_.'/ant_customgroup/models/CustomGroup.php');
|
||
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
|
||
|
||
class AdminAntCustomgroup extends AdminTab
|
||
{
|
||
|
||
protected $_html;
|
||
public $module_name;
|
||
public $config_tab;
|
||
public $controller;
|
||
public $helperForm;
|
||
public $_object;
|
||
|
||
public function __construct($config_tab = true)
|
||
{
|
||
parent::__construct();
|
||
$this->_object = false;
|
||
$this->controller = 'AdminModules';
|
||
$this->module_name = 'ant_customgroup';
|
||
$this->config_tab = (bool)$config_tab;
|
||
if ($config_tab) {
|
||
$this->controller = 'AdminAntCustomgroup';
|
||
}
|
||
$this->helperForm = new HelperFormBootstrap();
|
||
$this->helperForm->_inputSwitch = true;
|
||
}
|
||
|
||
public function display()
|
||
{
|
||
parent::displayForm();
|
||
|
||
$this->_html = '';
|
||
|
||
$this->_postProcess();
|
||
|
||
$this->_addCss();
|
||
$this->_html .= $this->helperForm->renderStyle();
|
||
|
||
$this->_displayForm();
|
||
$this->_displayList();
|
||
|
||
$this->_html .='<div class="clearfix"></div>';
|
||
$this->_addJs();
|
||
$this->_html .= $this->helperForm->renderScript();
|
||
echo $this->_html;
|
||
}
|
||
|
||
|
||
protected function _addJs()
|
||
{
|
||
$this->helperForm->_js .= '<script type="text/javascript"></script>';
|
||
}
|
||
|
||
protected function _addCss()
|
||
{
|
||
$this->helperForm->_css .='
|
||
.table tr th {
|
||
background: #565485;
|
||
background: rgba(86,84,133,0.9);
|
||
color: #fff;
|
||
font-size: 12px;
|
||
}
|
||
.table tr:nth-child(even) {
|
||
background: #F1F1F1;
|
||
}
|
||
.table .input-group-btn .btn {
|
||
padding: 4px 5px;
|
||
color: #504d8b;
|
||
|
||
}
|
||
.table .input-group-btn .btn .anticon{
|
||
font-size: 12px;
|
||
}
|
||
.bg-grey{
|
||
background: #EFEFEF;
|
||
border-radius:4px;
|
||
}
|
||
.bg-grey .div-title {
|
||
border-bottom: 2px solid #504D8B;
|
||
}
|
||
';
|
||
}
|
||
|
||
protected function _displayList()
|
||
{
|
||
global $cookie, $currentIndex;
|
||
|
||
$id_lang = (int)$cookie->id_lang;
|
||
|
||
$custom_groups = CustomGroup::getGroups(false);
|
||
$_current_index = ($this->config_tab ? $currentIndex . '&token=' . Tools::getAdminTokenLite($this->controller) : $_SERVER['REQUEST_URI']);
|
||
$row_data = array();
|
||
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
|
||
|
||
$this->_html .='
|
||
<div class="col-md-12">
|
||
<div class="panel">
|
||
<div class="panel-title">
|
||
<h2><span class="text-rose anticon anticon-list"></span> '.$this->l('Liste des groupes').'</h2>
|
||
<div class="clearfix"></div>
|
||
</div>
|
||
<div class="panel-content">
|
||
<table class="table table-custombordered" style="width: 100%;">
|
||
<thead>
|
||
<tr>
|
||
<th class="text-left">'.$this->l('ID').'</th>
|
||
<th class="text-left">'.$this->l('Name').'</th>
|
||
<th class="text-center">'.$this->l('Subscription days').'</th>
|
||
<th class="text-center">'.$this->l('Last order days').'</th>
|
||
<th class="text-center">'.$this->l('Retention days').'</th>
|
||
<th class="text-center">'.$this->l('Minimum order amount').'</th>
|
||
<th class="text-center">'.$this->l('Active').'</th>
|
||
<th class="text-center">'.$this->l('Nb').'</th>
|
||
<th class="text-center">'.$this->l('Action').'</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>';
|
||
foreach ($custom_groups as $custom_group)
|
||
{
|
||
// $selected_order_stats = "";
|
||
// foreach (CustomGroup::getOrderStatsIds((int)$custom_group['id_custom_group']) as $order_stats_id)
|
||
// {
|
||
// $selected_order_stats .= Customer::$order_stats_categories[$order_stats_id] . ",";
|
||
// }
|
||
// $selected_sales = "";
|
||
// if(count(CustomGroup::getSalesIds((int)$custom_group['id_custom_group'])) > 0){
|
||
// foreach (
|
||
// Db::getInstance()->executeQ('
|
||
// SELECT cl.name
|
||
// FROM `' . _DB_PREFIX_ . 'privatesale` ps
|
||
// ON cl.id_category = ps.id_category
|
||
// AND cl.id_lang = ' . $id_lang . '
|
||
// WHERE ps.id_sale IN (' .
|
||
// implode( ',' , CustomGroup::getSalesIds((int)$custom_group['id_custom_group'])) .
|
||
// ")") as $row)
|
||
// {
|
||
// $selected_sales .= $row['name'] . ",";
|
||
// };
|
||
// }
|
||
$customer_number = CustomGroup::getCount((int)$custom_group['id_custom_group']);
|
||
|
||
if ($custom_group['minimum_order_amount'] > 0.0){
|
||
$minimum_order_amount = Tools::displayPrice($custom_group['minimum_order_amount'], $currency, false);
|
||
} else {
|
||
$minimum_order_amount = '<span class="anticon anticon-minus text-orange"></span>';
|
||
}
|
||
|
||
if ($custom_group['register_date'] == 0) {
|
||
$register_date = '<span class="anticon anticon-minus text-orange"></span>';
|
||
} else {
|
||
$register_date = $custom_group['register_date'] . " jours";
|
||
}
|
||
|
||
if ($custom_group['last_order_date'] == 0) {
|
||
$last_order_date = '<span class="anticon anticon-minus text-orange"></span>';
|
||
} else {
|
||
$last_order_date = $custom_group['last_order_date'] . " jours";
|
||
}
|
||
|
||
if ($custom_group['nb_retention_days'] == 0) {
|
||
$nb_retention_days = '<span class="anticon anticon-minus text-orange"></span>';
|
||
} else {
|
||
$nb_retention_days = $custom_group['nb_retention_days'] . " jours";
|
||
}
|
||
|
||
// $row_data[] = array(
|
||
// 'id_custom_group' => (int)$custom_group['id_custom_group'],
|
||
// 'name' => $custom_group['name'],
|
||
// 'register_date' => $register_date,
|
||
// 'last_order_date' => $last_order_date,
|
||
// 'nb_retention_days' => $nb_retention_days,
|
||
// 'minimum_order_amount' => $minimum_order_amount,
|
||
// // 'id_sales' => $selected_sales,
|
||
// // 'id_order_stats_categories' => $selected_order_stats,
|
||
// 'active' => (int)$custom_group['active'],
|
||
// 'number' => $customer_number
|
||
// );
|
||
|
||
$this->_html .='
|
||
<tr>
|
||
<td valign="middle" align="left">#'.$custom_group['id_custom_group'].'</td>
|
||
<td valign="middle" align="left"><b>'.$custom_group['name'].'</b></td>
|
||
<td valign="middle" align="center">'.$register_date.'</td>
|
||
<td valign="middle" align="center">'.$last_order_date.'</td>
|
||
<td valign="middle" align="center">'.$nb_retention_days.'</td>
|
||
<td valign="middle" align="center">'.$minimum_order_amount.'</td>
|
||
<td align="center">'.((int)$custom_group['active']?'<span class="anticon anticon-checkmark text-green-light"></span>':'<span class="anticon anticon-cross text-rose"></span>').'</td>
|
||
<td valign="middle" align="center">'.$customer_number.'</td>
|
||
<td valign="middle" align="center">
|
||
<div class="input-group-btn" role="group" aria-label="...">
|
||
<a href="'.$_current_index.'&loadGroup=1&id='.$custom_group['id_custom_group'].'" class="btn btn-default"><span class="anticon anticon-pencil2"></span></a>
|
||
<a href="'.$_current_index.'&refreshGroup=1&id='.$custom_group['id_custom_group'].'" class="btn btn-default"><span class="anticon anticon-loop2"></span></a>
|
||
<a href="'.$_current_index.'&deleteGroup=1&id='.$custom_group['id_custom_group'].'" class="btn btn-default"><span class="anticon anticon-bin"></span></a>
|
||
</div>
|
||
</td>
|
||
</tr>';
|
||
}
|
||
$this->_html .='
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>';
|
||
|
||
}
|
||
|
||
protected function _postProcess()
|
||
{
|
||
if (Tools::isSubmit('newGroup')) {
|
||
|
||
} elseif (Tools::isSubmit('addGroup')) {
|
||
$this->_addOrUpdateGroup(false);
|
||
} elseif (Tools::isSubmit('editGroup')) {
|
||
$this->_addOrUpdateGroup(true);
|
||
} elseif (Tools::isSubmit('loadGroup') && Tools::getValue('id')) {
|
||
$this->_object = new CustomGroup((int)Tools::getValue('id'));
|
||
} elseif (Tools::isSubmit('deleteGroup') && Tools::getValue('id')) {
|
||
$deleted_group = new CustomGroup((int)Tools::getValue('id'));
|
||
$res = $deleted_group->delete();
|
||
if ($res) {
|
||
$this->_html .= HelperFormBootstrap::displaySuccess($this->l('Group deleted : #') . (int)Tools::getValue('id'));
|
||
} else {
|
||
$this->_html .= HelperFormBootstrap::displayError($this->l('Group cannot be deleted : #') . (int)Tools::getValue('id'));
|
||
}
|
||
return $res;
|
||
} elseif (Tools::isSubmit('refreshGroup') && Tools::getValue('id')) {
|
||
if (CustomGroup::refreshCustomGroupStatic(Tools::getValue('id'))) {
|
||
$this->_html .= HelperFormBootstrap::displaySuccess($this->l('Group updated with : #') . CustomGroup::getCount(Tools::getValue('id')));
|
||
} else {
|
||
$this->_html .= HelperFormBootstrap::displayError($this->l('Error occured during update for group : #') . (int)Tools::getValue('id'));
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
protected function _addOrUpdateGroup($edit = false)
|
||
{
|
||
if ($edit) {
|
||
$customGroup = new CustomGroup((int)Tools::getValue('id_custom_group'));
|
||
} else {
|
||
$customGroup = new CustomGroup();
|
||
}
|
||
|
||
$id_order_stats_categories = array();
|
||
// foreach (Tools::getValue('id_order_stats_categories') as $id_order_stats_category) {
|
||
// $id_order_stats_categories[] = $id_order_stats_category;
|
||
// }
|
||
|
||
if (count($id_order_stats_categories) > 0) {
|
||
$customGroup->customer_order_stats = $id_order_stats_categories;
|
||
} else {
|
||
$customGroup->customer_order_stats = array();
|
||
}
|
||
|
||
$customGroup->name = Tools::getValue('name');
|
||
$customGroup->register_date = (int)Tools::getValue('register_date');
|
||
$customGroup->last_order_date = (int)Tools::getValue('last_order_date');
|
||
$customGroup->nb_retention_days = (int)Tools::getValue('nb_retention_days');
|
||
$customGroup->minimum_order_amount = (float)Tools::getValue('minimum_order_amount');
|
||
$customGroup->sales = array();
|
||
$customGroup->active = (int)Tools::getValue('active');
|
||
|
||
// if ($sales_id_string = trim(Tools::getValue('comma_separated_sales'))) {
|
||
// if (substr($sales_id_string, strlen($sales_id_string) - 1, 1) == ",") {
|
||
// $sales_id_string = substr($sales_id_string, 0, strlen($sales_id_string) - 1);
|
||
// }
|
||
// $customGroup->sales = explode(",", $sales_id_string);
|
||
// } else {
|
||
// $customGroup->sales = array();
|
||
// }
|
||
|
||
if ($customGroup->save()) {
|
||
if ($edit) {
|
||
$this->_html .= HelperFormBootstrap::displaySuccess($this->l('Group has been updated'));
|
||
} else {
|
||
$this->_html .= HelperFormBootstrap::displaySuccess($this->l('Group has been created'));
|
||
}
|
||
} else {
|
||
$this->_html .= HelperFormBootstrap::displayError($this->l('Error occured while updating group'));
|
||
}
|
||
}
|
||
|
||
private function _displayForm()
|
||
{
|
||
global $cookie, $currentIndex;
|
||
|
||
$order_stats_categories = array();
|
||
$selected_order_stats_array = array();
|
||
if (Validate::isLoadedObject($this->_object)){
|
||
$customGroup = $this->_object;
|
||
}
|
||
// if (Validate::isLoadedObject($this->_object)) {
|
||
// $selected_order_stats_array = CustomGroup::getOrderStatsIds((int)$this->_object->id);
|
||
// $this->_object->comma_separated_sales = implode(",", CustomGroup::getSalesIds($this->_object->id));
|
||
// }
|
||
|
||
// foreach (Customer::$order_stats_categories as $key => $value) {
|
||
// if (!(is_null($value))) {
|
||
// $selected = (bool)($this->_object && in_array($key, $selected_order_stats_array, true));
|
||
// $order_stats_categories[] = array(
|
||
// 'label' => (int)$key . ' - ' . $value,
|
||
// 'value' => (int)$key,
|
||
// 'selected' => $selected
|
||
// );
|
||
// }
|
||
// }
|
||
|
||
$this->helperForm->_forms = array(
|
||
array(
|
||
'action' => $currentIndex . '&token=' . Tools::getAdminTokenLite('AdminAntCustomgroup'),
|
||
'title' => '<span class="text-rose anticon anticon-make-group"></span> '.$this->l('Segmentation'),
|
||
'class' => 'form-horizontal',
|
||
'class_div' => 'col-md-12',
|
||
'sections' => array(
|
||
array(
|
||
'class' => 'col-md-6',
|
||
'inputs' => array(
|
||
array(
|
||
'type' => 'simpleText',
|
||
'name' => 'name',
|
||
'label-class' => 'col-md-5',
|
||
'input-class' => 'col-md-6',
|
||
'label' => $this->l('Name'),
|
||
'default' => (isset($customGroup)?$customGroup->name:'')
|
||
),
|
||
array(
|
||
'type' => 'simpleText',
|
||
'name' => 'register_date',
|
||
'label-class' => 'col-md-5',
|
||
'input-class' => 'col-md-6',
|
||
'label' => $this->l('Registration Date'),
|
||
'default' => (isset($customGroup)?$customGroup->register_date:'')
|
||
),
|
||
array(
|
||
'type' => 'simpleText',
|
||
'name' => 'last_order_date',
|
||
'label-class' => 'col-md-5',
|
||
'input-class' => 'col-md-6',
|
||
'label' => $this->l('Last order date'),
|
||
'default' => (isset($customGroup)?$customGroup->last_order_date:'')
|
||
),
|
||
array(
|
||
'type' => 'simpleText',
|
||
'name' => 'nb_retention_days',
|
||
'label-class' => 'col-md-5',
|
||
'input-class' => 'col-md-6',
|
||
'label' => $this->l('Number of days'),
|
||
'default' => (isset($customGroup)?$customGroup->nb_retention_days:'')
|
||
),
|
||
array(
|
||
'type' => 'simpleText',
|
||
'name' => 'minimum_order_amount',
|
||
'label-class' => 'col-md-5',
|
||
'input-class' => 'col-md-6',
|
||
'label' => $this->l('Minimum order amount'),
|
||
'default' => (isset($customGroup)?$customGroup->minimum_order_amount:'')
|
||
),
|
||
array(
|
||
'type' => 'switch',
|
||
'label' => $this->l('Active'),
|
||
'label-class' => 'col-md-5',
|
||
'input-class' => 'col-md-6',
|
||
'class-group' => 'switch',
|
||
'name' => 'active',
|
||
'title' => ' ',
|
||
'default' => (isset($customGroup)?($customGroup->active==0?0:1):1),
|
||
'checked' => (isset($customGroup)?($customGroup->active==0?0:1):1),
|
||
),
|
||
),
|
||
'actions' => array(),
|
||
'actions-class' => 'text-right',
|
||
),
|
||
array(
|
||
'class' => 'col-md-6 bg-grey',
|
||
'title' => '<span class="anticon anticon-info"></span> Informations',
|
||
'info_html' => '
|
||
<p>L\'inscrit est ajouté au groupe une fois la condition requise et en ressort lorsqu\'il depasse cette date</p>
|
||
<p>Le nombre de jours depuis l’inscription OU depuis la dernière commande est strictement égal à la valeur renseignée
|
||
si un nombre de jours de rétention est spécifié (Nombre de jours de rétention différent de 0).<br>
|
||
Par exemple :</p>
|
||
<ul>
|
||
<li>Nb jrs depuis l\'inscription : 8</li>
|
||
<li>Nombre de jours de rétention : 31</li>
|
||
</ul>
|
||
<p>Tous les membres inscrits il y a 8 jours exactement resteront dans le groupe pendant 31 jours (et pourront utiliser le code reçu pendant 31 jours).
|
||
A l’inverse, s’il n’y a pas de nombre de jours de rétention précisé, alors pour le nombre de jours depuis l’inscription ou la dernière commande, la valeur renseignée s’entend supérieure ou égale.
|
||
</p>
|
||
<ul>
|
||
<li>Nb jrs depuis l\'inscription : 8</li>
|
||
<li>Nombre de jours de rétention : 0</li>
|
||
</ul>
|
||
<p>Tous les membres inscrits depuis 8 jours et plus peuvent utiliser le code.</p>
|
||
<p></p>'
|
||
),
|
||
),
|
||
'actions' => array(),
|
||
'actions-class' => 'text-right',
|
||
)
|
||
);
|
||
|
||
|
||
if (isset($customGroup)) {
|
||
$this->helperForm->_forms[0]['sections'][0]['title'] = "Editer le groupe ".$customGroup->name;
|
||
$this->helperForm->_forms[0]['sections'][0]['inputs'][] = array(
|
||
'type' => 'hidden',
|
||
'name' => 'id_custom_group',
|
||
'value' => $customGroup->id,
|
||
'class' => 'large'
|
||
);
|
||
$this->helperForm->_forms[0]['sections'][0]['actions'] = array(
|
||
array(
|
||
'type' => 'submit',
|
||
'class' => 'btn-default',
|
||
'name' => 'newGroup',
|
||
'value' => $this->l('Nouveau groupe')
|
||
),
|
||
array(
|
||
'type' => 'submit',
|
||
'class' => 'btn-primary',
|
||
'name' => 'editGroup',
|
||
'value' => $this->l('Editer le groupe')
|
||
),
|
||
);
|
||
} else {
|
||
$this->helperForm->_forms[0]['sections'][0]['title'] = "Ajouter un groupe";
|
||
$this->helperForm->_forms[0]['sections'][0]['actions'] = array(
|
||
array(
|
||
'type' => 'submit',
|
||
'class' => 'btn-primary',
|
||
'name' => 'addGroup',
|
||
'value' => $this->l('Ajouter le groupe')
|
||
),
|
||
);
|
||
}
|
||
|
||
$this->helperForm->renderForm();
|
||
}
|
||
}
|