[+] Project: it's possible to create new genders, "Miss" gender is now added

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8578 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-09-14 15:15:51 +00:00
parent 62a578b314
commit 03eaee9bf4
35 changed files with 777 additions and 526 deletions
+60 -60
View File
@@ -92,12 +92,12 @@ abstract class AdminTabCore
/** @var array Fields to display in list */
public $fieldsDisplay = array();
public $optionTitle = null;
/** @var string shop | group_shop */
public $shopLinkType;
/** @var bool */
public $shopShareDatas = false;
@@ -125,7 +125,7 @@ abstract class AdminTabCore
/** @var string Order way (ASC, DESC) determined by arrows in list header */
protected $_orderWay;
/** @var integer Max image size for upload
/** @var integer Max image size for upload
* As of 1.5 it is recommended to not set a limit to max image size
**/
protected $maxImageSize;
@@ -144,27 +144,27 @@ abstract class AdminTabCore
/** @var string specificConfirmDelete */
public $specificConfirmDelete = NULL;
public static $currentIndex;
public $smarty;
protected $identifiersDnd = array('id_product' => 'id_product', 'id_category' => 'id_category_to_move','id_cms_category' => 'id_cms_category_to_move', 'id_cms' => 'id_cms');
/** @var bool Redirect or not ater a creation */
protected $_redirect = true;
/** @var bool If false, don't add form tags in options forms */
protected $formOptions = true;
public $_fieldsOptions = array();
/**
* @since 1.5.0
* @var array
*/
public $optionsList = array();
/**
* @since 1.5.0
* @var Context
@@ -196,7 +196,7 @@ abstract class AdminTabCore
public function __construct()
{
$this->context = Context::getContext();
$this->id = Tab::getCurrentTabId();
$this->_conf = array(
1 => $this->l('Deletion successful'), 2 => $this->l('Selection successfully deleted'),
@@ -255,8 +255,8 @@ abstract class AdminTabCore
}
/**
* ajaxDisplay is the default ajax return sytem
*
* ajaxDisplay is the default ajax return sytem
*
* @return void
*/
public function displayAjax()
@@ -531,8 +531,8 @@ abstract class AdminTabCore
}
/**
* ajaxPreProcess is a method called in ajax-tab.php before displayConf().
*
* ajaxPreProcess is a method called in ajax-tab.php before displayConf().
*
* @return void
*/
public function ajaxPreProcess()
@@ -541,7 +541,7 @@ abstract class AdminTabCore
/**
* ajaxProcess is the default handle method for request with ajax-tab.php
*
*
* @return void
*/
public function ajaxProcess()
@@ -557,7 +557,7 @@ abstract class AdminTabCore
return false;
// set token
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
// Sub included tab postProcessing
$this->includeSubTab('postProcess', array('status', 'submitAdd1', 'submitDel', 'delete', 'submitFilter', 'submitReset'));
@@ -892,7 +892,7 @@ abstract class AdminTabCore
$type = 'group_shop';
else
return ;
$assos = array();
foreach ($_POST AS $k => $row)
{
@@ -923,7 +923,7 @@ abstract class AdminTabCore
foreach ($this->optionsList as $category => $categoryData)
{
$fields = $categoryData['fields'];
/* Check required fields */
foreach ($fields AS $field => $values)
if (isset($values['required']) AND $values['required'] && !isset($_POST['configUseDefault'][$field]))
@@ -935,7 +935,7 @@ abstract class AdminTabCore
}
elseif (($value = Tools::getValue($field)) == false AND (string)$value != '0')
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.');
/* Check fields validity */
foreach ($fields AS $field => $values)
if (isset($values['type']) AND $values['type'] == 'textLang')
@@ -948,7 +948,7 @@ abstract class AdminTabCore
elseif (Tools::getValue($field) AND isset($values['validation']))
if (!Validate::$values['validation'](Tools::getValue($field)))
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
/* Default value if null */
foreach ($fields AS $field => $values)
if (!Tools::getValue($field) AND isset($values['default']))
@@ -960,7 +960,7 @@ abstract class AdminTabCore
{
if (isset($options['visibility']) && $options['visibility'] > Context::getContext()->shop->getContextType())
continue;
if (Shop::isMultiShopActivated() && isset($_POST['configUseDefault'][$key]))
{
Configuration::deleteFromContext($key);
@@ -986,7 +986,7 @@ abstract class AdminTabCore
}
}
Configuration::updateValue($key, $list);
}
}
else
{
$val = (isset($options['cast']) ? $options['cast'](Tools::getValue($key)) : Tools::getValue($key));
@@ -1001,14 +1001,14 @@ abstract class AdminTabCore
}
}
}
if (count($this->_errors) <= 0)
Tools::redirectAdmin(self::$currentIndex.'&conf=6&token='.$token);
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
/**
* Can be overriden
*/
@@ -1027,10 +1027,10 @@ abstract class AdminTabCore
{
$this->_errors[] = Tools::displayError($field['title'].' : Incorrect value');
return false;
}
}
}
}
}
return true;
}
@@ -1044,7 +1044,7 @@ abstract class AdminTabCore
else
return false;
// Check image validity
$max_size = isset($this->maxImageSize) ? $this->maxImageSize : 0;
if ($error = checkImage($_FILES[$name], Tools::getMaxUploadSize($max_size)))
@@ -1279,7 +1279,7 @@ abstract class AdminTabCore
/* SQL table : orders, but class name is Order */
$sqlTable = $this->table == 'order' ? 'orders' : $this->table;
// Add SQL shop restriction
$selectShop = $joinShop = $whereShop = '';
if ($this->shopLinkType)
@@ -1313,7 +1313,7 @@ abstract class AdminTabCore
$this->_group = 'GROUP BY a.'.pSQL($this->identifier);
else if (!preg_match('#(\s|,)\s*a\.`?'.pSQL($this->identifier).'`?(\s|,|$)#', $this->_group))
$this->_group .= ', a.'.pSQL($this->identifier);
if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !preg_match('#`?'.preg_quote(_DB_PREFIX_.$this->table.'_'.$filterKey).'`? *sa#', $this->_join))
$filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.' IN ('.implode(', ', $idenfierShop).'))';
}
@@ -1383,7 +1383,7 @@ abstract class AdminTabCore
echo '<form method="post" action="'.self::$currentIndex;
if(Tools::getIsset($this->identifier))
echo '&'.$this->identifier.'='.(int)(Tools::getValue($this->identifier));
echo '&token='.$token;
echo '&token='.$token;
if (Tools::getIsset($this->table.'Orderby'))
echo '&'.$this->table.'Orderby='.urlencode($this->_orderBy).'&'.$this->table.'Orderway='.urlencode(strtolower($this->_orderWay));
echo '#'.$this->table.'" class="form">
@@ -1656,13 +1656,13 @@ abstract class AdminTabCore
// item_id is the product id in a product image context, else it is the image id.
$item_id = isset($params['image_id']) ? $tr[$params['image_id']] : $id;
// If it's a product image
if (isset($tr['id_image']))
if (isset($tr['id_image']))
{
$image = new Image((int)$tr['id_image']);
$path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$image->getExistingImgPath().'.'.$this->imageType;
}else
$path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$item_id.(isset($tr['id_image']) ? '-'.(int)($tr['id_image']) : '').'.'.$this->imageType;
echo cacheImage($path_to_image, $this->table.'_mini_'.$item_id.'.'.$this->imageType, 45, $this->imageType);
}
elseif (isset($params['icon']) AND (isset($params['icon'][$tr[$key]]) OR isset($params['icon']['default'])))
@@ -1684,7 +1684,7 @@ abstract class AdminTabCore
else
$echo = $tr[$key];
echo isset($params['callback']) ? call_user_func_array(array($this->className, $params['callback']), array($echo, $tr)) : $echo;
echo isset($params['callback']) ? call_user_func_array(array((isset($params['callback_object'])) ? $params['callback_object'] : $this->className, $params['callback']), array($echo, $tr)) : $echo;
}
else
echo '--';
@@ -1692,7 +1692,7 @@ abstract class AdminTabCore
echo (isset($params['suffix']) ? $params['suffix'] : '').
'</td>';
}
if ($this->shopLinkType)
{
$name = (Tools::strlen($tr['shop_name']) > 15) ? Tools::substr($tr['shop_name'], 0, 15).'...' : $tr['shop_name'];
@@ -1716,7 +1716,7 @@ abstract class AdminTabCore
}
}
}
protected function displayAddButton()
{
echo '<br /><a href="'.self::$currentIndex.'&add'.$this->table.'&token='.$this->token.'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add new').'</a><br /><br />';
@@ -1826,7 +1826,7 @@ abstract class AdminTabCore
$legend = '<img src="'.(!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif" /> ';
$legend .= ((isset($categoryData['title'])) ? $categoryData['title'] : $this->l('Options'));
echo '<legend>'.$legend.'</legend>';
// Category fields
if (!isset($categoryData['fields']))
continue;
@@ -1841,10 +1841,10 @@ abstract class AdminTabCore
$value = Tools::getValue($key, Configuration::get($key));
if (!Validate::isCleanHtml($value))
$value = Configuration::get($key);
if (isset($field['defaultValue']) && !$value)
$value = $field['defaultValue'];
// Check if var is invisible (can't edit it in current shop context), or disable (use default value for multishop)
$isDisabled = $isInvisible = false;
if (Shop::isMultiShopActivated())
@@ -1889,14 +1889,14 @@ abstract class AdminTabCore
<input type="checkbox" name="configUseDefault['.$key.']" value="1" '.(($isDisabled) ? 'checked="checked"' : '').' onclick="checkMultishopDefaultValue(this, \''.$key.'\')" /> '.$this->l('Use default value').'
</label>
</div>';
// Field description
//echo (isset($field['desc']) ? '<p class="preference_description">'.((isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'after') ? '<img src="'.$field['thumb']['file'].'" alt="'.$field['title'].'" title="'.$field['title'].'" style="float:left;" />' : '' ).$field['desc'].'</p>' : '');
echo (isset($field['desc']) ? '<p class="preference_description">'.$field['desc'].'</p>' : '');
// Is this field invisible in current shop context ?
echo ($isInvisible) ? '<p class="multishop_warning">'.$this->l('You can\'t change the value of this configuration field in this shop context').'</p>' : '';
echo '</div></div>';
}
@@ -1905,7 +1905,7 @@ abstract class AdminTabCore
echo '</div>';
if ($required)
echo '<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>';
echo '</fieldset><br />';
$this->displayBottomOptionCategory($category, $categoryData);
}
@@ -1936,7 +1936,7 @@ abstract class AdminTabCore
echo '<option value="'.(isset($option['cast']) ? $option['cast']($option[$field['identifier']]) : $option[$field['identifier']]).'"'.(($value == $option[$field['identifier']]) ? ' selected="selected"' : '').'>'.$option['name'].'</option>';
echo '</select>';
}
/**
* Type = bool
*/
@@ -1950,7 +1950,7 @@ abstract class AdminTabCore
echo '<input type="radio" name="'.$key.'" id="'.$key.'_off" value="0" '.(!$value ? ' checked="checked" ' : '').(isset($field['js']['off']) ? $field['js']['off'] : '').' />';
echo '<label class="t" for="'.$key.'_off"> '.$this->l('No').'</label>';
}
/**
* Type = radio
*/
@@ -1960,7 +1960,7 @@ abstract class AdminTabCore
echo '<input type="radio" name="'.$key.'" id="'.$key.$k.'_on" value="'.(int)$v.'"'.(($k == $value) ? ' checked="checked"' : '').(isset($field['js'][$k]) ? ' '.$field['js'][$k] : '').' /><label class="t" for="'.$key.$k.'_on"> '.$v.'</label><br />';
echo '<br />';
}
/**
* Type = text
*/
@@ -1968,7 +1968,7 @@ abstract class AdminTabCore
{
echo '<input type="'.$field['type'].'"'.(isset($field['id']) ? ' id="'.$field['id'].'"' : '').' size="'.(isset($field['size']) ? (int)$field['size'] : 5).'" name="'.$key.'" value="'.htmlentities($value, ENT_COMPAT, 'UTF-8').'" />'.(isset($field['next']) ? '&nbsp;'.(string)$field['next'] : '');
}
/**
* Type = password
*/
@@ -1976,7 +1976,7 @@ abstract class AdminTabCore
{
$this->displayOptionTypeText($key, $field, '');
}
/**
* Type = textarea
*/
@@ -1984,7 +1984,7 @@ abstract class AdminTabCore
{
echo '<textarea name='.$key.' cols="'.$field['cols'].'" rows="'.$field['rows'].'">'.htmlentities($value, ENT_COMPAT, 'UTF-8').'</textarea>';
}
/**
* Type = file
*/
@@ -1994,7 +1994,7 @@ abstract class AdminTabCore
echo '<img src="'.$field['thumb']['file'].'" alt="'.$field['title'].'" title="'.$field['title'].'" /><br />';
echo '<input type="file" name="'.$key.'" />';
}
/**
* Type = image
*/
@@ -2034,7 +2034,7 @@ abstract class AdminTabCore
echo '</tr>';
echo '</table>';
}
/**
* Type = textLang
*/
@@ -2050,7 +2050,7 @@ abstract class AdminTabCore
}
$this->displayFlags($languages, $this->context->language->id, $key, $key);
}
/**
* Type = TextareaLang
*/
@@ -2067,7 +2067,7 @@ abstract class AdminTabCore
$this->displayFlags($languages, $this->context->language->id, $key, $key);
echo '<br style="clear:both">';
}
/**
* Type = selectLang
*/
@@ -2085,7 +2085,7 @@ abstract class AdminTabCore
}
$this->displayFlags($languages, $this->context->language->id, $key, $key);
}
/**
* Type = price
*/
@@ -2095,7 +2095,7 @@ abstract class AdminTabCore
$this->displayOptionTypeText($key, $field, $value);
echo $this->context->currency->getSign('right').' '.$this->l('(tax excl.)');
}
/**
* Type = disabled
*/
@@ -2296,7 +2296,7 @@ abstract class AdminTabCore
return $this->fieldsDisplay[$filter];
return false;
}
protected function warnDomainName()
{
if ($_SERVER['HTTP_HOST'] != Configuration::get('PS_SHOP_DOMAIN') AND $_SERVER['HTTP_HOST'] != Configuration::get('PS_SHOP_DOMAIN_SSL'))
@@ -2305,7 +2305,7 @@ abstract class AdminTabCore
<a href="index.php?tab=AdminMeta&token='.Tools::getAdminTokenLite('AdminMeta').'#SEO%20%26%20URLs">'.
$this->l('Click here if you want to modify the main shop domain name').'</a>');
}
protected function displayAssoShop($type = 'shop')
{
if (!Shop::isMultiShopActivated() || (!$this->_object && $this->context->shop->getContextType() != Shop::CONTEXT_ALL))
@@ -2364,7 +2364,7 @@ abstract class AdminTabCore
});
$('.input_group_shop[value='+id_group+']').attr('checked', groupChecked);
}
function check_all_shop()
{
var allChecked = true;
@@ -2411,7 +2411,7 @@ EOF;
/**
* Get current URL
*
*
* @param array $remove List of keys to remove from URL
* @return string
*/
@@ -2420,7 +2420,7 @@ EOF;
$url = $_SERVER['REQUEST_URI'];
if (!$remove)
return $url;
if (!is_array($remove))
$remove = array($remove);
+31 -31
View File
@@ -28,11 +28,11 @@
class CustomerCore extends ObjectModel
{
public $id;
public $id_shop;
public $id_group_shop;
/** @var string Secure key */
public $secure_key;
@@ -40,7 +40,7 @@ class CustomerCore extends ObjectModel
public $note;
/** @var integer Gender ID */
public $id_gender = 9;
public $id_gender = 0;
/** @var integer Default group ID */
public $id_default_group = _PS_DEFAULT_CUSTOMER_GROUP_;
@@ -80,7 +80,7 @@ class CustomerCore extends ObjectModel
/** @var boolean Status */
public $is_guest = 0;
/** @var boolean True if carrier has been deleted (staying in database as deleted) */
public $deleted = 0;
@@ -93,20 +93,20 @@ class CustomerCore extends ObjectModel
public $years;
public $days;
public $months;
/** @var int customer id_country as determined by geolocation */
public $geoloc_id_country;
/** @var int customer id_state as determined by geolocation */
public $geoloc_id_state;
/** @var string customer postcode as determined by geolocation */
public $geoloc_postcode;
/** @var boolean is the customer logged in */
public $logged = 0;
/** @var int id_guest meaning the guest table, not the guest customer */
public $id_guest;
protected $tables = array ('customer');
protected $fieldsRequired = array('lastname', 'passwd', 'firstname', 'email');
@@ -137,7 +137,7 @@ class CustomerCore extends ObjectModel
$this->validateFields();
if (isset($this->id))
$fields['id_customer'] = (int)($this->id);
$fields['id_shop'] = (int)$this->id_shop;
$fields['id_group_shop'] = (int)$this->id_group_shop;
$fields['secure_key'] = pSQL($this->secure_key);
@@ -211,7 +211,7 @@ class CustomerCore extends ObjectModel
{
if (!$shop)
$shop = Context::getContext()->shop;
$sql = 'SELECT `id_customer`, `email`, `firstname`, `lastname`
FROM `'._DB_PREFIX_.'customer`
WHERE 1 '.$shop->sqlRestriction(Shop::SHARE_CUSTOMER).'
@@ -286,10 +286,10 @@ class CustomerCore extends ObjectModel
{
if (!Validate::isEmail($email))
die (Tools::displayError());
if (!$shop)
$shop = Context::getContext()->shop;
$sql = 'SELECT `id_customer`
FROM `'._DB_PREFIX_.'customer`
WHERE `email` = \''.pSQL($email).'\'
@@ -322,7 +322,7 @@ class CustomerCore extends ObjectModel
}
return self::$_customerHasAddress[$id_customer];
}
public static function resetAddressCache($id_customer)
{
if (array_key_exists($id_customer, self::$_customerHasAddress))
@@ -389,7 +389,7 @@ class CustomerCore extends ObjectModel
{
if (!$shop)
$shop = Context::getContext()->shop;
$sql = 'SELECT *
FROM `'._DB_PREFIX_.'customer`
WHERE (
@@ -407,7 +407,7 @@ class CustomerCore extends ObjectModel
* @return array Stats
*/
public function getStats()
{
{
$result = Db::getInstance()->getRow('
SELECT COUNT(`id_order`) AS nb_orders, SUM(`total_paid` / o.`conversion_rate`) AS total_orders
FROM `'._DB_PREFIX_.'orders` o
@@ -483,7 +483,7 @@ class CustomerCore extends ObjectModel
{
if (!Group::isFeatureActive())
return array(1);
$groups = array();
$result = Db::getInstance()->ExecuteS('
SELECT cg.`id_group`
@@ -533,7 +533,7 @@ class CustomerCore extends ObjectModel
$ids = Address::getCountryAndState($id_address);
return (int)($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
}
public function toggleStatus()
{
parent::toggleStatus();
@@ -550,7 +550,7 @@ class CustomerCore extends ObjectModel
{
return (bool)$this->is_guest;
}
public function transformToCustomer($id_lang, $password = NULL)
{
if (!$this->isGuest())
@@ -559,7 +559,7 @@ class CustomerCore extends ObjectModel
$password = Tools::passwdGen();
if (!Validate::isPasswd($password))
return false;
$this->is_guest = 0;
$this->passwd = Tools::encrypt($password);
if ($this->update())
@@ -570,13 +570,13 @@ class CustomerCore extends ObjectModel
'{email}' => $this->email,
'{passwd}' => $password
);
Mail::Send((int)$id_lang, 'guest_to_customer', Mail::l('Your guest account has been transformed to customer account'), $vars, $this->email, $this->firstname.' '.$this->lastname);
return true;
}
return false;
}
public static function printNewsIcon($id_customer, $tr)
{
$customer = new Customer($tr['id_customer']);
@@ -586,7 +586,7 @@ class CustomerCore extends ObjectModel
($customer->newsletter ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
'</a>';
}
public static function printOptinIcon($id_customer, $tr)
{
$customer = new Customer($tr['id_customer']);
@@ -596,7 +596,7 @@ class CustomerCore extends ObjectModel
($customer->optin ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
'</a>';
}
public function setWsPasswd($passwd)
{
if ($this->id != 0)
@@ -608,28 +608,28 @@ class CustomerCore extends ObjectModel
$this->passwd = Tools::encrypt($passwd);
return true;
}
/**
* Check customer informations and return customer validity
*
* @since 1.5.0
* @param boolean $withGuest
* @param boolean $withGuest
* @return boolean customer validity
*/
public function isLogged($withGuest = false)
{
if (!$withGuest AND $this->is_guest == 1)
return false;
/* Customer is valid only if it can be load and if object password is the same as database one */
if ($this->logged == 1 AND $this->id AND Validate::isUnsignedId($this->id) AND self::checkPassword($this->id, $this->passwd))
return true;
return false;
}
/**
* Logout
*
*
* @since 1.5.0
*/
public function logout()
@@ -642,7 +642,7 @@ class CustomerCore extends ObjectModel
/**
* Soft logout, delete everything links to the customer
* but leave there affiliate's informations
*
*
* @since 1.5.0
*/
public function mylogout()
@@ -650,5 +650,5 @@ class CustomerCore extends ObjectModel
if (isset(Context::getContext()->cookie))
Context::getContext()->cookie->mylogout();
$this->logged = 0;
}
}
}
+97
View File
@@ -0,0 +1,97 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5.0
*/
class GenderCore extends ObjectModel
{
public $id_gender;
public $name;
public $type;
protected $fieldsRequired = array('type');
protected $fieldsSize = array();
protected $fieldsValidate = array();
protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array('name' => 20);
protected $fieldsValidateLang = array('name' => 'isString');
protected $table = 'gender';
protected $identifier = 'id_gender';
public function __construct($id = null, $id_lang = null, $id_shop = null)
{
parent::__construct($id, $id_lang, $id_shop);
$this->image_dir = _PS_GENDERS_DIR_;
}
public function getFields()
{
$this->validateFields();
$fields['id_gender'] = (int)$this->id_gender;
$fields['type'] = (int)$this->type;
return $fields;
}
/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array(
'name',
));
}
public function getGenders($id_lang = null)
{
if (is_null($id_lang))
$id_lang = Context::getContext()->language->id;
$sql = 'SELECT g.id_gender, gl.name
FROM '._DB_PREFIX_.'gender g
LEFT JOIN '._DB_PREFIX_.'gender_lang gl ON g.id_gender = gl.id_gender AND gl.id_lang = '.(int)$id_lang;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
}
public function getStaticImage($id, $useUnknown = false)
{
if (!file_exists(_PS_GENDERS_DIR_.$id.'.jpg'))
return ($useUnknown) ? _PS_ADMIN_IMG_.'unknown.gif' : false;
return _THEME_GENDERS_DIR_.$id.'.jpg';
}
public function getImage($useUnknown = false)
{
return Gender::getStaticImage($this->id, $useUnknown);
}
}
+25 -25
View File
@@ -32,11 +32,11 @@ abstract class ObjectModelCore
/** @var integer lang id */
protected $id_lang = NULL;
protected $id_shop = NULL;
private $getShopFromContext = true;
/** @var string SQL Table name */
protected $table = NULL;
@@ -63,7 +63,7 @@ abstract class ObjectModelCore
/** @var array Multilingual fields validity functions for admin panel forms */
protected $fieldsValidateLang = array();
protected $langMultiShop = false;
/** @var array tables */
@@ -76,7 +76,7 @@ abstract class ObjectModelCore
/** @var string path to image directory. Used for image deletion. */
protected $image_dir = NULL;
/** @var string file type of image files. Used for image deletion. */
protected $image_format = 'jpg';
@@ -153,7 +153,7 @@ abstract class ObjectModelCore
foreach ($result AS $key => $value)
if (key_exists($key, $this))
$this->{$key} = stripslashes($value);
if (!$id_lang AND method_exists($this, 'getTranslationsFieldsChild'))
{
$sql = 'SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang`
@@ -248,7 +248,7 @@ abstract class ObjectModelCore
$result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT');
}
}
if (!Shop::isMultishopActivated())
{
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop')
@@ -285,7 +285,7 @@ abstract class ObjectModelCore
if (!$result)
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'))
{
$fields = $this->getTranslationsFieldsChild();
@@ -417,7 +417,7 @@ abstract class ObjectModelCore
return $fields;
}
protected function makeTranslationFields(&$fields, &$fieldsArray, $id_language)
{
$fields[$id_language]['id_lang'] = $id_language;
@@ -433,13 +433,13 @@ abstract class ObjectModelCore
$fieldName = $k;
$html = (isset($field['html'])) ? $field['html'] : false;
}
/* Check fields validity */
if (!Validate::isTableOrIdentifier($fieldName))
die(Tools::displayError());
/* Copy the field, or the default language field if it's both required and empty */
if ((!$this->id_lang AND isset($this->{$fieldName}[$id_language]) AND !empty($this->{$fieldName}[$id_language]))
if ((!$this->id_lang AND isset($this->{$fieldName}[$id_language]) AND !empty($this->{$fieldName}[$id_language]))
OR ($this->id_lang AND isset($this->$fieldName) AND !empty($this->$fieldName)))
$fields[$id_language][$fieldName] = $this->id_lang ? pSQL($this->$fieldName, $html) : pSQL($this->{$fieldName}[$id_language], $html);
elseif (in_array($fieldName, $this->fieldsRequiredLang))
@@ -715,7 +715,7 @@ abstract class ObjectModelCore
public function getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit)
{
$assoc = Shop::getAssoTables();
if (array_key_exists($this->table ,$assoc))
{
$multi_shop_join = ' LEFT JOIN `'._DB_PREFIX_.$this->table.'_'.$assoc[$this->table]['type'].'` AS multi_shop_'.$this->table.' ON (main.'.$this->identifier.' = '.'multi_shop_'.$this->table.'.'.$this->identifier.')';
@@ -778,7 +778,7 @@ abstract class ObjectModelCore
{
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID();
$sql = 'SELECT id_shop
FROM `'.pSQL(_DB_PREFIX_.$this->table).'_shop`
WHERE `'.$this->identifier.'` = '.(int)$this->id.'
@@ -788,9 +788,9 @@ abstract class ObjectModelCore
/**
* This function associate an item to its context
*
* @param int|array $id_shops
* @param string $type
*
* @param int|array $id_shops
* @param string $type
* @return boolean
*/
public function associateTo($id_shops, $type = 'shop')
@@ -800,13 +800,13 @@ abstract class ObjectModelCore
$sql = '';
if (!is_array($id_shops))
$id_shops = array($id_shops);
foreach ($id_shops as $id_shop)
{
if (($type == 'shop' && !$this->isAssociatedToShop($id_shop)) || ($type == 'group_shop' && !$this->isAssociatedToGroupShop($id_shop)))
$sql .= '('.(int)$this->id.','.(int)$id_shop.'),';
}
if (!empty($sql))
return Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.$this->table.'_'.$type.'` (`'.$this->identifier.'`, `id_'.$type.'`) VALUES '.rtrim($sql,','));
return true;
@@ -823,7 +823,7 @@ abstract class ObjectModelCore
{
if (is_null($id_group_shop))
$id_group_shop = Context::getContext()->shop->getGroupID();
$sql = 'SELECT id_group_shop
FROM `'.pSQL(_DB_PREFIX_.$this->table).'_group_shop`
WHERE `'.$this->identifier.'`='.(int)$this->id.' AND id_group_shop='.(int)$id_group_shop;
@@ -849,7 +849,7 @@ abstract class ObjectModelCore
$ids[] = $row['id_shop'];
return $this->associateTo($ids);
}
return false;
}
@@ -871,20 +871,20 @@ abstract class ObjectModelCore
/* Deleting object images and thumbnails (cache) */
if ($this->image_dir)
{
if (file_exists($this->image_dir.$this->id.'.'.$this->image_format)
if (file_exists($this->image_dir.$this->id.'.'.$this->image_format)
&& !unlink($this->image_dir.$this->id.'.'.$this->image_format))
return false;
}
if (file_exists(_PS_TMP_IMG_DIR_.$this->table.'_'.$this->id.'.'.$this->image_format)
if (file_exists(_PS_TMP_IMG_DIR_.$this->table.'_'.$this->id.'.'.$this->image_format)
&& !unlink(_PS_TMP_IMG_DIR_.$this->table.'_'.$this->id.'.'.$this->image_format))
return false;
if (file_exists(_PS_TMP_IMG_DIR_.$this->table.'_mini_'.$this->id.'.'.$this->image_format)
if (file_exists(_PS_TMP_IMG_DIR_.$this->table.'_mini_'.$this->id.'.'.$this->image_format)
&& !unlink(_PS_TMP_IMG_DIR_.$this->table.'_mini_'.$this->id.'.'.$this->image_format))
return false;
$types = ImageType::getImagesTypes();
foreach ($types AS $image_type)
if (file_exists($this->image_dir.$this->id.'-'.stripslashes($image_type['name']).'.'.$this->image_format)
if (file_exists($this->image_dir.$this->id.'-'.stripslashes($image_type['name']).'.'.$this->image_format)
&& !unlink($this->image_dir.$this->id.'-'.stripslashes($image_type['name']).'.'.$this->image_format))
return false;
return true;