La méthode "getStatus()" a également été modifiée en "getCurrentStatus()" pour une meilleure homogénéité.refactoring
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getStatus() == USER::STATUS_ADMIN | |||||
|| User::getStatus() == USER::STATUS_PRODUCER; | |||||
return User::getCurrentStatus() == USER::STATUS_ADMIN | |||||
|| User::getCurrentStatus() == USER::STATUS_PRODUCER; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
$order->getAmount(Order::AMOUNT_PAID), | $order->getAmount(Order::AMOUNT_PAID), | ||||
$order->distribution->id_producer, | $order->distribution->id_producer, | ||||
$order->id_user, | $order->id_user, | ||||
User::getId() | |||||
User::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
$montant_paye, | $montant_paye, | ||||
Producer::getId(), | Producer::getId(), | ||||
$commande->id_user, | $commande->id_user, | ||||
User::getId() | |||||
User::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
$montant, | $montant, | ||||
Producer::getId(), | Producer::getId(), | ||||
$commande->id_user, | $commande->id_user, | ||||
User::getId() | |||||
User::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getStatus() == USER::STATUS_ADMIN; | |||||
return User::getCurrentStatus() == USER::STATUS_ADMIN; | |||||
} | } | ||||
] | ] | ||||
], | ], |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getStatus() == User::STATUS_ADMIN ; | |||||
return User::getCurrentStatus() == User::STATUS_ADMIN ; | |||||
} | } | ||||
], | ], | ||||
], | ], |
$user = User::find()->with('userProducer')->where(['id' => $model['id']])->one(); | $user = User::find()->with('userProducer')->where(['id' => $model['id']])->one(); | ||||
$userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => Producer::getId()]); | $userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => Producer::getId()]); | ||||
if (($userBelongToProducer && count($user->userProducer) == 1) || User::getStatus() == USER::STATUS_ADMIN) { | |||||
if (($userBelongToProducer && count($user->userProducer) == 1) || User::getCurrentStatus() == USER::STATUS_ADMIN) { | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
// on envoie le mail de bienvenue si le mail vient d'être défini | // on envoie le mail de bienvenue si le mail vient d'être défini | ||||
$user = User::find()->with('userProducer')->where(['id' => $id])->one(); | $user = User::find()->with('userProducer')->where(['id' => $id])->one(); | ||||
$userProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => Producer::getId()]); | $userProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => Producer::getId()]); | ||||
if (($userProducer) || User::getStatus() == User::STATUS_ADMIN) { | |||||
if (($userProducer) || User::getCurrentStatus() == User::STATUS_ADMIN) { | |||||
$creditForm = new CreditForm; | $creditForm = new CreditForm; | ||||
if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) { | if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) { |
] ; | ] ; | ||||
} | } | ||||
if(User::getStatus() == USER::STATUS_ADMIN) { | |||||
if(User::getCurrentStatus() == USER::STATUS_ADMIN) { | |||||
$columns[] = [ | $columns[] = [ | ||||
'class' => 'yii\grid\ActionColumn', | 'class' => 'yii\grid\ActionColumn', | ||||
'template' => '{update}', | 'template' => '{update}', |
<?php endif; ?> | <?php endif; ?> | ||||
<?php if (!Yii::$app->user->isGuest): ?> | <?php if (!Yii::$app->user->isGuest): ?> | ||||
<div class="name-producer"> | <div class="name-producer"> | ||||
<?php if (User::getStatus() == User::STATUS_PRODUCER): ?> | |||||
<?php if (User::getCurrentStatus() == User::STATUS_PRODUCER): ?> | |||||
<span><?= Html::encode(Yii::$app->user->identity->getNameProducer()); ?></span> | <span><?= Html::encode(Yii::$app->user->identity->getNameProducer()); ?></span> | ||||
<?php elseif (User::getStatus() == User::STATUS_ADMIN): ?> | |||||
<?php elseif (User::getCurrentStatus() == User::STATUS_ADMIN): ?> | |||||
<?php $form = ActiveForm::begin(['id' => 'select-producer']); ?> | <?php $form = ActiveForm::begin(['id' => 'select-producer']); ?> | ||||
<?= | <?= | ||||
Html::dropDownList('select_producer', Producer::getId(), ArrayHelper::map(Producer::find()->orderBy('name ASC')->all(), 'id', function($model, $defaultValue) { | Html::dropDownList('select_producer', Producer::getId(), ArrayHelper::map(Producer::find()->orderBy('name ASC')->all(), 'id', function($model, $defaultValue) { |
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public static function getId() { | |||||
public static function getCurrentId() { | |||||
if(!Yii::$app->user->isGuest) { | if(!Yii::$app->user->isGuest) { | ||||
return Yii::$app->user->identity->id ; | return Yii::$app->user->identity->id ; | ||||
} | } | ||||
* | * | ||||
* @return integer|boolean | * @return integer|boolean | ||||
*/ | */ | ||||
public static function getStatus() | |||||
public static function getCurrentStatus() | |||||
{ | { | ||||
if(!Yii::$app->user->isGuest) { | if(!Yii::$app->user->isGuest) { | ||||
return Yii::$app->user->identity->status ; | return Yii::$app->user->identity->status ; | ||||
public static function hasAccessBackend() | public static function hasAccessBackend() | ||||
{ | { | ||||
return User::getStatus() == USER::STATUS_ADMIN || User::getStatus() == USER::STATUS_PRODUCER; | |||||
return User::getCurrentStatus() == USER::STATUS_ADMIN || User::getCurrentStatus() == USER::STATUS_PRODUCER; | |||||
} | } | ||||
} | } |
$producerCodeForm->id_producer = $id ; | $producerCodeForm->id_producer = $id ; | ||||
if($producerCodeForm->load(Yii::$app->request->post()) && $producerCodeForm->validate()) { | if($producerCodeForm->load(Yii::$app->request->post()) && $producerCodeForm->validate()) { | ||||
Producer::addUser(User::getId(), $id) ; | |||||
Producer::addUser(User::getCurrentId(), $id) ; | |||||
$this->redirect(Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index','slug_producer' => $producer->slug])); | $this->redirect(Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index','slug_producer' => $producer->slug])); | ||||
} | } | ||||
if (Yii::$app->user->isGuest) { | if (Yii::$app->user->isGuest) { | ||||
if ($loginForm->load(Yii::$app->request->post()) && $loginForm->login()) { | if ($loginForm->load(Yii::$app->request->post()) && $loginForm->login()) { | ||||
Producer::addUser(User::getId(), $id) ; | |||||
Producer::addUser(User::getCurrentId(), $id) ; | |||||
$this->redirect($returnUrl); | $this->redirect($returnUrl); | ||||
} | } | ||||
*/ | */ | ||||
public function actionUpdate() | public function actionUpdate() | ||||
{ | { | ||||
$model = $this->findModel(User::getId()); | |||||
$model = $this->findModel(User::getCurrentId()); | |||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) { | if ($model->load(Yii::$app->request->post()) && $model->validate()) { | ||||
// l'utilisateur ne peut pas changer d'adresse email | // l'utilisateur ne peut pas changer d'adresse email | ||||
$oldModel = $this->findModel(User::getId()); | |||||
$oldModel = $this->findModel(User::getCurrentId()); | |||||
$model->email = $oldModel->email; | $model->email = $oldModel->email; | ||||
// modification du mot de passe | // modification du mot de passe |
$producer = Producer::findOne($this->id_producer); | $producer = Producer::findOne($this->id_producer); | ||||
$userProducerExist = UserProducer::searchOne([ | $userProducerExist = UserProducer::searchOne([ | ||||
'id_user' => User::getId(), | |||||
'id_user' => User::getCurrentId(), | |||||
'active' => 0 | 'active' => 0 | ||||
]) ; | ]) ; | ||||
$userProducerExist->save(); | $userProducerExist->save(); | ||||
} else { | } else { | ||||
$userProducer = new UserProducer(); | $userProducer = new UserProducer(); | ||||
$userProducer->id_user = User::getId(); | |||||
$userProducer->id_user = User::getCurrentId(); | |||||
$userProducer->id_producer = $this->id_producr; | $userProducer->id_producer = $this->id_producr; | ||||
$userProducer->credit = 0; | $userProducer->credit = 0; | ||||
$userProducer->actif = 1; | $userProducer->actif = 1; |
$producersArray = Producer::find() | $producersArray = Producer::find() | ||||
->joinWith(['userProducer user_producer']) | ->joinWith(['userProducer user_producer']) | ||||
->where([ | ->where([ | ||||
'user_producer.id_user' => User::getId(), | |||||
'user_producer.id_user' => User::getCurrentId(), | |||||
'user_producer.bookmark' => 1, | 'user_producer.bookmark' => 1, | ||||
'producer.active' => 1 | 'producer.active' => 1 | ||||
]) | ]) |
->with('userPointSale') | ->with('userPointSale') | ||||
->where(['id_producer' => $idProducer]) | ->where(['id_producer' => $idProducer]) | ||||
->andWhere('restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND point_sale_user.id_user = :id_user) > 0)') | ->andWhere('restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND point_sale_user.id_user = :id_user) > 0)') | ||||
->params([':id_user' => User::getId()]) | |||||
->params([':id_user' => User::getCurrentId()]) | |||||
->all(); | ->all(); | ||||
// jours de production | // jours de production | ||||
} | } | ||||
$orders = Order::searchAll([ | $orders = Order::searchAll([ | ||||
'id_user' => User::getId() | |||||
'id_user' => User::getCurrentId() | |||||
]) ; | ]) ; | ||||
if ($idProducer) { | if ($idProducer) { | ||||
$userProducer = UserProducer::searchOne([ | $userProducer = UserProducer::searchOne([ | ||||
'id_producer' => $idProducer, | 'id_producer' => $idProducer, | ||||
'id_user' => User::getId() | |||||
'id_user' => User::getCurrentId() | |||||
]) ; | ]) ; | ||||
$credit = $userProducer->credit; | $credit = $userProducer->credit; | ||||
public function actionRemoveProducer($id = 0) | public function actionRemoveProducer($id = 0) | ||||
{ | { | ||||
$userProducer = UserProducer::find() | $userProducer = UserProducer::find() | ||||
->where(['id_producer' => $id, 'id_user' => User::getId()]) | |||||
->where(['id_producer' => $id, 'id_user' => User::getCurrentId()]) | |||||
->one(); | ->one(); | ||||
$userProducer->active = 0; | $userProducer->active = 0; | ||||
if ($order->load($posts)) { | if ($order->load($posts)) { | ||||
$order = Order::find()->where('id_distribution = ' . $posts['Order']['id_distribution'])->andWhere('id_user = ' . User::getid())->one(); | |||||
$order = Order::find()->where('id_distribution = ' . $posts['Order']['id_distribution'])->andWhere('id_user = ' . User::getCurrentId())->one(); | |||||
if (!$order) { | if (!$order) { | ||||
$order = new Order; | $order = new Order; | ||||
$order->load(Yii::$app->request->post()); | $order->load(Yii::$app->request->post()); | ||||
$order->id_user = User::getId(); | |||||
$order->id_user = User::getCurrentId(); | |||||
$order->date = date('Y-m-d H:i:s'); | $order->date = date('Y-m-d H:i:s'); | ||||
$order->type = Order::ORIGIN_USER; | $order->type = Order::ORIGIN_USER; | ||||
} | } | ||||
$order->save(); | $order->save(); | ||||
// ajout de l'utilisateur à l'établissement | // ajout de l'utilisateur à l'établissement | ||||
Producer::addUser(User::getId(), $distribution->id_producer) ; | |||||
Producer::addUser(User::getCurrentId(), $distribution->id_producer) ; | |||||
// suppression de tous les enregistrements ProductOrder | // suppression de tous les enregistrements ProductOrder | ||||
if (!is_null($order)) { | if (!is_null($order)) { | ||||
CreditHistory::TYPE_PAYMENT, | CreditHistory::TYPE_PAYMENT, | ||||
$amountRemaining, | $amountRemaining, | ||||
$distribution->id_producer, | $distribution->id_producer, | ||||
User::getId(), | |||||
User::getId() | |||||
User::getCurrentId(), | |||||
User::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
} | } | ||||
CreditHistory::TYPE_REFUND, | CreditHistory::TYPE_REFUND, | ||||
$amountSurplus, | $amountSurplus, | ||||
$distribution->id_producer, | $distribution->id_producer, | ||||
User::getId(), | |||||
User::getId() | |||||
User::getCurrentId(), | |||||
User::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
} | } | ||||
throw new UserException('Vous ne pouvez plus annuler cette commande.'); | throw new UserException('Vous ne pouvez plus annuler cette commande.'); | ||||
} | } | ||||
if ($order && User::getId() == $order->id_user) { | |||||
if ($order && User::getCurrentId() == $order->id_user) { | |||||
// remboursement | // remboursement | ||||
if ($order->getAmount(Order::AMOUNT_PAID)) { | if ($order->getAmount(Order::AMOUNT_PAID)) { | ||||
$order->creditHistory( | $order->creditHistory( | ||||
CreditHistory::PAYMENT_REFUND, | CreditHistory::PAYMENT_REFUND, | ||||
$order->getAmount(Order::AMOUNT_PAID), | $order->getAmount(Order::AMOUNT_PAID), | ||||
$order->distribution->id_producer, | $order->distribution->id_producer, | ||||
User::getId(), | |||||
User::getId() | |||||
User::getCurrentId(), | |||||
User::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
// delete | // delete |
else { | else { | ||||
$userProducer = UserProducer::find() | $userProducer = UserProducer::find() | ||||
->where([ | ->where([ | ||||
'id_user' => User::getId(), | |||||
'id_user' => User::getCurrentId(), | |||||
'id_producer' => $producer->id | 'id_producer' => $producer->id | ||||
]) | ]) | ||||
->one() ; | ->one() ; |
$producer = $this->getProducer() ; | $producer = $this->getProducer() ; | ||||
$userProducer = UserProducer::find() | $userProducer = UserProducer::find() | ||||
->where([ | ->where([ | ||||
'id_user' => User::getId(), | |||||
'id_user' => User::getCurrentId(), | |||||
'id_producer' => $producer->id | 'id_producer' => $producer->id | ||||
]) | ]) | ||||
->one() ; | ->one() ; | ||||
if(!$userProducer) { | if(!$userProducer) { | ||||
$userProducer = Producer::addUser(User::getId(), $producer->id) ; | |||||
$userProducer = Producer::addUser(User::getCurrentId(), $producer->id) ; | |||||
} | } | ||||
if($userProducer) { | if($userProducer) { |
<h1><?= Html::encode($producer->name); ?> <span>/ <?= Html::encode($producer->type) ?> à <?= Html::encode($producer->city); ?> (<?= Html::encode($producer->postcode); ?>)</span></h1> | <h1><?= Html::encode($producer->name); ?> <span>/ <?= Html::encode($producer->type) ?> à <?= Html::encode($producer->city); ?> (<?= Html::encode($producer->postcode); ?>)</span></h1> | ||||
<?php if(!Yii::$app->user->isGuest): ?> | <?php if(!Yii::$app->user->isGuest): ?> | ||||
<?php | <?php | ||||
$userProducer = UserProducer::findOne(['id_user' => User::getId(), 'id_producer' => $producer->id ]) ; | |||||
$userProducer = UserProducer::findOne(['id_user' => User::getCurrentId(), 'id_producer' => $producer->id ]) ; | |||||
if($userProducer): | if($userProducer): | ||||
?> | ?> | ||||
<div id="credit"> | <div id="credit"> |
{ | { | ||||
foreach($pointSale->userPointSale as $userPointSale) | foreach($pointSale->userPointSale as $userPointSale) | ||||
{ | { | ||||
if($userPointSale->id_user == User::getId() && strlen($userPointSale->comment)) | |||||
if($userPointSale->id_user == User::getCurrentId() && strlen($userPointSale->comment)) | |||||
{ | { | ||||
$comment = '<div class="commentaire"><span>'.Html::encode($userPointSale->comment).'</span></div>' ; | $comment = '<div class="commentaire"><span>'.Html::encode($userPointSale->comment).'</span></div>' ; | ||||
} | } |
# Codeception Test Suite Configuration | |||||
# | |||||
# Suite for acceptance tests. | |||||
# Perform tests in browser using the WebDriver or PhpBrowser. | |||||
# If you need both WebDriver and PHPBrowser tests - create a separate suite. | |||||
actor: AcceptanceTester | |||||
modules: | |||||
enabled: | |||||
- PhpBrowser: | |||||
url: http://localhost/myapp | |||||
- \Helper\Acceptance |
# Codeception Test Suite Configuration | |||||
# | |||||
# Suite for functional tests | |||||
# Emulate web requests and make application process them | |||||
# Include one of framework modules (Symfony2, Yii2, Laravel5) to use it | |||||
# Remove this suite if you don't use frameworks | |||||
actor: FunctionalTester | |||||
modules: | |||||
enabled: | |||||
# add a framework module here | |||||
- \Helper\Functional |