235 lines
8.8 KiB
PHP
235 lines
8.8 KiB
PHP
<?php
|
|
/**
|
|
* 2007-2022 PrestaShop
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
* that is bundled with this package in the file LICENSE.txt.
|
|
* It is also available through the world-wide-web at this URL:
|
|
* http://opensource.org/licenses/afl-3.0.php
|
|
* If you did not receive a copy of the license and are unable to
|
|
* obtain it through the world-wide-web, please send an email
|
|
* to license@prestashop.com so we can send you a copy immediately.
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
* versions in the future. If you wish to customize PrestaShop for your
|
|
* needs please refer to http://www.prestashop.com for more information.
|
|
*
|
|
* @author PrestaShop SA <contact@prestashop.com>
|
|
* @copyright 2007-2022 PrestaShop SA
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
* International Registered Trademark & Property of PrestaShop SA
|
|
*/
|
|
|
|
class AdminPchCustomerfieldController extends ModuleAdminController
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->className = 'PchCustomerfieldModel';
|
|
$this->table = 'pchcustomerfield';
|
|
$this->deleted = false;
|
|
$this->identifier = 'id_pchcustomerfield';
|
|
$this->lang = true;
|
|
$this->bootstrap = true;
|
|
$this->explicitSelect = true;
|
|
$this->context = Context::getContext();
|
|
parent::__construct();
|
|
|
|
$this->position_identifier = 'position';
|
|
$this->_orderBy = 'position';
|
|
|
|
$this->fields_list = array(
|
|
'id_pchcustomerfield' => array(
|
|
'title' => $this->l('ID'),
|
|
'align' => 'center',
|
|
'class' => 'fixed-width-xs'
|
|
),
|
|
'title' => array(
|
|
'title' => $this->l('Field value'),
|
|
'lang' => true
|
|
),
|
|
'active' => array(
|
|
'title' => $this->l('Status'),
|
|
'active' => 'status',
|
|
'type' => 'bool',
|
|
'align' => 'center',
|
|
'orderby' => false,
|
|
'search' => false,
|
|
'class' => 'fixed-width-xs'
|
|
),
|
|
'position' => array(
|
|
'title' => $this->l('Position'),
|
|
'filter_key' => 'a!position',
|
|
'align' => 'center',
|
|
'class' => 'fixed-width-sm',
|
|
'position' => 'position',
|
|
'search' => false,
|
|
)
|
|
);
|
|
/*$this->bulk_actions = array(
|
|
'delete' => array(
|
|
'text' => $this->l('Delete selected'),
|
|
'confirm' => $this->l('Delete selected items?'),
|
|
'icon' => 'icon-trash'
|
|
)
|
|
);*/
|
|
}
|
|
|
|
protected function _childValidation()
|
|
{
|
|
$definition = ObjectModel::getDefinition($this->className);
|
|
|
|
/** @var $object ObjectModel */
|
|
$object = new $this->className();
|
|
|
|
$default_language = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
|
|
$languages = Language::getLanguages(false);
|
|
|
|
foreach ($definition['fields'] as $field => $def) {
|
|
if (isset($def['lang']) && $def['lang']) {
|
|
if (isset($def['required']) && $def['required']) {
|
|
foreach ($languages as $language) {
|
|
if ($language['id_lang'] !== $default_language->id) {
|
|
$value = Tools::getValue($field . '_' . $language['id_lang']);
|
|
if (!isset($value) || '' == $value) {
|
|
$this->errors[$field . '_' . $language['id_lang']] = $this->trans(
|
|
'The field %field_name% is required at in %lang%.',
|
|
array('%field_name%' => $object->displayFieldName($field, $this->className), '%lang%' => $language['name']),
|
|
'Admin.Notifications.Error'
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function renderList()
|
|
{
|
|
$this->addRowAction('edit');
|
|
//$this->addRowAction('delete');
|
|
return parent::renderList();
|
|
}
|
|
|
|
public function renderForm()
|
|
{
|
|
$this->fields_form = array(
|
|
'tinymce' => false,
|
|
'legend' => array(
|
|
'title' => $this->l('Specialization Field value'),
|
|
'icon' => 'icon-link'
|
|
),
|
|
'input' => array(
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Field value'),
|
|
'name' => 'title',
|
|
'lang' => true,
|
|
'required' => true,
|
|
'hint' => $this->l('Invalid characters:').' <>;=#{}',
|
|
'desc' => $this->l('You can use this heading in creating a specialization value.'),
|
|
),
|
|
array(
|
|
'type' => 'switch',
|
|
'label' => $this->l('Enabled'),
|
|
'name' => 'active',
|
|
'is_bool' => true,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'active_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Yes')
|
|
),
|
|
array(
|
|
'id' => 'active_off',
|
|
'value' => 0,
|
|
'label' => $this->l('No')
|
|
)
|
|
),
|
|
),
|
|
),
|
|
'submit' => array(
|
|
'title' => $this->l('Save'),
|
|
),
|
|
);
|
|
|
|
$languages = Language::getLanguages(false);
|
|
|
|
if (count($languages) > 1) {
|
|
return $this->getMultiLanguageInfoMsg() . parent::renderForm();
|
|
} else {
|
|
return parent::renderForm();
|
|
}
|
|
}
|
|
|
|
protected function getMultiLanguageInfoMsg()
|
|
{
|
|
return '<p class="alert alert-warning">'.
|
|
$this->l('Since multiple languages are activated on your shop, please mind to add field value for each one of them').
|
|
'</p>';
|
|
}
|
|
|
|
public function setMedia($isNewTheme = false)
|
|
{
|
|
parent::setMedia($isNewTheme);
|
|
$this->addJqueryUI('ui.sortable');
|
|
}
|
|
|
|
protected function beforeAdd($object)
|
|
{
|
|
if (empty($object->position) || !PchCustomerfieldModel::positionOccupied($object->position)) {
|
|
$object->position = PchCustomerfieldModel::getHigherPosition() + 1;
|
|
}
|
|
parent::beforeAdd($object);
|
|
}
|
|
|
|
public function ajaxProcessUpdatePositions()
|
|
{
|
|
$way = (int)(Tools::getValue('way'));
|
|
$id_field = (int)(Tools::getValue('id'));
|
|
$positions = Tools::getValue('pchcustomerfield');
|
|
|
|
foreach ($positions as $position => $value) {
|
|
$pos = explode('_', $value);
|
|
|
|
if (isset($pos[2]) && (int)$pos[2] === $id_field) {
|
|
if ($field = new PchCustomerfieldModel((int)$pos[2])) {
|
|
if (isset($position) && $field->updatePosition($way, $position)) {
|
|
echo 'ok position '.(int)$position.' for field '.(int)$pos[1].'\r\n';
|
|
} else {
|
|
echo '{"hasError" : true, "errors" : "Can not update field '.(int)$id_field.' to position '.(int)$position.' "}';
|
|
}
|
|
} else {
|
|
echo '{"hasError" : true, "errors" : "This field ('.(int)$id_field.') can t be loaded"}';
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function processPosition()
|
|
{
|
|
if (Tools::getIsset('update'.$this->table)) {
|
|
$object = new PchCustomerfieldModel((int)Tools::getValue('id_pchcustomerfield'));
|
|
self::$currentIndex = self::$currentIndex.'&update'.$this->table;
|
|
} else {
|
|
$object = new PchCustomerfieldModel((int)Tools::getValue('id'));
|
|
}
|
|
if (!Validate::isLoadedObject($object)) {
|
|
$this->errors[] = $this->l('An error occurred while updating the status for an object.').
|
|
' <b>'.$this->table.'</b> '.$this->l('(cannot load object)');
|
|
} elseif (!$object->updatePosition((int)Tools::getValue('way'), (int)Tools::getValue('position'))) {
|
|
$this->errors[] = $this->l('Failed to update the position.');
|
|
} else {
|
|
$id_identifier_str = ($id_identifier = (int)Tools::getValue($this->identifier)) ? '&'.$this->identifier.'='.$id_identifier : '';
|
|
$redirect = self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.$id_identifier_str.'&token='.$this->token;
|
|
$this->redirect_after = $redirect;
|
|
}
|
|
return $object;
|
|
}
|
|
}
|