diff --git a/modules/blockwishlist/WishList.php b/modules/blockwishlist/WishList.php index baf1a3494..ea039f967 100644 --- a/modules/blockwishlist/WishList.php +++ b/modules/blockwishlist/WishList.php @@ -28,43 +28,40 @@ if (!defined('_PS_VERSION_')) exit; -class WishList extends ObjectModel +class WishList extends ObjectModel { /** @var integer Wishlist ID */ - public $id; + public $id; /** @var integer Customer ID */ - public $id_customer; + public $id_customer; /** @var integer Token */ - public $token; + public $token; /** @var integer Name */ - public $name; + public $name; /** @var string Object creation date */ - public $date_add; + public $date_add; /** @var string Object last modification date */ - public $date_upd; + public $date_upd; - protected $fieldsSize = array('name' => 64, 'token' => 64); - protected $fieldsRequired = array('id_customer', 'name', 'token'); - protected $fieldsValidate = array('id_customer' => 'isUnsignedId', 'name' => 'isMessage', - 'token' => 'isMessage'); - protected $table = 'wishlist'; - protected $identifier = 'id_wishlist'; - - public function getFields() - { - $this->validateFields(); - $fields['id_customer'] = (int)($this->id_customer); - $fields['token'] = pSQL($this->token); - $fields['name'] = pSQL($this->name); - $fields['date_add'] = pSQL($this->date_add); - $fields['date_upd'] = pSQL($this->date_upd); - return ($fields); - } + /** + * @see ObjectModel::$definition + */ + public static $definition = array( + 'table' => 'wishlist', + 'primary' => 'id_wishlist', + 'fields' => array( + 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'token' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'required' => true), + 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'required' => true), + 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + ) + ); public function delete() { @@ -86,15 +83,18 @@ class WishList extends ObjectModel if (!Validate::isUnsignedId($id_wishlist)) die (Tools::displayError()); $result = Db::getInstance()->getRow(' - SELECT `counter` - FROM `'._DB_PREFIX_.'wishlist` - WHERE `id_wishlist` = '.(int)($id_wishlist)); - if ($result == false OR !sizeof($result) OR empty($result) === true) + SELECT `counter` + FROM `'._DB_PREFIX_.'wishlist` + WHERE `id_wishlist` = '.(int)$id_wishlist + ); + if ($result == false || !count($result) || empty($result) === true) return (false); - return (Db::getInstance()->execute(' - UPDATE `'._DB_PREFIX_.'wishlist` SET - `counter` = '.(int)($result['counter'] + 1).' - WHERE `id_wishlist` = '.(int)($id_wishlist))); + + return Db::getInstance()->execute(' + UPDATE `'._DB_PREFIX_.'wishlist` SET + `counter` = '.(int)($result['counter'] + 1).' + WHERE `id_wishlist` = '.(int)$id_wishlist + ); } @@ -102,10 +102,10 @@ class WishList extends ObjectModel { $context = Context::getContext(); return Db::getInstance()->getValue(' - SELECT COUNT(*) AS total - FROM `'._DB_PREFIX_.'wishlist` - WHERE `name` = \''.pSQL($name).'\' - AND `id_customer` = '.(int)$context->customer->id + SELECT COUNT(*) AS total + FROM `'._DB_PREFIX_.'wishlist` + WHERE `name` = \''.pSQL($name).'\' + AND `id_customer` = '.(int)$context->customer->id ); } diff --git a/modules/editorial/EditorialClass.php b/modules/editorial/EditorialClass.php index 0ae8c655c..f0ee66c50 100755 --- a/modules/editorial/EditorialClass.php +++ b/modules/editorial/EditorialClass.php @@ -25,68 +25,43 @@ * International Registered Trademark & Property of PrestaShop SA */ -class EditorialClass extends ObjectModel +class EditorialClass extends ObjectModel { /** @var integer editorial id*/ - public $id = 1; + public $id = 1; /** @var string body_title*/ - public $body_home_logo_link; + public $body_home_logo_link; /** @var string body_title*/ - public $body_title; + public $body_title; /** @var string body_title*/ - public $body_subheading; + public $body_subheading; /** @var string body_title*/ - public $body_paragraph; + public $body_paragraph; /** @var string body_title*/ - public $body_logo_subheading; - - protected $table = 'editorial'; - protected $identifier = 'id_editorial'; - - protected $fieldsValidate = array('body_home_logo_link' => 'isUrl'); - protected $fieldsValidateLang = array( - 'body_title' => 'isGenericName', - 'body_subheading' => 'isGenericName', - 'body_paragraph' => 'isCleanHtml', - 'body_logo_subheading' => 'isGenericName'); - + public $body_logo_subheading; + /** - * Check then return multilingual fields for database interaction - * - * @return array Multilingual fields - */ - public function getTranslationsFieldsChild() - { - $this->validateFieldsLang(); + * @see ObjectModel::$definition + */ + public static $definition = array( + 'table' => 'editorial', + 'primary' => 'id_editorial', + 'fields' => array( + 'body_home_logo_link' => array('type' => self::TYPE_STRING, 'validate' => 'isUrl'), + + // Lang fields + 'body_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName'), + 'body_subheading' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName'), + 'body_paragraph' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'), + 'body_logo_subheading' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName'), + ) + ); - $fieldsArray = array('body_title', 'body_subheading', 'body_paragraph', 'body_logo_subheading'); - $fields = array(); - $languages = Language::getLanguages(false); - $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); - foreach ($languages as $language) - { - $fields[$language['id_lang']]['id_lang'] = (int)($language['id_lang']); - $fields[$language['id_lang']][$this->identifier] = (int)($this->id); - foreach ($fieldsArray as $field) - { - if (!Validate::isTableOrIdentifier($field)) - die(Tools::displayError()); - 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']], true); - elseif (in_array($field, $this->fieldsRequiredLang)) - $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage], true); - else - $fields[$language['id_lang']][$field] = ''; - } - } - return $fields; - } - public function copyFromPost() { /* Classical fields */ @@ -104,12 +79,4 @@ class EditorialClass extends ObjectModel $this->{$field}[(int)($language['id_lang'])] = $_POST[$field.'_'.(int)($language['id_lang'])]; } } - - public function getFields() - { - $this->validateFields(); - $fields['id_editorial'] = (int)($this->id); - $fields['body_home_logo_link'] = pSQL($this->body_home_logo_link); - return $fields; - } } diff --git a/modules/homeslider/HomeSlide.php b/modules/homeslider/HomeSlide.php index 0fba6f47c..ef6b7a347 100644 --- a/modules/homeslider/HomeSlide.php +++ b/modules/homeslider/HomeSlide.php @@ -35,54 +35,24 @@ class HomeSlide extends ObjectModel public $active; public $position; - protected $fieldsValidate = array( - 'active' => 'isunsignedInt', - 'position' => 'isunsignedInt' - ); - protected $fieldsRequired = array( - 'active', - 'position' - ); - protected $fieldsRequiredLang = array('title', 'url', 'legend'); - protected $fieldsSizeLang = array( - 'description' => 4000, - 'title' => 255, - 'legend' => 255, - 'url' => 255, - 'image' => 255 - ); - protected $fieldsValidateLang = array( - 'title' => 'isCleanHtml', - 'description' => 'isCleanHtml', - 'url' => 'isUrl', - 'legend' => 'isCleanHtml', - 'image' => 'isCleanHtml' - ); + /** + * @see ObjectModel::$definition + */ + public static $definition = array( + 'table' => 'homeslider_slides', + 'primary' => 'id_homeslider_slides', + 'fields' => array( + 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true), + 'position' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => true), - protected $tables = array('homeslider_slides, homeslider_slides_lang'); - protected $table = 'homeslider_slides'; - protected $identifier = 'id_homeslider_slides'; - - public function getFields() - { - $this->validateFields(); - $fields['id_homeslider_slides'] = (int)$this->id; - $fields['active'] = (int)$this->active; - $fields['position'] = (int)$this->position; - return $fields; - } - - public function getTranslationsFieldsChild() - { - $this->validateFieldsLang(); - return $this->getTranslationsFields(array( - 'title', - 'description', - 'url', - 'legend', - 'image' - )); - } + // Lang fields + 'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 4000), + 'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 255), + 'legend' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 255), + 'url' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isUrl', 'required' => true, 'size' => 255), + 'image' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 255), + ) + ); public function __construct($id_slide = null, $id_lang = null, $id_shop = null, Context $context = null) { diff --git a/modules/loyalty/LoyaltyModule.php b/modules/loyalty/LoyaltyModule.php index 6d56b04e7..310d7faaa 100644 --- a/modules/loyalty/LoyaltyModule.php +++ b/modules/loyalty/LoyaltyModule.php @@ -38,24 +38,22 @@ class LoyaltyModule extends ObjectModel public $date_add; public $date_upd; - protected $fieldsRequired = array('id_customer', 'points'); - protected $fieldsValidate = array('id_loyalty_state' => 'isInt', 'id_customer' => 'isInt', 'id_cart_rule' => 'isInt', 'id_order' => 'isInt', 'points' => 'isInt'); - - protected $table = 'loyalty'; - protected $identifier = 'id_loyalty'; - - public function getFields() - { - $this->validateFields(); - $fields['id_loyalty_state'] = (int)$this->id_loyalty_state; - $fields['id_customer'] = (int)$this->id_customer; - $fields['id_order'] = (int)$this->id_order; - $fields['id_cart_rule'] = (int)$this->id_cart_rule; - $fields['points'] = (int)$this->points; - $fields['date_add'] = pSQL($this->date_add); - $fields['date_upd'] = pSQL($this->date_upd); - return $fields; - } + /** + * @see ObjectModel::$definition + */ + public static $definition = array( + 'table' => 'loyalty', + 'primary' => 'id_loyalty', + 'fields' => array( + 'id_loyalty_state' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), + 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true), + 'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), + 'id_cart_rule' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), + 'points' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true), + 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + ) + ); public function save($nullValues = false, $autodate = true) { diff --git a/modules/loyalty/LoyaltyStateModule.php b/modules/loyalty/LoyaltyStateModule.php index c7d710348..cc413ad26 100644 --- a/modules/loyalty/LoyaltyStateModule.php +++ b/modules/loyalty/LoyaltyStateModule.php @@ -33,31 +33,19 @@ class LoyaltyStateModule extends ObjectModel public $name; public $id_order_state; - protected $fieldsValidate = array('id_order_state' => 'isInt'); - protected $fieldsRequiredLang = array('name'); - protected $fieldsSizeLang = array('name' => 128); - protected $fieldsValidateLang = array('name' => 'isGenericName'); - - protected $table = 'loyalty_state'; - protected $identifier = 'id_loyalty_state'; - - public function getFields() - { - $this->validateFields(); - $fields['id_order_state'] = (int)($this->id_order_state); - return $fields; - } - /** - * Check then return multilingual fields for database interaction - * - * @return array Multilingual fields - */ - public function getTranslationsFieldsChild() - { - $this->validateFieldsLang(); - return $this->getTranslationsFields(array('name')); - } + * @see ObjectModel::$definition + */ + public static $definition = array( + 'table' => 'loyalty_state', + 'primary' => 'id_loyalty_state', + 'fields' => array( + 'id_order_state' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), + + // Lang fields + 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), + ), + ); public static function getDefaultId() { return 1; } public static function getValidationId() { return 2; } diff --git a/modules/productcomments/ProductComment.php b/modules/productcomments/ProductComment.php index c3a78bf2c..a1617a152 100644 --- a/modules/productcomments/ProductComment.php +++ b/modules/productcomments/ProductComment.php @@ -62,35 +62,26 @@ class ProductComment extends ObjectModel /** @var string Object creation date */ public $date_add; - protected $fieldsRequired = array('id_product', 'id_customer', 'content'); - protected $fieldsSize = array('content' => 65535); - protected $fieldsValidate = array( - 'id_product' => 'isUnsignedId', - 'id_customer' => 'isUnsignedId', - 'content' => 'isMessage', - 'grade' => 'isFloat', - 'validate' => 'isBool' + /** + * @see ObjectModel::$definition + */ + public static $definition = array( + 'table' => 'product_comment', + 'primary' => 'id_product_comment', + 'fields' => array( + 'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'id_guest' => array('type' => self::TYPE_INT), + 'customer_name' => array('type' => self::TYPE_STRING), + 'title' => array('type' => self::TYPE_STRING), + 'content' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 65535, 'required' => true), + 'grade' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'), + 'validate' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), + 'deleted' => array('type' => self::TYPE_BOOL), + 'date_add' => array('type' => self::TYPE_DATE), + ) ); - protected $table = 'product_comment'; - protected $identifier = 'id_product_comment'; - - public function getFields() - { - $this->validateFields(false); - $fields['id_product'] = (int)$this->id_product; - $fields['id_customer'] = (int)$this->id_customer; - $fields['id_guest'] = (int)$this->id_guest; - $fields['customer_name'] = pSQL($this->customer_name); - $fields['title'] = pSQL($this->title); - $fields['content'] = pSQL($this->content); - $fields['grade'] = (float)$this->grade; - $fields['validate'] = (int)$this->validate; - $fields['deleted'] = (int)$this->deleted; - $fields['date_add'] = pSQL($this->date_add); - return ($fields); - } - /** * Get comments by IdProduct * diff --git a/modules/productcomments/ProductCommentCriterion.php b/modules/productcomments/ProductCommentCriterion.php index 18f5b5b79..10363c251 100644 --- a/modules/productcomments/ProductCommentCriterion.php +++ b/modules/productcomments/ProductCommentCriterion.php @@ -31,27 +31,23 @@ class ProductCommentCriterion extends ObjectModel public $id_product_comment_criterion_type; public $name; - public $active = 1; - protected $fieldsRequiredLang = array('name'); - protected $fieldsSizeLang = array('name' => 128); - protected $fieldsValidateLang = array('name' => 'isGenericName'); - - protected $table = 'product_comment_criterion'; - protected $identifier = 'id_product_comment_criterion'; - - - public function getFields() - { - $this->validateFields(); - return array('id_product_comment_criterion_type' => (int)$this->id_product_comment_criterion_type, 'active' => (int)$this->active); - } - - public function getTranslationsFieldsChild() - { - $this->validateFieldsLang(); - return $this->getTranslationsFields(array('name')); - } - + public $active = true; + + /** + * @see ObjectModel::$definition + */ + public static $definition = array( + 'table' => 'product_comment_criterion', + 'primary' => 'id_product_comment_criterion', + 'fields' => array( + 'id_product_comment_criterion_type' => array('type' => self::TYPE_INT), + 'active' => array('type' => self::TYPE_BOOL), + + // Lang fields + 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), + ) + ); + public function delete() { if (!parent::delete()) diff --git a/modules/referralprogram/ReferralProgramModule.php b/modules/referralprogram/ReferralProgramModule.php index 2f7081456..589b0e9b4 100644 --- a/modules/referralprogram/ReferralProgramModule.php +++ b/modules/referralprogram/ReferralProgramModule.php @@ -40,26 +40,24 @@ class ReferralProgramModule extends ObjectModel public $date_add; public $date_upd; - protected $fieldsRequired = array('id_sponsor', 'email', 'lastname', 'firstname'); - protected $fieldsSize = array('id_sponsor' => 8, 'email' => 255, 'lastname' => 128, 'firstname' => 128, 'id_customer' => 8, 'id_discount' => 8, 'id_discount_sponsor' => 8); - protected $fieldsValidate = array( 'id_sponsor' => 'isUnsignedId', 'email' => 'isEmail', 'lastname' => 'isName', 'firstname' => 'isName', 'id_customer' => 'isUnsignedId', 'id_discount' => 'isUnsignedId', 'id_discount_sponsor' => 'isUnsignedId'); - protected $table = 'referralprogram'; - protected $identifier = 'id_referralprogram'; - - public function getFields() - { - $this->validateFields(); - $fields['id_sponsor'] = (int)$this->id_sponsor; - $fields['email'] = pSQL($this->email); - $fields['lastname'] = pSQL($this->lastname); - $fields['firstname'] = pSQL($this->firstname); - $fields['id_customer'] = (int)$this->id_customer; - $fields['id_discount'] = (int)$this->id_discount; - $fields['id_discount_sponsor'] = (int)$this->id_discount_sponsor; - $fields['date_add'] = pSQL($this->date_add); - $fields['date_upd'] = pSQL($this->date_upd); - return $fields; - } + /** + * @see ObjectModel::$definition + */ + public static $definition = array( + 'table' => 'referralprogram', + 'primary' => 'id_referralprogram', + 'fields' => array( + 'id_sponsor' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 255), + 'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 128), + 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 128), + 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_discount' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_discount_sponsor' =>array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + ), + ); public static function getDiscountPrefix() {