[*] Classes: ObjectModel::getTranslationsField|Child() is now deprecated, use ObjectModel::getFieldsLang() if need instead

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11256 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-12-15 13:24:03 +00:00
parent af2feac665
commit 13a70e1044
33 changed files with 245 additions and 451 deletions
+4 -8
View File
@@ -47,17 +47,13 @@ class AttachmentCore extends ObjectModel
'file' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 40), 'file' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 40),
'mime' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 128), 'mime' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 128),
'file_name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 128), 'file_name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 128),
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
'description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isCleanHtml'), // Lang fields
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml'),
), ),
); );
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name', 'description'));
}
public function delete() public function delete()
{ {
@unlink(_PS_DOWNLOAD_DIR_.$this->file); @unlink(_PS_DOWNLOAD_DIR_.$this->file);
+3 -12
View File
@@ -47,7 +47,9 @@ class AttributeCore extends ObjectModel
'id_attribute_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_attribute_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor'), 'color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor'),
'position' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'position' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
// Lang fields
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
), ),
); );
@@ -69,17 +71,6 @@ class AttributeCore extends ObjectModel
parent::__construct($id, $id_lang, $id_shop); parent::__construct($id, $id_lang, $id_shop);
} }
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name'));
}
public function delete() public function delete()
{ {
$result = Db::getInstance()->executeS(' $result = Db::getInstance()->executeS('
+4 -13
View File
@@ -47,8 +47,10 @@ class AttributeGroupCore extends ObjectModel
'is_color_group' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'is_color_group' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'group_type' => array('type' => self::TYPE_STRING), 'group_type' => array('type' => self::TYPE_STRING),
'position' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'position' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
'public_name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64), // Lang fields
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
'public_name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
), ),
); );
@@ -84,17 +86,6 @@ class AttributeGroupCore extends ObjectModel
return $return; return $return;
} }
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name', 'public_name'));
}
public static function cleanDeadCombinations() public static function cleanDeadCombinations()
{ {
$attribute_combinations = Db::getInstance()->executeS(' $attribute_combinations = Db::getInstance()->executeS('
+5 -17
View File
@@ -50,11 +50,11 @@ class CMSCore extends ObjectModel
'active' => array('type' => self::TYPE_BOOL), 'active' => array('type' => self::TYPE_BOOL),
// Lang fields // Lang fields
'meta_description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'meta_keywords' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'meta_title' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
'link_rewrite' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128),
'content' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), 'content' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999),
), ),
); );
@@ -63,18 +63,6 @@ class CMSCore extends ObjectModel
'objectsNodeName' => 'content_management_system', 'objectsNodeName' => 'content_management_system',
); );
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array(
'meta_description',
'meta_keywords',
'meta_title',
'link_rewrite',
'content' => array('html' => true),
));
}
public function add($autodate = true, $nullValues = false) public function add($autodate = true, $nullValues = false)
{ {
$this->position = CMS::getLastPosition((int)$this->id_cms_category); $this->position = CMS::getLastPosition((int)$this->id_cms_category);
+6 -17
View File
@@ -86,12 +86,12 @@ class CMSCategoryCore extends ObjectModel
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
'link_rewrite' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 64), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 64),
'description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isCleanHtml'), 'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml'),
'meta_title' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 128), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
'meta_description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'meta_keywords' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
), ),
); );
@@ -100,17 +100,6 @@ class CMSCategoryCore extends ObjectModel
parent::__construct($id_cms_category, $id_lang); parent::__construct($id_cms_category, $id_lang);
} }
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name', 'description', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description'));
}
public function add($autodate = true, $nullValues = false) public function add($autodate = true, $nullValues = false)
{ {
$this->position = self::getLastPosition((int)$this->id_parent); $this->position = self::getLastPosition((int)$this->id_parent);
+1 -12
View File
@@ -142,7 +142,7 @@ class CarrierCore extends ObjectModel
'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
// Lang fields // Lang fields
'delay' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'delay' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
), ),
); );
@@ -168,17 +168,6 @@ class CarrierCore extends ObjectModel
$this->name = Configuration::get('PS_SHOP_NAME'); $this->name = Configuration::get('PS_SHOP_NAME');
} }
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('delay'));
}
public function add($autodate = true, $null_values = false) public function add($autodate = true, $null_values = false)
{ {
if (!parent::add($autodate, $null_values) || !Validate::isLoadedObject($this)) if (!parent::add($autodate, $null_values) || !Validate::isLoadedObject($this))
+1 -8
View File
@@ -94,17 +94,10 @@ class CartRuleCore extends ObjectModel
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 254), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 254),
), ),
); );
public function getTranslationsFieldsChild()
{
if (!$this->validateFieldsLang())
return false;
return $this->getTranslationsFields(array('name'));
}
public function add($autodate = true, $nullValues = false) public function add($autodate = true, $nullValues = false)
{ {
if (!parent::add($autodate, $nullValues)) if (!parent::add($autodate, $nullValues))
+7 -25
View File
@@ -90,19 +90,19 @@ class CategoryCore extends ObjectModel
'nleft' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'nleft' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'nright' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'nright' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'level_depth' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'level_depth' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true, 'size' => 1), 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
'id_parent' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'id_parent' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'position' => array('type' => self::TYPE_INT), 'position' => array('type' => self::TYPE_INT),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
'link_rewrite' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 64), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 64),
'description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isString'), 'description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'),
'meta_title' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 128), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
'meta_description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'meta_keywords' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
), ),
); );
@@ -140,24 +140,6 @@ class CategoryCore extends ObjectModel
return strip_tags(stripslashes($description)); return strip_tags(stripslashes($description));
} }
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array(
'name',
'description' => array('html' => true),
'link_rewrite',
'meta_title',
'meta_keywords',
'meta_description',
));
}
public function add($autodate = true, $nullValues = false) public function add($autodate = true, $nullValues = false)
{ {
$this->position = self::getLastPosition((int)$this->id_parent); $this->position = self::getLastPosition((int)$this->id_parent);
+3 -5
View File
@@ -74,16 +74,14 @@ class ConfigurationCore extends ObjectModel
); );
/** /**
* Check then return multilingual fields for database interaction * @see ObjectModel::getFieldsLang()
*
* @return array Multilingual fields * @return array Multilingual fields
*/ */
public function getTranslationsFieldsChild() public function getFieldsLang()
{ {
if (!is_array($this->value)) if (!is_array($this->value))
return true; return true;
$this->validateFieldsLang(); return $this->getFieldsLang();
return $this->getTranslationsFields(array('value'));
} }
/** /**
+2 -13
View File
@@ -52,22 +52,11 @@ class ContactCore extends ObjectModel
'customer_service' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'customer_service' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
'description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isCleanHtml'), 'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml'),
), ),
); );
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name', 'description'));
}
/** /**
* Return available contacts * Return available contacts
* *
+1 -12
View File
@@ -84,7 +84,7 @@ class CountryCore extends ObjectModel
'display_tax_label' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true), 'display_tax_label' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
), ),
); );
@@ -96,17 +96,6 @@ class CountryCore extends ObjectModel
), ),
); );
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name'));
}
public function delete() public function delete()
{ {
if (!parent::delete()) if (!parent::delete())
-1
View File
@@ -65,7 +65,6 @@ class CurrencyCore extends ObjectModel
public static $definition = array( public static $definition = array(
'table' => 'currency', 'table' => 'currency',
'primary' => 'id_currency', 'primary' => 'id_currency',
'multilang' => true,
'fields' => array( 'fields' => array(
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32), 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
'iso_code' => array('type' => self::TYPE_STRING, 'validate' => 'isLanguageIsoCode', 'required' => true, 'size' => 3), 'iso_code' => array('type' => self::TYPE_STRING, 'validate' => 'isLanguageIsoCode', 'required' => true, 'size' => 3),
+2 -13
View File
@@ -41,7 +41,7 @@ class FeatureCore extends ObjectModel
'position' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'position' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
), ),
); );
@@ -52,17 +52,6 @@ class FeatureCore extends ObjectModel
'fields' => array(), 'fields' => array(),
); );
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name'));
}
/** /**
* Get a feature data for a given id_feature and id_lang * Get a feature data for a given id_feature and id_lang
* *
@@ -160,7 +149,7 @@ class FeatureCore extends ObjectModel
$this->clearCache(); $this->clearCache();
$result = 1; $result = 1;
$fields = $this->getTranslationsFieldsChild(); $fields = $this->getFieldsLang();
foreach ($fields as $field) foreach ($fields as $field)
{ {
foreach (array_keys($field) as $key) foreach (array_keys($field) as $key)
+1 -12
View File
@@ -48,7 +48,7 @@ class FeatureValueCore extends ObjectModel
'custom' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'custom' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
// Lang fields // Lang fields
'value' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255), 'value' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
), ),
); );
@@ -60,17 +60,6 @@ class FeatureValueCore extends ObjectModel
), ),
); );
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('value'));
}
/** /**
* Get all values for a given feature * Get all values for a given feature
* *
+1 -14
View File
@@ -45,7 +45,7 @@ class GenderCore extends ObjectModel
'type' => array('type' => self::TYPE_INT, 'required' => true), 'type' => array('type' => self::TYPE_INT, 'required' => true),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isString', 'required' => true, 'size' => 20), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isString', 'required' => true, 'size' => 20),
), ),
); );
@@ -56,19 +56,6 @@ class GenderCore extends ObjectModel
$this->image_dir = _PS_GENDERS_DIR_; $this->image_dir = _PS_GENDERS_DIR_;
} }
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array(
'name',
));
}
public static function getGenders($id_lang = null) public static function getGenders($id_lang = null)
{ {
if (is_null($id_lang)) if (is_null($id_lang))
+1 -8
View File
@@ -58,7 +58,7 @@ class GroupCore extends ObjectModel
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
// Lang fields // Lang fields
'name' => array('type' => self::TYPE_INT, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
), ),
); );
@@ -67,13 +67,6 @@ class GroupCore extends ObjectModel
protected $webserviceParameters = array(); protected $webserviceParameters = array();
public function getTranslationsFieldsChild()
{
if (!$this->validateFieldsLang())
return false;
return $this->getTranslationsFields(array('name'));
}
public static function getGroups($id_lang) public static function getGroups($id_lang)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
+1 -7
View File
@@ -72,7 +72,7 @@ class ImageCore extends ObjectModel
'cover' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'cover' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
// Lang fields // Lang fields
'legend' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'legend' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
), ),
); );
@@ -85,12 +85,6 @@ class ImageCore extends ObjectModel
$this->source_index = _PS_PROD_IMG_DIR_.'index.php'; $this->source_index = _PS_PROD_IMG_DIR_.'index.php';
} }
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('legend'));
}
public function add($autodate = true, $null_values = false) public function add($autodate = true, $null_values = false)
{ {
if ($this->position <= 0) if ($this->position <= 0)
+5 -18
View File
@@ -79,11 +79,11 @@ class ManufacturerCore extends ObjectModel
'date_upd' => array('type' => self::TYPE_DATE), 'date_upd' => array('type' => self::TYPE_DATE),
// Lang fields // Lang fields
'description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isString'), 'description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'),
'short_description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isString', 'size' => 254), 'short_description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 254),
'meta_title' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 128), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
'meta_description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'meta_keywords' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName'), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName'),
), ),
); );
@@ -109,19 +109,6 @@ class ManufacturerCore extends ObjectModel
$this->image_dir = _PS_MANU_IMG_DIR_; $this->image_dir = _PS_MANU_IMG_DIR_;
} }
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array(
'meta_description',
'meta_keywords',
'meta_title',
'description' => array('html' => true),
'short_description' => array('html' => true),
));
}
public function delete() public function delete()
{ {
$address = new Address($this->id_address); $address = new Address($this->id_address);
+4 -10
View File
@@ -46,19 +46,13 @@ class MetaCore extends ObjectModel
'page' => array('type' => self::TYPE_STRING, 'validate' => 'isFileName', 'required' => true, 'size' => 64), 'page' => array('type' => self::TYPE_STRING, 'validate' => 'isFileName', 'required' => true, 'size' => 64),
// Lang fields // Lang fields
'title' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 128), 'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
'description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'keywords' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'url_rewrite' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isLinkRewrite', 'size' => 255), 'url_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'size' => 255),
), ),
); );
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('title', 'description', 'keywords', 'url_rewrite'));
}
public static function getPages($excludeFilled = false, $addPage = false) public static function getPages($excludeFilled = false, $addPage = false)
{ {
$selectedPages = array(); $selectedPages = array();
+174 -92
View File
@@ -35,7 +35,7 @@ abstract class ObjectModelCore
const TYPE_STRING = 3; const TYPE_STRING = 3;
const TYPE_FLOAT = 4; const TYPE_FLOAT = 4;
const TYPE_DATE = 5; const TYPE_DATE = 5;
const TYPE_HTML = 5; const TYPE_HTML = 6;
/** /**
* List of association types * List of association types
@@ -174,10 +174,10 @@ abstract class ObjectModelCore
{ {
$this->id = (int)$id; $this->id = (int)$id;
foreach ($result as $key => $value) foreach ($result as $key => $value)
if (key_exists($key, $this)) if (array_key_exists($key, $this))
$this->{$key} = $value; $this->{$key} = $value;
if (!$id_lang && method_exists($this, 'getTranslationsFieldsChild')) if (!$id_lang && isset($this->def['multilang']) && $this->def['multilang'])
{ {
$sql = 'SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang` $sql = 'SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang`
WHERE `'.$this->def['primary'].'` = '.(int)$id WHERE `'.$this->def['primary'].'` = '.(int)$id
@@ -220,44 +220,103 @@ abstract class ObjectModelCore
public function getFields() public function getFields()
{ {
$this->validateFields(); $this->validateFields();
return $this->formatFields();
}
/**
* Prepare multilang fields
*
* @return array
*/
public function getFieldsLang()
{
// Retrocompatibility
if (method_exists($this, 'getTranslationsFieldsChild'))
return $this->getTranslationsFieldsChild();
$this->validateFieldsLang();
$fields = array(); $fields = array();
if (is_null($this->id_lang))
foreach (Language::getLanguages(false) as $language)
$fields[$language['id_lang']] = $this->formatFields($language['id_lang']);
else
$fields = $this->formatFields($this->id_lang);
return $fields;
}
/**
* @param int $id_lang If this parameter is given, only take lang fields
* @return array
*/
public function formatFields($id_lang = null)
{
$fields = array();
// Set primary key in fields
if ($this->id) if ($this->id)
$fields[$this->def['primary']] = $this->id; $fields[$this->def['primary']] = $this->id;
// Set id_lang field for multilang fields and id_shop for multishop field
if ($id_lang)
{
$fields['id_lang'] = $id_lang;
if ($this->id_shop && $this->isLangMultishop())
$fields['id_shop'] = (int)$this->id_shop;
}
foreach ($this->def['fields'] as $field => $data) foreach ($this->def['fields'] as $field => $data)
if (!isset($data['lang']) || !$data['lang']) {
switch ($data['type']) // If $id_lang take only language fields, else take only classic fields
{ if (($id_lang && empty($data['lang'])) || (!$id_lang && !empty($data['lang'])))
case self::TYPE_INT : continue;
$fields[$field] = (int)$this->$field;
break;
case self::TYPE_BOOL : // Get field value, if value is multilang and field is empty, use value from default lang
$fields[$field] = (int)$this->$field; $value = $this->$field;
break; if ($id_lang && is_array($value))
{
if (!empty($value[$id_lang]))
$value = $value[$id_lang];
else if (!empty($data['required']))
$value = $value[Configuration::get('PS_LANG_DEFAULT')];
else
$value = '';
}
case self::TYPE_FLOAT : // Format field value
$fields[$field] = (float)$this->$field; switch ($data['type'])
break; {
case self::TYPE_INT :
$fields[$field] = (int)$value;
break;
case self::TYPE_DATE : case self::TYPE_BOOL :
$fields[$field] = pSQL($this->$field); $fields[$field] = (int)$value;
break; break;
case self::TYPE_STRING : case self::TYPE_FLOAT :
$fields[$field] = pSQL($this->$field); $fields[$field] = (float)$value;
break; break;
case self::TYPE_STRING : case self::TYPE_DATE :
$fields[$field] = pSQL($this->$field, true); $fields[$field] = pSQL($value);
break; break;
default : case self::TYPE_STRING :
if (method_exists($this, 'formatType'.$data['type'])) $fields[$field] = pSQL($value);
$fields[$field] = $this->{'formatType'.$data['type']}($this->$field); break;
break;
} case self::TYPE_HTML :
$fields[$field] = pSQL($value, true);
break;
default :
if (method_exists($this, 'formatType'.$data['type']))
$fields[$field] = $this->{'formatType'.$data['type']}($value);
break;
}
}
return $fields; return $fields;
} }
@@ -265,30 +324,35 @@ abstract class ObjectModelCore
/** /**
* Save current object to database (add or update) * Save current object to database (add or update)
* *
* return boolean Insertion result * @param bool $null_values
* @param bool $autodate
* @return boolean Insertion result
*/ */
public function save($nullValues = false, $autodate = true) public function save($null_values = false, $autodate = true)
{ {
return (int)($this->id) > 0 ? $this->update($nullValues) : $this->add($autodate, $nullValues); return (int)$this->id > 0 ? $this->update($null_values) : $this->add($autodate, $null_values);
} }
/** /**
* Add current object to database * Add current object to database
* *
* return boolean Insertion result * @param bool $null_values
* @param bool $autodate
* @return boolean Insertion result
*/ */
public function add($autodate = true, $nullValues = false) public function add($autodate = true, $null_values = false)
{ {
/* Hook */ // @hook actionObject*AddBefore
Hook::exec('actionObject'.get_class($this).'AddBefore', array('object' => $this)); Hook::exec('actionObject'.get_class($this).'AddBefore', array('object' => $this));
/* Automatically fill dates */ // Automatically fill dates
if ($autodate AND key_exists('date_add', $this)) if ($autodate && array_key_exists('date_add', $this))
$this->date_add = date('Y-m-d H:i:s'); $this->date_add = date('Y-m-d H:i:s');
if ($autodate AND key_exists('date_upd', $this)) if ($autodate && array_key_exists('date_upd', $this))
$this->date_upd = date('Y-m-d H:i:s'); $this->date_upd = date('Y-m-d H:i:s');
/* Database insertion */
if ($nullValues) // Database insertion
if ($null_values)
$result = Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'INSERT'); $result = Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'INSERT');
else else
$result = Db::getInstance()->autoExecute(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'INSERT'); $result = Db::getInstance()->autoExecute(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'INSERT');
@@ -296,16 +360,17 @@ abstract class ObjectModelCore
if (!$result) if (!$result)
return false; return false;
/* Get object id in database */ // Get object id in database
$this->id = Db::getInstance()->Insert_ID(); $this->id = Db::getInstance()->Insert_ID();
$assos = Shop::getAssoTables(); $assos = Shop::getAssoTables();
/* Database insertion for multilingual fields related to the object */
if (method_exists($this, 'getTranslationsFieldsChild')) // Database insertion for multilingual fields related to the object
if (isset($this->def['multilang']) && $this->def['multilang'])
{ {
$fields = $this->getTranslationsFieldsChild(); $fields = $this->getFieldsLang();
$shops = Shop::getShops(true, null, true); $shops = Shop::getShops(true, null, true);
if ($fields AND is_array($fields)) if ($fields && is_array($fields))
foreach ($fields AS &$field) foreach ($fields as &$field)
{ {
foreach (array_keys($field) AS $key) foreach (array_keys($field) AS $key)
if (!Validate::isTableOrIdentifier($key)) if (!Validate::isTableOrIdentifier($key))
@@ -335,7 +400,7 @@ abstract class ObjectModelCore
$result &= $this->associateTo(Context::getContext()->shop->getGroupID(), 'group_shop'); $result &= $this->associateTo(Context::getContext()->shop->getGroupID(), 'group_shop');
} }
/* Hook */ // @hook actionObject*AddAfter
Hook::exec('actionObject'.get_class($this).'AddAfter', array('object' => $this)); Hook::exec('actionObject'.get_class($this).'AddAfter', array('object' => $this));
return $result; return $result;
@@ -344,20 +409,22 @@ abstract class ObjectModelCore
/** /**
* Update current object to database * Update current object to database
* *
* @param bool $null_values
* @return boolean Update result * @return boolean Update result
*/ */
public function update($nullValues = false) public function update($null_values = false)
{ {
/* Hook */ // @hook actionObject*UpdateBefore
Hook::exec('actionObject'.get_class($this).'UpdateBefore', array('object' => $this)); Hook::exec('actionObject'.get_class($this).'UpdateBefore', array('object' => $this));
$this->clearCache(); $this->clearCache();
/* Automatically fill dates */
if (key_exists('date_upd', $this)) // Automatically fill dates
if (array_key_exists('date_upd', $this))
$this->date_upd = date('Y-m-d H:i:s'); $this->date_upd = date('Y-m-d H:i:s');
/* Database update */ // Database update
if ($nullValues) if ($null_values)
$result = Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'UPDATE', '`'.pSQL($this->def['primary']).'` = '.(int)($this->id)); $result = Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'UPDATE', '`'.pSQL($this->def['primary']).'` = '.(int)($this->id));
else else
$result = Db::getInstance()->autoExecute(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'UPDATE', '`'.pSQL($this->def['primary']).'` = '.(int)($this->id)); $result = Db::getInstance()->autoExecute(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'UPDATE', '`'.pSQL($this->def['primary']).'` = '.(int)($this->id));
@@ -365,9 +432,9 @@ abstract class ObjectModelCore
return false; return false;
// Database update for multilingual fields related to the object // Database update for multilingual fields related to the object
if (method_exists($this, 'getTranslationsFieldsChild')) if (isset($this->def['multilang']) && $this->def['multilang'])
{ {
$fields = $this->getTranslationsFieldsChild(); $fields = $this->getFieldsLang();
if (is_array($fields)) if (is_array($fields))
{ {
foreach ($fields as $field) foreach ($fields as $field)
@@ -407,7 +474,7 @@ abstract class ObjectModelCore
} }
} }
/* Hook */ // @hook actionObject*UpdateAfter
Hook::exec('actionObject'.get_class($this).'UpdateAfter', array('object' => $this)); Hook::exec('actionObject'.get_class($this).'UpdateAfter', array('object' => $this));
return $result; return $result;
@@ -416,23 +483,23 @@ abstract class ObjectModelCore
/** /**
* Delete current object from database * Delete current object from database
* *
* return boolean Deletion result * @return boolean Deletion result
*/ */
public function delete() public function delete()
{ {
/* Hook */ // @hook actionObject*DeleteBefore
Hook::exec('actionObject'.get_class($this).'DeleteBefore', array('object' => $this)); Hook::exec('actionObject'.get_class($this).'DeleteBefore', array('object' => $this));
$this->clearCache(); $this->clearCache();
/* Database deletion */ // Database deletion
$result = Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'` WHERE `'.pSQL($this->def['primary']).'` = '.(int)($this->id)); $result = Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'` WHERE `'.pSQL($this->def['primary']).'` = '.(int)$this->id);
if (!$result) if (!$result)
return false; return false;
/* Database deletion for multilingual fields related to the object */ // Database deletion for multilingual fields related to the object
if (method_exists($this, 'getTranslationsFieldsChild')) if (isset($this->def['multilang']) && $this->def['multilang'])
Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang` WHERE `'.pSQL($this->def['primary']).'` = '.(int)($this->id)); Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang` WHERE `'.pSQL($this->def['primary']).'` = '.(int)$this->id);
$assos = Shop::getAssoTables(); $assos = Shop::getAssoTables();
if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'shop') if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'shop')
@@ -442,7 +509,7 @@ abstract class ObjectModelCore
if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'group_shop') if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'group_shop')
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$this->def['table'].'_group_shop` WHERE `'.$this->def['primary'].'`='.(int)$this->id); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$this->def['table'].'_group_shop` WHERE `'.$this->def['primary'].'`='.(int)$this->id);
/* Hook */ // @hook actionObject*DeleteAfter
Hook::exec('actionObject'.get_class($this).'DeleteAfter', array('object' => $this)); Hook::exec('actionObject'.get_class($this).'DeleteAfter', array('object' => $this));
return $result; return $result;
@@ -451,6 +518,7 @@ abstract class ObjectModelCore
/** /**
* Delete several objects from database * Delete several objects from database
* *
* @param array $selection
* @return bool Deletion result * @return bool Deletion result
*/ */
public function deleteSelection($selection) public function deleteSelection($selection)
@@ -467,33 +535,30 @@ abstract class ObjectModelCore
/** /**
* Toggle object status in database * Toggle object status in database
* *
* return boolean Update result * @return boolean Update result
*/ */
public function toggleStatus() public function toggleStatus()
{ {
/* Object must have a variable called 'active' */ // Object must have a variable called 'active'
if (!key_exists('active', $this)) if (!array_key_exists('active', $this))
throw new PrestashopException('property "active is missing in object '.get_class($this)); throw new PrestashopException('property "active is missing in object '.get_class($this));
/* Update active status on object */ // Update active status on object
$this->active = !(int)$this->active; $this->active = !(int)$this->active;
/* Change status to active/inactive */ // Change status to active/inactive
return Db::getInstance()->execute(' return Db::getInstance()->execute('
UPDATE `'.pSQL(_DB_PREFIX_.$this->def['table']).'` UPDATE `'.pSQL(_DB_PREFIX_.$this->def['table']).'`
SET `active` = !`active` SET `active` = !`active`
WHERE `'.pSQL($this->def['primary']).'` = '.(int)($this->id)); WHERE `'.pSQL($this->def['primary']).'` = '.(int)$this->id
);
} }
/** /**
* Prepare multilingual fields for database insertion * @deprecated 1.5.0 (use getFieldsLang())
*
* @param array $fieldsArray Multilingual fields to prepare
* return array Prepared fields for database insertion
*/ */
protected function getTranslationsFields($fieldsArray) protected function getTranslationsFields($fieldsArray)
{ {
/* WARNING : Product do not use this function, so do not forget to report any modification if necessary */
$fields = array(); $fields = array();
if ($this->id_lang == NULL) if ($this->id_lang == NULL)
@@ -505,6 +570,9 @@ abstract class ObjectModelCore
return $fields; return $fields;
} }
/**
* @deprecated 1.5.0
*/
protected function makeTranslationFields(&$fields, &$fieldsArray, $id_language) protected function makeTranslationFields(&$fields, &$fieldsArray, $id_language)
{ {
$fields[$id_language]['id_lang'] = $id_language; $fields[$id_language]['id_lang'] = $id_language;
@@ -538,8 +606,12 @@ abstract class ObjectModelCore
/** /**
* Check for fields validity before database interaction * Check for fields validity before database interaction
*
* @param bool $die
* @param bool $error_return
* @return bool|string
*/ */
public function validateFields($die = true, $errorReturn = false) public function validateFields($die = true, $error_return = false)
{ {
$fieldsRequired = array_merge($this->fieldsRequired, (isset(self::$fieldsRequiredDatabase[get_class($this)]) ? self::$fieldsRequiredDatabase[get_class($this)] : array())); $fieldsRequired = array_merge($this->fieldsRequired, (isset(self::$fieldsRequiredDatabase[get_class($this)]) ? self::$fieldsRequiredDatabase[get_class($this)] : array()));
foreach ($fieldsRequired as $field) foreach ($fieldsRequired as $field)
@@ -547,45 +619,51 @@ abstract class ObjectModelCore
{ {
if ($die) if ($die)
throw new PrestashopException('property empty : '.get_class($this).'->'.$field); throw new PrestashopException('property empty : '.get_class($this).'->'.$field);
return $errorReturn ? get_class($this).' -> '.$field.' is empty' : false; return $error_return ? get_class($this).' -> '.$field.' is empty' : false;
} }
foreach ($this->fieldsSize as $field => $size) foreach ($this->fieldsSize as $field => $size)
if (isset($this->{$field}) && Tools::strlen($this->{$field}) > $size) if (isset($this->{$field}) && Tools::strlen($this->{$field}) > $size)
{ {
if ($die) if ($die)
throw new PrestashopException('fieldsize error : '.get_class($this).'->'.$field.' > '.$size); throw new PrestashopException('fieldsize error : '.get_class($this).'->'.$field.' > '.$size);
return $errorReturn ? get_class($this).' -> '.$field.' Length '.$size : false; return $error_return ? get_class($this).' -> '.$field.' Length '.$size : false;
} }
$validate = new Validate();
foreach ($this->fieldsValidate as $field => $method) foreach ($this->fieldsValidate as $field => $method)
if (!method_exists($validate, $method)) if (!method_exists('Validate', $method))
throw new PrestashopException('Validation function not found. '.$method); throw new PrestashopException('Validation function not found. '.$method);
elseif (!empty($this->{$field}) && !call_user_func(array('Validate', $method), $this->{$field})) elseif (!empty($this->{$field}) && !call_user_func(array('Validate', $method), $this->{$field}))
{ {
if ($die) if ($die)
throw new PrestashopException('Field not valid : '.get_class($this).'->'.$field.' = '.$this->{$field}); throw new PrestashopException('Field not valid : '.get_class($this).'->'.$field.' = '.$this->{$field});
return $errorReturn ? get_class($this).' -> '.$field.' = '.$this->{$field} : false; return $error_return ? get_class($this).' -> '.$field.' = '.$this->{$field} : false;
} }
return true; return true;
} }
/** /**
* Check for multilingual fields validity before database interaction * Check for multilingual fields validity before database interaction
*
* @param bool $die
* @param bool $error_return
* @return bool|string
*/ */
public function validateFieldsLang($die = true, $errorReturn = false) public function validateFieldsLang($die = true, $error_return = false)
{ {
$defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); $defaultLanguage = (int)Configuration::get('PS_LANG_DEFAULT');
foreach ($this->fieldsRequiredLang as $fieldArray) foreach ($this->fieldsRequiredLang as $fieldArray)
{ {
if (!is_array($this->{$fieldArray})) if (!is_array($this->{$fieldArray}))
continue ; continue ;
if (!$this->{$fieldArray} OR !sizeof($this->{$fieldArray}) OR ($this->{$fieldArray}[$defaultLanguage] !== '0' AND empty($this->{$fieldArray}[$defaultLanguage]))) if (!$this->{$fieldArray} || !count($this->{$fieldArray}) || ($this->{$fieldArray}[$defaultLanguage] !== '0' && empty($this->{$fieldArray}[$defaultLanguage])))
{ {
if ($die) if ($die)
throw new PrestashopException('empty for default language : '.get_class($this).'->'.$fieldArray); throw new PrestashopException('empty for default language : '.get_class($this).'->'.$fieldArray);
return $errorReturn ? get_class($this).'->'.$fieldArray.' '.Tools::displayError('is empty for default language.') : false; return $error_return ? get_class($this).'->'.$fieldArray.' '.Tools::displayError('is empty for default language.') : false;
} }
} }
foreach ($this->fieldsSizeLang as $fieldArray => $size) foreach ($this->fieldsSizeLang as $fieldArray => $size)
{ {
if (!is_array($this->{$fieldArray})) if (!is_array($this->{$fieldArray}))
@@ -595,22 +673,22 @@ abstract class ObjectModelCore
{ {
if ($die) if ($die)
throw new PrestashopException('fieldsize error '.get_class($this).'->'.$fieldArray.' length of '.$size.' for language'); throw new PrestashopException('fieldsize error '.get_class($this).'->'.$fieldArray.' length of '.$size.' for language');
return $errorReturn ? get_class($this).'->'.$fieldArray.' '.Tools::displayError('Length').' '.$size.' '.Tools::displayError('for language') : false; return $error_return ? get_class($this).'->'.$fieldArray.' '.Tools::displayError('Length').' '.$size.' '.Tools::displayError('for language') : false;
} }
} }
$validate = new Validate();
foreach ($this->fieldsValidateLang as $fieldArray => $method) foreach ($this->fieldsValidateLang as $fieldArray => $method)
{ {
if (!is_array($this->{$fieldArray})) if (!is_array($this->{$fieldArray}))
continue ; continue ;
foreach ($this->{$fieldArray} as $k => $value) foreach ($this->{$fieldArray} as $k => $value)
if (!method_exists($validate, $method)) if (!method_exists('Validate', $method))
throw new PrestashopException('Validation function not found for lang: '.$method); throw new PrestashopException('Validation function not found for lang: '.$method);
elseif (!empty($value) && !call_user_func(array('Validate', $method), $value)) elseif (!empty($value) && !call_user_func(array('Validate', $method), $value))
{ {
if ($die) if ($die)
throw new PrestashopException('Field not valid : '.get_class($this).'->'.$field.' = '.$this->{$field}. 'for language '.$k); throw new PrestashopException('Field not valid : '.get_class($this).'->'.$fieldArray.' = '.$value. 'for language '.$k);
return $errorReturn ? Tools::displayError('The following field is invalid according to the validate method ').'<b>'.$method.'</b>:<br/> ('. get_class($this).'->'.$fieldArray.' = '.$value.' '.Tools::displayError('for language').' '.$k : false; return $error_return ? Tools::displayError('The following field is invalid according to the validate method ').'<b>'.$method.'</b>:<br/> ('. get_class($this).'->'.$fieldArray.' = '.$value.' '.Tools::displayError('for language').' '.$k : false;
} }
} }
return true; return true;
@@ -1148,6 +1226,10 @@ abstract class ObjectModelCore
else else
$this->def['primary'] = $this->identifier; $this->def['primary'] = $this->identifier;
// Check multilang retrocompatibility
if (method_exists($this, 'getTranslationsFieldsChild'))
$this->def['multilang'] = true;
// Retrocompatibility with $fieldsValidate, $fieldsRequired and $fieldsSize properties ($definition['fields']) // Retrocompatibility with $fieldsValidate, $fieldsRequired and $fieldsSize properties ($definition['fields'])
if (isset($this->def['fields'])) if (isset($this->def['fields']))
{ {
+2 -23
View File
@@ -267,8 +267,8 @@ class ProductCore extends ObjectModel
'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128),
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 128), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 128),
'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isString'), 'description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'),
'description_short' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isString'), 'description_short' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'),
'available_now' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'available_now' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'available_later' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'IsGenericName', 'size' => 255), 'available_later' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'IsGenericName', 'size' => 255),
), ),
@@ -429,27 +429,6 @@ class ProductCore extends ObjectModel
return $return; return $return;
} }
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array(
'meta_description',
'meta_keywords',
'meta_title',
'link_rewrite',
'name',
'available_now',
'available_later',
'description' => array('html' => true),
'description_short' => array('html' => true),
));
}
public static function initPricesComputation($id_customer = null) public static function initPricesComputation($id_customer = null)
{ {
if ($id_customer) if ($id_customer)
+1 -12
View File
@@ -39,21 +39,10 @@ class ProfileCore extends ObjectModel
'multilang' => true, 'multilang' => true,
'fields' => array( 'fields' => array(
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
), ),
); );
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name'));
}
/** /**
* Get all available profiles * Get all available profiles
* *
+1 -12
View File
@@ -48,21 +48,10 @@ class QuickAccessCore extends ObjectModel
'new_window' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true), 'new_window' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
), ),
); );
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name'));
}
/** /**
* Get all available quick_accesses * Get all available quick_accesses
* *
+1 -12
View File
@@ -53,7 +53,7 @@ class SceneCore extends ObjectModel
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true), 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 100), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 100),
), ),
); );
@@ -70,17 +70,6 @@ class SceneCore extends ObjectModel
$this->image_dir = _PS_SCENE_IMG_DIR_; $this->image_dir = _PS_SCENE_IMG_DIR_;
} }
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name'));
}
public function update($nullValues = false) public function update($nullValues = false)
{ {
if (!$this->updateZoneProducts()) if (!$this->updateZoneProducts())
+1 -1
View File
@@ -135,7 +135,7 @@ class StateCore extends ObjectModel
return false; return false;
/* Database deletion for multilingual fields related to the object */ /* Database deletion for multilingual fields related to the object */
if (method_exists($this, 'getTranslationsFieldsChild')) if (!empty($this->def['multilang']))
Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang` WHERE `'.$this->def['primary'].'` = '.(int)$this->id); Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang` WHERE `'.$this->def['primary'].'` = '.(int)$this->id);
return $result; return $result;
} }
+4 -10
View File
@@ -80,10 +80,10 @@ class SupplierCore extends ObjectModel
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
// Lang fields // Lang fields
'description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName'), 'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName'),
'meta_title' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 128), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
'meta_description' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'meta_keywords' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
), ),
); );
@@ -106,12 +106,6 @@ class SupplierCore extends ObjectModel
return Tools::link_rewrite($this->name, false); return Tools::link_rewrite($this->name, false);
} }
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('description', 'meta_title', 'meta_keywords', 'meta_description'));
}
/** /**
* Return suppliers * Return suppliers
* *
+1 -2
View File
@@ -55,11 +55,10 @@ class TabCore extends ObjectModel
'class_name' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 64), 'class_name' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 64),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
), ),
); );
protected static $_getIdFromClassName = null; protected static $_getIdFromClassName = null;
public function getTranslationsFieldsChild() public function getTranslationsFieldsChild()
+2 -8
View File
@@ -47,8 +47,8 @@ class OrderMessageCore extends ObjectModel
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
'message' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isMessage', 'required' => true, 'size' => 1200), 'message' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isMessage', 'required' => true, 'size' => 1200),
), ),
); );
@@ -60,12 +60,6 @@ class OrderMessageCore extends ObjectModel
) )
); );
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name', 'message'));
}
public static function getOrderMessages($id_lang) public static function getOrderMessages($id_lang)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
+1 -12
View File
@@ -44,21 +44,10 @@ class OrderReturnStateCore extends ObjectModel
'color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor'), 'color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor'),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
), ),
); );
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name'));
}
/** /**
* Get all available order states * Get all available order states
* *
+2 -13
View File
@@ -74,8 +74,8 @@ class OrderStateCore extends ObjectModel
'hidden' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'hidden' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
'template' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isTplName', 'size' => 64), 'template' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isTplName', 'size' => 64),
), ),
); );
@@ -87,17 +87,6 @@ class OrderStateCore extends ObjectModel
), ),
); );
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name', 'template'));
}
/** /**
* Get all available order states * Get all available order states
* *
+1 -7
View File
@@ -59,7 +59,7 @@ class StockMvtReasonCore extends ObjectModel
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
), ),
); );
@@ -68,12 +68,6 @@ class StockMvtReasonCore extends ObjectModel
'objectNodeName' => 'stock_movement_reason', 'objectNodeName' => 'stock_movement_reason',
); );
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name'));
}
public static function getStockMvtReasons($id_lang, $sign = null) public static function getStockMvtReasons($id_lang, $sign = null)
{ {
$query = new DbQuery(); $query = new DbQuery();
+1 -10
View File
@@ -81,19 +81,10 @@ class SupplyOrderStateCore extends ObjectModel
'color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor'), 'color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor'),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
), ),
); );
/**
* @see ObjectModel::getTranslationsFieldsChild()
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name'));
}
/** /**
* Gets the list of supply order states * Gets the list of supply order states
* *
+1 -12
View File
@@ -56,7 +56,7 @@ class TaxCore extends ObjectModel
'deleted' => array('type' => self::TYPE_BOOL), 'deleted' => array('type' => self::TYPE_BOOL),
// Lang fields // Lang fields
'name' => array('type' => 'FILL_ME', 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
), ),
); );
@@ -68,17 +68,6 @@ class TaxCore extends ObjectModel
'objectsNodeName' => 'taxes', 'objectsNodeName' => 'taxes',
); );
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array('name'));
}
public function delete() public function delete()
{ {
/* Clean associations */ /* Clean associations */