Pārlūkot izejas kodu

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 pirms 6 gadiem
vecāks
revīzija
4063d2b576
19 mainītis faili ar 2336 papildinājumiem un 41 dzēšanām
  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 Parādīt failu

@@ -64,8 +64,8 @@ class OrderController extends BackendController
'allow' => true,
'roles' => ['@'],
'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;
}
]
],
@@ -182,7 +182,7 @@ class OrderController extends BackendController
$order->getAmount(Order::AMOUNT_PAID),
$order->distribution->id_producer,
$order->id_user,
User::getId()
User::getCurrentId()
);
}

@@ -1004,7 +1004,7 @@ class OrderController extends BackendController
$montant_paye,
Producer::getId(),
$commande->id_user,
User::getId()
User::getCurrentId()
);
}

@@ -1334,7 +1334,7 @@ class OrderController extends BackendController
$montant,
Producer::getId(),
$commande->id_user,
User::getId()
User::getCurrentId()
);
}


+ 1
- 1
backend/controllers/ProducerAdminController.php Parādīt failu

@@ -70,7 +70,7 @@ class EtablissementAdminController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getStatus() == USER::STATUS_ADMIN;
return User::getCurrentStatus() == USER::STATUS_ADMIN;
}
]
],

+ 1
- 1
backend/controllers/SiteController.php Parādīt failu

@@ -82,7 +82,7 @@ class SiteController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getStatus() == User::STATUS_ADMIN ;
return User::getCurrentStatus() == User::STATUS_ADMIN ;
}
],
],

+ 2
- 2
backend/controllers/UserController.php Parādīt failu

@@ -161,7 +161,7 @@ class UserController extends BackendController
$user = User::find()->with('userProducer')->where(['id' => $model['id']])->one();
$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()) {
// on envoie le mail de bienvenue si le mail vient d'être défini
@@ -256,7 +256,7 @@ class UserController extends BackendController
$user = User::find()->with('userProducer')->where(['id' => $id])->one();
$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;
if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) {

+ 1
- 1
backend/views/development/index.php Parādīt failu

@@ -162,7 +162,7 @@ $this->params['breadcrumbs'][] = $this->title;
] ;
}
if(User::getStatus() == USER::STATUS_ADMIN) {
if(User::getCurrentStatus() == USER::STATUS_ADMIN) {
$columns[] = [
'class' => 'yii\grid\ActionColumn',
'template' => '{update}',

+ 2
- 2
backend/views/layouts/main.php Parādīt failu

@@ -209,9 +209,9 @@ if(!Yii::$app->user->isGuest) {
<?php endif; ?>
<?php if (!Yii::$app->user->isGuest): ?>
<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>
<?php elseif (User::getStatus() == User::STATUS_ADMIN): ?>
<?php elseif (User::getCurrentStatus() == User::STATUS_ADMIN): ?>
<?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) {

+ 3
- 3
common/models/User.php Parādīt failu

@@ -516,7 +516,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
*
* @return mixed
*/
public static function getId() {
public static function getCurrentId() {
if(!Yii::$app->user->isGuest) {
return Yii::$app->user->identity->id ;
}
@@ -529,7 +529,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
*
* @return integer|boolean
*/
public static function getStatus()
public static function getCurrentStatus()
{
if(!Yii::$app->user->isGuest) {
return Yii::$app->user->identity->status ;
@@ -540,7 +540,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
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 Parādīt failu

@@ -349,7 +349,7 @@ class SiteController extends FrontendController
$producerCodeForm->id_producer = $id ;
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]));
}
@@ -381,7 +381,7 @@ class SiteController extends FrontendController
if (Yii::$app->user->isGuest) {
if ($loginForm->load(Yii::$app->request->post()) && $loginForm->login()) {
Producer::addUser(User::getId(), $id) ;
Producer::addUser(User::getCurrentId(), $id) ;
$this->redirect($returnUrl);
}


+ 2
- 2
frontend/controllers/UserController.php Parādīt failu

@@ -81,12 +81,12 @@ class UserController extends FrontendController
*/
public function actionUpdate()
{
$model = $this->findModel(User::getId());
$model = $this->findModel(User::getCurrentId());

if ($model->load(Yii::$app->request->post()) && $model->validate()) {

// l'utilisateur ne peut pas changer d'adresse email
$oldModel = $this->findModel(User::getId());
$oldModel = $this->findModel(User::getCurrentId());
$model->email = $oldModel->email;

// modification du mot de passe

+ 2
- 2
frontend/models/AddProducerForm.php Parādīt failu

@@ -118,7 +118,7 @@ class AddProducerForm extends Model
$producer = Producer::findOne($this->id_producer);

$userProducerExist = UserProducer::searchOne([
'id_user' => User::getId(),
'id_user' => User::getCurrentId(),
'active' => 0
]) ;

@@ -127,7 +127,7 @@ class AddProducerForm extends Model
$userProducerExist->save();
} else {
$userProducer = new UserProducer();
$userProducer->id_user = User::getId();
$userProducer->id_user = User::getCurrentId();
$userProducer->id_producer = $this->id_producr;
$userProducer->credit = 0;
$userProducer->actif = 1;

+ 1
- 1
frontend/views/layouts/main.php Parādīt failu

@@ -159,7 +159,7 @@ $isHome = (Yii::$app->controller->id == 'site' && Yii::$app->controller->action-
$producersArray = Producer::find()
->joinWith(['userProducer user_producer'])
->where([
'user_producer.id_user' => User::getId(),
'user_producer.id_user' => User::getCurrentId(),
'user_producer.bookmark' => 1,
'producer.active' => 1
])

+ 14
- 14
producer/controllers/OrderController.php Parādīt failu

@@ -121,7 +121,7 @@ class OrderController extends ProducerBaseController
->with('userPointSale')
->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)')
->params([':id_user' => User::getId()])
->params([':id_user' => User::getCurrentId()])
->all();

// jours de production
@@ -187,13 +187,13 @@ class OrderController extends ProducerBaseController
}

$orders = Order::searchAll([
'id_user' => User::getId()
'id_user' => User::getCurrentId()
]) ;

if ($idProducer) {
$userProducer = UserProducer::searchOne([
'id_producer' => $idProducer,
'id_user' => User::getId()
'id_user' => User::getCurrentId()
]) ;

$credit = $userProducer->credit;
@@ -254,7 +254,7 @@ class OrderController extends ProducerBaseController
public function actionRemoveProducer($id = 0)
{
$userProducer = UserProducer::find()
->where(['id_producer' => $id, 'id_user' => User::getId()])
->where(['id_producer' => $id, 'id_user' => User::getCurrentId()])
->one();

$userProducer->active = 0;
@@ -282,11 +282,11 @@ class OrderController extends ProducerBaseController

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) {
$order = new Order;
$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->type = Order::ORIGIN_USER;
}
@@ -420,7 +420,7 @@ class OrderController extends ProducerBaseController
$order->save();
// 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
if (!is_null($order)) {
@@ -473,8 +473,8 @@ class OrderController extends ProducerBaseController
CreditHistory::TYPE_PAYMENT,
$amountRemaining,
$distribution->id_producer,
User::getId(),
User::getId()
User::getCurrentId(),
User::getCurrentId()
);
}
}
@@ -485,8 +485,8 @@ class OrderController extends ProducerBaseController
CreditHistory::TYPE_REFUND,
$amountSurplus,
$distribution->id_producer,
User::getId(),
User::getId()
User::getCurrentId(),
User::getCurrentId()
);
}
}
@@ -529,15 +529,15 @@ class OrderController extends ProducerBaseController
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
if ($order->getAmount(Order::AMOUNT_PAID)) {
$order->creditHistory(
CreditHistory::PAYMENT_REFUND,
$order->getAmount(Order::AMOUNT_PAID),
$order->distribution->id_producer,
User::getId(),
User::getId()
User::getCurrentId(),
User::getCurrentId()
);
}
// delete

+ 1
- 1
producer/controllers/ProducerBaseController.php Parādīt failu

@@ -75,7 +75,7 @@ class ProducerBaseController extends CommonController
else {
$userProducer = UserProducer::find()
->where([
'id_user' => User::getId(),
'id_user' => User::getCurrentId(),
'id_producer' => $producer->id
])
->one() ;

+ 2
- 2
producer/controllers/SiteController.php Parādīt failu

@@ -157,13 +157,13 @@ class SiteController extends ProducerBaseController
$producer = $this->getProducer() ;
$userProducer = UserProducer::find()
->where([
'id_user' => User::getId(),
'id_user' => User::getCurrentId(),
'id_producer' => $producer->id
])
->one() ;
if(!$userProducer) {
$userProducer = Producer::addUser(User::getId(), $producer->id) ;
$userProducer = Producer::addUser(User::getCurrentId(), $producer->id) ;
}
if($userProducer) {

+ 1
- 1
producer/views/layouts/main.php Parādīt failu

@@ -111,7 +111,7 @@ $producer = $this->context->getProducer() ;
<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
$userProducer = UserProducer::findOne(['id_user' => User::getId(), 'id_producer' => $producer->id ]) ;
$userProducer = UserProducer::findOne(['id_user' => User::getCurrentId(), 'id_producer' => $producer->id ]) ;
if($userProducer):
?>
<div id="credit">

+ 1
- 1
producer/views/order/_form.php Parādīt failu

@@ -122,7 +122,7 @@ use yii\widgets\ActiveForm;
{
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>' ;
}

+ 2271
- 0
tests/codeception/tests/_support/_generated/AcceptanceTesterActions.php
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 12
- 0
tests/codeception/tests/acceptance.suite.yml Parādīt failu

@@ -0,0 +1,12 @@
# 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 Parādīt failu

@@ -0,0 +1,12 @@
# 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

Notiek ielāde…
Atcelt
Saglabāt