Add model

This commit is contained in:
Michael RICOIS 2018-02-21 09:35:02 +01:00
parent c3f5f5f54c
commit 679179bc74
5 changed files with 145 additions and 19 deletions

View File

@ -7,40 +7,52 @@ require_once PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php';
class AdminSkinStatic extends AdminTab
{
public $_html = '';
protected $maxImageSize = NULL;
protected $maxFileSize = NULL;
public function __construct()
{
$this->table = 'skinstatic';
$this->className = 'Skinstatic';
$this->lang = true;
$this->view = true;
$this->edit = true;
$this->delete = true;
$this->maxImageSize = (Configuration::get('PS_LIMIT_UPLOAD_IMAGE_VALUE') * 1000000);
$this->maxFileSize = (Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000);
$this->fieldsDisplay = array(
'id_skinstatic' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Name'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'name', 'orderby' => false),
'a!active' => array('title' => $this->l('Active'), 'active' => 'status', 'filter_key' => 'a!active', 'align' => 'center', 'type' => 'bool', 'orderby' => false),
'start_at' => array('title' => $this->l('Start at'), 'widthColumn' => 100, 'width' => 140),
'end_at' => array('title' => $this->l('End at'), 'widthColumn' => 100, 'width' => 140),
);
parent::__construct();
}
public function postProcess()
{
parent::postProcess();
}
public function display()
{
echo "Display";
parent::display();
}
// List
public function displayList()
{
echo "DisplayList";
parent::displayList();
}
// Form
public function displayForm()
{
echo "DisplayForm";
parent::displayForm();
echo "TEST";
}
// Fallback
private function displayFallback()
{
echo "DisplayFallback";
}
// Form fallback
private function displayFallbackForm()
{
echo "DisplayFallbackForm";
}
}

View File

@ -0,0 +1,15 @@
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
require_once PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php';
class AdminSkinStaticFallback extends AdminTab
{
public function __construct()
{
}
}

View File

@ -0,0 +1,87 @@
<?php
class Skinstatic extends ObjectModel
{
public $id;
public $id_skinstatic;
public $name;
public $active;
public $start_at;
public $end_at;
public $image;
public $link_left;
public $link_right;
public $new_window;
protected $fieldRequired = array();
protected $fieldValidate = array(
'id_skinstatic' => 'isUnsignedId',
'name' => 'isString',
'active' => 'isBool',
'start_at' => 'isDate',
'end_at' => 'isDate',
);
protected $tables = array('skinstatic', 'skinstatic_lang');
protected $table = 'skinstatic';
protected $identifier = 'id_skinstatic';
public function getFields()
{
parent::validateFields();
if (isset($this->id)) {
$fields['id_skinstatic'] = (int)($this->id);
}
$fields['name'] = (int)($this->name);
$fields['active'] = (int)($this->active);
$fields['start_at'] = pSQL($this->start_at);
$fields['end_at'] = pSQL($this->end_at);
return $fields;
}
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
self::validateFieldsLang();
$fieldsArray = array('image', 'link_left', 'link_right', 'new_window');
$fields = array();
$languages = Language::getLanguages(false);
$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
foreach ($languages as $language)
{
$fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
$fields[$language['id_lang']][$this->identifier] = (int)($this->id);
$fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']])) ? pSQL($this->description[$language['id_lang']], true) : '';
$fields[$language['id_lang']]['description_short'] = (isset($this->description_short[$language['id_lang']])) ? pSQL($this->description_short[$language['id_lang']], true) : '';
foreach ($fieldsArray as $field)
{
if (!Validate::isTableOrIdentifier($field))
die(Tools::displayError());
/* Check fields validity */
if (isset($this->{$field}[$language['id_lang']]) AND !empty($this->{$field}[$language['id_lang']]))
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
elseif (in_array($field, $this->fieldsRequiredLang))
{
if ($this->{$field} != '')
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
}
else
$fields[$language['id_lang']][$field] = '';
}
}
return $fields;
}
}

View File

@ -0,0 +1,6 @@
<?php
class SkinstaticFallback extends ObjectModel
{
}

View File

@ -30,5 +30,11 @@ class SkinStatic extends Module
public function install()
{
// See SQL file for installation
if (!(parent::install()) {
return false;
}
return true;
}
}