Bläddra i källkod

Refactoring services #885

refactoring
Guillaume Bourgeois 1 år sedan
förälder
incheckning
f1a25c6816
100 ändrade filer med 1042 tillägg och 574 borttagningar
  1. +8
    -8
      backend/controllers/AccessController.php
  2. +4
    -4
      backend/controllers/CommunicateAdminController.php
  3. +2
    -2
      backend/controllers/CommunicateController.php
  4. +4
    -4
      backend/controllers/CronController.php
  5. +2
    -2
      backend/controllers/DevelopmentController.php
  6. +17
    -17
      backend/controllers/DistributionController.php
  7. +5
    -5
      backend/controllers/DocumentController.php
  8. +12
    -12
      backend/controllers/OrderController.php
  9. +3
    -3
      backend/controllers/PointSaleController.php
  10. +3
    -3
      backend/controllers/ProducerAdminController.php
  11. +2
    -2
      backend/controllers/ProducerController.php
  12. +2
    -2
      backend/controllers/ProducerPriceRangeAdminController.php
  13. +2
    -2
      backend/controllers/ProductCategoryController.php
  14. +5
    -5
      backend/controllers/ProductController.php
  15. +3
    -3
      backend/controllers/ReportController.php
  16. +5
    -5
      backend/controllers/SiteController.php
  17. +2
    -2
      backend/controllers/StatsController.php
  18. +2
    -2
      backend/controllers/TaxRateAdminController.php
  19. +22
    -22
      backend/controllers/UserController.php
  20. +2
    -2
      backend/controllers/UserGroupController.php
  21. +5
    -5
      backend/models/AccessUserProducerForm.php
  22. +4
    -4
      backend/models/CreditForm.php
  23. +3
    -3
      backend/views/development/development.php
  24. +1
    -1
      backend/views/development/index.php
  25. +7
    -7
      backend/views/layouts/header.php
  26. +4
    -4
      backend/views/layouts/main-old.php
  27. +1
    -1
      backend/views/producer-admin/billing.php
  28. +2
    -2
      backend/views/producer-admin/index.php
  29. +1
    -1
      backend/views/producer-price-range-admin/index.php
  30. +1
    -1
      backend/views/producer/billing.php
  31. +2
    -2
      backend/views/product/update/prices/_form.php
  32. +2
    -2
      backend/views/subscription/_form.php
  33. +1
    -1
      backend/views/tax-rate-admin/index.php
  34. +4
    -4
      backend/views/user/index.php
  35. +50
    -9
      common/components/BusinessLogic.php
  36. +6
    -6
      common/components/View.php
  37. +1
    -1
      common/config/main.php
  38. +0
    -20
      common/containers/CreditHistoryContainer.php
  39. +0
    -19
      common/containers/ProducerContainer.php
  40. +0
    -19
      common/containers/ProducerPriceRangeContainer.php
  41. +0
    -19
      common/containers/UserContainer.php
  42. +0
    -19
      common/containers/UserProducerContainer.php
  43. +90
    -0
      common/logic/BaseService.php
  44. +8
    -0
      common/logic/BuilderInterface.php
  45. +9
    -0
      common/logic/ContainerInterface.php
  46. +34
    -0
      common/logic/CreditHistory/CreditHistoryBuilder.php
  47. +47
    -0
      common/logic/CreditHistory/CreditHistoryContainer.php
  48. +15
    -0
      common/logic/CreditHistory/CreditHistoryFactory.php
  49. +2
    -2
      common/logic/CreditHistory/CreditHistoryModel.php
  50. +4
    -3
      common/logic/CreditHistory/CreditHistoryRepository.php
  51. +22
    -39
      common/logic/CreditHistory/CreditHistorySolver.php
  52. +8
    -0
      common/logic/FactoryInterface.php
  53. +19
    -34
      common/logic/Producer/ProducerBuilder.php
  54. +46
    -0
      common/logic/Producer/ProducerContainer.php
  55. +20
    -0
      common/logic/Producer/ProducerFactory.php
  56. +9
    -6
      common/logic/Producer/ProducerModel.php
  57. +9
    -9
      common/logic/Producer/ProducerRepository.php
  58. +25
    -0
      common/logic/Producer/ProducerUtils.php
  59. +26
    -0
      common/logic/ProducerPriceRange/ProducerPriceRangeContainer.php
  60. +95
    -0
      common/logic/ProducerPriceRange/ProducerPriceRangeModel.php
  61. +15
    -0
      common/logic/ProducerPriceRange/ProducerPriceRangeRepository.php
  62. +8
    -0
      common/logic/RepositoryInterface.php
  63. +8
    -0
      common/logic/SolverInterface.php
  64. +22
    -0
      common/logic/User/UserBuilder.php
  65. +47
    -0
      common/logic/User/UserContainer.php
  66. +17
    -0
      common/logic/User/UserFactory.php
  67. +27
    -24
      common/logic/User/UserModel.php
  68. +15
    -0
      common/logic/User/UserRepository.php
  69. +28
    -0
      common/logic/User/UserUtils.php
  70. +22
    -14
      common/logic/UserProducer/UserProducerBuilder.php
  71. +28
    -0
      common/logic/UserProducer/UserProducerContainer.php
  72. +7
    -10
      common/logic/UserProducer/UserProducerModel.php
  73. +7
    -6
      common/logic/UserProducer/UserProducerRepository.php
  74. +8
    -0
      common/logic/UtilsInterface.php
  75. +1
    -1
      common/mail/passwordResetToken-html.php
  76. +1
    -1
      common/mail/passwordResetToken-text.php
  77. +2
    -2
      common/mail/signup-html.php
  78. +2
    -2
      common/mail/signup-text.php
  79. +1
    -1
      common/models/Distribution.php
  80. +1
    -1
      common/models/Document.php
  81. +5
    -5
      common/models/Order.php
  82. +2
    -2
      common/models/OrderStatusHistory.php
  83. +3
    -3
      common/models/PointSale.php
  84. +1
    -1
      common/models/Product.php
  85. +1
    -1
      common/models/ProductPrice.php
  86. +6
    -6
      common/models/Subscription.php
  87. +3
    -3
      common/models/UserModelSearch.php
  88. +0
    -13
      common/repositories/ProducerPriceRangeRepository.php
  89. +0
    -14
      common/repositories/UserRepository.php
  90. +0
    -12
      common/services/ProducerPriceRangeService.php
  91. +0
    -44
      common/services/UserService.php
  92. +1
    -1
      console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php
  93. +10
    -10
      frontend/controllers/SiteController.php
  94. +4
    -4
      frontend/controllers/UserController.php
  95. +6
    -6
      frontend/forms/PasswordResetRequestForm.php
  96. +3
    -3
      frontend/forms/ResetPasswordForm.php
  97. +9
    -9
      frontend/forms/SignupForm.php
  98. +15
    -11
      frontend/views/layouts/main.php
  99. +3
    -1
      frontend/views/site/_prices_producer.php
  100. +13
    -13
      frontend/views/site/index.php

+ 8
- 8
backend/controllers/AccessController.php Visa fil

@@ -40,8 +40,8 @@ namespace backend\controllers;

use common\helpers\GlobalParam;
use common\models\Producer ;
use common\models\User ;
use common\models\UserSearch ;
use common\models\UserModel ;
use common\models\UserModelSearch ;
use backend\models\AccessUserProducerForm ;

/**
@@ -64,7 +64,7 @@ class AccessController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
return UserModel::hasAccessBackend();
}
]
],
@@ -80,7 +80,7 @@ class AccessController extends BackendController
*/
public function actionIndex()
{
$userSearch = new UserSearch ;
$userSearch = new UserModelSearch ;
$usersArray = $userSearch->search()->query->all() ;
$modelAccessUserProducerForm = new AccessUserProducerForm ;
@@ -88,10 +88,10 @@ class AccessController extends BackendController
Yii::$app->getSession()->setFlash('success', 'Droits ajoutés à l\'utilisateur');
}
$usersAccessArray = User::find()
$usersAccessArray = UserModel::find()
->where([
'id_producer' => GlobalParam::getCurrentProducerId(),
'status' => User::STATUS_PRODUCER
'status' => UserModel::STATUS_PRODUCER
])
->all() ;
@@ -110,13 +110,13 @@ class AccessController extends BackendController
*/
public function actionDelete($idUser)
{
$user = User::searchOne([
$user = UserModel::searchOne([
'id' => $idUser
]) ;
if($user) {
$user->id_producer = 0 ;
$user->status = User::STATUS_ACTIVE ;
$user->status = UserModel::STATUS_ACTIVE ;
$user->save() ;
Yii::$app->getSession()->setFlash('success', 'Droits de l\'utilisateur supprimé.');
}

+ 4
- 4
backend/controllers/CommunicateAdminController.php Visa fil

@@ -40,7 +40,7 @@ namespace backend\controllers;

use backend\models\MailForm ;
use yii\web\NotFoundHttpException ;
use common\models\User ;
use common\models\UserModel ;

/**
* UserController implements the CRUD actions for User model.
@@ -64,7 +64,7 @@ class CommunicateAdminController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == USER::STATUS_ADMIN;
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN;
}
]
],
@@ -97,9 +97,9 @@ class CommunicateAdminController extends BackendController
}
}
elseif($section == 'users') {
$users = User::find()
$users = UserModel::find()
->where([
'user.status' => User::STATUS_ACTIVE
'user.status' => UserModel::STATUS_ACTIVE
])
->all() ;
$usersArray = [];

+ 2
- 2
backend/controllers/CommunicateController.php Visa fil

@@ -39,7 +39,7 @@ termes.
namespace backend\controllers;

use common\models\Producer ;
use common\models\User ;
use common\models\UserModel ;

/**
* UserController implements the CRUD actions for User model.
@@ -62,7 +62,7 @@ class CommunicateController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
return UserModel::hasAccessBackend();
}
]
],

+ 4
- 4
backend/controllers/CronController.php Visa fil

@@ -39,7 +39,7 @@
namespace backend\controllers;

use Yii;
use common\models\User;
use common\models\UserModel;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
@@ -204,7 +204,7 @@ class CronController extends BackendController
$order->getAmount(Order::AMOUNT_REMAINING),
$order->distribution->id_producer,
$order->id_user,
User::ID_USER_SYSTEM
UserModel::ID_USER_SYSTEM
);
$countOrders++;
}
@@ -255,9 +255,9 @@ class CronController extends BackendController
$mail->setSubject($subject);

// envoi des emails à tous les comptes users (statut producer) associés à ce producteur
$userArray = User::searchAll([
$userArray = UserModel::searchAll([
'id_producer' => $producer->id,
'status' => User::STATUS_PRODUCER
'status' => UserModel::STATUS_PRODUCER
]);

foreach ($userArray as $user) {

+ 2
- 2
backend/controllers/DevelopmentController.php Visa fil

@@ -40,7 +40,7 @@ namespace backend\controllers;

use common\helpers\GlobalParam;
use Yii;
use common\models\User;
use common\models\UserModel;
use common\models\Development;
use common\models\DevelopmentPriority;
use yii\data\ActiveDataProvider;
@@ -66,7 +66,7 @@ class DevelopmentController extends Controller
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend() ;
return UserModel::hasAccessBackend() ;
}
]
],

+ 17
- 17
backend/controllers/DistributionController.php Visa fil

@@ -48,11 +48,11 @@ use common\models\Product;
use common\models\Producer;
use common\models\Order;
use common\models\ProductCategory;
use common\models\User;
use common\models\UserModel;
use common\models\Subscription;
use common\helpers\Price;
use common\models\PointSaleDistribution;
use common\models\UserProducer;
use common\logic\UserProducer\UserProducerModel;
use DateTime;

class DistributionController extends BackendController
@@ -73,8 +73,8 @@ class DistributionController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == USER::STATUS_ADMIN
|| User::getCurrentStatus() == USER::STATUS_PRODUCER;
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN
|| UserModel::getCurrentStatus() == UserModel::STATUS_PRODUCER;
}
]
],
@@ -379,7 +379,7 @@ class DistributionController extends BackendController
];

// utilisateurs
$usersArray = User::findBy()->all();
$usersArray = UserModel::findBy()->all();

$json['users'] = $usersArray;

@@ -446,7 +446,7 @@ class DistributionController extends BackendController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$user = User::findOne(['id' => $idUser]);
$user = UserModel::findOne(['id' => $idUser]);
$favoritePointSale = $user->getFavoritePointSale();
$idFavoritePointSale = 0;
if ($favoritePointSale) {
@@ -469,7 +469,7 @@ class DistributionController extends BackendController

$order = Order::searchOne(['id' => $idOrder]);
$distribution = Distribution::findOne($idDistribution);
$user = User::findOne($idUser);
$user = UserModel::findOne($idUser);
$pointSale = PointSale::findOne($idPointSale);

$productsArray = Product::find()
@@ -525,7 +525,7 @@ class DistributionController extends BackendController
if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) {
$userProducer = null;
if ($order->id_user) {
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $order->id_user,
'id_producer' => GlobalParam::getCurrentProducerId()
]);
@@ -1571,10 +1571,10 @@ class DistributionController extends BackendController
$order->save();

// init invoice prices
$user = User::searchOne([
$user = UserModel::searchOne([
'id' => $deliveryNote->id_user
]);
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $deliveryNote->id_user,
'id_producer' => GlobalParam::getCurrentProducerId()
]);
@@ -1663,16 +1663,16 @@ class DistributionController extends BackendController

if ($firstOrder->pointSale->id_user) {
$deliveryNote->id_user = $firstOrder->pointSale->id_user;
$user = User::searchOne([
$user = UserModel::searchOne([
'id' => $deliveryNote->id_user
]);
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $deliveryNote->id_user,
'id_producer' => GlobalParam::getCurrentProducerId()
]);
} else {
$user = new User;
$user->type = User::TYPE_LEGAL_PERSON;
$user = new UserModel;
$user->type = UserModel::TYPE_LEGAL_PERSON;
$user->name_legal_person = $firstOrder->pointSale->name;
$user->address = $firstOrder->pointSale->address;
$user->id_producer = 0;
@@ -1684,7 +1684,7 @@ class DistributionController extends BackendController
}
$user->save();

$userProducer = new UserProducer;
$userProducer = new UserProducerModel;
$userProducer->id_user = $user->id;
$userProducer->id_producer = GlobalParam::getCurrentProducerId();
$userProducer->credit = 0;
@@ -1709,10 +1709,10 @@ class DistributionController extends BackendController
}

if (!isset($user) || !$user) {
$user = User::searchOne([
$user = UserModel::searchOne([
'id' => $deliveryNote->id_user
]);
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $deliveryNote->id_user,
'id_producer' => GlobalParam::getCurrentProducerId()
]);

+ 5
- 5
backend/controllers/DocumentController.php Visa fil

@@ -43,11 +43,11 @@ use common\models\Invoice;
use common\models\PointSale;
use common\models\Product;
use common\models\Quotation;
use common\models\User;
use common\models\UserModel;
use common\models\Document;
use common\helpers\GlobalParam;
use common\models\Order;
use common\models\UserProducer;
use common\logic\UserProducer\UserProducerModel;
use kartik\mpdf\Pdf;
use yii\base\UserException;
use yii;
@@ -69,7 +69,7 @@ class DocumentController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
return UserModel::hasAccessBackend();
}
]
],
@@ -349,7 +349,7 @@ class DocumentController extends BackendController
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

if ($idUser > 0) {
$user = User::searchOne([
$user = UserModel::searchOne([
'id' => $idUser
]);

@@ -536,7 +536,7 @@ class DocumentController extends BackendController
);
}

$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $document->user->id,
'id_producer' => GlobalParam::getCurrentProducerId()
]);

+ 12
- 12
backend/controllers/OrderController.php Visa fil

@@ -43,11 +43,11 @@ use common\models\CreditHistory;
use common\models\Order;
use common\models\ProductOrder;
use common\models\Product;
use common\models\User;
use common\models\UserModel;
use common\models\ProductDistribution;
use common\models\Distribution;
use common\models\Producer;
use common\models\UserProducer;
use common\logic\UserProducer\UserProducerModel;

class OrderController extends BackendController
{
@@ -63,8 +63,8 @@ class OrderController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == USER::STATUS_ADMIN
|| User::getCurrentStatus() == USER::STATUS_PRODUCER;
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN
|| UserModel::getCurrentStatus() == UserModel::STATUS_PRODUCER;
}
]
],
@@ -176,7 +176,7 @@ class OrderController extends BackendController

// users
$arrayUsers = [0 => '--'];
$users = User::searchAll([], ['orderby' => 'lastname, name ASC']);
$users = UserModel::searchAll([], ['orderby' => 'lastname, name ASC']);

foreach ($users as $user) {
$arrayUsers[$user->id] = $user->name . ' ' . $user->lastname;
@@ -791,7 +791,7 @@ class OrderController extends BackendController
$order->getAmount(Order::AMOUNT_PAID),
$order->distribution->id_producer,
$order->id_user,
User::getCurrentId()
UserModel::getCurrentId()
);
}

@@ -862,7 +862,7 @@ class OrderController extends BackendController
$userProducer = false;
if (isset($order->user) && $order->user) {
$user = $order->user;
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $user->id,
'id_producer' => $order->distribution->id_producer
]);
@@ -960,10 +960,10 @@ class OrderController extends BackendController
$order->id_user = 0;
}

$user = User::searchOne(['id' => $order->id_user]);
$user = UserModel::searchOne(['id' => $order->id_user]);
$userProducer = false;
if ($user) {
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $user->id,
'id_producer' => $order->distribution->id_producer
]);
@@ -1033,7 +1033,7 @@ class OrderController extends BackendController
$amountPaid,
GlobalParam::getCurrentProducerId(),
$oldIdUser,
User::getCurrentId()
UserModel::getCurrentId()
);
$order = Order::searchOne(['id' => $order->id]);
}
@@ -1058,7 +1058,7 @@ class OrderController extends BackendController
$html = '';

if ($order->id_user) {
$userProducer = UserProducer::find()
$userProducer = UserProducerModel::find()
->where([
'id_user' => $order->id_user,
'id_producer' => $order->distribution->id_producer
@@ -1145,7 +1145,7 @@ class OrderController extends BackendController
$amount,
GlobalParam::getCurrentProducerId(),
$order->id_user,
User::getCurrentId()
UserModel::getCurrentId()
);
}


+ 3
- 3
backend/controllers/PointSaleController.php Visa fil

@@ -45,7 +45,7 @@ use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\User;
use common\models\UserModel;
use common\models\UserPointSale;
use common\models\Order ;
use common\models\Producer ;
@@ -73,7 +73,7 @@ class PointSaleController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
return UserModel::hasAccessBackend();
}
],
],
@@ -157,7 +157,7 @@ class PointSaleController extends BackendController
*/
public function initForm($id = 0)
{
$users = User::findBy()
$users = UserModel::findBy()
->leftJoin('user_point_sale', 'user_point_sale.id_user = user.id AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $id])
->orderBy('user_point_sale.id_point_sale DESC, lastname ASC, name ASC')
->all();

+ 3
- 3
backend/controllers/ProducerAdminController.php Visa fil

@@ -40,7 +40,7 @@ namespace backend\controllers;

use common\helpers\GlobalParam;
use Yii;
use common\models\User;
use common\models\UserModel;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
@@ -74,7 +74,7 @@ class ProducerAdminController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == USER::STATUS_ADMIN;
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN;
}
]
],
@@ -154,7 +154,7 @@ class ProducerAdminController extends BackendController
$fromProducerId = (int) $fromProducerId;
$toProducerId = (int) $toProducerId;
$count = 0;
$usersArray = User::findBy(['id_producer' => $fromProducerId])->all();
$usersArray = UserModel::findBy(['id_producer' => $fromProducerId])->all();

foreach($usersArray as $user) {
$idUser = $user['user_id'];

+ 2
- 2
backend/controllers/ProducerController.php Visa fil

@@ -41,7 +41,7 @@ namespace backend\controllers;
use common\helpers\GlobalParam;
use common\models\ProducerPriceRange;
use Yii;
use common\models\User;
use common\models\UserModel;
use backend\models\MailForm;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
@@ -76,7 +76,7 @@ class ProducerController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
return UserModel::hasAccessBackend();
}
]
],

+ 2
- 2
backend/controllers/ProducerPriceRangeAdminController.php Visa fil

@@ -40,7 +40,7 @@ namespace backend\controllers;

use common\models\ProducerPriceRange;
use Yii;
use common\models\User;
use common\models\UserModel;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
@@ -67,7 +67,7 @@ class ProducerPriceRangeAdminController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == USER::STATUS_ADMIN;
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN;
}
]
],

+ 2
- 2
backend/controllers/ProductCategoryController.php Visa fil

@@ -50,7 +50,7 @@ use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\User;
use common\models\UserModel;
use common\models\UserPointSale;
use common\models\Order;
use common\models\Producer;
@@ -77,7 +77,7 @@ class ProductCategoryController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
return UserModel::hasAccessBackend();
}
],
],

+ 5
- 5
backend/controllers/ProductController.php Visa fil

@@ -43,13 +43,13 @@ use common\models\ProductDistribution;
use common\models\ProductPrice;
use common\models\ProductPriceSearch;
use common\models\ProductSearch;
use common\models\UserSearch;
use common\models\UserModelSearch;
use Yii;
use yii\filters\AccessControl;
use common\models\Product;
use common\models\Distribution;
use common\models\User;
use common\models\UserProducer;
use common\models\UserModel;
use common\logic\UserProducer\UserProducerModel;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
@@ -79,7 +79,7 @@ class ProductController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
return UserModel::hasAccessBackend();
}
]
],
@@ -230,7 +230,7 @@ class ProductController extends BackendController
'id_product' => $id
]));

$userProducerWithProductPercent = UserProducer::searchAll([], [
$userProducerWithProductPercent = UserProducerModel::searchAll([], [
'join_with' => ['user'],
'conditions' => 'user_producer.product_price_percent != 0',
]);

+ 3
- 3
backend/controllers/ReportController.php Visa fil

@@ -41,7 +41,7 @@ namespace backend\controllers;
use common\helpers\GlobalParam;
use Yii;
use yii\filters\AccessControl;
use common\models\User;
use common\models\UserModel;
use common\models\Distribution ;

class ReportController extends BackendController
@@ -58,7 +58,7 @@ class ReportController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend() ;
return UserModel::hasAccessBackend() ;
}
]
],
@@ -76,7 +76,7 @@ class ReportController extends BackendController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$usersArray = User::findBy()->all() ;
$usersArray = UserModel::findBy()->all() ;
$pointsSaleArray = PointSale::searchAll() ;
// distributions

+ 5
- 5
backend/controllers/SiteController.php Visa fil

@@ -42,7 +42,7 @@ use common\helpers\GlobalParam;
use Yii;
use yii\filters\AccessControl;
use common\forms\LoginForm;
use common\models\User;
use common\models\UserModel;
use yii\filters\VerbFilter;
use common\models\Product;
use common\models\PointSale;
@@ -74,7 +74,7 @@ class SiteController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend() ;
return UserModel::hasAccessBackend() ;
}
],
[
@@ -82,7 +82,7 @@ class SiteController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == User::STATUS_ADMIN ;
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN ;
}
],
],
@@ -175,12 +175,12 @@ class SiteController extends BackendController
]);

// clients
$usersArray = User::findBy()
$usersArray = UserModel::findBy()
->orderBy('created_at DESC')
->limit(5)
->all();

$usersNegativeCredit = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()])
$usersNegativeCredit = UserModel::findBy(['id_producer' => GlobalParam::getCurrentProducerId()])
->andWhere('user_producer.credit < 0')
->all();


+ 2
- 2
backend/controllers/StatsController.php Visa fil

@@ -42,7 +42,7 @@ use common\helpers\GlobalParam;
use yii\web\Controller;
use yii\filters\AccessControl;
use Yii;
use common\models\User;
use common\models\UserModel;
use common\models\Order;
use DateTime;
use DateInterval;
@@ -61,7 +61,7 @@ class StatsController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend() ;
return UserModel::hasAccessBackend() ;
}
]
],

+ 2
- 2
backend/controllers/TaxRateAdminController.php Visa fil

@@ -40,7 +40,7 @@ namespace backend\controllers;

use common\models\TaxRate;
use Yii;
use common\models\User;
use common\models\UserModel;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
@@ -71,7 +71,7 @@ class TaxRateAdminController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == USER::STATUS_ADMIN;
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN;
}
]
],

+ 22
- 22
backend/controllers/UserController.php Visa fil

@@ -41,12 +41,12 @@ namespace backend\controllers;
use backend\models\CreditForm;
use common\helpers\GlobalParam;
use common\helpers\Mailjet;
use common\models\User;
use common\models\UserModel;
use common\models\Producer;
use common\models\Distribution;
use backend\models\MailForm;
use common\models\UserGroup;
use common\models\UserProducer;
use common\logic\UserProducer\UserProducerModel;
use common\models\UserPointSale;
use common\models\PointSale;
use common\models\UserUserGroup;
@@ -72,7 +72,7 @@ class UserController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
return UserModel::hasAccessBackend();
}
]
],
@@ -144,7 +144,7 @@ class UserController extends BackendController
}

// product price percent
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_producer' => GlobalParam::getCurrentProducerId(),
'id_user' => $model->id
]);
@@ -184,13 +184,13 @@ class UserController extends BackendController
*/
public function actionCreate()
{
$model = new User();
$model = new UserModel();

$userExist = false;
$posts = Yii::$app->request->post();

if ($posts && isset($posts['User']['email']) && strlen($posts['User']['email']) > 0) {
$userExist = User::searchOne([
$userExist = UserModel::searchOne([
'email' => $posts['User']['email']
]);
}
@@ -215,7 +215,7 @@ class UserController extends BackendController
$model->save();

// liaison etablissement / user
$useProducer = new UserProducer();
$useProducer = new UserProducerModel();
$useProducer->id_user = $model->id;
$useProducer->id_producer = GlobalParam::getCurrentProducerId();
$useProducer->credit = 0;
@@ -228,7 +228,7 @@ class UserController extends BackendController
$this->processProductPricePercent($model);

Yii::$app->getSession()->setFlash('success', 'Utilisateur créé.');
$model = new User();
$model = new UserModel();
}
}

@@ -250,8 +250,8 @@ class UserController extends BackendController

// Moodification du profil
$previousMail = $model->email;
$user = User::find()->with('userProducer')->where(['id' => $model['id']])->one();
$userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]);
$user = UserModel::find()->with('userProducer')->where(['id' => $model['id']])->one();
$userBelongToProducer = UserProducerModel::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]);
if ($userBelongToProducer) {
if ($model->load(Yii::$app->request->post()) && $model->save()) {

@@ -306,7 +306,7 @@ class UserController extends BackendController
/**
* Lie un utilisateur aux points de vente sélectionnés.
*
* @param User $modelUser
* @param UserModel $modelUser
*/
public function processLinkPointSale($modelUser)
{
@@ -334,7 +334,7 @@ class UserController extends BackendController
/**
* Lie un utilisateur aux groupes d'utilisateurs sélectionnés.
*
* @param User $modelUser
* @param UserModel $modelUser
*/
public function processLinkUserGroup($modelUser)
{
@@ -363,7 +363,7 @@ class UserController extends BackendController

public function processProductPricePercent($model)
{
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_producer' => GlobalParam::getCurrentProducerId(),
'id_user' => $model->id
]);
@@ -379,7 +379,7 @@ class UserController extends BackendController
*/
public function actionDelete($id)
{
$userProducer = UserProducer::findOne([
$userProducer = UserProducerModel::findOne([
'id_user' => $id,
'id_producer' => GlobalParam::getCurrentProducerId()
]);
@@ -416,7 +416,7 @@ class UserController extends BackendController
$usersPointSaleLink = 1;
}

$users = User::findBy([
$users = UserModel::findBy([
'id_producer' => GlobalParam::getCurrentProducerId(),
'id_point_sale' => $idPointSale,
'users_point_sale_link' => $usersPointSaleLink,
@@ -495,10 +495,10 @@ class UserController extends BackendController
*/
public function actionCredit($id)
{
$user = User::find()->with('userProducer')->where(['id' => $id])->one();
$userProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]);
$user = UserModel::find()->with('userProducer')->where(['id' => $id])->one();
$userProducer = UserProducerModel::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]);

if (($userProducer) || User::getCurrentStatus() == User::STATUS_ADMIN) {
if (($userProducer) || UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN) {

$creditForm = new CreditForm();
if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) {
@@ -536,7 +536,7 @@ class UserController extends BackendController
*/
public function actionOrders($id)
{
$user = User::findOne($id);
$user = UserModel::findOne($id);
$searchModel = new OrderSearch;
$dataProvider = $searchModel->search(array_merge(Yii::$app->request->queryParams, ['id_user' => $id]));

@@ -556,7 +556,7 @@ class UserController extends BackendController
*/
public function actionStateCredit($idUser, $state)
{
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $idUser
]);

@@ -572,12 +572,12 @@ class UserController extends BackendController
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return User the loaded model
* @return UserModel the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = User::findOne($id)) !== null) {
if (($model = UserModel::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');

+ 2
- 2
backend/controllers/UserGroupController.php Visa fil

@@ -48,7 +48,7 @@ use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\User;
use common\models\UserModel;
use common\models\UserPointSale;
use common\models\Order;
use common\models\Producer;
@@ -76,7 +76,7 @@ class UserGroupController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
return UserModel::hasAccessBackend();
}
],
],

+ 5
- 5
backend/models/AccessUserProducerForm.php Visa fil

@@ -41,9 +41,9 @@ namespace backend\models;
use common\helpers\GlobalParam;
use Yii;
use yii\base\Model;
use common\models\User ;
use common\models\UserModel ;
use common\models\Producer ;
use common\models\UserProducer ;
use common\logic\UserProducer\UserProducerModel ;

/**
* ContactForm is the model behind the contact form.
@@ -76,14 +76,14 @@ class AccessUserProducerForm extends Model
public function save()
{
$user = User::searchOne([
$user = UserModel::searchOne([
'id' => $this->id_user
]) ;
if($user) {
$user->id_producer = GlobalParam::getCurrentProducerId() ;
if($user->status != User::STATUS_PRODUCER && $user->status != User::STATUS_ADMIN) {
$user->status = User::STATUS_PRODUCER ;
if($user->status != UserModel::STATUS_PRODUCER && $user->status != UserModel::STATUS_ADMIN) {
$user->status = UserModel::STATUS_PRODUCER ;
}
return $user->save();
}

+ 4
- 4
backend/models/CreditForm.php Visa fil

@@ -43,9 +43,9 @@ use common\helpers\Mailjet;
use Yii;
use yii\base\Model;
use common\models\CreditHistory ;
use common\models\User ;
use common\models\UserModel ;
use common\models\Producer ;
use common\models\UserProducer ;
use common\logic\UserProducer\UserProducerModel ;
use common\helpers\Mail ;

/**
@@ -117,9 +117,9 @@ class CreditForm extends Model
// on prévient l'utilisateur que son compte vient d'être crédité
if($this->send_mail) {
$user = User::findOne($this->id_user) ;
$user = UserModel::findOne($this->id_user) ;
$producer = GlobalParam::getCurrentProducer() ;
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $this->id_user
]);


+ 3
- 3
backend/views/development/development.php Visa fil

@@ -40,7 +40,7 @@ use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Development;
use common\models\DevelopmentPriority;
use common\models\User;
use common\models\UserModel;
use common\helpers\Url;
use common\helpers\GlobalParam;

@@ -126,7 +126,7 @@ $this->addBreadcrumb($this->getTitle());
];


if (User::hasAccessBackend()) {
if (UserModel::hasAccessBackend()) {

$columns[] = [
'header' => 'Priorité',
@@ -160,7 +160,7 @@ $this->addBreadcrumb($this->getTitle());
];
}

if (User::getCurrentStatus() == USER::STATUS_ADMIN) {
if (UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN) {
$columns[] = [
'class' => 'yii\grid\ActionColumn',
'template' => '{update}',

+ 1
- 1
backend/views/development/index.php Visa fil

@@ -40,7 +40,7 @@ use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Development;
use common\models\DevelopmentPriority;
use common\models\User;
use common\models\UserModel;
use common\helpers\Url;
use common\helpers\GlobalParam;


+ 7
- 7
backend/views/layouts/header.php Visa fil

@@ -38,7 +38,7 @@

use yii\helpers\Html;
use common\models\Producer;
use common\models\User;
use common\models\UserModel;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use common\helpers\GlobalParam;
@@ -63,7 +63,7 @@ $producer = GlobalParam::getCurrentProducer();
<div class="navbar-custom-menu">
<?php

$usersArray = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()])
$usersArray = UserModel::findBy(['id_producer' => GlobalParam::getCurrentProducerId()])
->andWhere('CAST(FROM_UNIXTIME(user.created_at) AS date) > \'' . date("Y-m-d", strtotime("-7 days")) . '\'')
->orderBy('created_at DESC')
->all();
@@ -175,7 +175,7 @@ $producer = GlobalParam::getCurrentProducer();

<?php

$usersNegativeCreditArray = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()])
$usersNegativeCreditArray = UserModel::findBy(['id_producer' => GlobalParam::getCurrentProducerId()])
->andWhere('user_producer.credit < 0')
->orderBy('lastname, name ASC')
->all();
@@ -198,7 +198,7 @@ $producer = GlobalParam::getCurrentProducer();
<?php foreach ($usersNegativeCreditArray as $user): ?>
<li>
<a href="<?= Yii::$app->urlManagerBackend->createUrl(['user/credit', 'id' => $user['user_id']]); ?>">
<h5><?= User::getUsernameFromArray($user); ?>
<h5><?= UserModel::getUsernameFromArray($user); ?>
<small>
<i class="fa fa-euro"></i> <?= Price::format($user['credit']); ?>
</small>
@@ -215,7 +215,7 @@ $producer = GlobalParam::getCurrentProducer();

</li>

<?php if (User::isCurrentProducer() || User::isCurrentAdmin()): ?>
<?php if (UserModel::isCurrentProducer() || UserModel::isCurrentAdmin()): ?>
<li class="dropdown producer-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">

@@ -229,7 +229,7 @@ $producer = GlobalParam::getCurrentProducer();
</a>

<ul class="dropdown-menu">
<?php if (User::isCurrentAdmin()): ?>
<?php if (UserModel::isCurrentAdmin()): ?>
<li>
<a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => GlobalParam::getCurrentProducer()->slug]); ?>">
<i class="fa fa-th-large"></i>
@@ -258,7 +258,7 @@ $producer = GlobalParam::getCurrentProducer();
<li class="dropdown user user-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-user"></i>
<span class="hidden-xs"><?= Html::encode(User::getCurrent()->name . ' ' . User::getCurrent()->lastname); ?></span>
<span class="hidden-xs"><?= Html::encode(UserModel::getCurrent()->name . ' ' . UserModel::getCurrent()->lastname); ?></span>
<i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-menu">

+ 4
- 4
backend/views/layouts/main-old.php Visa fil

@@ -41,7 +41,7 @@ use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use common\models\Producer;
use common\models\User;
use common\models\UserModel;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use common\helpers\Url;
@@ -167,7 +167,7 @@ if (!Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Connexion', 'url' => ['/site/login']];
} else {

if (Yii::$app->user->identity->status == USER::STATUS_ADMIN) {
if (Yii::$app->user->identity->status == UserModel::STATUS_ADMIN) {
$menuItems[] = [
'label' => '<span class="glyphicon glyphicon-asterisk"></span>',
'url' => '#',
@@ -211,9 +211,9 @@ if (!Yii::$app->user->isGuest) {
<?php endif; ?>
<?php if (!Yii::$app->user->isGuest): ?>
<div class="name-producer">
<?php if (User::getCurrentStatus() == User::STATUS_PRODUCER): ?>
<?php if (UserModel::getCurrentStatus() == UserModel::STATUS_PRODUCER): ?>
<span><?= Html::encode(Yii::$app->user->identity->getNameProducer()); ?></span>
<?php elseif (User::getCurrentStatus() == User::STATUS_ADMIN): ?>
<?php elseif (UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN): ?>
<?php $form = ActiveForm::begin(['id' => 'select-producer']); ?>
<?=
Html::dropDownList('select_producer', GlobalParam::getCurrentProducerId(), ArrayHelper::map(Producer::find()->orderBy('name ASC')->all(), 'id', function ($model, $defaultValue) {

+ 1
- 1
backend/views/producer-admin/billing.php Visa fil

@@ -38,7 +38,7 @@ termes.

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\User ;
use common\models\UserModel ;
use common\models\Etablissement ;

$this->title = 'Facturation';

+ 2
- 2
backend/views/producer-admin/index.php Visa fil

@@ -38,7 +38,7 @@ termes.

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\User ;
use common\models\UserModel ;
use common\models\Producer ;
use common\models\Distribution ;

@@ -119,7 +119,7 @@ $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphico
else {
foreach($model->user as $u)
{
if($u->status == User::STATUS_PRODUCER)
if($u->status == UserModel::STATUS_PRODUCER)
{
return Html::encode($u->lastname.' '.$u->name)
.'<br />'.Html::encode($u->email)

+ 1
- 1
backend/views/producer-price-range-admin/index.php Visa fil

@@ -38,7 +38,7 @@

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\User;
use common\models\UserModel;
use common\models\Producer;
use common\models\Distribution;


+ 1
- 1
backend/views/producer/billing.php Visa fil

@@ -38,7 +38,7 @@ termes.

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\User ;
use common\models\UserModel ;
use common\models\Producer ;
use yii\bootstrap\ActiveForm;


+ 2
- 2
backend/views/product/update/prices/_form.php Visa fil

@@ -7,7 +7,7 @@ use yii\helpers\ArrayHelper;
use common\models\TaxRate;
use common\models\Producer;
use common\helpers\GlobalParam;
use common\models\User ;
use common\models\UserModel ;


?>
@@ -27,7 +27,7 @@ use common\models\User ;
'options' => ['enctype' => 'multipart/form-data']
]); ?>

<?= $form->field($model, 'id_user')->dropDownList(User::populateDropdownList()); ?>
<?= $form->field($model, 'id_user')->dropDownList(UserModel::populateDropdownList()); ?>
<?= $form->field($model, 'id_user_group')->dropDownList(UserGroup::populateDropdownList()); ?>
<?= $form->field($model, 'id_point_sale')->dropDownList(PointSale::populateDropdownList()); ?>
<?= $form->field($model, 'from_quantity')->label('À partir de la quantité ('.Product::strUnit(Product::getRefUnit($modelProduct->unit), 'wording').')'); ?>

+ 2
- 2
backend/views/subscription/_form.php Visa fil

@@ -39,7 +39,7 @@ termes.
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper ;
use common\models\User ;
use common\models\UserModel ;
use common\models\PointSale ;
use common\helpers\GlobalParam ;

@@ -53,7 +53,7 @@ use common\helpers\GlobalParam ;
<?= $form->field($model, 'id')->hiddenInput() ?>
<?php endif; ?>
<div class="col-md-5" id="bloc-select-user">
<?= $form->field($model, 'id_user')->dropDownList(User::populateDropdownList(), ['class' => 'select2']); ?>
<?= $form->field($model, 'id_user')->dropDownList(UserModel::populateDropdownList(), ['class' => 'select2']); ?>
</div>
<div class="col-md-1" id="or-user">
<span>OU</span>

+ 1
- 1
backend/views/tax-rate-admin/index.php Visa fil

@@ -38,7 +38,7 @@

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\User;
use common\models\UserModel;
use common\models\Producer;
use common\models\Distribution;


+ 4
- 4
backend/views/user/index.php Visa fil

@@ -38,7 +38,7 @@

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\User;
use common\models\UserModel;
use common\models\Order;

$this->setTitle('Utilisateurs');
@@ -67,14 +67,14 @@ $this->render('_menu', [
'attribute' => 'username',
'label' => 'Nom',
'value' => function ($model) {
return User::getUsernameFromArray($model);
return UserModel::getUsernameFromArray($model);
}
],
[
'attribute' => 'type',
'label' => 'Type',
'value' => function ($model) {
$typeArray = User::getTypeChoicesArray();
$typeArray = UserModel::getTypeChoicesArray();
if(isset($typeArray[$model['type']])) {
return $typeArray[$model['type']];
}
@@ -159,7 +159,7 @@ $this->render('_menu', [
'buttons' => [
'update' => function ($url, $model) {
$url = Yii::$app->urlManager->createUrl(['user/update', 'id' => $model->id]);
$user = User::find()->with('userProducer')->where(['id' => $model->id])->one();
$user = UserModel::find()->with('userProducer')->where(['id' => $model->id])->one();
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
]);

+ 50
- 9
common/components/BusinessLogic.php Visa fil

@@ -2,36 +2,77 @@

namespace common\components;

use common\containers\CreditHistoryContainer;
use common\containers\ProducerPriceRangeContainer;
use common\containers\UserContainer;
use common\containers\ProducerContainer;
use common\containers\UserProducerContainer;
use common\logic\CreditHistory\CreditHistoryContainer;
use common\logic\Producer\ProducerContainer;
use common\logic\ProducerPriceRange\ProducerPriceRangeContainer;
use common\logic\User\UserContainer;
use yii\base\ErrorException;

class BusinessLogic
{
public function getUserContainer()
public function getContainers()
{
return [
$this->getUserContainer(),
$this->getProducerContainer(),
$this->getCreditHistoryContainer(),
$this->getProducerPriceRangeContainer(),
$this->getUserProducerContainer(),
];
}

public function getUserContainer(): UserContainer
{
return new UserContainer();
}

public function getProducerContainer()
public function getProducerContainer(): ProducerContainer
{
return new ProducerContainer();
}

public function getProducerPriceRangeContainer()
public function getProducerPriceRangeContainer(): ProducerPriceRangeContainer
{
return new ProducerPriceRangeContainer();
}

public function getUserProducerContainer()
public function getUserProducerContainer(): UserProducerContainer
{
return new UserProducerContainer();
}

public function getCreditHistoryContainer()
public function getCreditHistoryContainer(): CreditHistoryContainer
{
return new CreditHistoryContainer();
}

/*
* Hiérarchie des apps
*/

public function getContainerLevelHierarchyByService($serviceClass): int
{
$containersArray = $this->getContainers();
$entityFqcnService = $this->getEntityFqcnByService($serviceClass);

foreach($containersArray as $key => $container) {
if($container->getEntityFqcn() == $entityFqcnService) {
return $key;
}
}
}

public function getEntityFqcnByService(string $serviceClass): string
{
$containersArray = $this->getContainers();

foreach($containersArray as $container) {
if(in_array($serviceClass, $container->getServices())) {
return $container->getEntityFqcn();
}
}

throw new ErrorException('Service '.$serviceClass.' introuvable dans le container.');
}
}

+ 6
- 6
common/components/View.php Visa fil

@@ -46,7 +46,7 @@ class View extends \yii\web\View

public function getLogic()
{
return Yii::$app->logic;
return \Yii::$app->logic;
}

public function setTitle($title, $page_title = '')
@@ -77,7 +77,7 @@ class View extends \yii\web\View
public function getControllerAction()
{
return Yii::$app->controller->id.'/'.Yii::$app->controller->action->id ;
return \Yii::$app->controller->id.'/'.\Yii::$app->controller->action->id ;
}
public function addBreadcrumb($breadcrumb)
@@ -92,7 +92,7 @@ class View extends \yii\web\View
public function setMeta($name, $content)
{
Yii::$app->view->registerMetaTag([
\Yii::$app->view->registerMetaTag([
'name' => $name,
'content' => $content
]);
@@ -100,16 +100,16 @@ class View extends \yii\web\View

public function getUrlManagerFrontend()
{
return Yii::$app->urlManagerFrontend;
return \Yii::$app->urlManagerFrontend;
}

public function getUrlManagerProducer()
{
return Yii::$app->urlManagerProducer;
return \Yii::$app->urlManagerProducer;
}

public function getUrlManagerBackend()
{
return Yii::$app->urlManagerBackend;
return \Yii::$app->urlManagerBackend;
}
}

+ 1
- 1
common/config/main.php Visa fil

@@ -61,7 +61,7 @@ return [
],
'user' => [
'class' => 'yii\web\User',
'identityClass' => 'common\models\User',
'identityClass' => 'common\logic\User\UserModel',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => 'distrib',

+ 0
- 20
common/containers/CreditHistoryContainer.php Visa fil

@@ -1,20 +0,0 @@
<?php

namespace common\containers;

use common\repositories\UserRepository;
use common\services\CreditHistoryService;
use common\services\UserService;

class CreditHistoryContainer
{
public function getService()
{
return new CreditHistoryService();
}

public function getRepository()
{
return new CreditHistoryService();
}
}

+ 0
- 19
common/containers/ProducerContainer.php Visa fil

@@ -1,19 +0,0 @@
<?php

namespace common\containers;

use common\repositories\ProducerRepository;
use common\services\ProducerService;

class ProducerContainer
{
public function getService()
{
return new ProducerService();
}

public function getRepository()
{
return new ProducerRepository();
}
}

+ 0
- 19
common/containers/ProducerPriceRangeContainer.php Visa fil

@@ -1,19 +0,0 @@
<?php

namespace common\containers;

use common\repositories\ProducerPriceRangeRepository;
use common\services\ProducerPriceRangeService;

class ProducerPriceRangeContainer
{
public function getService()
{
return new ProducerPriceRangeService();
}

public function getRepository()
{
return new ProducerPriceRangeRepository();
}
}

+ 0
- 19
common/containers/UserContainer.php Visa fil

@@ -1,19 +0,0 @@
<?php

namespace common\containers;

use common\repositories\UserRepository;
use common\services\UserService;

class UserContainer
{
public function getService()
{
return new UserService();
}

public function getRepository()
{
return new UserRepository();
}
}

+ 0
- 19
common/containers/UserProducerContainer.php Visa fil

@@ -1,19 +0,0 @@
<?php

namespace common\containers;

use common\repositories\UserProducerRepository;
use common\services\UserProducerService;

class UserProducerContainer
{
public function getService()
{
return new UserProducerService();
}

public function getRepository()
{
return new UserProducerRepository();
}
}

+ 90
- 0
common/logic/BaseService.php Visa fil

@@ -0,0 +1,90 @@
<?php

namespace common\logic;

use yii\base\ErrorException;

class BaseService
{
public function getHierarchy(): array
{
return [
FactoryInterface::class,
SolverInterface::class,
BuilderInterface::class,
ServiceInterface::class,
];
}

public function loadService(string $serviceClass)
{
if(!$this->respectHierarchy($serviceClass)) {
throw new ErrorException('Le service '.$serviceClass.' ne peut pas être chargé ici.');
}

return new $serviceClass;
}

public function respectHierarchy(string $serviceClassAsked): bool
{
$businessLogic = \Yii::$app->logic;
$serviceCurrentClass = get_class($this);
$levelHierarchyServiceAsked = $this->getServiceLevelHierarchy($serviceClassAsked);
$levelHierarchyServiceCurrent = $this->getServiceLevelHierarchy($serviceCurrentClass);

if($levelHierarchyServiceAsked < $levelHierarchyServiceCurrent) {
return true;
}
elseif($levelHierarchyServiceAsked == $levelHierarchyServiceCurrent
&& $businessLogic->getContainerLevelHierarchyByService($serviceClassAsked)
< $businessLogic->getContainerLevelHierarchyByService($serviceCurrentClass)) {

return true;
}

return false;
}

public function getServiceLevelHierarchy(string $serviceClass): int
{
$hierarchyArray = $this->getHierarchy();

foreach($hierarchyArray as $key => $interface) {
if($this->classImplementsInterface($interface, $serviceClass)) {
return $key;
}
}

throw new ErrorException('Service introuvable dans la hiérarchie. Attention à bien ajouter
FactoryInterface, SolverInterface ou BuilderInterface au service.');
}

public function isFactory(): bool
{
return $this->classImplementsInterface(FactoryInterface::class);
}

public function isSolver(): bool
{
return $this->classImplementsInterface(SolverInterface::class);
}

public function isBuilder(): bool
{
return $this->classImplementsInterface(BuilderInterface::class);
}

public function isService(): bool
{
return $this->classImplementsInterface(ServiceInterface::class);
}

protected function classImplementsInterface(string $interface, $object = null): bool
{
if(is_null($object)) {
$object = $this;
}

return class_implements($object, $interface);
}
}

+ 8
- 0
common/logic/BuilderInterface.php Visa fil

@@ -0,0 +1,8 @@
<?php

namespace common\logic;

interface BuilderInterface
{

}

+ 9
- 0
common/logic/ContainerInterface.php Visa fil

@@ -0,0 +1,9 @@
<?php

namespace common\logic;

interface ContainerInterface
{
public function getEntityFqcn(): string;
public function getServices(): array;
}

+ 34
- 0
common/logic/CreditHistory/CreditHistoryBuilder.php Visa fil

@@ -0,0 +1,34 @@
<?php

namespace common\logic\CreditHistory;

use common\logic\BaseService;
use common\logic\BuilderInterface;
use common\services\CreditHistory\CreditHistorySolver;

class CreditHistoryBuilder extends BaseService implements BuilderInterface
{
protected CreditHistorySolver $creditHistorySolver;

public function __construct()
{
$this->creditHistorySolver = $this->loadService(CreditHistorySolver::class);
}

public function save(CreditHistory $creditHistory): bool
{
if ($creditHistory->getAmount() > -0.01 && $creditHistory->getAmount() < 0.01) {
return false;
}

// Initialisation du commentaire avant sauvegarde
$creditHistory->setComment($creditHistory->getComment() . $this->creditHistorySolver->getStrComment($creditHistory));

$creditHistory->save();

// Mise à jour du crédit au niveau de UserProducer
\Yii::$app->logic->getUserProducerContainer()->getService()->updateCredit($creditHistory);

return true;
}
}

+ 47
- 0
common/logic/CreditHistory/CreditHistoryContainer.php Visa fil

@@ -0,0 +1,47 @@
<?php

namespace common\logic\CreditHistory;

use common\logic\ContainerInterface;
use common\logic\CreditHistory\CreditHistoryBuilder;
use common\logic\CreditHistory\CreditHistoryFactory;
use common\logic\CreditHistory\CreditHistoryRepository;
use common\logic\CreditHistory\CreditHistorySolver;

class CreditHistoryContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return CreditHistory::class;
}

public function getServices(): array
{
return [
CreditHistoryFactory::class,
CreditHistorySolver::class,
CreditHistoryBuilder::class,
CreditHistoryRepository::class,
];
}

public function getFactory(): CreditHistoryFactory
{
return new CreditHistoryFactory();
}

public function getSolver(): CreditHistorySolver
{
return new CreditHistorySolver();
}

public function getBuilder(): CreditHistoryBuilder
{
return new CreditHistoryBuilder();
}

public function getRepository(): CreditHistoryRepository
{
return new CreditHistoryRepository();
}
}

+ 15
- 0
common/logic/CreditHistory/CreditHistoryFactory.php Visa fil

@@ -0,0 +1,15 @@
<?php

namespace common\logic\CreditHistory;

use common\logic\FactoryInterface;

class CreditHistoryFactory implements FactoryInterface
{
public function create()
{
$creditHistory = new CreditHistory();

return $creditHistory;
}
}

common/models/CreditHistory.php → common/logic/CreditHistory/CreditHistoryModel.php Visa fil

@@ -36,13 +36,13 @@
* termes.
*/

namespace common\models;
namespace common\logic\CreditHistory;

use common\components\ActiveRecordCommon;
use yii\db\ActiveQuery;


class CreditHistory extends ActiveRecordCommon
class CreditHistoryModel extends ActiveRecordCommon
{
const TYPE_INITIAL_CREDIT = 'initial-credit';
const TYPE_CREDIT = 'credit';

common/repositories/CreditHistoryRepository.php → common/logic/CreditHistory/CreditHistoryRepository.php Visa fil

@@ -1,10 +1,11 @@
<?php

namespace common\repositories;
namespace common\logic\CreditHistory;

use common\models\CreditHistory;
use common\logic\BaseService;
use common\logic\RepositoryInterface;

class CreditHistoryRepository
class CreditHistoryRepository extends BaseService implements RepositoryInterface
{
/**
* Retourne les options de base nécessaires à la fonction de recherche.

common/services/CreditHistoryService.php → common/logic/CreditHistory/CreditHistorySolver.php Visa fil

@@ -1,33 +1,16 @@
<?php

namespace common\services;
namespace common\logic\CreditHistory;

use common\helpers\MeanPayment;
use common\models\CreditHistory;
use common\logic\SolverInterface;
use common\models\Order;
use yii\helpers\Html;

class CreditHistoryService
class CreditHistorySolver implements SolverInterface
{

public function save(CreditHistory $creditHistory): bool
{
if ($creditHistory->getAmount() > -0.01 && $creditHistory->getAmount() < 0.01) {
return false;
}

// Initialisation du commentaire avant sauvegarde
$creditHistory->setComment($creditHistory->getComment() . $this->getStrComment($creditHistory));

$creditHistory->save();

// Mise à jour du crédit au niveau de UserProducer
\Yii::$app->logic->getUserProducerContainer()->getService()->updateCredit($creditHistory);

return true;
}

public function isTypeDebit(CreditHistory $creditHistory): bool
public function isTypeDebit(CreditHistoryModel $creditHistory): bool
{
return in_array($creditHistory->type, [
CreditHistory::TYPE_DEBIT,
@@ -35,21 +18,21 @@ class CreditHistoryService
]);
}

public function isTypeCredit(CreditHistory $creditHistory): bool
public function isTypeCredit(CreditHistoryModel $creditHistory): bool
{
return in_array($creditHistory->type, [
CreditHistory::TYPE_CREDIT,
CreditHistory::TYPE_INITIAL_CREDIT,
CreditHistory::TYPE_REFUND
CreditHistoryModel::TYPE_CREDIT,
CreditHistoryModel::TYPE_INITIAL_CREDIT,
CreditHistoryModel::TYPE_REFUND
]);
}

public function getAmount(CreditHistory $creditHistory, bool $format = false): string
public function getAmount(CreditHistoryModel $creditHistory, bool $format = false): string
{
if ($format) {
return number_format($creditHistory->amount, 2) . '&nbsp;€';
return number_format($creditHistory->getAmount(), 2) . '&nbsp;€';
} else {
return $creditHistory->amount;
return $creditHistory->getAmount();
}
}

@@ -58,24 +41,24 @@ class CreditHistoryService
* éventuellement de la date de sa commande associée.
*
*/
public function getStrWording(CreditHistory $creditHistory): string
public function getStrWording(CreditHistoryModel $creditHistory): string
{
$str = '';
$type = $creditHistory->getType();

if (CreditHistory::TYPE_INITIAL_CREDIT == $type) {
if (CreditHistoryModel::TYPE_INITIAL_CREDIT == $type) {
$str = 'Crédit initial';
} elseif (CreditHistory::TYPE_CREDIT == $type) {
} elseif (CreditHistoryModel::TYPE_CREDIT == $type) {
$str = 'Crédit';
} elseif (CreditHistory::TYPE_PAYMENT == $type) {
} elseif (CreditHistoryModel::TYPE_PAYMENT == $type) {
$str = 'Paiement';
} elseif (CreditHistory::TYPE_REFUND == $type) {
} elseif (CreditHistoryModel::TYPE_REFUND == $type) {
$str = 'Remboursement';
} elseif (CreditHistory::TYPE_DEBIT == $type) {
} elseif (CreditHistoryModel::TYPE_DEBIT == $type) {
$str = 'Débit';
}

if (CreditHistory::TYPE_PAYMENT == $type || CreditHistory::TYPE_REFUND == $type) {
if (CreditHistoryModel::TYPE_PAYMENT == $type || CreditHistoryModel::TYPE_REFUND == $type) {
$order = $creditHistory->getOrderObject();
if ($order && $order->getDistributionOject()) {
$str .= '<br />Commande : ' . date('d/m/Y', strtotime($order->getDistributionOject()->getDate()));
@@ -92,7 +75,7 @@ class CreditHistoryService
* (libellé, montant, client, action) au format HTML.
*
*/
public function getStrComment(CreditHistory $creditHistory): string
public function getStrComment(CreditHistoryModel $creditHistory): string
{
$str = '';
if (strlen($creditHistory->getComment())) {
@@ -119,7 +102,7 @@ class CreditHistoryService
return $str;
}

public function getDate(CreditHistory $creditHistory, bool $format = false): string
public function getDate(CreditHistoryModel $creditHistory, bool $format = false): string
{
$date = $creditHistory->getDate();

@@ -130,13 +113,13 @@ class CreditHistoryService
}
}

public function getStrMeanPayment(CreditHistory $creditHistory): string
public function getStrMeanPayment(CreditHistoryModel $creditHistory): string
{
return MeanPayment::getStrBy($creditHistory->getMeanPayment());
}

// strUserAction
public function getStrUserAction(CreditHistory $creditHistory): string
public function getStrUserAction(CreditHistoryModel $creditHistory): string
{
$userAction = $creditHistory->getUserActionObject();


+ 8
- 0
common/logic/FactoryInterface.php Visa fil

@@ -0,0 +1,8 @@
<?php

namespace common\logic;

interface FactoryInterface
{

}

common/services/ProducerService.php → common/logic/Producer/ProducerBuilder.php Visa fil

@@ -1,32 +1,32 @@
<?php

namespace common\services;
namespace common\services\Producer;

use common\helpers\Password;
use common\logic\BaseService;
use common\logic\BuilderInterface;
use common\logic\ServiceInterface;
use common\models\Producer;
use common\models\UserProducer;
use common\logic\UserProducer\UserProducerModel;
use common\repositories\ProducerRepository;

class ProducerService
class ProducerBuilder extends BaseService implements BuilderInterface
{
public function createInstance()
{
$producer = new Producer;

$producer->order_deadline = 20;
$producer->order_delay = 1;
protected ProducerRepository $producerRepository;

return $producer;
public function __construct()
{
$this->producerRepository = $this->loadService(ProducerRepository::class);
}

public function init($producer)
public function init(Producer $producer): void
{
$this->initSlug($producer);
$this->initCode($producer);
}

public function initSlug($producer)
public function initSlug(Producer $producer): void
{
$producerRepository = Yii::$app->logic->getProducerContainer()->getRepository();
$cptSlug = 0 ;
do {
$slug = \common\helpers\Url::slugify($producer->name) ;
@@ -35,45 +35,30 @@ class ProducerService
}
$producer->slug = $slug ;
$cptSlug ++ ;
} while($producerRepository->getOneBySlug($producer->slug)) ;
} while($this->producerRepository->getOneBySlug($producer->slug)) ;
}

public function initCode($producer)
public function initCode(Producer $producer): void
{
$producer->code = Password::generate();
}

public function sendEmailNewProducer($producer)
{
Yii::$app->mailer->compose(
[
'html' => 'new-producer-html',
'text' => 'new-producer-text'
], [
'producer' => $producer
])
->setTo(Yii::$app->params['adminEmail'])
->setFrom([Yii::$app->params['adminEmail'] => 'distrib'])
->setSubject('[Opendistrib] Nouveau producteur')
->send();
}

/**
* Lie un utilisateur à un producteur.
*
* @param integer $id_user
* @param integer $id_producer
* @return UserProducer
* @return UserProducerModel
*/
public static function addUser($idUser, $idProducer, $bookmark = 1)
public static function addUser(int $idUser, int $idProducer, int $bookmark = 1)
{
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'user_producer.id_user' => $idUser,
'user_producer.id_producer' => $idProducer
]);

if (!$userProducer) {
$newUserProducer = new UserProducer;
$newUserProducer = new UserProducerModel;
$newUserProducer->id_producer = $idProducer;
$newUserProducer->id_user = $idUser;
$newUserProducer->credit = 0;

+ 46
- 0
common/logic/Producer/ProducerContainer.php Visa fil

@@ -0,0 +1,46 @@
<?php

namespace common\logic\Producer;

use common\logic\ContainerInterface;
use common\services\Producer\ProducerBuilder;
use common\services\Producer\ProducerFactory;
use common\services\Producer\ProducerUtils;

class ProducerContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return ProducerModel::class;
}

public function getServices(): array
{
return [
ProducerFactory::class,
ProducerRepository::class,
ProducerBuilder::class,
ProducerUtils::class
];
}

public function getFactory(): ProducerFactory
{
return new ProducerFactory();
}

public function getRepository()
{
return new ProducerRepository();
}

public function getBuilder(): ProducerBuilder
{
return new ProducerBuilder();
}

public function getUtils(): ProducerUtils
{
return new ProducerUtils();
}
}

+ 20
- 0
common/logic/Producer/ProducerFactory.php Visa fil

@@ -0,0 +1,20 @@
<?php

namespace common\services\Producer;

use common\logic\BaseService;
use common\models\Producer;
use common\logic\FactoryInterface;

class ProducerFactory extends BaseService implements FactoryInterface
{
public function create()
{
$producer = new Producer;

$producer->order_deadline = 20;
$producer->order_delay = 1;

return $producer;
}
}

common/models/Producer.php → common/logic/Producer/ProducerModel.php Visa fil

@@ -36,8 +36,11 @@
* termes.
*/

namespace common\models;
namespace common\logic\Producer;

use common\logic\User\UserModel;
use common\models\TaxRate;
use common\logic\UserProducer\UserProducerModel;
use Yii;
use common\components\ActiveRecordCommon;
use common\helpers\Departments;
@@ -65,7 +68,7 @@ use yii\helpers\Html;
* @property string background_color_logo
*
*/
class Producer extends ActiveRecordCommon
class ProducerModel extends ActiveRecordCommon
{
const CREDIT_FUNCTIONING_MANDATORY = 'mandatory';
const CREDIT_FUNCTIONING_OPTIONAL = 'optional';
@@ -190,7 +193,7 @@ class Producer extends ActiveRecordCommon
'code',
function ($attribute, $params) {
$code = $this->$attribute;
$producer = Producer::findOne(['code' => $code]);
$producer = ProducerModel::findOne(['code' => $code]);
if ($producer && $producer->id != $this->id) {
$this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.');
}
@@ -420,19 +423,19 @@ class Producer extends ActiveRecordCommon
public function getUserProducer()
{
return $this->hasMany(
UserProducer::className(),
UserProducerModel::class,
['id_producer' => 'id']
);
}

public function getUser()
{
return $this->hasMany(User::className(), ['id_producer' => 'id']);
return $this->hasMany(UserModel::className(), ['id_producer' => 'id']);
}

public function getContact()
{
return $this->hasMany(User::className(), ['id_producer' => 'id'])
return $this->hasMany(UserModel::className(), ['id_producer' => 'id'])
->where(['status' => User::STATUS_PRODUCER]);
}


common/repositories/ProducerRepository.php → common/logic/Producer/ProducerRepository.php Visa fil

@@ -1,26 +1,27 @@
<?php

namespace common\repositories;
namespace common\logic\Producer;

use common\helpers\Departments;
use common\models\Producer;
use common\logic\BaseService;
use common\logic\RepositoryInterface;
use yii\helpers\Html;

class ProducerRepository
class ProducerRepository extends BaseService implements RepositoryInterface
{
public function getOneById($id)
{
return Producer::searchOne(['id' => $id]);
return ProducerModel::searchOne(['id' => $id]);
}

public function getOneBySlug($slug)
{
return Producer::searchOne(['slug' => $slug]);
return ProducerModel::searchOne(['slug' => $slug]);
}

public function queryActive()
{
return Producer::find()
return ProducerModel::find()
->where([
'active' => true,
])
@@ -30,11 +31,10 @@ class ProducerRepository
/**
* Retourne le compte producteur de démonstration.
*
* @return Producer
*/
public function getOneDemoAccount()
{
return Producer::find()->where('name LIKE \'Démo\'')->one();
return ProducerModel::find()->where('name LIKE \'Démo\'')->one();
}

/**
@@ -45,7 +45,7 @@ class ProducerRepository
*/
public static function getPopulateDropdown()
{
$producers = Producer::find()
$producers = ProducerModel::find()
->where([
'active' => true,
])

+ 25
- 0
common/logic/Producer/ProducerUtils.php Visa fil

@@ -0,0 +1,25 @@
<?php

namespace common\services\Producer;

use common\logic\BaseService;
use common\logic\UtilsInterface;
use common\models\Producer;

class ProducerUtils extends BaseService implements UtilsInterface
{
public function sendEmailNewProducer(Producer $producer)
{
\Yii::$app->mailer->compose(
[
'html' => 'new-producer-html',
'text' => 'new-producer-text'
], [
'producer' => $producer
])
->setTo(\Yii::$app->params['adminEmail'])
->setFrom([\Yii::$app->params['adminEmail'] => 'distrib'])
->setSubject('[Opendistrib] Nouveau producteur')
->send();
}
}

+ 26
- 0
common/logic/ProducerPriceRange/ProducerPriceRangeContainer.php Visa fil

@@ -0,0 +1,26 @@
<?php

namespace common\logic\ProducerPriceRange;

use common\logic\ContainerInterface;
use common\models\ProducerPriceRange;

class ProducerPriceRangeContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return ProducerPriceRange::class;
}

public function getServices(): array
{
return [
ProducerPriceRangeRepository::class
];
}

public function getRepository()
{
return new ProducerPriceRangeRepository();
}
}

+ 95
- 0
common/logic/ProducerPriceRange/ProducerPriceRangeModel.php Visa fil

@@ -0,0 +1,95 @@
<?php

/**
* Copyright distrib (2018)
*
* contact@opendistrib.net
*
* Ce logiciel est un programme informatique servant à aider les producteurs
* à distribuer leur production en circuits courts.
*
* Ce logiciel est régi par la licence CeCILL soumise au droit français et
* respectant les principes de diffusion des logiciels libres. Vous pouvez
* utiliser, modifier et/ou redistribuer ce programme sous les conditions
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
* sur le site "http://www.cecill.info".
*
* En contrepartie de l'accessibilité au code source et des droits de copie,
* de modification et de redistribution accordés par cette licence, il n'est
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
* seule une responsabilité restreinte pèse sur l'auteur du programme, le
* titulaire des droits patrimoniaux et les concédants successifs.
*
* A cet égard l'attention de l'utilisateur est attirée sur les risques
* associés au chargement, à l'utilisation, à la modification et/ou au
* développement et à la reproduction du logiciel par l'utilisateur étant
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à
* manipuler et qui le réserve donc à des développeurs et des professionnels
* avertis possédant des connaissances informatiques approfondies. Les
* utilisateurs sont donc invités à charger et tester l'adéquation du
* logiciel à leurs besoins dans des conditions permettant d'assurer la
* sécurité de leurs systèmes et ou de leurs données et, plus généralement,
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
*
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
* pris connaissance de la licence CeCILL, et que vous en avez accepté les
* termes.
*/

namespace common\logic\ProducerPriceRange;

use common\components\ActiveRecordCommon;

/**
* This is the model class for table "producer_price_range".
*
* @property integer $id
*/
class ProducerPriceRangeModel extends ActiveRecordCommon
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'producer_price_range';
}

/**
* @inheritdoc
*/
public function rules()
{
return [
[['range_begin', 'range_end', 'price'], 'double'],
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'range_begin' => 'Début',
'range_end' => 'Fin',
'price' => 'Tarif (HT)',
];
}

/**
* Retourne les options de base nécessaires à la fonction de recherche.
*
* @return array
*/
public static function defaultOptionsSearch()
{
return [
'with' => [],
'join_with' => [],
'orderby' => '',
'attribute_id_producer' => ''
];
}
}

+ 15
- 0
common/logic/ProducerPriceRange/ProducerPriceRangeRepository.php Visa fil

@@ -0,0 +1,15 @@
<?php

namespace common\logic\ProducerPriceRange;

use common\logic\BaseService;
use common\logic\RepositoryInterface;
use common\models\ProducerPriceRange;

class ProducerPriceRangeRepository extends BaseService implements RepositoryInterface
{
public function query()
{
return ProducerPriceRange::find()->orderBy('range_begin ASC');
}
}

+ 8
- 0
common/logic/RepositoryInterface.php Visa fil

@@ -0,0 +1,8 @@
<?php

namespace common\logic;

interface RepositoryInterface
{

}

+ 8
- 0
common/logic/SolverInterface.php Visa fil

@@ -0,0 +1,8 @@
<?php

namespace common\logic;

interface SolverInterface
{

}

+ 22
- 0
common/logic/User/UserBuilder.php Visa fil

@@ -0,0 +1,22 @@
<?php

namespace common\services\User;

use common\logic\BaseService;
use common\logic\BuilderInterface;
use common\models\UserModel;

class UserBuilder extends BaseService implements BuilderInterface
{
public function initPassword($user, $password)
{
$user->setPassword($password);
$user->generateAuthKey();
}

public function initProducer($user, $producer)
{
$user->id_producer = $producer->id;
$user->status = UserModel::STATUS_PRODUCER;
}
}

+ 47
- 0
common/logic/User/UserContainer.php Visa fil

@@ -0,0 +1,47 @@
<?php

namespace common\logic\User;

use common\logic\ContainerInterface;
use common\logic\User\UserModel;
use common\services\User\UserBuilder;
use common\services\User\UserFactory;
use common\services\User\UserUtils;

class UserContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return UserModel::class;
}

public function getServices(): array
{
return [
UserFactory::class,
UserRepository::class,
UserBuilder::class,
UserUtils::class,
];
}

public function getFactory(): UserFactory
{
return new UserFactory();
}

public function getRepository(): UserRepository
{
return new UserRepository();
}

public function getBuilder(): UserBuilder
{
return new UserBuilder();
}

public function getUtils(): UserUtils
{
return new UserUtils();
}
}

+ 17
- 0
common/logic/User/UserFactory.php Visa fil

@@ -0,0 +1,17 @@
<?php

namespace common\services\User;

use common\logic\BaseService;
use common\logic\FactoryInterface;
use common\models\UserModel;

class UserFactory extends BaseService implements FactoryInterface
{
public function create()
{
$user = new UserModel();

return $user;
}
}

common/models/User.php → common/logic/User/UserModel.php Visa fil

@@ -36,9 +36,11 @@
* termes.
*/

namespace common\models;
namespace common\logic\User;

use common\helpers\GlobalParam;
use common\logic\Producer\ProducerModel;
use yii\behaviors\TimestampBehavior;
use yii\web\IdentityInterface;
use yii\db\Query;
use common\components\ActiveRecordCommon;
@@ -58,7 +60,7 @@ use common\components\ActiveRecordCommon;
* @property string $password write-only password
* @property boolean $confiance
*/
class User extends ActiveRecordCommon implements IdentityInterface
class UserModel extends ActiveRecordCommon implements IdentityInterface
{

const TYPE_INDIVIDUAL = 'individual';
@@ -94,7 +96,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
public function behaviors()
{
return [
TimestampBehavior::className(),
TimestampBehavior::class,
];
}

@@ -227,9 +229,9 @@ class User extends ActiveRecordCommon implements IdentityInterface
public function verifyEmail($attribute, $params)
{
if ($this->id) {
$user = User::find()->where("email LIKE :email AND type != :guest AND id != :id")->params(array(':email' => '%' . $this->email . '%', ':id' => $this->id, ':guest' => 'guest'))->one();
$user = UserModel::find()->where("email LIKE :email AND type != :guest AND id != :id")->params(array(':email' => '%' . $this->email . '%', ':id' => $this->id, ':guest' => 'guest'))->one();
} else {
$user = User::find()->where("email LIKE :email AND type != :guest")->params(array(':email' => '%' . $this->email . '%', ':guest' => 'guest'))->one();
$user = UserModel::find()->where("email LIKE :email AND type != :guest")->params(array(':email' => '%' . $this->email . '%', ':guest' => 'guest'))->one();
}

if ($user) {
@@ -257,7 +259,7 @@ class User extends ActiveRecordCommon implements IdentityInterface

public function getUserProducer()
{
return $this->hasMany(UserProducer::className(), ['id_user' => 'id']);
return $this->hasMany(UserProducerModel::className(), ['id_user' => 'id']);
}

public function getUserUserGroup()
@@ -311,7 +313,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
* Recherche un utilisateur via son adresse email.
*
* @param string $email
* @return User
* @return UserModel
*/
public static function findByEmail($email)
{
@@ -510,7 +512,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
/**
* Retourne l'utilisateur courant.
*
* @return User
* @return UserModel
*/
public static function getCurrent()
{
@@ -538,7 +540,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
*/
public function isProducer()
{
return ($this->status == User::STATUS_ADMIN || $this->status == User::STATUS_PRODUCER) && $this->id_producer;
return ($this->status == UserModel::STATUS_ADMIN || $this->status == UserModel::STATUS_PRODUCER) && $this->id_producer;
}

/**
@@ -548,7 +550,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
*/
public static function isCurrentProducer()
{
$user = User::getCurrent();
$user = UserModel::getCurrent();
if ($user) {
return $user->isProducer();
}
@@ -562,7 +564,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
*/
public function isAdmin()
{
return $this->status == User::STATUS_ADMIN;
return $this->status == UserModel::STATUS_ADMIN;
}

/**
@@ -572,7 +574,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
*/
public static function isCurrentAdmin()
{
$user = User::getCurrent();
$user = UserModel::getCurrent();
if ($user) {
return $user->isAdmin();
}
@@ -586,8 +588,9 @@ class User extends ActiveRecordCommon implements IdentityInterface
*/
public function getNameProducer()
{
$producer = Producer::findOne($this->id_producer);
return $producer->name;
$producer = ProducerModel::findOne($this->id_producer);

return $producer->getName();
}

/**
@@ -616,7 +619,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
*/
public function getCredit($idProducer)
{
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $this->id
]);

@@ -683,7 +686,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
public function sendMailWelcome($password)
{
if (strlen($this->email)) {
$producer = Producer::findOne(GlobalParam::getCurrentProducerId());
$producer = ProducerModel::findOne(GlobalParam::getCurrentProducerId());
Yii::$app->mailer->compose();
$mail = Yii::$app->mailer->compose(
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $this, 'producer' => $producer, 'password' => $password]
@@ -747,11 +750,11 @@ class User extends ActiveRecordCommon implements IdentityInterface

public static function populateDropdownList()
{
$usersArray = User::findBy()->all();
$usersArray = UserModel::findBy()->all();
$usersArrayDropdown = ['' => '--'];

foreach ($usersArray as $user) {
$usersArrayDropdown[$user['user_id']] = User::getUsernameFromArray($user, true);
$usersArrayDropdown[$user['user_id']] = UserModel::getUsernameFromArray($user, true);
}

return $usersArrayDropdown;;
@@ -765,8 +768,8 @@ class User extends ActiveRecordCommon implements IdentityInterface
*/
public static function getCurrentId()
{
if (!Yii::$app->user->isGuest) {
return Yii::$app->user->identity->id;
if (!\Yii::$app->user->isGuest) {
return \Yii::$app->user->identity->id;
}

return false;
@@ -788,7 +791,7 @@ class User extends ActiveRecordCommon implements IdentityInterface

public static function hasAccessBackend()
{
return User::getCurrentStatus() == USER::STATUS_ADMIN || User::getCurrentStatus() == USER::STATUS_PRODUCER;
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN || UserModel::getCurrentStatus() == UserModel::STATUS_PRODUCER;
}

public function belongsToUserGroup($userGroupId)
@@ -813,9 +816,9 @@ class User extends ActiveRecordCommon implements IdentityInterface
public static function getTypeChoicesArray()
{
return [
User::TYPE_INDIVIDUAL => 'Particulier',
User::TYPE_LEGAL_PERSON => 'Personne morale',
User::TYPE_GUEST => 'Visiteur'
UserModel::TYPE_INDIVIDUAL => 'Particulier',
UserModel::TYPE_LEGAL_PERSON => 'Personne morale',
UserModel::TYPE_GUEST => 'Visiteur'
];
}
}

+ 15
- 0
common/logic/User/UserRepository.php Visa fil

@@ -0,0 +1,15 @@
<?php

namespace common\logic\User;

use common\logic\BaseService;
use common\logic\RepositoryInterface;

class UserRepository extends BaseService implements RepositoryInterface
{
public function getOneById($id)
{
return UserModel::searchOne(['id' => $id]);
}

}

+ 28
- 0
common/logic/User/UserUtils.php Visa fil

@@ -0,0 +1,28 @@
<?php

namespace common\services\User;

use common\logic\BaseService;
use common\logic\Producer\ProducerModel;
use common\logic\UtilsInterface;
use common\models\UserModel;

class UserUtils extends BaseService implements UtilsInterface
{
public function sendEmailSignup(UserModel $user, ProducerModel $producer)
{
\Yii::$app->mailer->compose(
[
'html' => 'signup-html',
'text' => 'signup-text'
],
[
'user' => $user,
'producer' => $producer
])
->setTo($user->email)
->setFrom([\Yii::$app->params['adminEmail'] => 'distrib'])
->setSubject('[Opendistrib] Inscription')
->send();
}
}

common/services/UserProducerService.php → common/logic/UserProducer/UserProducerBuilder.php Visa fil

@@ -1,26 +1,34 @@
<?php

namespace common\services;
namespace common\services\UserProducer;

use common\helpers\MeanPayment;
use common\logic\BaseService;
use common\logic\BuilderInterface;
use common\logic\CreditHistory\CreditHistoryModel;
use common\logic\CreditHistory\CreditHistorySolver;
use common\logic\Producer\ProducerModel;
use common\models\Order;
use common\models\Producer;
use common\logic\UserProducer\UserProducerModel;
use common\repositories\UserProducerRepository;

class UserProducerService
class UserProducerBuilder extends BaseService implements BuilderInterface
{
protected CreditHistoryService $creditHistoryService;
protected CreditHistorySolver $creditHistorySolver;
protected UserProducerRepository $userProducerRepository;

public function __construct()
{
$this->creditHistoryService = \Yii::$app->logic->getCreditHistoryContainer()->getService();
$this->creditHistorySolver = $this->loadService(CreditHistorySolver::class);
$this->userProducerRepository = $this->loadService(UserProducerRepository::class);
}

public function updateCredit($creditHistory)
public function updateCredit(CreditHistoryModel $creditHistory): void
{
$userProducer = Yii::$app->logic->getUserProducerContainer()->getRepository()->getOne($creditHistory->id_user, $creditHistory->id_producer);
$userProducer = $this->userProducerRepository->getOne($creditHistory->getIdUser(), $creditHistory->getIdProducer());

if ($userProducer) {
$oldCredit = $userProducer->credit;
$oldCredit = $userProducer->getCredit();

$this->deductCredit($userProducer, $creditHistory);
$this->initMeanPaymentOrder($creditHistory);
@@ -28,12 +36,12 @@ class UserProducerService
}
}

public function deductCredit($userProducer, $creditHistory)
public function deductCredit(UserProducerModel $userProducer, CreditHistoryModel $creditHistory)
{
if ($this->creditHistoryService->isTypeCredit($creditHistory)) {
$userProducer->credit += $creditHistory->amount;
} elseif ($this->creditHistoryService->isTypeDebit($creditHistory)) {
$userProducer->credit -= $creditHistory->amount;
if ($this->creditHistorySolver->isTypeCredit($creditHistory)) {
$userProducer->setCredit($userProducer->getCredit() + $creditHistory->getAmount());
} elseif ($this->creditHistorySolver->isTypeDebit($creditHistory)) {
$userProducer->setCredit($userProducer->getCredit() - $creditHistory->getAmount());
}

$userProducer->save();
@@ -88,7 +96,7 @@ class UserProducerService

public function isCreditLimitCrossed($oldCredit, $newCredit)
{
$creditLimitReminder = Producer::getConfig('credit_limit_reminder');
$creditLimitReminder = ProducerModel::getConfig('credit_limit_reminder');

return !is_null($creditLimitReminder) &&
$oldCredit > $creditLimitReminder

+ 28
- 0
common/logic/UserProducer/UserProducerContainer.php Visa fil

@@ -0,0 +1,28 @@
<?php

namespace common\containers;

use common\logic\ContainerInterface;
use common\logic\UserProducer\UserProducerModel;
use common\repositories\UserProducerRepository;

class UserProducerContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return UserProducerModel::class;
}

public function getServices(): array
{
return [
UserProducerRepository::class
];
}


public function getRepository()
{
return new UserProducerRepository();
}
}

common/models/UserProducer.php → common/logic/UserProducer/UserProducerModel.php Visa fil

@@ -36,22 +36,19 @@
* termes.
*/

namespace common\models;
namespace common\logic\UserProducer;

use common\logic\Producer\ProducerModel;
use common\logic\User\UserModel;
use Yii;
use common\components\ActiveRecordCommon;

/**
* This is the model class for table "user_etablissement".
* This is the model class for table "user_producer".
*
* @property integer $id_user
* @property integer $id_etablissement
* @property boolean $actif
* @property boolean $favoris
*/
class UserProducer extends ActiveRecordCommon
class UserProducerModel extends ActiveRecordCommon
{

/**
* @inheritdoc
*/
@@ -90,12 +87,12 @@ class UserProducer extends ActiveRecordCommon

public function getProducer()
{
return $this->hasOne(Producer::className(), ['id' => 'id_producer']);
return $this->hasOne(ProducerModel::class, ['id' => 'id_producer']);
}

public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'id_user']);
return $this->hasOne(UserModel::class, ['id' => 'id_user']);
}

/**

common/repositories/UserProducerRepository.php → common/logic/UserProducer/UserProducerRepository.php Visa fil

@@ -1,15 +1,16 @@
<?php

namespace common\repositories;
namespace common\logic\UserProducer;

use common\models\User;
use common\models\UserProducer;
use common\logic\BaseService;
use common\logic\RepositoryInterface;
use common\logic\UserProducer\UserProducerModel;

class UserProducerRepository
class UserProducerRepository extends BaseService implements RepositoryInterface
{
public function getOne($idUser, $idProducer)
{
return UserProducer::searchOne([
return UserProducerModel::searchOne([
'id_user' => $idUser,
'id_producer' => $idProducer
]);
@@ -17,7 +18,7 @@ class UserProducerRepository

public function getBy($idUser, $active = 1, $bookmark = 1)
{
return UserProducer::find()
return UserProducerModel::find()
->with(['producer'])
->where([
'id_user' => $idUser,

+ 8
- 0
common/logic/UtilsInterface.php Visa fil

@@ -0,0 +1,8 @@
<?php

namespace common\logic;

interface UtilsInterface
{

}

+ 1
- 1
common/mail/passwordResetToken-html.php Visa fil

@@ -39,7 +39,7 @@ termes.
use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $user common\models\User */
/* @var $user common\models\UserModel */

$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
?>

+ 1
- 1
common/mail/passwordResetToken-text.php Visa fil

@@ -37,7 +37,7 @@ termes.
*/

/* @var $this yii\web\View */
/* @var $user common\models\User */
/* @var $user common\models\UserModel */

$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
?>

+ 2
- 2
common/mail/signup-html.php Visa fil

@@ -37,7 +37,7 @@ termes.
*/

use yii\helpers\Html;
use common\models\User ;
use common\models\UserModel ;
use common\helpers\Url ;

?>
@@ -49,7 +49,7 @@ use common\helpers\Url ;
<p>Voici votre identifiant de connexion : <br />
<strong><?= Html::encode($user->email) ?></strong></p>

<?php if($user->status == User::STATUS_PRODUCER): ?>
<?php if($user->status == UserModel::STATUS_PRODUCER): ?>
<p>Vous pouvez dès maintenant vous connecter à votre <a href="<?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?>">Espace producteur</a> pour mettre
en place votre système de réservation.</p>
<?php else: ?>

+ 2
- 2
common/mail/signup-text.php Visa fil

@@ -36,7 +36,7 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

use common\models\User ;
use common\models\UserModel ;
use common\helpers\Url ;

?>
@@ -48,7 +48,7 @@ Votre inscription sur distrib a bien été prise en compte.
Voici votre identifiant de connexion :
<?= $user->email ?>

<?php if($user->status == User::STATUS_PRODUCER): ?>
<?php if($user->status == UserModel::STATUS_PRODUCER): ?>
Vous pouvez dès maintenant vous connecter à votre Espace boulanger pour mettre en place votre système de réservation :
<?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?>
<?php else: ?>

+ 1
- 1
common/models/Distribution.php Visa fil

@@ -348,7 +348,7 @@ class Distribution extends ActiveRecordCommon
$userProducer = false;
if(isset($order->user) && $order->user) {
$user = $order->user;
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $user->id,
'id_producer' => $order->distribution->id_producer
]) ;

+ 1
- 1
common/models/Document.php Visa fil

@@ -99,7 +99,7 @@ class Document extends ActiveRecordCommon

public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'id_user']);
return $this->hasOne(UserModel::className(), ['id' => 'id_user']);
}

public function getProducer()

+ 5
- 5
common/models/Order.php Visa fil

@@ -152,7 +152,7 @@ class Order extends ActiveRecordCommon

public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'id_user']);
return $this->hasOne(UserModel::className(), ['id' => 'id_user']);
}

public function getProductOrder()
@@ -364,7 +364,7 @@ class Order extends ActiveRecordCommon
$amountPaid,
GlobalParam::getCurrentProducerId(),
$this->id_user,
User::getCurrentId()
UserModel::getCurrentId()
);
}

@@ -456,7 +456,7 @@ class Order extends ActiveRecordCommon
public function addOrderStatusHistory($newStatus, $origin)
{
$orderStatusHistory = new OrderStatusHistory();
$orderStatusHistory->id_user = User::getCurrentId();
$orderStatusHistory->id_user = UserModel::getCurrentId();
$orderStatusHistory->id_order = $this->id;
$orderStatusHistory->status = $newStatus;
$orderStatusHistory->origin = $origin;
@@ -567,7 +567,7 @@ class Order extends ActiveRecordCommon
$creditHistory->id_producer = $idProducer;
$creditHistory->id_user_action = $idUserAction;
$creditHistory->populateRelation('order', $this);
$creditHistory->populateRelation('user', User::find()->where(['id' => $this->id_user])->one());
$creditHistory->populateRelation('user', UserModel::find()->where(['id' => $this->id_user])->one());

$creditHistoryService->save($creditHistory);
}
@@ -599,7 +599,7 @@ class Order extends ActiveRecordCommon
$amount,
GlobalParam::getCurrentProducerId(),
$this->id_user,
User::getCurrentId()
UserModel::getCurrentId()
);
}
}

+ 2
- 2
common/models/OrderStatusHistory.php Visa fil

@@ -56,12 +56,12 @@ class OrderStatusHistory extends ActiveRecordCommon

public function getOrder()
{
return $this->hasOne(User::className(), ['id' => 'id_order']);
return $this->hasOne(UserModel::className(), ['id' => 'id_order']);
}

public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'id_user']);
return $this->hasOne(UserModel::className(), ['id' => 'id_user']);
}

/**

+ 3
- 3
common/models/PointSale.php Visa fil

@@ -157,7 +157,7 @@ class PointSale extends ActiveRecordCommon
public function getUser()
{
return $this->hasOne(
User::className(),
UserModel::className(),
['id' => 'id_user']
) ;
}
@@ -249,7 +249,7 @@ class PointSale extends ActiveRecordCommon

if (is_array($this->users) && count($this->users)) {
foreach ($this->users as $key => $val) {
$user = User::findOne($val);
$user = UserModel::findOne($val);
if ($user) {
$userPointSale = new UserPointSale;
$userPointSale->id_user = $val;
@@ -272,7 +272,7 @@ class PointSale extends ActiveRecordCommon
{
if (isset($this->userPointSale)) {
foreach ($this->userPointSale as $userPointSale) {
if ($userPointSale->id_user == User::getCurrentId()) {
if ($userPointSale->id_user == UserModel::getCurrentId()) {
return $userPointSale->comment;
}
}

+ 1
- 1
common/models/Product.php Visa fil

@@ -394,7 +394,7 @@ class Product extends ActiveRecordCommon

$userProducer = null;
if ($user) {
$userProducer = UserProducer::searchOne([
$userProducer = UserProducerModel::searchOne([
'id_user' => $user->id,
]);
}

+ 1
- 1
common/models/ProductPrice.php Visa fil

@@ -153,7 +153,7 @@ class ProductPrice extends ActiveRecordCommon
public function getUser()
{
return $this->hasOne(
User::className(),
UserModel::className(),
['id' => 'id_user']
);
}

+ 6
- 6
common/models/Subscription.php Visa fil

@@ -40,7 +40,7 @@ namespace common\models;

use common\helpers\GlobalParam;
use common\models\PointSale;
use common\models\User;
use common\models\UserModel;
use Yii;
use common\components\ActiveRecordCommon;
use common\models\Producer;
@@ -128,7 +128,7 @@ class Subscription extends ActiveRecordCommon

public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'id_user']);
return $this->hasOne(UserModel::className(), ['id' => 'id_user']);
}

public function getProducer()
@@ -201,7 +201,7 @@ class Subscription extends ActiveRecordCommon

$user = false;
if ($this->id_user) {
$user = User::findOne($this->id_user);
$user = UserModel::findOne($this->id_user);
}

$order->date = date('Y-m-d H:i:s');
@@ -227,8 +227,8 @@ class Subscription extends ActiveRecordCommon
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) {
$order->auto_payment = 1;
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) {
$user = User::findOne($order->id_user);
$userProducer = UserProducer::searchOne([
$user = UserModel::findOne($order->id_user);
$userProducer = UserProducerModel::searchOne([
'id_user' => $order->id_user,
'id_producer' => $distribution->id_producer
]);
@@ -484,7 +484,7 @@ class Subscription extends ActiveRecordCommon
$theOrder->getAmount(Order::AMOUNT_PAID),
$theOrder->distribution->id_producer,
$theOrder->id_user,
User::getCurrentId()
UserModel::getCurrentId()
);
}


common/models/UserSearch.php → common/models/UserModelSearch.php Visa fil

@@ -39,9 +39,9 @@
namespace common\models;

use common\helpers\GlobalParam;
use common\models\User;
use common\models\UserModel;

class UserSearch extends User
class UserModelSearch extends UserModel
{
var $id_point_sale;
var $subscribers;
@@ -62,7 +62,7 @@ class UserSearch extends User
{
$optionsSearch = self::defaultOptionsSearch();

$query = User::find()
$query = UserModel::find()
->select(
'`user`.id, '
. '`user`.username,'

+ 0
- 13
common/repositories/ProducerPriceRangeRepository.php Visa fil

@@ -1,13 +0,0 @@
<?php

namespace common\repositories;

use common\models\ProducerPriceRange;

class ProducerPriceRangeRepository
{
public function query()
{
return ProducerPriceRange::find()->orderBy('range_begin ASC');
}
}

+ 0
- 14
common/repositories/UserRepository.php Visa fil

@@ -1,14 +0,0 @@
<?php

namespace common\repositories;

use common\models\User;

class UserRepository
{
public function getOneById($id)
{
return User::searchOne(['id' => $id]);
}

}

+ 0
- 12
common/services/ProducerPriceRangeService.php Visa fil

@@ -1,12 +0,0 @@
<?php

namespace common\services;

use common\helpers\Password;
use common\models\Producer;
use common\models\UserProducer;

class ProducerPriceRangeService
{

}

+ 0
- 44
common/services/UserService.php Visa fil

@@ -1,44 +0,0 @@
<?php

namespace common\services;

use common\models\User;

class UserService
{
public function createInstance()
{
$user = new User();

return $user;
}

public function initPassword($user, $password)
{
$user->setPassword($this->password);
$user->generateAuthKey();
}

public function initProducer($user, $producer)
{
$user->id_producer = $producer->id;
$user->status = User::STATUS_PRODUCER;
}

public function sendEmailSignup($user, $producer)
{
Yii::$app->mailer->compose(
[
'html' => 'signup-html',
'text' => 'signup-text'
],
[
'user' => $user,
'producer' => $producer
])
->setTo($user->email)
->setFrom([Yii::$app->params['adminEmail'] => 'distrib'])
->setSubject('[Opendistrib] Inscription')
->send();
}
}

+ 1
- 1
console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php Visa fil

@@ -16,7 +16,7 @@ class m190226_084104_lien_utilisateur_point_de_vente extends Migration
->all();
foreach($pointsSaleArray as $pointSale) {
$usersArray = common\models\User::find()->innerJoin(
$usersArray = common\models\UserModel::find()->innerJoin(
'order',
'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
[':id_point_sale' => $pointSale->id]

+ 10
- 10
frontend/controllers/SiteController.php Visa fil

@@ -38,7 +38,7 @@

namespace frontend\controllers;

use common\models\User;
use common\models\UserModel;
use frontend\forms\ProducerCodeForm;
use Yii;
use frontend\forms\PasswordResetRequestForm;
@@ -108,10 +108,10 @@ class SiteController extends FrontendController
*/
public function actionError()
{
$exception = Yii::$app->errorHandler->exception;
$exception = \Yii::$app->errorHandler->exception;

if ($exception->getMessage() == 'Producteur introuvable'
|| Yii::$app->getRequest()->getQueryParam('producer_not_found')) {
|| \Yii::$app->getRequest()->getQueryParam('producer_not_found')) {
return $this->render('error-404-producer', ['exception' => $exception]);
}

@@ -188,12 +188,12 @@ class SiteController extends FrontendController
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return Yii::$app->getResponse()->redirect(['site/index']);
return \Yii::$app->getResponse()->redirect(['site/index']);
}

$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$returnUrl = Yii::$app->request->get('return_url');
$returnUrl = \Yii::$app->request->get('return_url');

if ($returnUrl) {
return $this->redirect($returnUrl);
@@ -202,7 +202,7 @@ class SiteController extends FrontendController
$userProducerArray = $this->getLogic()
->getUserProducerContainer()
->getRepository()
->getBy(User::getCurrentId());
->getBy(UserModel::getCurrentId());

if ($userProducerArray
&& is_array($userProducerArray)
@@ -228,7 +228,7 @@ class SiteController extends FrontendController
*/
public function actionLogout()
{
Yii::$app->user->logout();
\Yii::$app->user->logout();

return $this->goHome();
}
@@ -267,7 +267,7 @@ class SiteController extends FrontendController
public function actionSignup()
{
$model = new SignupForm();
$producerRepository = Yii::$app->logic->getProducerContainer()->getRepository();
$producerRepository = \Yii::$app->logic->getProducerContainer()->getRepository();

if ($model->load(Yii::$app->request->post())) {
$user = $model->signup();
@@ -381,7 +381,7 @@ class SiteController extends FrontendController
if ($producerCodeForm->load($this->getRequest()->post())
&& $producerCodeForm->validate()) {

$producerContainer->getService()->addUser(User::getCurrentId(), $id);
$producerContainer->getService()->addUser(UserModel::getCurrentId(), $id);

$this->redirect($this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]));
}
@@ -414,7 +414,7 @@ class SiteController extends FrontendController
if ($this->getUser()->isGuest) {
if ($loginForm->load($this->getRequest()->post()) && $loginForm->login()) {
if (!strlen($producer->code)) {
$producerContainer->getService()->addUser(User::getCurrentId(), $id);
$producerContainer->getService()->addUser(UserModel::getCurrentId(), $id);
}

$this->redirect($returnUrl);

+ 4
- 4
frontend/controllers/UserController.php Visa fil

@@ -39,7 +39,7 @@ termes.
namespace frontend\controllers;

use Yii;
use common\models\User;
use common\models\UserModel;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
@@ -81,7 +81,7 @@ class UserController extends FrontendController
*/
public function actionUpdate()
{
$idUser = User::getCurrentId();
$idUser = UserModel::getCurrentId();
$model = $this->findModel($idUser);

if ($model->load($this->getRequest()->post())
@@ -93,7 +93,7 @@ class UserController extends FrontendController

// modification du mot de passe
if (strlen($model->password_new)) {
$model->password_hash = Yii::$app->security->generatePasswordHash($model->password_new);
$model->password_hash = \Yii::$app->security->generatePasswordHash($model->password_new);

$model->password_old = '';
$model->password_new = '';
@@ -123,7 +123,7 @@ class UserController extends FrontendController
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return User the loaded model
* @return UserModel the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)

+ 6
- 6
frontend/forms/PasswordResetRequestForm.php Visa fil

@@ -38,7 +38,7 @@ termes.

namespace frontend\forms;

use common\models\User;
use common\models\UserModel;
use yii\base\Model;
use yii;

@@ -60,7 +60,7 @@ class PasswordResetRequestForm extends Model
['email', 'required'],
['email', 'email'],
['email', 'exist',
'targetClass' => '\common\models\User',
'targetClass' => '\common\models\UserModel',
'message' => 'There is no user with such email.'
],
];
@@ -73,19 +73,19 @@ class PasswordResetRequestForm extends Model
*/
public function sendEmail()
{
/* @var $user User */
$user = User::findOne([
/* @var $user UserModel */
$user = UserModel::findOne([
'email' => $this->email,
]);

if ($user) {
if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
if (!UserModel::isPasswordResetTokenValid($user->password_reset_token)) {
$user->generatePasswordResetToken();
}

if ($user->save()) {

return Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])
return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])
->setFrom(['contact@opendistrib.net' => 'distrib'])
->setTo($this->email)
->setSubject('[distrib] Mot de passe oublié')

+ 3
- 3
frontend/forms/ResetPasswordForm.php Visa fil

@@ -38,7 +38,7 @@ termes.

namespace frontend\forms;

use common\models\User;
use common\models\UserModel;
use yii\base\InvalidParamException;
use yii\base\Model;
use Yii;
@@ -52,7 +52,7 @@ class ResetPasswordForm extends Model
public $password;

/**
* @var \common\models\User
* @var \common\models\UserModel
*/
private $_user;

@@ -68,7 +68,7 @@ class ResetPasswordForm extends Model
if (empty($token) || !is_string($token)) {
throw new InvalidParamException('Password reset token cannot be blank.');
}
$this->_user = User::findByPasswordResetToken($token);
$this->_user = UserModel::findByPasswordResetToken($token);
if (!$this->_user) {
throw new InvalidParamException('Wrong password reset token.');
}

+ 9
- 9
frontend/forms/SignupForm.php Visa fil

@@ -39,10 +39,10 @@
namespace frontend\forms;

use Yii;
use common\models\User;
use common\models\UserModel;
use common\models\Producer;
use yii\base\Model;
use common\models\UserProducer;
use common\models\UserProducerModel;
use common\helpers\Password;

/**
@@ -83,7 +83,7 @@ class SignupForm extends Model
['email', function ($attribute, $params) {
$email = $this->$attribute;

$userExist = User::searchOne([
$userExist = UserModel::searchOne([
'type' => 'individual',
'email' => $email
]);
@@ -230,12 +230,12 @@ class SignupForm extends Model
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
* @return UserModel|null the saved model or null if saving fails
*/
public function signup()
{
$userContainer = Yii::$app->logic->getUserContainer();
$producerContainer = Yii::$app->logic->getProducerContainer();
$userContainer = \Yii::$app->logic->getUserContainer();
$producerContainer = \Yii::$app->logic->getProducerContainer();

if ($this->validate()) {

@@ -279,8 +279,8 @@ class SignupForm extends Model

public function processFormProducer($user)
{
$userContainer = Yii::$app->logic->getUserContainer();
$producerContainer = Yii::$app->logic->getProducerContainer();
$userContainer = \Yii::$app->logic->getUserContainer();
$producerContainer = \Yii::$app->logic->getProducerContainer();

// Création du producteur
$producer = $producerContainer->getService()->createInstance();
@@ -302,7 +302,7 @@ class SignupForm extends Model

public function populateUser($user)
{
$userContainer = Yii::$app->logic->getUserContainer();
$userContainer = \Yii::$app->logic->getUserContainer();

$user->username = $this->email;
$user->email = $this->email;

+ 15
- 11
frontend/views/layouts/main.php Visa fil

@@ -42,18 +42,20 @@ use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use common\widgets\Alert;
use common\helpers\Url;
use common\logic\Producer\ProducerModel;
use common\logic\User\UserModel;

/* @var $this \yii\web\View */
/* @var $content string */

$isHome = (Yii::$app->controller->id == 'site' && Yii::$app->controller->action->id == 'index');
$isHome = (Yii::$app->controller->id == 'site' && \Yii::$app->controller->action->id == 'index');

\common\assets\CommonAsset::register($this);
\frontend\assets\AppAsset::register($this);

$producer = null;
if (!Yii::$app->user->isGuest && Yii::$app->user->identity->id_producer > 0) {
$producer = Producer::searchOne(['id' => Yii::$app->user->identity->id_producer]);
if (!Yii::$app->user->isGuest && \Yii::$app->user->identity->id_producer > 0) {
$producer = ProducerModel::searchOne(['id' => \Yii::$app->user->identity->id_producer]);
}

?>
@@ -65,7 +67,7 @@ if (!Yii::$app->user->isGuest && Yii::$app->user->identity->id_producer > 0) {
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<link rel="icon" type="image/png" href="<?= $this->getUrlManager()->getBaseUrl(); ?>/img/favicon-distrib.png"/>
<!--[if IE]><link rel="shortcut icon" type="image/x-icon" href="<?= Yii::$app->urlManager->getBaseUrl(); ?>/img/favicon.ico" /><![endif]-->
<!--[if IE]><link rel="shortcut icon" type="image/x-icon" href="<?= \Yii::$app->urlManager->getBaseUrl(); ?>/img/favicon.ico" /><![endif]-->
<?php $this->head() ?>
<!--[if lt IE 9]>
<script src="<?= $this->getUrlManager()->getBaseUrl(); ?>/js/html5shiv.min.js"></script>
@@ -149,13 +151,13 @@ if (!Yii::$app->user->isGuest && Yii::$app->user->identity->id_producer > 0) {
[
'label' => '<span class="glyphicon glyphicon-log-in"></span> Connexion',
'url' => $this->getUrlManager()->createUrl(['site/login']),
'visible' => Yii::$app->user->isGuest,
'visible' => \Yii::$app->user->isGuest,
'active' => $this->getControllerAction() == 'site/login'
],
[
'label' => '<span class="glyphicon glyphicon-user"></span> Inscription',
'url' => $this->getUrlManager()->createUrl(['site/signup']),
'visible' => Yii::$app->user->isGuest,
'visible' => \Yii::$app->user->isGuest,
'active' => $this->getControllerAction() == 'site/signup'
],
[
@@ -186,20 +188,22 @@ if (!Yii::$app->user->isGuest && Yii::$app->user->identity->id_producer > 0) {
<section id="bookmarked-producers">
<div class="container">
<?php
$producersArray = Producer::find()

$producersArray = ProducerModel::find()
->joinWith(['userProducer user_producer'])
->where([
'user_producer.id_user' => User::getCurrentId(),
'user_producer.id_user' => UserModel::getCurrentId(),
'user_producer.bookmark' => 1,
])
->all();

?>
<?php if (count($producersArray)): ?>
<h2>Mes producteurs &gt;</h2>
<div id="producers">
<?php foreach ($producersArray as $producer): ?>
<a class="btn btn-xs btn-default"
href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]); ?>"><?= Html::encode($producer->name); ?></a>
href="<?= \Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]); ?>"><?= Html::encode($producer->name); ?></a>
<?php endforeach; ?>
</div>
<?php else: ?>
@@ -219,12 +223,12 @@ if (!Yii::$app->user->isGuest && Yii::$app->user->identity->id_producer > 0) {
<section class="container" id="content">
<?php if (Yii::$app->session->hasFlash('error')): ?>
<div class="alert alert-danger" role="alert">
<?= Yii::$app->session->getFlash('error') ?>
<?= \Yii::$app->session->getFlash('error') ?>
</div>
<?php endif; ?>
<?php if (Yii::$app->session->hasFlash('success')): ?>
<div class="alert alert-success" role="alert">
<?= Yii::$app->session->getFlash('success') ?>
<?= \Yii::$app->session->getFlash('success') ?>
</div>
<?php endif; ?>


+ 3
- 1
frontend/views/site/_prices_producer.php Visa fil

@@ -36,6 +36,8 @@
* termes.
*/

use yii\grid\GridView;

?>

<div class="alert alert-warning" role="alert">
@@ -78,6 +80,6 @@ GridView::widget([
]);
?>
<?php if (!isset($noButton)){ ?>
<a class="btn btn-default" href="<?= Yii::$app->urlManagerFrontend->createUrl(['site/prices']) ?>"><span class="glyphicon glyphicon-eur"></span> En savoir plus sur nos tarifs</a>
<a class="btn btn-default" href="<?= \Yii::$app->urlManagerFrontend->createUrl(['site/prices']) ?>"><span class="glyphicon glyphicon-eur"></span> En savoir plus sur nos tarifs</a>
<?php } ?>


+ 13
- 13
frontend/views/site/index.php Visa fil

@@ -65,16 +65,16 @@ $this->setMeta('description', 'Simplifiez la distribution de vos produits en cir
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">
<img class="img" src="<?= Yii::$app->urlManager->getBaseUrl(); ?>/img/cagette.png" id="img-producer" />
<img class="img" src="<?= \Yii::$app->urlManager->getBaseUrl(); ?>/img/cagette.png" id="img-producer" />
<span class="the-title">Producteurs</span>
</h2>
</div>
<div class="panel-body">
<p class="presentation">Simplifiez la distribution de vos produits<br /> avec des outils adaptés.</p>
<?php if(Yii::$app->user->isGuest): ?>
<a class="btn btn-primary" href="<?= Yii::$app->urlManagerFrontend->createUrl(['site/signup']) ; ?>"><span class="glyphicon glyphicon-user"></span> Je crée mon espace</a>
<a class="btn btn-primary" href="<?= \Yii::$app->urlManagerFrontend->createUrl(['site/signup']) ; ?>"><span class="glyphicon glyphicon-user"></span> Je crée mon espace</a>
<?php endif; ?>
<a class="btn btn-default" href="<?= Yii::$app->urlManagerFrontend->createUrl(['site/contact']) ; ?>"><span class="glyphicon glyphicon-info-sign"></span> Demande d'informations</a>
<a class="btn btn-default" href="<?= \Yii::$app->urlManagerFrontend->createUrl(['site/contact']) ; ?>"><span class="glyphicon glyphicon-info-sign"></span> Demande d'informations</a>
</div>
</div>
</div>
@@ -82,7 +82,7 @@ $this->setMeta('description', 'Simplifiez la distribution de vos produits en cir
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">
<img class="img" src="<?= Yii::$app->urlManager->getBaseUrl(); ?>/img/users.png" id="img-users" />
<img class="img" src="<?= \Yii::$app->urlManager->getBaseUrl(); ?>/img/users.png" id="img-users" />
<span class="the-title">Clients</span>
</h2>
</div>
@@ -90,9 +90,9 @@ $this->setMeta('description', 'Simplifiez la distribution de vos produits en cir
<p class="presentation">Réservez vos produits en ligne et récupérez votre commande
chez votre producteur ou dans un dépôt près de chez vous.</p>
<?php if(Yii::$app->user->isGuest): ?>
<a class="btn btn-primary" href="<?= Yii::$app->urlManagerFrontend->createUrl(['site/signup']) ; ?>"><span class="glyphicon glyphicon-user"></span> Je m'inscris</a>
<a class="btn btn-primary" href="<?= \Yii::$app->urlManagerFrontend->createUrl(['site/signup']) ; ?>"><span class="glyphicon glyphicon-user"></span> Je m'inscris</a>
<?php endif; ?>
<a class="btn btn-default" href="<?= Yii::$app->urlManagerFrontend->createUrl(['site/producers']) ; ?>"><span class="glyphicon glyphicon-search"></span> Je recherche un producteur</a>
<a class="btn btn-default" href="<?= \Yii::$app->urlManagerFrontend->createUrl(['site/producers']) ; ?>"><span class="glyphicon glyphicon-search"></span> Je recherche un producteur</a>
</div>
</div>
</div>
@@ -113,35 +113,35 @@ $this->setMeta('description', 'Simplifiez la distribution de vos produits en cir
</div>
<div class="panel-body">
<div class="block block-order col-md-6">
<img src="<?= Yii::$app->urlManager->getBaseUrl(); ?>/img/order.png" />
<img src="<?= \Yii::$app->urlManager->getBaseUrl(); ?>/img/order.png" />
<p>Prise de commande en ligne automatisée avec génération d'un récapitulatif par jour de distribution.</p>
<div class="clr"></div>
</div>
<div class="block block-payment col-md-6">
<img src="<?= Yii::$app->urlManager->getBaseUrl(); ?>/img/payment.png" />
<img src="<?= \Yii::$app->urlManager->getBaseUrl(); ?>/img/payment.png" />
<p>Système de crédit permettant la comptabilisation des paiements.</p>
<div class="clr"></div>
</div>
<div class="clr"></div>
<div class="block block-points-sale-products col-md-6">
<img src="<?= Yii::$app->urlManager->getBaseUrl(); ?>/img/map-marker.png" />
<img src="<?= \Yii::$app->urlManager->getBaseUrl(); ?>/img/map-marker.png" />
<p>Gestion des différents points de vente et produits.</p>
<div class="clr"></div>
</div>
<div class="block block-subscriptions col-md-6">
<img src="<?= Yii::$app->urlManager->getBaseUrl(); ?>/img/subscription.png" />
<img src="<?= \Yii::$app->urlManager->getBaseUrl(); ?>/img/subscription.png" />
<p>Gestion des abonnement.</p>
<div class="clr"></div>
</div>
<div class="clr"></div>
<div class="block block-communication col-md-6">
<img src="<?= Yii::$app->urlManager->getBaseUrl(); ?>/img/megaphone.png" />
<img src="<?= \Yii::$app->urlManager->getBaseUrl(); ?>/img/megaphone.png" />
<p>Communication simplifiée avec les clients.</p>
<div class="clr"></div>
</div>
<div class="block block-evolution col-md-6">
<img src="<?= Yii::$app->urlManager->getBaseUrl(); ?>/img/idea.png" />
<p><a href="<?= Yii::$app->urlManager->createUrl(['site/contact']) ?>">Proposez-nous</a> vos idées afin de faire évoluer l'outil !</p>
<img src="<?= \Yii::$app->urlManager->getBaseUrl(); ?>/img/idea.png" />
<p><a href="<?= \Yii::$app->urlManager->createUrl(['site/contact']) ?>">Proposez-nous</a> vos idées afin de faire évoluer l'outil !</p>
<div class="clr"></div>
</div>
</div>

Vissa filer visades inte eftersom för många filer har ändrats

Laddar…
Avbryt
Spara