283 lines
5.2 KiB
PHP
283 lines
5.2 KiB
PHP
<?php
|
|
class Scores_Utilisateur
|
|
{
|
|
protected $identity = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$auth = Zend_Auth::getInstance();
|
|
if ( $auth->hasIdentity() ) {
|
|
$this->identity = $auth->getIdentity();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if user is log in
|
|
* @return boolean
|
|
*/
|
|
public function isLog()
|
|
{
|
|
if ( $this->identity === null ) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Détermine si l'utilisateur est Administrateur
|
|
*/
|
|
public function isAdmin()
|
|
{
|
|
if ($this->identity->profil == 'Administrateur'){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Détermine si l'utilisateur est SuperAdministrateur
|
|
*/
|
|
public function isSuperAdmin()
|
|
{
|
|
if ($this->identity->profil == 'SuperAdministrateur'){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Retourne le profile utilisateur
|
|
*/
|
|
public function getProfil()
|
|
{
|
|
return $this->identity->profil;
|
|
}
|
|
|
|
/**
|
|
* Retourne l'identifiant client
|
|
*/
|
|
public function getIdClient()
|
|
{
|
|
return $this->identity->idClient;
|
|
}
|
|
|
|
/**
|
|
* Retourne l'identifiant de l'utilisateur
|
|
*/
|
|
public function getId()
|
|
{
|
|
return $this->identity->id;
|
|
}
|
|
|
|
/**
|
|
* Retourne le login de l'utiliateur
|
|
*/
|
|
public function getLogin()
|
|
{
|
|
return $this->identity->username;
|
|
}
|
|
|
|
/**
|
|
* Retourne le password de l'utilisateur
|
|
*/
|
|
public function getPassword()
|
|
{
|
|
return $this->identity->password;
|
|
}
|
|
|
|
/**
|
|
* Retourne le nom de l'utiliateur
|
|
*/
|
|
public function getNom()
|
|
{
|
|
return $this->identity->nom;
|
|
}
|
|
|
|
/**
|
|
* Retourne le prénom de l'utiliateur
|
|
*/
|
|
public function getPrenom()
|
|
{
|
|
return $this->identity->prenom;
|
|
}
|
|
|
|
/**
|
|
* Retourne l'email de l'utilisateur
|
|
*/
|
|
public function getEmail()
|
|
{
|
|
return $this->identity->email;
|
|
}
|
|
|
|
/**
|
|
* Retourne le téléphone de l'utilisateur
|
|
*/
|
|
public function getTel()
|
|
{
|
|
return $this->identity->tel;
|
|
}
|
|
|
|
/**
|
|
* Retourne le fax de l'utilisateur
|
|
*/
|
|
public function getFax()
|
|
{
|
|
return $this->identity->fax;
|
|
}
|
|
|
|
/**
|
|
* Retourne le type de score
|
|
*/
|
|
public function getTypeScore()
|
|
{
|
|
if (isset($this->identity->typeScore)
|
|
&& !empty($this->identity->typeScore)){
|
|
return $this->identity->typeScore;
|
|
}
|
|
return '100';
|
|
}
|
|
|
|
/**
|
|
* Retourne le nombre de réponse
|
|
*/
|
|
public function getNbRep()
|
|
{
|
|
return $this->identity->nbReponses;
|
|
}
|
|
|
|
/**
|
|
* Retourne l'adresse Ip de l'utilisateur
|
|
*/
|
|
public function getIpAddress()
|
|
{
|
|
if ( !isset($this->identity->ip) || empty($this->identity->ip) ){
|
|
return $_SERVER['REMOTE_ADDR'];
|
|
}
|
|
return $this->identity->ip;
|
|
}
|
|
|
|
/**
|
|
* Retourne la date de dernière connexion
|
|
*/
|
|
public function getDateDerniereConnexion()
|
|
{
|
|
return $this->identity->dateDerniereConnexion;
|
|
}
|
|
|
|
/**
|
|
* Vérifie que l'utiliasteur a le mode edition
|
|
* @return boolean
|
|
*/
|
|
public function checkModeEdition()
|
|
{
|
|
//On vérfie le mode edition dans les permissions
|
|
if ( $this->checkPerm('edition') ) {
|
|
return true;
|
|
}
|
|
//On vérfie le mode edition dans la session
|
|
if ( $this->identity->modeEdition ) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
/**
|
|
* Vérifie que l'utilisateur possède bien un droits
|
|
* @param string $perm
|
|
* Le code de la permission
|
|
* @return boolean
|
|
*/
|
|
public function checkPerm($perm)
|
|
{
|
|
$hasPerm = false;
|
|
if (preg_match('/\b'.$perm.'\b/i', $this->identity->droits)){
|
|
$hasPerm = true;
|
|
}
|
|
return $hasPerm;
|
|
}
|
|
|
|
/**
|
|
* Vérifie que l'utilisateur à cocher cette préférence
|
|
* @param string $pref
|
|
*/
|
|
public function checkPref($pref)
|
|
{
|
|
$hasPref = false;
|
|
if (preg_match('/\b'.$pref.'\b/i', $this->identity->pref)){
|
|
$hasPref = true;
|
|
}
|
|
return $hasPref;
|
|
}
|
|
|
|
/**
|
|
* Retourne la langue par défaut du client
|
|
*/
|
|
public function getLang()
|
|
{
|
|
return $this->identity->lang;
|
|
}
|
|
|
|
/**
|
|
* Retourne la langue de l'interface du client
|
|
*/
|
|
public function getLangTmp()
|
|
{
|
|
return $this->identity->langtmp;
|
|
}
|
|
|
|
/**
|
|
* Sets interface's language new value
|
|
* @param $langtmp
|
|
*/
|
|
public function setLangTmp($langtmp)
|
|
{
|
|
$this->identity->langtmp = $langtmp;
|
|
}
|
|
|
|
/**
|
|
* Get browser information
|
|
*/
|
|
public function getBrowserInfo()
|
|
{
|
|
return $this->identity->browser;
|
|
}
|
|
|
|
/**
|
|
* Set browser information
|
|
* @param string $name
|
|
* @param string $version
|
|
* @param int $mobile
|
|
* @param string $screenSize
|
|
*/
|
|
public function setBrowserInfo($platform, $name, $version, $mobile, $screenSize = 'unknow')
|
|
{
|
|
//Save info to session
|
|
$browserInfo = new stdClass();
|
|
$browserInfo->platform = $platform;
|
|
$browserInfo->name = $name;
|
|
$browserInfo->version = $version;
|
|
$browserInfo->mobile = $mobile;
|
|
$browserInfo->screenSize = $screenSize;
|
|
$this->identity->browser = $browserInfo;
|
|
$auth = Zend_Auth::getInstance();
|
|
$auth->getStorage()->write($this->identity);
|
|
|
|
//Save info to database
|
|
$data = array(
|
|
'idClient' => $this->getIdClient(),
|
|
'login' => $this->getLogin(),
|
|
'dateInsert' => date('Y-m-d H:i:s'),
|
|
'platform' => $platform,
|
|
'browserName' => $name,
|
|
'browserVersion' => $version,
|
|
'isMobile' => $mobile,
|
|
'screenSize' => $screenSize
|
|
);
|
|
$clientstatM = new Application_Model_ClientStat();
|
|
$id = $clientstatM->insert($data);
|
|
Zend_Registry::get('firebug')->info('Insertion : '.$id);
|
|
}
|
|
|
|
} |