2016-10-04 15:17:02 +02:00

139 lines
5.6 KiB
PHP
Executable File

<?php
class Customer extends CustomerCore{
public $segmentation;
public $pro;
public $pro_update;
public $pro_passwd;
public $last_adleadlogin;
public $is_affilnet_lead;
public $connexion_count;
public $frequence_nw;
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'customer',
'primary' => 'id_customer',
'fields' => array(
'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5', 'copy_post' => false),
'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128),
'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 32),
'last_passwd_gen' => array('type' => self::TYPE_STRING, 'copy_post' => false),
'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate'),
'newsletter' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'newsletter_date_add' => array('type' => self::TYPE_DATE,'copy_post' => false),
'ip_registration_newsletter' => array('type' => self::TYPE_STRING, 'copy_post' => false),
'optin' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'website' => array('type' => self::TYPE_STRING, 'validate' => 'isUrl'),
'company' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
'siret' => array('type' => self::TYPE_STRING, 'validate' => 'isSiret'),
'ape' => array('type' => self::TYPE_STRING, 'validate' => 'isApe'),
'outstanding_allow_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'copy_post' => false),
'show_public_prices' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'id_risk' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
'max_payment_days' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'note' => array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'size' => 65000, 'copy_post' => false),
'is_guest' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
'id_shop_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
'id_default_group' => array('type' => self::TYPE_INT, 'copy_post' => false),
'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
'segmentation' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
'pro' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'pro_update' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'pro_passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
'last_adleadlogin' => array('type' => self::TYPE_DATE),
'is_affilnet_lead' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'connexion_count' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'frequence_nw' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
),
);
/**
* Logout
*
* @since 1.5.0
*/
public function logout()
{
if (isset(Context::getContext()->cookie))
Context::getContext()->cookie->mylogout();
$this->logged = 0;
}
public function isPro()
{
return $this->pro == 1;
}
public static function isGroupPro($id) {
$sql = '
SELECT cg.id_group FROM '._DB_PREFIX_.'customer_group cg
LEFT JOIN '._DB_PREFIX_.'group gp ON gp.id_group = cg.id_group
LEFT JOIN '._DB_PREFIX_.'customer c ON c.id_customer = cg.id_customer
WHERE (cg.id_customer = '.(int)$id.' AND (cg.id_group = 3 OR cg.id_group = 4))';
$group = Db::getInstance()->getValue($sql);
if ($group == 4) {
return true;
} else {
return false;
}
}
public static function getUrlAutologin($id, $email) {
$sql = 'SELECT hash FROM '._DB_PREFIX_.'ant_autologin WHERE id_user = '.(int)$id;
$hash = Db::getInstance()->getValue($sql);
return _PS_BASE_URL_.__PS_BASE_URI__.'module/autologin/login?data=' . urlencode($email) . ':' . $hash;
}
public function isProNoValid()
{
return $this->isPro() && $this->pro_update == 0;
}
public function addVisit()
{
$this->connexion_count = $this->connexion_count + 1;
$this->save();
}
public function getAge() {
$birthDate = isset($this->birthday) ? $this->birthday : '0000-00-00';
$age = 0;
if ($birthDate !== '0000-00-00') {
list($byear, $bmonth, $bday) = explode('-', $birthDate);
list($cday, $cmonth, $cyear) = explode('-', date('d-m-Y'));
$age = $cyear - $byear;
if ((int)$bmonth < (int)$cmonth) {
--$age;
} elseif ((int)$bmonth === (int)$cmonth) {
if ((int)$bday < (int)$cday) {
--$age;
}
}
}
return $age;
}
}
?>