ldc-gen-game-web/ldccrm_client/CPCUser.class.php
2020-10-29 15:40:23 +01:00

520 lines
12 KiB
PHP
Raw Blame History

<?php
include_once ('CPCUserField.class.php') ;
include_once ('emailValidation.php') ;
/**
* Classe faisant abstraction d'un utilisateur
*
* @package PlatosClient
* @name CPCUser
*/
class CPCUser
{
/**
* @var int Identifiant unique de l'utilisateur
* @access public
*/
public $iId ;
/**
* @var string Email de l'utilisateur
* @access public
*/
public $zEmail ;
/**
* @var string Login de l'utilisateur
* @access public
*/
public $zLogin ;
/**
* @var string Mot de passe de l'utilisateur
* @access public
*/
public $zPassword ;
/**
* @var string HashCode de l'utilisateur (En lecture seulement)
* @access public
*/
public $zHashCode ;
/**
* @var string Code du langage utilis? par de l'utilisateur
* @access public
*/
public $zLanguageCode ;
/**
* @var string Civilit? de l'utilisateur
* @access public
*/
public $zCivilite ;
/**
* @var string Nom de l'utilisateur
* @access public
*/
public $zNom ;
/**
* @var string Pr?nom de l'utilisateur
* @access public
*/
public $zPrenom ;
/**
* @var string La date de naissance de l'utilisateur
* @access public
*/
public $zDateNaissance ;
/**
* @var string 1ere adr?sse de l'utilisateur
* @access public
*/
public $zAdresse1 ;
/**
* @var string 2e adr?sse de l'utilisateur
* @access public
*/
public $zAdresse2 ;
/**
* @var string Code postal de l'utilisateur
* @access public
*/
public $zCodePostal ;
/**
* @var string ville de l'utilisateur
* @access public
*/
public $zVille ;
/**
* @var boolean Inscription au newLetter de l'utilisateur
* @access public
*/
public $iInscritNewLetter ;
/**
* @var string ean128 l'utilisateur
* @access public
*/
public $zEan128 ;
/**
* @var array Tableau contenant les champs dynamiques valu<6C>s de l'utilisateur
* @access private
*/
private $toFields ;
/**
* @var array Tableau contenant les champs dynamiques de l'utilisateur
* @access private
*/
private $toFieldsConfig ;
/**
* @var array Tableau contenant les services correspondant
* @access private
*/
private $toServices ;
/**
* Constructeur
*
* @param int $_iId Identifiant de l'utilisateur
*/
public function __construct ($_iId = 0)
{
$this->iId = $_iId ;
$this->zEmail = "" ;
$this->zLogin = "" ;
$this->zPassword = "" ;
$this->zHashCode = "" ;
$this->zLanguageCode = "" ;
$this->zCivilite = "" ;
$this->zNom = "" ;
$this->zPrenom = "" ;
$this->zDateNaissance = "" ;
$this->zAdresse1 = "" ;
$this->zAdresse2 = "" ;
$this->zVille = "" ;
$this->zCodePostal = 0 ;
$this->iInscritNewLetter = 0 ;
$this->zEan128 = "" ;
$this->toFields = array () ;
$this->toFieldsConfig = array () ;
$this->toServices = array () ;
}
/**
* Liste les champs dynamiques d?finis par cet utilisateur
*
* @return array Liste des codes des champs d?finis par l'utilisateur
*/
public function getDynamicFieldsList ()
{
if ( isset ($this->toFields) )
{
return array_keys ($this->toFields) ;
}
else
{
return 0 ;
}
}
/**
* Ajoute un nouveau champ dans l'utilisateur
*
* @param string $_zFieldCode Code du champ
* @param int $_iFieldType Type du champ
* @param string $_zFieldPattern Motif de v?rification du champ
* @param string $_zFieldValue Valeur du champ
*/
public function addField ($_zFieldCode, $_iFieldType = FIELDTYPE_TEXT, $_zFieldPattern = "", $_zFieldValue = "")
{
$oNewField = new CPCUserField ($_zFieldCode, $_iFieldType, $_zFieldPattern, $_zFieldValue) ;
$this->toFields[$_zFieldCode] = $oNewField ;
}
/**
* Ajoute un nouveau champ dans l'utilisateur
*
* @param string $_zFieldCode Code du champ
* @param string $_zFieldValue Valeur du champ
*/
public function setField ($_zFieldCode, $_zFieldValue = 0)
{
if (!array_key_exists ($_zFieldCode, $this->toFields))
{
$this->addField ($_zFieldCode) ;
}
$this->toFields[$_zFieldCode]->zValue = $_zFieldValue ;
}
/**
* R<>cup<75>re la valeur d'un champ dynamique utilisateur
*
* @param string $_zFieldCode Code du champ
* @return string Valeur du champ ou FALSE si champ inexsitant
*/
public function getField ($_zFieldCode)
{
$zRet = false ;
if (array_key_exists ($_zFieldCode, $this->toFields))
{
$zRet = $this->toFields[$_zFieldCode]->zValue ;
}
else
{
return null ;
}
return $zRet ;
}
/**
* V?rificaion de la conformit? interne du champs
*
* @return bool R?sultat de la v?rification de conformit?
*/
public function check ()
{
$bRet = true ;
if (!$this->checkEmailFormat ($this->zEmail))
{
$bRet = false ;
throw new Exception ("Format d'Email invalide : [" . $this->zEmail . "]") ;
}
try
{
$this->checkEmailOnMX ($this->zEmail) ;
}
catch (Exception $_eInvalideMail)
{
$bRet = false ;
}
if ($bRet)
{
foreach ($this->toFields as $oField)
{
try
{
$bRet = $bRet && $oField->check();
}
catch (Exception $_oException)
{
$bRet = false ;
throw new Exception ($_oException->getMessage ()) ;
}
}
}
return $bRet ;
}
/**
* Fonction de v?rification d'un email
*
* @param string $_zInputEmail l'Adresse email ? v?rifier
* @return bool R?sultat de la v?rification du format
*/
public function checkEmailOnMX ($_zInputEmail, $_zLocalUser = "root", $_zLocalHost = "localhost")
{
$bRes = true ;
/*
if (isset ($_zInputEmail))
{
$oEmailValidator = new email_validation_class () ;
$oEmailValidator->timeout = 5 ;
$oEmailValidator->data_timeout = 0 ;
$oEmailValidator->localuser = $_zLocalUser ;
$oEmailValidator->localhost = $_zLocalHost ;
$oEmailValidator->debug = 0 ;
$oEmailValidator->html_debug = 0 ;
$oEmailValidator->exclude_address = "" ;
if (!$oEmailValidator->ValidateEmailBox ($_zInputEmail))
{
$bRes = false ;
throw new Exception ("Email non reconnu par le serveur : [" . $_zInputEmail . "]") ;
}
}
*/
return $bRes ;
}
/**
* Fonction de v?rification du format d'un email
*
* @param string $_zInputEmail l'Adresse email ? v?rifier
* @return bool R?sultat de la v?rification du format
*/
public function checkEmailFormat ($_zInputEmail)
{
$zPattern2 = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i" ;
$bRet = (preg_match ($zPattern2, $_zInputEmail)) ;
return $bRet ;
}
/**
* Liste les champs dynamiques d<>finis par la configuration de l'utilisateur
*
* @return array Liste des codes des champs par la configuration de l'utilisateur
*/
public function getFieldsConfig ()
{
if (isset ($this->toFieldsConfig))
{
$toResults = array_keys ($this->toFieldsConfig) ;
if (count ($toResults) > 0)
{
return $toResults ;
}
else
{
return null ;
}
}
else
{
return null ;
}
}
/**
* Liste des services correspondant <20> l'utilisateur
*
* @return array Liste des services
*/
public function getAllServicesCorresponding ()
{
if (isset ($this->toServices))
{
$toResults = $this->toServices ;
if (count ($toResults) > 0)
{
return $toResults ;
}
else
{
return null ;
}
}
else
{
return null ;
}
}
/**
* Fonction d'ajout d'une configuration de champs
*
* @param string $_zFieldCode
* @param CPlatosFieldConfig $_oFieldConfig ;
*/
public function addFieldConfig ($_zFieldCode, $_oFieldConfig)
{
$oNewFieldConfig = new CPCFieldConfig () ;
$oNewFieldConfig->zFieldId = $_oFieldConfig->zFieldId ;
$oNewFieldConfig->iFieldType = $_oFieldConfig->iFieldType ;
$oNewFieldConfig->zLabel = $_oFieldConfig->zLabel ;
foreach ($_oFieldConfig->toAttributes as $oAttr)
{
$oNewAttr = new CPCFieldAttribute () ;
$oNewAttr->iId = $oAttr->iId ;
$oNewAttr->zLabel = $oAttr->zLabel ;
array_push ($oNewFieldConfig->toAttributes, $oNewAttr) ;
}
$this->toFieldsConfig[$_zFieldCode] = $oNewFieldConfig ;
}
/**
* R<>cup<75>ration du lib<69>ll<6C> d'un champ
*
* @param string $_zFieldCode
* @return string|null Type du champ
*/
public function getFieldLabel ($_zFieldCode)
{
if (array_key_exists ($_zFieldCode, $this->toFieldsConfig))
{
return $this->toFieldsConfig[$_zFieldCode]->zLabel ;
}
else
{
return null ;
}
}
/**
* R<>cup<75>ration du type d'un champ
*
* @param string $_zFieldCode
* @return int|null Type du champ
*/
public function getFieldType ($_zFieldCode)
{
if (array_key_exists ($_zFieldCode, $this->toFieldsConfig))
{
return $this->toFieldsConfig[$_zFieldCode]->iFieldType ;
}
else
{
return null ;
}
}
/**
* R<>cup<75>ration du type d'un champ
*
* @param string $_zFieldCode
* @return array|null Type du champ
*/
public function getFieldAttributes ($_zFieldCode)
{
if (array_key_exists ($_zFieldCode, $this->toFieldsConfig))
{
$tzResults = array () ;
foreach ($this->toFieldsConfig[$_zFieldCode]->toAttributes as $oAttr)
{
$tzResults[$oAttr->iId] = $oAttr->zLabel ;
}
return $tzResults ;
}
else
{
return null ;
}
}
/**
* Fonction d'ajout des services correspondants
*
* @param CPlatosServices $_oServices
*/
public function addServiceCorresponding ($_oServices)
{
$oServices = new CPCServices () ;
$oServices->iServiceId = $_oServices->iServiceId ;
$oServices->zServiceName = $_oServices->zServiceName ;
array_push ($this->toServices, $oServices) ;
}
/**
* Recuperation des champs
* @return array Liste des champs
*/
public function getFields ()
{
return $this->toFields ;
}
}
/**
* Classe faisant d'une valeur autoris<69> pour un champs
*/
class CPCFieldAttribute
{
public $iId ;
public $zLabel ;
}
/**
* Classe faisant abstraction d'une liste de valeur autoris<69> pour un champs (Type liste)
*/
class CPCFieldConfig
{
public $zFieldId ;
public $iFieldType ;
public $zLabel ;
public $zPattern ;
public $toAttributes = array () ;
}
/**
* Classe faisant abstraction d'un service
*/
class CPCServices
{
public $iServiceId ;
public $zServiceName ;
}
?>