Browse Source

La méthode "getId()" de User devient "getCurrentId()" car "getId()" est déjà utilisé dans l'interface IdentityInterface

La méthode "getStatus()" a également été modifiée en "getCurrentStatus()" pour une meilleure homogénéité.
refactoring
Guillaume Bourgeois 6 years ago
parent
commit
4063d2b576
19 changed files with 2336 additions and 41 deletions
  1. +5
    -5
      backend/controllers/OrderController.php
  2. +1
    -1
      backend/controllers/ProducerAdminController.php
  3. +1
    -1
      backend/controllers/SiteController.php
  4. +2
    -2
      backend/controllers/UserController.php
  5. +1
    -1
      backend/views/development/index.php
  6. +2
    -2
      backend/views/layouts/main.php
  7. +3
    -3
      common/models/User.php
  8. +2
    -2
      frontend/controllers/SiteController.php
  9. +2
    -2
      frontend/controllers/UserController.php
  10. +2
    -2
      frontend/models/AddProducerForm.php
  11. +1
    -1
      frontend/views/layouts/main.php
  12. +14
    -14
      producer/controllers/OrderController.php
  13. +1
    -1
      producer/controllers/ProducerBaseController.php
  14. +2
    -2
      producer/controllers/SiteController.php
  15. +1
    -1
      producer/views/layouts/main.php
  16. +1
    -1
      producer/views/order/_form.php
  17. +2271
    -0
      tests/codeception/tests/_support/_generated/AcceptanceTesterActions.php
  18. +12
    -0
      tests/codeception/tests/acceptance.suite.yml
  19. +12
    -0
      tests/codeception/tests/functional.suite.yml

+ 5
- 5
backend/controllers/OrderController.php View File

'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()
); );
} }



+ 1
- 1
backend/controllers/ProducerAdminController.php View File

'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;
} }
] ]
], ],

+ 1
- 1
backend/controllers/SiteController.php View File

'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 ;
} }
], ],
], ],

+ 2
- 2
backend/controllers/UserController.php View File

$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()) {

+ 1
- 1
backend/views/development/index.php View File

] ; ] ;
} }
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}',

+ 2
- 2
backend/views/layouts/main.php View File

<?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) {

+ 3
- 3
common/models/User.php View File

* *
* @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;
} }


} }

+ 2
- 2
frontend/controllers/SiteController.php View File

$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);
} }



+ 2
- 2
frontend/controllers/UserController.php View File

*/ */
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

+ 2
- 2
frontend/models/AddProducerForm.php View File

$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;

+ 1
- 1
frontend/views/layouts/main.php View File

$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
]) ])

+ 14
- 14
producer/controllers/OrderController.php View File

->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

+ 1
- 1
producer/controllers/ProducerBaseController.php View File

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() ;

+ 2
- 2
producer/controllers/SiteController.php View File

$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) {

+ 1
- 1
producer/views/layouts/main.php View File

<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">

+ 1
- 1
producer/views/order/_form.php View File

{ {
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>' ;
} }

+ 2271
- 0
tests/codeception/tests/_support/_generated/AcceptanceTesterActions.php
File diff suppressed because it is too large
View File


+ 12
- 0
tests/codeception/tests/acceptance.suite.yml View File

# 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

+ 12
- 0
tests/codeception/tests/functional.suite.yml View File

# 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

Loading…
Cancel
Save