Browse Source

[producer] Correction bug UserProducer non initialisé

dev
Guillaume Bourgeois 5 years ago
parent
commit
4f3daa9a9b
2 changed files with 14 additions and 10 deletions
  1. +2
    -2
      common/models/Producer.php
  2. +12
    -8
      producer/controllers/ProducerBaseController.php

+ 2
- 2
common/models/Producer.php View File

* @param integer $id_producer * @param integer $id_producer
* @return UserProducer * @return UserProducer
*/ */
public static function addUser($idUser, $idProducer)
public static function addUser($idUser, $idProducer, $bookmark = 1)
{ {
$userProducer = UserProducer::searchOne([ $userProducer = UserProducer::searchOne([
'user_producer.id_user' => $idUser, 'user_producer.id_user' => $idUser,
$newUserProducer->id_user = $idUser; $newUserProducer->id_user = $idUser;
$newUserProducer->credit = 0; $newUserProducer->credit = 0;
$newUserProducer->active = 1; $newUserProducer->active = 1;
$newUserProducer->bookmark = 1;
$newUserProducer->bookmark = (int) $bookmark ;
$newUserProducer->save(); $newUserProducer->save();
} else { } else {
if (!$userProducer->active) { if (!$userProducer->active) {

+ 12
- 8
producer/controllers/ProducerBaseController.php View File

public function beforeAction($event) public function beforeAction($event)
{ {
$producer = $this->getProducer() ; $producer = $this->getProducer() ;
$userProducer = UserProducer::find()
->where([
'id_user' => User::getCurrentId(),
'id_producer' => $producer->id
])
->one() ;
/* /*
* Producteur protègé par un code * Producteur protègé par un code
*/ */
} }
// si l'utilisateur est connecté et qu'il n'a pas encore saisi de code // si l'utilisateur est connecté et qu'il n'a pas encore saisi de code
else { else {
$userProducer = UserProducer::find()
->where([
'id_user' => User::getCurrentId(),
'id_producer' => $producer->id
])
->one() ;
if(!$userProducer || ($userProducer && !$userProducer->active)) { if(!$userProducer || ($userProducer && !$userProducer->active)) {
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ; $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ;
} }
} }
} }
/* /*
* Producteur hors ligne * Producteur hors ligne
*/ */
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ; $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ;
} }
if(!$userProducer) {
Producer::addUser(User::getCurrentId(), $producer->id, 0) ;
}
return parent::beforeAction($event); return parent::beforeAction($event);
} }

Loading…
Cancel
Save