|
|
|
|
|
|
|
|
const STATUS_PRODUCER = 11; |
|
|
const STATUS_PRODUCER = 11; |
|
|
const STATUS_ADMIN = 13; |
|
|
const STATUS_ADMIN = 13; |
|
|
|
|
|
|
|
|
const ID_USER_SYSTEM = 0 ; |
|
|
|
|
|
|
|
|
const ID_USER_SYSTEM = 0 ; |
|
|
|
|
|
|
|
|
var $password_old; |
|
|
var $password_old; |
|
|
var $password_new; |
|
|
var $password_new; |
|
|
|
|
|
|
|
|
[['date_derniere_connexion', 'password_old', 'password_new', 'password_new_confirm', 'password_hash'], 'safe'], |
|
|
[['date_derniere_connexion', 'password_old', 'password_new', 'password_new_confirm', 'password_hash'], 'safe'], |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function attributeLabels() |
|
|
|
|
|
{ |
|
|
|
|
|
return [ |
|
|
|
|
|
'id' => 'ID', |
|
|
|
|
|
'username' => 'Identifiant', |
|
|
|
|
|
'password' => 'Mot de passe', |
|
|
|
|
|
'rememberMe' => 'Se souvenir de moi', |
|
|
|
|
|
'confiance' => 'De confiance', |
|
|
|
|
|
'no_mail' => 'Ne pas recevoir d\'email de la part du Chat des Noisettes', |
|
|
|
|
|
'mail_prod_lundi' => 'Lundi', |
|
|
|
|
|
'mail_prod_mardi' => 'Mardi', |
|
|
|
|
|
'mail_prod_mercredi' => 'Mercredi', |
|
|
|
|
|
'mail_prod_jeudi' => 'Jeudi', |
|
|
|
|
|
'mail_prod_vendredi' => 'Vendredi', |
|
|
|
|
|
'mail_prod_samedi' => 'Samedi', |
|
|
|
|
|
'mail_prod_dimanche' => 'Dimanche', |
|
|
|
|
|
'password_old' => 'Ancien mot de passe', |
|
|
|
|
|
'password_new' => 'Nouveau mot de passe', |
|
|
|
|
|
'password_new_confirm' => 'Confirmation du nouveau mot de passe', |
|
|
|
|
|
'prix_libre' => 'Prix libre', |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne les options de base nécessaires à la fonction de recherche. |
|
|
|
|
|
* |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function defaultOptionsSearch() { |
|
|
|
|
|
return [ |
|
|
|
|
|
'with' => [], |
|
|
|
|
|
'join_with' => [], |
|
|
|
|
|
'orderby' => 'user.name ASC, user.lastname ASC', |
|
|
|
|
|
'attribute_id_producer' => '' |
|
|
|
|
|
] ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Vérifie le mot de passe envoyé par l'utilisateur. |
|
|
* Vérifie le mot de passe envoyé par l'utilisateur. |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
$user = User::find()->where("email LIKE :email AND id != :id")->params(array(':email' => '%' . $this->email . '%', ':id' => $this->id))->one(); |
|
|
$user = User::find()->where("email LIKE :email AND id != :id")->params(array(':email' => '%' . $this->email . '%', ':id' => $this->id))->one(); |
|
|
|
|
|
|
|
|
if ($user) |
|
|
|
|
|
|
|
|
if ($user) { |
|
|
$this->addError($attribute, 'Cette adresse email est déjà utilisée par un autre utilisateur '); |
|
|
$this->addError($attribute, 'Cette adresse email est déjà utilisée par un autre utilisateur '); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public static function findIdentity($id) |
|
|
public static function findIdentity($id) |
|
|
{ |
|
|
{ |
|
|
return static::findOne(['id' => $id/* , 'status' => self::STATUS_ACTIVE */]); |
|
|
|
|
|
|
|
|
return static::findOne(['id' => $id]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return static::findOne([ |
|
|
return static::findOne([ |
|
|
'password_reset_token' => $token, |
|
|
|
|
|
|
|
|
'password_reset_token' => $token, |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public static function findBy($params = []) |
|
|
public static function findBy($params = []) |
|
|
{ |
|
|
{ |
|
|
if (!isset($params['id_etablissement'])) |
|
|
|
|
|
$params['id_etablissement'] = Yii::$app->user->identity->id_etablissement; |
|
|
|
|
|
|
|
|
if (!isset($params['id_producer'])) { |
|
|
|
|
|
$params['id_producer'] = Producer::getCurrentId() ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$query = (new Query()) |
|
|
$query = (new Query()) |
|
|
->select(['user.id AS user_id', 'user.prenom', 'user.nom', 'user.telephone', 'user.email', 'user.created_at', 'user.date_derniere_connexion', 'user_etablissement.*']) |
|
|
|
|
|
|
|
|
->select(['user.id AS user_id', 'user.name', 'user.lastname', 'user.phone', 'user.email', 'user.created_at', 'user.date_last_connection', 'user_producer.*']) |
|
|
->from('user'); |
|
|
->from('user'); |
|
|
|
|
|
|
|
|
$actif = (isset($params['inactifs']) && $params['inactifs']) ? 0 : 1 ; |
|
|
|
|
|
$query->innerJoin('user_etablissement','user.id = user_etablissement.id_user AND user_etablissement.actif = '.$actif.' AND user_etablissement.id_etablissement = :id_etablissement', [':id_etablissement' => $params['id_etablissement']]) ; |
|
|
|
|
|
|
|
|
$active = (isset($params['inactive']) && $params['inactive']) ? 0 : 1 ; |
|
|
|
|
|
$query->innerJoin('user_producer','user.id = user_producer.id_user AND user_producer.active = '.$active.' AND user_producer.id_producer = :id_producer', [':id_producer' => $params['id_producer']]) ; |
|
|
|
|
|
|
|
|
if(isset($params['id_point_vente']) && $params['id_point_vente']) { |
|
|
|
|
|
$point_vente = PointVente::findOne(['id' => $params['id_point_vente']]) ; |
|
|
|
|
|
if($point_vente->acces_restreint) { |
|
|
|
|
|
$query->innerJoin('point_vente_user','user.id = point_vente_user.id_user AND point_vente_user.id_point_vente = :id_point_vente',[':id_point_vente' => $params['id_point_vente']]) ; |
|
|
|
|
|
|
|
|
if(isset($params['id_point_sale']) && $params['id_point_sale']) { |
|
|
|
|
|
$point_sale = PointSale::findOne(['id' => $params['id_point_sale']]) ; |
|
|
|
|
|
if($point_sale->restricted_access) { |
|
|
|
|
|
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $params['id_point_sale']]) ; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
$query->innerJoin( |
|
|
$query->innerJoin( |
|
|
'commande', |
|
|
|
|
|
'user.id = commande.id_user AND commande.id_point_vente = :id_point_vente', |
|
|
|
|
|
[':id_point_vente' => $params['id_point_vente']] |
|
|
|
|
|
|
|
|
'order', |
|
|
|
|
|
'user.id = order.id_user AND order.id_point_sale = :id_point_sale', |
|
|
|
|
|
[':id_point_sale' => $params['id_point_sale']] |
|
|
)->groupBy('user.id') ; |
|
|
)->groupBy('user.id') ; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(isset($params['inactifs']) && $params['inactifs']) { |
|
|
|
|
|
|
|
|
if(isset($params['inactive']) && $params['inactive']) { |
|
|
$query->innerJoin( |
|
|
$query->innerJoin( |
|
|
'commande', |
|
|
|
|
|
'user.id = commande.id_user' |
|
|
|
|
|
|
|
|
'order', |
|
|
|
|
|
'user.id = order.id_user' |
|
|
) |
|
|
) |
|
|
->groupBy('user.id'); |
|
|
->groupBy('user.id'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (isset($params['nom'])) { |
|
|
|
|
|
$query->andFilterWhere(['like', 'nom', $params['nom']]); |
|
|
|
|
|
|
|
|
if (isset($params['name'])) { |
|
|
|
|
|
$query->andFilterWhere(['like', 'name', $params['name']]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (isset($params['prenom'])) { |
|
|
|
|
|
$query->andFilterWhere(['like', 'prenom', $params['prenom']]); |
|
|
|
|
|
|
|
|
if (isset($params['lastname'])) { |
|
|
|
|
|
$query->andFilterWhere(['like', 'lastname', $params['lastname']]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (isset($params['email'])) { |
|
|
if (isset($params['email'])) { |
|
|
$query->andFilterWhere(['like', 'email', $params['email']]); |
|
|
$query->andFilterWhere(['like', 'email', $params['email']]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (isset($params['telephone'])) { |
|
|
|
|
|
$query->andFilterWhere(['like', 'telephone', $params['telephone']]); |
|
|
|
|
|
|
|
|
if (isset($params['phone'])) { |
|
|
|
|
|
$query->andFilterWhere(['like', 'phone', $params['phone']]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $query; |
|
|
return $query; |
|
|
|
|
|
|
|
|
$this->password_reset_token = null; |
|
|
$this->password_reset_token = null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function attributeLabels() |
|
|
|
|
|
{ |
|
|
|
|
|
return [ |
|
|
|
|
|
'id' => 'ID', |
|
|
|
|
|
'username' => 'Identifiant', |
|
|
|
|
|
'password' => 'Mot de passe', |
|
|
|
|
|
'rememberMe' => 'Se souvenir de moi', |
|
|
|
|
|
'confiance' => 'De confiance', |
|
|
|
|
|
'no_mail' => 'Ne pas recevoir d\'email de la part du Chat des Noisettes', |
|
|
|
|
|
'mail_prod_lundi' => 'Lundi', |
|
|
|
|
|
'mail_prod_mardi' => 'Mardi', |
|
|
|
|
|
'mail_prod_mercredi' => 'Mercredi', |
|
|
|
|
|
'mail_prod_jeudi' => 'Jeudi', |
|
|
|
|
|
'mail_prod_vendredi' => 'Vendredi', |
|
|
|
|
|
'mail_prod_samedi' => 'Samedi', |
|
|
|
|
|
'mail_prod_dimanche' => 'Dimanche', |
|
|
|
|
|
'password_old' => 'Ancien mot de passe', |
|
|
|
|
|
'password_new' => 'Nouveau mot de passe', |
|
|
|
|
|
'password_new_confirm' => 'Confirmation du nouveau mot de passe', |
|
|
|
|
|
'prix_libre' => 'Prix libre', |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Retourne si l'utilisateur est un boulanger ou non. |
|
|
* Retourne si l'utilisateur est un boulanger ou non. |
|
|
* |
|
|
* |
|
|
* @return boolean |
|
|
* @return boolean |
|
|
*/ |
|
|
*/ |
|
|
public function isBoulanger() |
|
|
|
|
|
|
|
|
public function isProducer() |
|
|
{ |
|
|
{ |
|
|
return ($this->status == User::STATUS_ADMIN || $this->status == User::STATUS_BOULANGER) && $this->id_etablissement; |
|
|
|
|
|
|
|
|
return ($this->status == User::STATUS_ADMIN || $this->status == User::STATUS_PRODUCER) && $this->id_producer; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* @return string |
|
|
* @return string |
|
|
*/ |
|
|
*/ |
|
|
public function getNomMagasin() |
|
|
|
|
|
|
|
|
public function getNameProducer() |
|
|
{ |
|
|
{ |
|
|
$etablissement = Etablissement::findOne($this->id_etablissement); |
|
|
|
|
|
return $etablissement->nom; |
|
|
|
|
|
|
|
|
$producer = Producer::findOne($this->id_producer); |
|
|
|
|
|
return $producer->name; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* @return array |
|
|
* @return array |
|
|
*/ |
|
|
*/ |
|
|
public function getEtablissementsFavoris() |
|
|
|
|
|
|
|
|
public function getBookmarksProducers() |
|
|
{ |
|
|
{ |
|
|
$etabs = (new \yii\db\Query()) |
|
|
|
|
|
|
|
|
$producers = (new \yii\db\Query()) |
|
|
->select('*') |
|
|
->select('*') |
|
|
->from(['user_etablissement', 'etablissement']) |
|
|
|
|
|
->where('user_etablissement.id_etablissement = etablissement.id') |
|
|
|
|
|
->andWhere(['user_etablissement.id_user' => $this->id]) |
|
|
|
|
|
->andWhere(['user_etablissement.actif' => 1]) |
|
|
|
|
|
|
|
|
->from(['user_producer', 'producer']) |
|
|
|
|
|
->where('user_producer.id_producer = producer.id') |
|
|
|
|
|
->andWhere(['user_producer.id_user' => $this->id]) |
|
|
|
|
|
->andWhere(['user_producer.active' => 1]) |
|
|
->all(); |
|
|
->all(); |
|
|
|
|
|
|
|
|
return $etabs; |
|
|
|
|
|
|
|
|
return $producers; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
|
|
|
* @param integer $id_etablissement |
|
|
* @param integer $id_etablissement |
|
|
* @return float |
|
|
* @return float |
|
|
*/ |
|
|
*/ |
|
|
public function getCredit($id_etablissement) |
|
|
|
|
|
|
|
|
public function getCredit($idProducer) |
|
|
{ |
|
|
{ |
|
|
$user_etablissement = UserEtablissement::find() |
|
|
|
|
|
->where([ |
|
|
|
|
|
'id_user' => $this->id, |
|
|
|
|
|
'id_etablissement' => $id_etablissement |
|
|
|
|
|
]) |
|
|
|
|
|
->one(); |
|
|
|
|
|
|
|
|
|
|
|
if ($user_etablissement) { |
|
|
|
|
|
return $user_etablissement->credit; |
|
|
|
|
|
|
|
|
$userProducer = UserProducer::searchOne([ |
|
|
|
|
|
'id_user' => $this->id |
|
|
|
|
|
]) ; |
|
|
|
|
|
|
|
|
|
|
|
if ($userProducer) { |
|
|
|
|
|
return $userProducer->credit; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Met à jour la date de dernière connexion de l'utilisateur. |
|
|
* Met à jour la date de dernière connexion de l'utilisateur. |
|
|
*/ |
|
|
*/ |
|
|
public function updateDerniereConnexion() |
|
|
|
|
|
|
|
|
public function updateLastConnection() |
|
|
{ |
|
|
{ |
|
|
$this->date_derniere_connexion = date('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
|
$this->date_last_connection = date('Y-m-d H:i:s'); |
|
|
$this->save(); |
|
|
$this->save(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function sendMailWelcome($password) |
|
|
public function sendMailWelcome($password) |
|
|
{ |
|
|
{ |
|
|
if (strlen($this->email)) { |
|
|
if (strlen($this->email)) { |
|
|
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement); |
|
|
|
|
|
|
|
|
$producer = Producer::findOne(Producer::getCurrentId()); |
|
|
Yii::$app->mailer->compose(); |
|
|
Yii::$app->mailer->compose(); |
|
|
$mail = Yii::$app->mailer->compose( |
|
|
$mail = Yii::$app->mailer->compose( |
|
|
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $this, 'etablissement' => $etablissement, 'password' => $password] |
|
|
|
|
|
|
|
|
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $this, 'producer' => $producer, 'password' => $password] |
|
|
) |
|
|
) |
|
|
->setTo($this->email) |
|
|
->setTo($this->email) |
|
|
->setFrom(['contact@laboiteapain.net' => 'La boîte à pain']) |
|
|
->setFrom(['contact@laboiteapain.net' => 'La boîte à pain']) |
|
|
|
|
|
|
|
|
->send(); |
|
|
->send(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne l'ID de l'utilisateur courant connecté. |
|
|
|
|
|
* |
|
|
|
|
|
* @return mixed |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function getCurrentId() { |
|
|
|
|
|
if(!Yii::$app->user->isGuest) { |
|
|
|
|
|
return Yii::$app->user->identity->id ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |