use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\models\User ; | |||||
use common\models\UserSearch ; | |||||
use common\models\UserModel ; | |||||
use common\models\UserModelSearch ; | |||||
use backend\models\AccessUserProducerForm ; | use backend\models\AccessUserProducerForm ; | ||||
/** | /** | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend(); | |||||
return UserModel::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
*/ | */ | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$userSearch = new UserSearch ; | |||||
$userSearch = new UserModelSearch ; | |||||
$usersArray = $userSearch->search()->query->all() ; | $usersArray = $userSearch->search()->query->all() ; | ||||
$modelAccessUserProducerForm = new AccessUserProducerForm ; | $modelAccessUserProducerForm = new AccessUserProducerForm ; | ||||
Yii::$app->getSession()->setFlash('success', 'Droits ajoutés à l\'utilisateur'); | Yii::$app->getSession()->setFlash('success', 'Droits ajoutés à l\'utilisateur'); | ||||
} | } | ||||
$usersAccessArray = User::find() | |||||
$usersAccessArray = UserModel::find() | |||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'status' => User::STATUS_PRODUCER | |||||
'status' => UserModel::STATUS_PRODUCER | |||||
]) | ]) | ||||
->all() ; | ->all() ; | ||||
*/ | */ | ||||
public function actionDelete($idUser) | public function actionDelete($idUser) | ||||
{ | { | ||||
$user = User::searchOne([ | |||||
$user = UserModel::searchOne([ | |||||
'id' => $idUser | 'id' => $idUser | ||||
]) ; | ]) ; | ||||
if($user) { | if($user) { | ||||
$user->id_producer = 0 ; | $user->id_producer = 0 ; | ||||
$user->status = User::STATUS_ACTIVE ; | |||||
$user->status = UserModel::STATUS_ACTIVE ; | |||||
$user->save() ; | $user->save() ; | ||||
Yii::$app->getSession()->setFlash('success', 'Droits de l\'utilisateur supprimé.'); | Yii::$app->getSession()->setFlash('success', 'Droits de l\'utilisateur supprimé.'); | ||||
} | } |
use backend\models\MailForm ; | use backend\models\MailForm ; | ||||
use yii\web\NotFoundHttpException ; | use yii\web\NotFoundHttpException ; | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getCurrentStatus() == USER::STATUS_ADMIN; | |||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
} | } | ||||
} | } | ||||
elseif($section == 'users') { | elseif($section == 'users') { | ||||
$users = User::find() | |||||
$users = UserModel::find() | |||||
->where([ | ->where([ | ||||
'user.status' => User::STATUS_ACTIVE | |||||
'user.status' => UserModel::STATUS_ACTIVE | |||||
]) | ]) | ||||
->all() ; | ->all() ; | ||||
$usersArray = []; | $usersArray = []; |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend(); | |||||
return UserModel::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], |
namespace backend\controllers; | namespace backend\controllers; | ||||
use Yii; | use Yii; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
use yii\web\Controller; | use yii\web\Controller; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
$order->getAmount(Order::AMOUNT_REMAINING), | $order->getAmount(Order::AMOUNT_REMAINING), | ||||
$order->distribution->id_producer, | $order->distribution->id_producer, | ||||
$order->id_user, | $order->id_user, | ||||
User::ID_USER_SYSTEM | |||||
UserModel::ID_USER_SYSTEM | |||||
); | ); | ||||
$countOrders++; | $countOrders++; | ||||
} | } | ||||
$mail->setSubject($subject); | $mail->setSubject($subject); | ||||
// envoi des emails à tous les comptes users (statut producer) associés à ce producteur | // envoi des emails à tous les comptes users (statut producer) associés à ce producteur | ||||
$userArray = User::searchAll([ | |||||
$userArray = UserModel::searchAll([ | |||||
'id_producer' => $producer->id, | 'id_producer' => $producer->id, | ||||
'status' => User::STATUS_PRODUCER | |||||
'status' => UserModel::STATUS_PRODUCER | |||||
]); | ]); | ||||
foreach ($userArray as $user) { | foreach ($userArray as $user) { |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use Yii; | use Yii; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\Development; | use common\models\Development; | ||||
use common\models\DevelopmentPriority; | use common\models\DevelopmentPriority; | ||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend() ; | |||||
return UserModel::hasAccessBackend() ; | |||||
} | } | ||||
] | ] | ||||
], | ], |
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\Order; | use common\models\Order; | ||||
use common\models\ProductCategory; | use common\models\ProductCategory; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\Subscription; | use common\models\Subscription; | ||||
use common\helpers\Price; | use common\helpers\Price; | ||||
use common\models\PointSaleDistribution; | use common\models\PointSaleDistribution; | ||||
use common\models\UserProducer; | |||||
use common\logic\UserProducer\UserProducerModel; | |||||
use DateTime; | use DateTime; | ||||
class DistributionController extends BackendController | class DistributionController extends BackendController | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | '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; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
]; | ]; | ||||
// utilisateurs | // utilisateurs | ||||
$usersArray = User::findBy()->all(); | |||||
$usersArray = UserModel::findBy()->all(); | |||||
$json['users'] = $usersArray; | $json['users'] = $usersArray; | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$user = User::findOne(['id' => $idUser]); | |||||
$user = UserModel::findOne(['id' => $idUser]); | |||||
$favoritePointSale = $user->getFavoritePointSale(); | $favoritePointSale = $user->getFavoritePointSale(); | ||||
$idFavoritePointSale = 0; | $idFavoritePointSale = 0; | ||||
if ($favoritePointSale) { | if ($favoritePointSale) { | ||||
$order = Order::searchOne(['id' => $idOrder]); | $order = Order::searchOne(['id' => $idOrder]); | ||||
$distribution = Distribution::findOne($idDistribution); | $distribution = Distribution::findOne($idDistribution); | ||||
$user = User::findOne($idUser); | |||||
$user = UserModel::findOne($idUser); | |||||
$pointSale = PointSale::findOne($idPointSale); | $pointSale = PointSale::findOne($idPointSale); | ||||
$productsArray = Product::find() | $productsArray = Product::find() | ||||
if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | ||||
$userProducer = null; | $userProducer = null; | ||||
if ($order->id_user) { | if ($order->id_user) { | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $order->id_user, | 'id_user' => $order->id_user, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
$order->save(); | $order->save(); | ||||
// init invoice prices | // init invoice prices | ||||
$user = User::searchOne([ | |||||
$user = UserModel::searchOne([ | |||||
'id' => $deliveryNote->id_user | 'id' => $deliveryNote->id_user | ||||
]); | ]); | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $deliveryNote->id_user, | 'id_user' => $deliveryNote->id_user, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
if ($firstOrder->pointSale->id_user) { | if ($firstOrder->pointSale->id_user) { | ||||
$deliveryNote->id_user = $firstOrder->pointSale->id_user; | $deliveryNote->id_user = $firstOrder->pointSale->id_user; | ||||
$user = User::searchOne([ | |||||
$user = UserModel::searchOne([ | |||||
'id' => $deliveryNote->id_user | 'id' => $deliveryNote->id_user | ||||
]); | ]); | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $deliveryNote->id_user, | 'id_user' => $deliveryNote->id_user, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
} else { | } 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->name_legal_person = $firstOrder->pointSale->name; | ||||
$user->address = $firstOrder->pointSale->address; | $user->address = $firstOrder->pointSale->address; | ||||
$user->id_producer = 0; | $user->id_producer = 0; | ||||
} | } | ||||
$user->save(); | $user->save(); | ||||
$userProducer = new UserProducer; | |||||
$userProducer = new UserProducerModel; | |||||
$userProducer->id_user = $user->id; | $userProducer->id_user = $user->id; | ||||
$userProducer->id_producer = GlobalParam::getCurrentProducerId(); | $userProducer->id_producer = GlobalParam::getCurrentProducerId(); | ||||
$userProducer->credit = 0; | $userProducer->credit = 0; | ||||
} | } | ||||
if (!isset($user) || !$user) { | if (!isset($user) || !$user) { | ||||
$user = User::searchOne([ | |||||
$user = UserModel::searchOne([ | |||||
'id' => $deliveryNote->id_user | 'id' => $deliveryNote->id_user | ||||
]); | ]); | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $deliveryNote->id_user, | 'id_user' => $deliveryNote->id_user, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); |
use common\models\PointSale; | use common\models\PointSale; | ||||
use common\models\Product; | use common\models\Product; | ||||
use common\models\Quotation; | use common\models\Quotation; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\Document; | use common\models\Document; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\models\Order; | use common\models\Order; | ||||
use common\models\UserProducer; | |||||
use common\logic\UserProducer\UserProducerModel; | |||||
use kartik\mpdf\Pdf; | use kartik\mpdf\Pdf; | ||||
use yii\base\UserException; | use yii\base\UserException; | ||||
use yii; | use yii; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend(); | |||||
return UserModel::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
if ($idUser > 0) { | if ($idUser > 0) { | ||||
$user = User::searchOne([ | |||||
$user = UserModel::searchOne([ | |||||
'id' => $idUser | 'id' => $idUser | ||||
]); | ]); | ||||
); | ); | ||||
} | } | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $document->user->id, | 'id_user' => $document->user->id, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); |
use common\models\Order; | use common\models\Order; | ||||
use common\models\ProductOrder; | use common\models\ProductOrder; | ||||
use common\models\Product; | use common\models\Product; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\ProductDistribution; | use common\models\ProductDistribution; | ||||
use common\models\Distribution; | use common\models\Distribution; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\UserProducer; | |||||
use common\logic\UserProducer\UserProducerModel; | |||||
class OrderController extends BackendController | class OrderController extends BackendController | ||||
{ | { | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | '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; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
// users | // users | ||||
$arrayUsers = [0 => '--']; | $arrayUsers = [0 => '--']; | ||||
$users = User::searchAll([], ['orderby' => 'lastname, name ASC']); | |||||
$users = UserModel::searchAll([], ['orderby' => 'lastname, name ASC']); | |||||
foreach ($users as $user) { | foreach ($users as $user) { | ||||
$arrayUsers[$user->id] = $user->name . ' ' . $user->lastname; | $arrayUsers[$user->id] = $user->name . ' ' . $user->lastname; | ||||
$order->getAmount(Order::AMOUNT_PAID), | $order->getAmount(Order::AMOUNT_PAID), | ||||
$order->distribution->id_producer, | $order->distribution->id_producer, | ||||
$order->id_user, | $order->id_user, | ||||
User::getCurrentId() | |||||
UserModel::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
$userProducer = false; | $userProducer = false; | ||||
if (isset($order->user) && $order->user) { | if (isset($order->user) && $order->user) { | ||||
$user = $order->user; | $user = $order->user; | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'id_producer' => $order->distribution->id_producer | 'id_producer' => $order->distribution->id_producer | ||||
]); | ]); | ||||
$order->id_user = 0; | $order->id_user = 0; | ||||
} | } | ||||
$user = User::searchOne(['id' => $order->id_user]); | |||||
$user = UserModel::searchOne(['id' => $order->id_user]); | |||||
$userProducer = false; | $userProducer = false; | ||||
if ($user) { | if ($user) { | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'id_producer' => $order->distribution->id_producer | 'id_producer' => $order->distribution->id_producer | ||||
]); | ]); | ||||
$amountPaid, | $amountPaid, | ||||
GlobalParam::getCurrentProducerId(), | GlobalParam::getCurrentProducerId(), | ||||
$oldIdUser, | $oldIdUser, | ||||
User::getCurrentId() | |||||
UserModel::getCurrentId() | |||||
); | ); | ||||
$order = Order::searchOne(['id' => $order->id]); | $order = Order::searchOne(['id' => $order->id]); | ||||
} | } | ||||
$html = ''; | $html = ''; | ||||
if ($order->id_user) { | if ($order->id_user) { | ||||
$userProducer = UserProducer::find() | |||||
$userProducer = UserProducerModel::find() | |||||
->where([ | ->where([ | ||||
'id_user' => $order->id_user, | 'id_user' => $order->id_user, | ||||
'id_producer' => $order->distribution->id_producer | 'id_producer' => $order->distribution->id_producer | ||||
$amount, | $amount, | ||||
GlobalParam::getCurrentProducerId(), | GlobalParam::getCurrentProducerId(), | ||||
$order->id_user, | $order->id_user, | ||||
User::getCurrentId() | |||||
UserModel::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
use yii\web\Controller; | use yii\web\Controller; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\UserPointSale; | use common\models\UserPointSale; | ||||
use common\models\Order ; | use common\models\Order ; | ||||
use common\models\Producer ; | use common\models\Producer ; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend(); | |||||
return UserModel::hasAccessBackend(); | |||||
} | } | ||||
], | ], | ||||
], | ], | ||||
*/ | */ | ||||
public function initForm($id = 0) | 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]) | ->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') | ->orderBy('user_point_sale.id_point_sale DESC, lastname ASC, name ASC') | ||||
->all(); | ->all(); |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use Yii; | use Yii; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getCurrentStatus() == USER::STATUS_ADMIN; | |||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
$fromProducerId = (int) $fromProducerId; | $fromProducerId = (int) $fromProducerId; | ||||
$toProducerId = (int) $toProducerId; | $toProducerId = (int) $toProducerId; | ||||
$count = 0; | $count = 0; | ||||
$usersArray = User::findBy(['id_producer' => $fromProducerId])->all(); | |||||
$usersArray = UserModel::findBy(['id_producer' => $fromProducerId])->all(); | |||||
foreach($usersArray as $user) { | foreach($usersArray as $user) { | ||||
$idUser = $user['user_id']; | $idUser = $user['user_id']; |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\models\ProducerPriceRange; | use common\models\ProducerPriceRange; | ||||
use Yii; | use Yii; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use backend\models\MailForm; | use backend\models\MailForm; | ||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
use yii\web\Controller; | use yii\web\Controller; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend(); | |||||
return UserModel::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], |
use common\models\ProducerPriceRange; | use common\models\ProducerPriceRange; | ||||
use Yii; | use Yii; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getCurrentStatus() == USER::STATUS_ADMIN; | |||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN; | |||||
} | } | ||||
] | ] | ||||
], | ], |
use yii\web\Controller; | use yii\web\Controller; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\UserPointSale; | use common\models\UserPointSale; | ||||
use common\models\Order; | use common\models\Order; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend(); | |||||
return UserModel::hasAccessBackend(); | |||||
} | } | ||||
], | ], | ||||
], | ], |
use common\models\ProductPrice; | use common\models\ProductPrice; | ||||
use common\models\ProductPriceSearch; | use common\models\ProductPriceSearch; | ||||
use common\models\ProductSearch; | use common\models\ProductSearch; | ||||
use common\models\UserSearch; | |||||
use common\models\UserModelSearch; | |||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\models\Product; | use common\models\Product; | ||||
use common\models\Distribution; | 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\data\ActiveDataProvider; | ||||
use yii\web\Controller; | use yii\web\Controller; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend(); | |||||
return UserModel::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
'id_product' => $id | 'id_product' => $id | ||||
])); | ])); | ||||
$userProducerWithProductPercent = UserProducer::searchAll([], [ | |||||
$userProducerWithProductPercent = UserProducerModel::searchAll([], [ | |||||
'join_with' => ['user'], | 'join_with' => ['user'], | ||||
'conditions' => 'user_producer.product_price_percent != 0', | 'conditions' => 'user_producer.product_price_percent != 0', | ||||
]); | ]); |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\Distribution ; | use common\models\Distribution ; | ||||
class ReportController extends BackendController | class ReportController extends BackendController | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend() ; | |||||
return UserModel::hasAccessBackend() ; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$usersArray = User::findBy()->all() ; | |||||
$usersArray = UserModel::findBy()->all() ; | |||||
$pointsSaleArray = PointSale::searchAll() ; | $pointsSaleArray = PointSale::searchAll() ; | ||||
// distributions | // distributions |
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\forms\LoginForm; | use common\forms\LoginForm; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use common\models\Product; | use common\models\Product; | ||||
use common\models\PointSale; | use common\models\PointSale; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend() ; | |||||
return UserModel::hasAccessBackend() ; | |||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getCurrentStatus() == User::STATUS_ADMIN ; | |||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN ; | |||||
} | } | ||||
], | ], | ||||
], | ], | ||||
]); | ]); | ||||
// clients | // clients | ||||
$usersArray = User::findBy() | |||||
$usersArray = UserModel::findBy() | |||||
->orderBy('created_at DESC') | ->orderBy('created_at DESC') | ||||
->limit(5) | ->limit(5) | ||||
->all(); | ->all(); | ||||
$usersNegativeCredit = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
$usersNegativeCredit = UserModel::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
->andWhere('user_producer.credit < 0') | ->andWhere('user_producer.credit < 0') | ||||
->all(); | ->all(); | ||||
use yii\web\Controller; | use yii\web\Controller; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use Yii; | use Yii; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\Order; | use common\models\Order; | ||||
use DateTime; | use DateTime; | ||||
use DateInterval; | use DateInterval; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend() ; | |||||
return UserModel::hasAccessBackend() ; | |||||
} | } | ||||
] | ] | ||||
], | ], |
use common\models\TaxRate; | use common\models\TaxRate; | ||||
use Yii; | use Yii; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getCurrentStatus() == USER::STATUS_ADMIN; | |||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN; | |||||
} | } | ||||
] | ] | ||||
], | ], |
use backend\models\CreditForm; | use backend\models\CreditForm; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\Mailjet; | use common\helpers\Mailjet; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\Distribution; | use common\models\Distribution; | ||||
use backend\models\MailForm; | use backend\models\MailForm; | ||||
use common\models\UserGroup; | use common\models\UserGroup; | ||||
use common\models\UserProducer; | |||||
use common\logic\UserProducer\UserProducerModel; | |||||
use common\models\UserPointSale; | use common\models\UserPointSale; | ||||
use common\models\PointSale; | use common\models\PointSale; | ||||
use common\models\UserUserGroup; | use common\models\UserUserGroup; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend(); | |||||
return UserModel::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
} | } | ||||
// product price percent | // product price percent | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'id_user' => $model->id | 'id_user' => $model->id | ||||
]); | ]); | ||||
*/ | */ | ||||
public function actionCreate() | public function actionCreate() | ||||
{ | { | ||||
$model = new User(); | |||||
$model = new UserModel(); | |||||
$userExist = false; | $userExist = false; | ||||
$posts = Yii::$app->request->post(); | $posts = Yii::$app->request->post(); | ||||
if ($posts && isset($posts['User']['email']) && strlen($posts['User']['email']) > 0) { | if ($posts && isset($posts['User']['email']) && strlen($posts['User']['email']) > 0) { | ||||
$userExist = User::searchOne([ | |||||
$userExist = UserModel::searchOne([ | |||||
'email' => $posts['User']['email'] | 'email' => $posts['User']['email'] | ||||
]); | ]); | ||||
} | } | ||||
$model->save(); | $model->save(); | ||||
// liaison etablissement / user | // liaison etablissement / user | ||||
$useProducer = new UserProducer(); | |||||
$useProducer = new UserProducerModel(); | |||||
$useProducer->id_user = $model->id; | $useProducer->id_user = $model->id; | ||||
$useProducer->id_producer = GlobalParam::getCurrentProducerId(); | $useProducer->id_producer = GlobalParam::getCurrentProducerId(); | ||||
$useProducer->credit = 0; | $useProducer->credit = 0; | ||||
$this->processProductPricePercent($model); | $this->processProductPricePercent($model); | ||||
Yii::$app->getSession()->setFlash('success', 'Utilisateur créé.'); | Yii::$app->getSession()->setFlash('success', 'Utilisateur créé.'); | ||||
$model = new User(); | |||||
$model = new UserModel(); | |||||
} | } | ||||
} | } | ||||
// Moodification du profil | // Moodification du profil | ||||
$previousMail = $model->email; | $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 ($userBelongToProducer) { | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
/** | /** | ||||
* Lie un utilisateur aux points de vente sélectionnés. | * Lie un utilisateur aux points de vente sélectionnés. | ||||
* | * | ||||
* @param User $modelUser | |||||
* @param UserModel $modelUser | |||||
*/ | */ | ||||
public function processLinkPointSale($modelUser) | public function processLinkPointSale($modelUser) | ||||
{ | { | ||||
/** | /** | ||||
* Lie un utilisateur aux groupes d'utilisateurs sélectionnés. | * Lie un utilisateur aux groupes d'utilisateurs sélectionnés. | ||||
* | * | ||||
* @param User $modelUser | |||||
* @param UserModel $modelUser | |||||
*/ | */ | ||||
public function processLinkUserGroup($modelUser) | public function processLinkUserGroup($modelUser) | ||||
{ | { | ||||
public function processProductPricePercent($model) | public function processProductPricePercent($model) | ||||
{ | { | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'id_user' => $model->id | 'id_user' => $model->id | ||||
]); | ]); | ||||
*/ | */ | ||||
public function actionDelete($id) | public function actionDelete($id) | ||||
{ | { | ||||
$userProducer = UserProducer::findOne([ | |||||
$userProducer = UserProducerModel::findOne([ | |||||
'id_user' => $id, | 'id_user' => $id, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
$usersPointSaleLink = 1; | $usersPointSaleLink = 1; | ||||
} | } | ||||
$users = User::findBy([ | |||||
$users = UserModel::findBy([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'id_point_sale' => $idPointSale, | 'id_point_sale' => $idPointSale, | ||||
'users_point_sale_link' => $usersPointSaleLink, | 'users_point_sale_link' => $usersPointSaleLink, | ||||
*/ | */ | ||||
public function actionCredit($id) | 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(); | $creditForm = new CreditForm(); | ||||
if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) { | if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) { | ||||
*/ | */ | ||||
public function actionOrders($id) | public function actionOrders($id) | ||||
{ | { | ||||
$user = User::findOne($id); | |||||
$user = UserModel::findOne($id); | |||||
$searchModel = new OrderSearch; | $searchModel = new OrderSearch; | ||||
$dataProvider = $searchModel->search(array_merge(Yii::$app->request->queryParams, ['id_user' => $id])); | $dataProvider = $searchModel->search(array_merge(Yii::$app->request->queryParams, ['id_user' => $id])); | ||||
*/ | */ | ||||
public function actionStateCredit($idUser, $state) | public function actionStateCredit($idUser, $state) | ||||
{ | { | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $idUser | 'id_user' => $idUser | ||||
]); | ]); | ||||
* Finds the User model based on its primary key value. | * Finds the User model based on its primary key value. | ||||
* If the model is not found, a 404 HTTP exception will be thrown. | * If the model is not found, a 404 HTTP exception will be thrown. | ||||
* @param integer $id | * @param integer $id | ||||
* @return User the loaded model | |||||
* @return UserModel the loaded model | |||||
* @throws NotFoundHttpException if the model cannot be found | * @throws NotFoundHttpException if the model cannot be found | ||||
*/ | */ | ||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = User::findOne($id)) !== null) { | |||||
if (($model = UserModel::findOne($id)) !== null) { | |||||
return $model; | return $model; | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); |
use yii\web\Controller; | use yii\web\Controller; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\UserPointSale; | use common\models\UserPointSale; | ||||
use common\models\Order; | use common\models\Order; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::hasAccessBackend(); | |||||
return UserModel::hasAccessBackend(); | |||||
} | } | ||||
], | ], | ||||
], | ], |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use Yii; | use Yii; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\models\UserProducer ; | |||||
use common\logic\UserProducer\UserProducerModel ; | |||||
/** | /** | ||||
* ContactForm is the model behind the contact form. | * ContactForm is the model behind the contact form. | ||||
public function save() | public function save() | ||||
{ | { | ||||
$user = User::searchOne([ | |||||
$user = UserModel::searchOne([ | |||||
'id' => $this->id_user | 'id' => $this->id_user | ||||
]) ; | ]) ; | ||||
if($user) { | if($user) { | ||||
$user->id_producer = GlobalParam::getCurrentProducerId() ; | $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(); | return $user->save(); | ||||
} | } |
use Yii; | use Yii; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use common\models\CreditHistory ; | use common\models\CreditHistory ; | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\models\UserProducer ; | |||||
use common\logic\UserProducer\UserProducerModel ; | |||||
use common\helpers\Mail ; | use common\helpers\Mail ; | ||||
/** | /** | ||||
// on prévient l'utilisateur que son compte vient d'être crédité | // on prévient l'utilisateur que son compte vient d'être crédité | ||||
if($this->send_mail) { | if($this->send_mail) { | ||||
$user = User::findOne($this->id_user) ; | |||||
$user = UserModel::findOne($this->id_user) ; | |||||
$producer = GlobalParam::getCurrentProducer() ; | $producer = GlobalParam::getCurrentProducer() ; | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $this->id_user | 'id_user' => $this->id_user | ||||
]); | ]); | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\Development; | use common\models\Development; | ||||
use common\models\DevelopmentPriority; | use common\models\DevelopmentPriority; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\helpers\Url; | use common\helpers\Url; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
]; | ]; | ||||
if (User::hasAccessBackend()) { | |||||
if (UserModel::hasAccessBackend()) { | |||||
$columns[] = [ | $columns[] = [ | ||||
'header' => 'Priorité', | 'header' => 'Priorité', | ||||
]; | ]; | ||||
} | } | ||||
if (User::getCurrentStatus() == USER::STATUS_ADMIN) { | |||||
if (UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN) { | |||||
$columns[] = [ | $columns[] = [ | ||||
'class' => 'yii\grid\ActionColumn', | 'class' => 'yii\grid\ActionColumn', | ||||
'template' => '{update}', | 'template' => '{update}', |
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\Development; | use common\models\Development; | ||||
use common\models\DevelopmentPriority; | use common\models\DevelopmentPriority; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\helpers\Url; | use common\helpers\Url; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use yii\helpers\ArrayHelper; | use yii\helpers\ArrayHelper; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
<div class="navbar-custom-menu"> | <div class="navbar-custom-menu"> | ||||
<?php | <?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")) . '\'') | ->andWhere('CAST(FROM_UNIXTIME(user.created_at) AS date) > \'' . date("Y-m-d", strtotime("-7 days")) . '\'') | ||||
->orderBy('created_at DESC') | ->orderBy('created_at DESC') | ||||
->all(); | ->all(); | ||||
<?php | <?php | ||||
$usersNegativeCreditArray = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
$usersNegativeCreditArray = UserModel::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
->andWhere('user_producer.credit < 0') | ->andWhere('user_producer.credit < 0') | ||||
->orderBy('lastname, name ASC') | ->orderBy('lastname, name ASC') | ||||
->all(); | ->all(); | ||||
<?php foreach ($usersNegativeCreditArray as $user): ?> | <?php foreach ($usersNegativeCreditArray as $user): ?> | ||||
<li> | <li> | ||||
<a href="<?= Yii::$app->urlManagerBackend->createUrl(['user/credit', 'id' => $user['user_id']]); ?>"> | <a href="<?= Yii::$app->urlManagerBackend->createUrl(['user/credit', 'id' => $user['user_id']]); ?>"> | ||||
<h5><?= User::getUsernameFromArray($user); ?> | |||||
<h5><?= UserModel::getUsernameFromArray($user); ?> | |||||
<small> | <small> | ||||
<i class="fa fa-euro"></i> <?= Price::format($user['credit']); ?> | <i class="fa fa-euro"></i> <?= Price::format($user['credit']); ?> | ||||
</small> | </small> | ||||
</li> | </li> | ||||
<?php if (User::isCurrentProducer() || User::isCurrentAdmin()): ?> | |||||
<?php if (UserModel::isCurrentProducer() || UserModel::isCurrentAdmin()): ?> | |||||
<li class="dropdown producer-menu"> | <li class="dropdown producer-menu"> | ||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> | <a href="#" class="dropdown-toggle" data-toggle="dropdown"> | ||||
</a> | </a> | ||||
<ul class="dropdown-menu"> | <ul class="dropdown-menu"> | ||||
<?php if (User::isCurrentAdmin()): ?> | |||||
<?php if (UserModel::isCurrentAdmin()): ?> | |||||
<li> | <li> | ||||
<a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => GlobalParam::getCurrentProducer()->slug]); ?>"> | <a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => GlobalParam::getCurrentProducer()->slug]); ?>"> | ||||
<i class="fa fa-th-large"></i> | <i class="fa fa-th-large"></i> | ||||
<li class="dropdown user user-menu"> | <li class="dropdown user user-menu"> | ||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> | <a href="#" class="dropdown-toggle" data-toggle="dropdown"> | ||||
<i class="fa fa-user"></i> | <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> | <i class="fa fa-caret-down"></i> | ||||
</a> | </a> | ||||
<ul class="dropdown-menu"> | <ul class="dropdown-menu"> |
use yii\bootstrap\NavBar; | use yii\bootstrap\NavBar; | ||||
use yii\widgets\Breadcrumbs; | use yii\widgets\Breadcrumbs; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use yii\helpers\ArrayHelper; | use yii\helpers\ArrayHelper; | ||||
use common\helpers\Url; | use common\helpers\Url; | ||||
$menuItems[] = ['label' => 'Connexion', 'url' => ['/site/login']]; | $menuItems[] = ['label' => 'Connexion', 'url' => ['/site/login']]; | ||||
} else { | } else { | ||||
if (Yii::$app->user->identity->status == USER::STATUS_ADMIN) { | |||||
if (Yii::$app->user->identity->status == UserModel::STATUS_ADMIN) { | |||||
$menuItems[] = [ | $menuItems[] = [ | ||||
'label' => '<span class="glyphicon glyphicon-asterisk"></span>', | 'label' => '<span class="glyphicon glyphicon-asterisk"></span>', | ||||
'url' => '#', | 'url' => '#', | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<?php if (!Yii::$app->user->isGuest): ?> | <?php if (!Yii::$app->user->isGuest): ?> | ||||
<div class="name-producer"> | <div class="name-producer"> | ||||
<?php if (User::getCurrentStatus() == User::STATUS_PRODUCER): ?> | |||||
<?php if (UserModel::getCurrentStatus() == UserModel::STATUS_PRODUCER): ?> | |||||
<span><?= Html::encode(Yii::$app->user->identity->getNameProducer()); ?></span> | <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']); ?> | <?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) { | Html::dropDownList('select_producer', GlobalParam::getCurrentProducerId(), ArrayHelper::map(Producer::find()->orderBy('name ASC')->all(), 'id', function ($model, $defaultValue) { |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
use common\models\Etablissement ; | use common\models\Etablissement ; | ||||
$this->title = 'Facturation'; | $this->title = 'Facturation'; |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\models\Distribution ; | use common\models\Distribution ; | ||||
else { | else { | ||||
foreach($model->user as $u) | foreach($model->user as $u) | ||||
{ | { | ||||
if($u->status == User::STATUS_PRODUCER) | |||||
if($u->status == UserModel::STATUS_PRODUCER) | |||||
{ | { | ||||
return Html::encode($u->lastname.' '.$u->name) | return Html::encode($u->lastname.' '.$u->name) | ||||
.'<br />'.Html::encode($u->email) | .'<br />'.Html::encode($u->email) |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\Distribution; | use common\models\Distribution; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use yii\bootstrap\ActiveForm; | use yii\bootstrap\ActiveForm; | ||||
use common\models\TaxRate; | use common\models\TaxRate; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
?> | ?> | ||||
'options' => ['enctype' => 'multipart/form-data'] | '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_user_group')->dropDownList(UserGroup::populateDropdownList()); ?> | ||||
<?= $form->field($model, 'id_point_sale')->dropDownList(PointSale::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').')'); ?> | <?= $form->field($model, 'from_quantity')->label('À partir de la quantité ('.Product::strUnit(Product::getRefUnit($modelProduct->unit), 'wording').')'); ?> |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use yii\helpers\ArrayHelper ; | use yii\helpers\ArrayHelper ; | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
use common\models\PointSale ; | use common\models\PointSale ; | ||||
use common\helpers\GlobalParam ; | use common\helpers\GlobalParam ; | ||||
<?= $form->field($model, 'id')->hiddenInput() ?> | <?= $form->field($model, 'id')->hiddenInput() ?> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<div class="col-md-5" id="bloc-select-user"> | <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> | ||||
<div class="col-md-1" id="or-user"> | <div class="col-md-1" id="or-user"> | ||||
<span>OU</span> | <span>OU</span> |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\Distribution; | use common\models\Distribution; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\Order; | use common\models\Order; | ||||
$this->setTitle('Utilisateurs'); | $this->setTitle('Utilisateurs'); | ||||
'attribute' => 'username', | 'attribute' => 'username', | ||||
'label' => 'Nom', | 'label' => 'Nom', | ||||
'value' => function ($model) { | 'value' => function ($model) { | ||||
return User::getUsernameFromArray($model); | |||||
return UserModel::getUsernameFromArray($model); | |||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'type', | 'attribute' => 'type', | ||||
'label' => 'Type', | 'label' => 'Type', | ||||
'value' => function ($model) { | 'value' => function ($model) { | ||||
$typeArray = User::getTypeChoicesArray(); | |||||
$typeArray = UserModel::getTypeChoicesArray(); | |||||
if(isset($typeArray[$model['type']])) { | if(isset($typeArray[$model['type']])) { | ||||
return $typeArray[$model['type']]; | return $typeArray[$model['type']]; | ||||
} | } | ||||
'buttons' => [ | 'buttons' => [ | ||||
'update' => function ($url, $model) { | 'update' => function ($url, $model) { | ||||
$url = Yii::$app->urlManager->createUrl(['user/update', 'id' => $model->id]); | $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, [ | return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ | ||||
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | ||||
]); | ]); |
namespace common\components; | 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\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 | 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(); | return new UserContainer(); | ||||
} | } | ||||
public function getProducerContainer() | |||||
public function getProducerContainer(): ProducerContainer | |||||
{ | { | ||||
return new ProducerContainer(); | return new ProducerContainer(); | ||||
} | } | ||||
public function getProducerPriceRangeContainer() | |||||
public function getProducerPriceRangeContainer(): ProducerPriceRangeContainer | |||||
{ | { | ||||
return new ProducerPriceRangeContainer(); | return new ProducerPriceRangeContainer(); | ||||
} | } | ||||
public function getUserProducerContainer() | |||||
public function getUserProducerContainer(): UserProducerContainer | |||||
{ | { | ||||
return new UserProducerContainer(); | return new UserProducerContainer(); | ||||
} | } | ||||
public function getCreditHistoryContainer() | |||||
public function getCreditHistoryContainer(): CreditHistoryContainer | |||||
{ | { | ||||
return new 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.'); | |||||
} | |||||
} | } |
public function getLogic() | public function getLogic() | ||||
{ | { | ||||
return Yii::$app->logic; | |||||
return \Yii::$app->logic; | |||||
} | } | ||||
public function setTitle($title, $page_title = '') | public function setTitle($title, $page_title = '') | ||||
public function getControllerAction() | 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) | public function addBreadcrumb($breadcrumb) | ||||
public function setMeta($name, $content) | public function setMeta($name, $content) | ||||
{ | { | ||||
Yii::$app->view->registerMetaTag([ | |||||
\Yii::$app->view->registerMetaTag([ | |||||
'name' => $name, | 'name' => $name, | ||||
'content' => $content | 'content' => $content | ||||
]); | ]); | ||||
public function getUrlManagerFrontend() | public function getUrlManagerFrontend() | ||||
{ | { | ||||
return Yii::$app->urlManagerFrontend; | |||||
return \Yii::$app->urlManagerFrontend; | |||||
} | } | ||||
public function getUrlManagerProducer() | public function getUrlManagerProducer() | ||||
{ | { | ||||
return Yii::$app->urlManagerProducer; | |||||
return \Yii::$app->urlManagerProducer; | |||||
} | } | ||||
public function getUrlManagerBackend() | public function getUrlManagerBackend() | ||||
{ | { | ||||
return Yii::$app->urlManagerBackend; | |||||
return \Yii::$app->urlManagerBackend; | |||||
} | } | ||||
} | } |
], | ], | ||||
'user' => [ | 'user' => [ | ||||
'class' => 'yii\web\User', | 'class' => 'yii\web\User', | ||||
'identityClass' => 'common\models\User', | |||||
'identityClass' => 'common\logic\User\UserModel', | |||||
'enableAutoLogin' => true, | 'enableAutoLogin' => true, | ||||
'identityCookie' => [ | 'identityCookie' => [ | ||||
'name' => 'distrib', | 'name' => 'distrib', |
<?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(); | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?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); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic; | |||||
interface BuilderInterface | |||||
{ | |||||
} |
<?php | |||||
namespace common\logic; | |||||
interface ContainerInterface | |||||
{ | |||||
public function getEntityFqcn(): string; | |||||
public function getServices(): array; | |||||
} |
<?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; | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\CreditHistory; | |||||
use common\logic\FactoryInterface; | |||||
class CreditHistoryFactory implements FactoryInterface | |||||
{ | |||||
public function create() | |||||
{ | |||||
$creditHistory = new CreditHistory(); | |||||
return $creditHistory; | |||||
} | |||||
} |
* termes. | * termes. | ||||
*/ | */ | ||||
namespace common\models; | |||||
namespace common\logic\CreditHistory; | |||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
use yii\db\ActiveQuery; | use yii\db\ActiveQuery; | ||||
class CreditHistory extends ActiveRecordCommon | |||||
class CreditHistoryModel extends ActiveRecordCommon | |||||
{ | { | ||||
const TYPE_INITIAL_CREDIT = 'initial-credit'; | const TYPE_INITIAL_CREDIT = 'initial-credit'; | ||||
const TYPE_CREDIT = 'credit'; | const TYPE_CREDIT = 'credit'; |
<?php | <?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. | * Retourne les options de base nécessaires à la fonction de recherche. |
<?php | <?php | ||||
namespace common\services; | |||||
namespace common\logic\CreditHistory; | |||||
use common\helpers\MeanPayment; | use common\helpers\MeanPayment; | ||||
use common\models\CreditHistory; | |||||
use common\logic\SolverInterface; | |||||
use common\models\Order; | use common\models\Order; | ||||
use yii\helpers\Html; | 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, [ | return in_array($creditHistory->type, [ | ||||
CreditHistory::TYPE_DEBIT, | CreditHistory::TYPE_DEBIT, | ||||
]); | ]); | ||||
} | } | ||||
public function isTypeCredit(CreditHistory $creditHistory): bool | |||||
public function isTypeCredit(CreditHistoryModel $creditHistory): bool | |||||
{ | { | ||||
return in_array($creditHistory->type, [ | 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) { | if ($format) { | ||||
return number_format($creditHistory->amount, 2) . ' €'; | |||||
return number_format($creditHistory->getAmount(), 2) . ' €'; | |||||
} else { | } else { | ||||
return $creditHistory->amount; | |||||
return $creditHistory->getAmount(); | |||||
} | } | ||||
} | } | ||||
* éventuellement de la date de sa commande associée. | * éventuellement de la date de sa commande associée. | ||||
* | * | ||||
*/ | */ | ||||
public function getStrWording(CreditHistory $creditHistory): string | |||||
public function getStrWording(CreditHistoryModel $creditHistory): string | |||||
{ | { | ||||
$str = ''; | $str = ''; | ||||
$type = $creditHistory->getType(); | $type = $creditHistory->getType(); | ||||
if (CreditHistory::TYPE_INITIAL_CREDIT == $type) { | |||||
if (CreditHistoryModel::TYPE_INITIAL_CREDIT == $type) { | |||||
$str = 'Crédit initial'; | $str = 'Crédit initial'; | ||||
} elseif (CreditHistory::TYPE_CREDIT == $type) { | |||||
} elseif (CreditHistoryModel::TYPE_CREDIT == $type) { | |||||
$str = 'Crédit'; | $str = 'Crédit'; | ||||
} elseif (CreditHistory::TYPE_PAYMENT == $type) { | |||||
} elseif (CreditHistoryModel::TYPE_PAYMENT == $type) { | |||||
$str = 'Paiement'; | $str = 'Paiement'; | ||||
} elseif (CreditHistory::TYPE_REFUND == $type) { | |||||
} elseif (CreditHistoryModel::TYPE_REFUND == $type) { | |||||
$str = 'Remboursement'; | $str = 'Remboursement'; | ||||
} elseif (CreditHistory::TYPE_DEBIT == $type) { | |||||
} elseif (CreditHistoryModel::TYPE_DEBIT == $type) { | |||||
$str = 'Débit'; | $str = 'Débit'; | ||||
} | } | ||||
if (CreditHistory::TYPE_PAYMENT == $type || CreditHistory::TYPE_REFUND == $type) { | |||||
if (CreditHistoryModel::TYPE_PAYMENT == $type || CreditHistoryModel::TYPE_REFUND == $type) { | |||||
$order = $creditHistory->getOrderObject(); | $order = $creditHistory->getOrderObject(); | ||||
if ($order && $order->getDistributionOject()) { | if ($order && $order->getDistributionOject()) { | ||||
$str .= '<br />Commande : ' . date('d/m/Y', strtotime($order->getDistributionOject()->getDate())); | $str .= '<br />Commande : ' . date('d/m/Y', strtotime($order->getDistributionOject()->getDate())); | ||||
* (libellé, montant, client, action) au format HTML. | * (libellé, montant, client, action) au format HTML. | ||||
* | * | ||||
*/ | */ | ||||
public function getStrComment(CreditHistory $creditHistory): string | |||||
public function getStrComment(CreditHistoryModel $creditHistory): string | |||||
{ | { | ||||
$str = ''; | $str = ''; | ||||
if (strlen($creditHistory->getComment())) { | if (strlen($creditHistory->getComment())) { | ||||
return $str; | return $str; | ||||
} | } | ||||
public function getDate(CreditHistory $creditHistory, bool $format = false): string | |||||
public function getDate(CreditHistoryModel $creditHistory, bool $format = false): string | |||||
{ | { | ||||
$date = $creditHistory->getDate(); | $date = $creditHistory->getDate(); | ||||
} | } | ||||
} | } | ||||
public function getStrMeanPayment(CreditHistory $creditHistory): string | |||||
public function getStrMeanPayment(CreditHistoryModel $creditHistory): string | |||||
{ | { | ||||
return MeanPayment::getStrBy($creditHistory->getMeanPayment()); | return MeanPayment::getStrBy($creditHistory->getMeanPayment()); | ||||
} | } | ||||
// strUserAction | // strUserAction | ||||
public function getStrUserAction(CreditHistory $creditHistory): string | |||||
public function getStrUserAction(CreditHistoryModel $creditHistory): string | |||||
{ | { | ||||
$userAction = $creditHistory->getUserActionObject(); | $userAction = $creditHistory->getUserActionObject(); | ||||
<?php | |||||
namespace common\logic; | |||||
interface FactoryInterface | |||||
{ | |||||
} |
<?php | <?php | ||||
namespace common\services; | |||||
namespace common\services\Producer; | |||||
use common\helpers\Password; | use common\helpers\Password; | ||||
use common\logic\BaseService; | |||||
use common\logic\BuilderInterface; | |||||
use common\logic\ServiceInterface; | |||||
use common\models\Producer; | 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->initSlug($producer); | ||||
$this->initCode($producer); | $this->initCode($producer); | ||||
} | } | ||||
public function initSlug($producer) | |||||
public function initSlug(Producer $producer): void | |||||
{ | { | ||||
$producerRepository = Yii::$app->logic->getProducerContainer()->getRepository(); | |||||
$cptSlug = 0 ; | $cptSlug = 0 ; | ||||
do { | do { | ||||
$slug = \common\helpers\Url::slugify($producer->name) ; | $slug = \common\helpers\Url::slugify($producer->name) ; | ||||
} | } | ||||
$producer->slug = $slug ; | $producer->slug = $slug ; | ||||
$cptSlug ++ ; | $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(); | $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. | * Lie un utilisateur à un producteur. | ||||
* | * | ||||
* @param integer $id_user | * @param integer $id_user | ||||
* @param integer $id_producer | * @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_user' => $idUser, | ||||
'user_producer.id_producer' => $idProducer | 'user_producer.id_producer' => $idProducer | ||||
]); | ]); | ||||
if (!$userProducer) { | if (!$userProducer) { | ||||
$newUserProducer = new UserProducer; | |||||
$newUserProducer = new UserProducerModel; | |||||
$newUserProducer->id_producer = $idProducer; | $newUserProducer->id_producer = $idProducer; | ||||
$newUserProducer->id_user = $idUser; | $newUserProducer->id_user = $idUser; | ||||
$newUserProducer->credit = 0; | $newUserProducer->credit = 0; |
<?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(); | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
* termes. | * 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 Yii; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
use common\helpers\Departments; | use common\helpers\Departments; | ||||
* @property string background_color_logo | * @property string background_color_logo | ||||
* | * | ||||
*/ | */ | ||||
class Producer extends ActiveRecordCommon | |||||
class ProducerModel extends ActiveRecordCommon | |||||
{ | { | ||||
const CREDIT_FUNCTIONING_MANDATORY = 'mandatory'; | const CREDIT_FUNCTIONING_MANDATORY = 'mandatory'; | ||||
const CREDIT_FUNCTIONING_OPTIONAL = 'optional'; | const CREDIT_FUNCTIONING_OPTIONAL = 'optional'; | ||||
'code', | 'code', | ||||
function ($attribute, $params) { | function ($attribute, $params) { | ||||
$code = $this->$attribute; | $code = $this->$attribute; | ||||
$producer = Producer::findOne(['code' => $code]); | |||||
$producer = ProducerModel::findOne(['code' => $code]); | |||||
if ($producer && $producer->id != $this->id) { | if ($producer && $producer->id != $this->id) { | ||||
$this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.'); | $this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.'); | ||||
} | } | ||||
public function getUserProducer() | public function getUserProducer() | ||||
{ | { | ||||
return $this->hasMany( | return $this->hasMany( | ||||
UserProducer::className(), | |||||
UserProducerModel::class, | |||||
['id_producer' => 'id'] | ['id_producer' => 'id'] | ||||
); | ); | ||||
} | } | ||||
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasMany(User::className(), ['id_producer' => 'id']); | |||||
return $this->hasMany(UserModel::className(), ['id_producer' => 'id']); | |||||
} | } | ||||
public function getContact() | public function getContact() | ||||
{ | { | ||||
return $this->hasMany(User::className(), ['id_producer' => 'id']) | |||||
return $this->hasMany(UserModel::className(), ['id_producer' => 'id']) | |||||
->where(['status' => User::STATUS_PRODUCER]); | ->where(['status' => User::STATUS_PRODUCER]); | ||||
} | } | ||||
<?php | <?php | ||||
namespace common\repositories; | |||||
namespace common\logic\Producer; | |||||
use common\helpers\Departments; | use common\helpers\Departments; | ||||
use common\models\Producer; | |||||
use common\logic\BaseService; | |||||
use common\logic\RepositoryInterface; | |||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
class ProducerRepository | |||||
class ProducerRepository extends BaseService implements RepositoryInterface | |||||
{ | { | ||||
public function getOneById($id) | public function getOneById($id) | ||||
{ | { | ||||
return Producer::searchOne(['id' => $id]); | |||||
return ProducerModel::searchOne(['id' => $id]); | |||||
} | } | ||||
public function getOneBySlug($slug) | public function getOneBySlug($slug) | ||||
{ | { | ||||
return Producer::searchOne(['slug' => $slug]); | |||||
return ProducerModel::searchOne(['slug' => $slug]); | |||||
} | } | ||||
public function queryActive() | public function queryActive() | ||||
{ | { | ||||
return Producer::find() | |||||
return ProducerModel::find() | |||||
->where([ | ->where([ | ||||
'active' => true, | 'active' => true, | ||||
]) | ]) | ||||
/** | /** | ||||
* Retourne le compte producteur de démonstration. | * Retourne le compte producteur de démonstration. | ||||
* | * | ||||
* @return Producer | |||||
*/ | */ | ||||
public function getOneDemoAccount() | public function getOneDemoAccount() | ||||
{ | { | ||||
return Producer::find()->where('name LIKE \'Démo\'')->one(); | |||||
return ProducerModel::find()->where('name LIKE \'Démo\'')->one(); | |||||
} | } | ||||
/** | /** | ||||
*/ | */ | ||||
public static function getPopulateDropdown() | public static function getPopulateDropdown() | ||||
{ | { | ||||
$producers = Producer::find() | |||||
$producers = ProducerModel::find() | |||||
->where([ | ->where([ | ||||
'active' => true, | 'active' => true, | ||||
]) | ]) |
<?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(); | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?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' => '' | |||||
]; | |||||
} | |||||
} |
<?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'); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic; | |||||
interface RepositoryInterface | |||||
{ | |||||
} |
<?php | |||||
namespace common\logic; | |||||
interface SolverInterface | |||||
{ | |||||
} |
<?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; | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
* termes. | * termes. | ||||
*/ | */ | ||||
namespace common\models; | |||||
namespace common\logic\User; | |||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Producer\ProducerModel; | |||||
use yii\behaviors\TimestampBehavior; | |||||
use yii\web\IdentityInterface; | use yii\web\IdentityInterface; | ||||
use yii\db\Query; | use yii\db\Query; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
* @property string $password write-only password | * @property string $password write-only password | ||||
* @property boolean $confiance | * @property boolean $confiance | ||||
*/ | */ | ||||
class User extends ActiveRecordCommon implements IdentityInterface | |||||
class UserModel extends ActiveRecordCommon implements IdentityInterface | |||||
{ | { | ||||
const TYPE_INDIVIDUAL = 'individual'; | const TYPE_INDIVIDUAL = 'individual'; | ||||
public function behaviors() | public function behaviors() | ||||
{ | { | ||||
return [ | return [ | ||||
TimestampBehavior::className(), | |||||
TimestampBehavior::class, | |||||
]; | ]; | ||||
} | } | ||||
public function verifyEmail($attribute, $params) | public function verifyEmail($attribute, $params) | ||||
{ | { | ||||
if ($this->id) { | 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 { | } 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) { | if ($user) { | ||||
public function getUserProducer() | public function getUserProducer() | ||||
{ | { | ||||
return $this->hasMany(UserProducer::className(), ['id_user' => 'id']); | |||||
return $this->hasMany(UserProducerModel::className(), ['id_user' => 'id']); | |||||
} | } | ||||
public function getUserUserGroup() | public function getUserUserGroup() | ||||
* Recherche un utilisateur via son adresse email. | * Recherche un utilisateur via son adresse email. | ||||
* | * | ||||
* @param string $email | * @param string $email | ||||
* @return User | |||||
* @return UserModel | |||||
*/ | */ | ||||
public static function findByEmail($email) | public static function findByEmail($email) | ||||
{ | { | ||||
/** | /** | ||||
* Retourne l'utilisateur courant. | * Retourne l'utilisateur courant. | ||||
* | * | ||||
* @return User | |||||
* @return UserModel | |||||
*/ | */ | ||||
public static function getCurrent() | public static function getCurrent() | ||||
{ | { | ||||
*/ | */ | ||||
public function isProducer() | 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; | |||||
} | } | ||||
/** | /** | ||||
*/ | */ | ||||
public static function isCurrentProducer() | public static function isCurrentProducer() | ||||
{ | { | ||||
$user = User::getCurrent(); | |||||
$user = UserModel::getCurrent(); | |||||
if ($user) { | if ($user) { | ||||
return $user->isProducer(); | return $user->isProducer(); | ||||
} | } | ||||
*/ | */ | ||||
public function isAdmin() | public function isAdmin() | ||||
{ | { | ||||
return $this->status == User::STATUS_ADMIN; | |||||
return $this->status == UserModel::STATUS_ADMIN; | |||||
} | } | ||||
/** | /** | ||||
*/ | */ | ||||
public static function isCurrentAdmin() | public static function isCurrentAdmin() | ||||
{ | { | ||||
$user = User::getCurrent(); | |||||
$user = UserModel::getCurrent(); | |||||
if ($user) { | if ($user) { | ||||
return $user->isAdmin(); | return $user->isAdmin(); | ||||
} | } | ||||
*/ | */ | ||||
public function getNameProducer() | public function getNameProducer() | ||||
{ | { | ||||
$producer = Producer::findOne($this->id_producer); | |||||
return $producer->name; | |||||
$producer = ProducerModel::findOne($this->id_producer); | |||||
return $producer->getName(); | |||||
} | } | ||||
/** | /** | ||||
*/ | */ | ||||
public function getCredit($idProducer) | public function getCredit($idProducer) | ||||
{ | { | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $this->id | 'id_user' => $this->id | ||||
]); | ]); | ||||
public function sendMailWelcome($password) | public function sendMailWelcome($password) | ||||
{ | { | ||||
if (strlen($this->email)) { | if (strlen($this->email)) { | ||||
$producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | |||||
$producer = ProducerModel::findOne(GlobalParam::getCurrentProducerId()); | |||||
Yii::$app->mailer->compose(); | Yii::$app->mailer->compose(); | ||||
$mail = Yii::$app->mailer->compose( | $mail = Yii::$app->mailer->compose( | ||||
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $this, 'producer' => $producer, 'password' => $password] | ['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $this, 'producer' => $producer, 'password' => $password] | ||||
public static function populateDropdownList() | public static function populateDropdownList() | ||||
{ | { | ||||
$usersArray = User::findBy()->all(); | |||||
$usersArray = UserModel::findBy()->all(); | |||||
$usersArrayDropdown = ['' => '--']; | $usersArrayDropdown = ['' => '--']; | ||||
foreach ($usersArray as $user) { | foreach ($usersArray as $user) { | ||||
$usersArrayDropdown[$user['user_id']] = User::getUsernameFromArray($user, true); | |||||
$usersArrayDropdown[$user['user_id']] = UserModel::getUsernameFromArray($user, true); | |||||
} | } | ||||
return $usersArrayDropdown;; | return $usersArrayDropdown;; | ||||
*/ | */ | ||||
public static function getCurrentId() | 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; | return false; | ||||
public static function hasAccessBackend() | 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) | public function belongsToUserGroup($userGroupId) | ||||
public static function getTypeChoicesArray() | public static function getTypeChoicesArray() | ||||
{ | { | ||||
return [ | 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' | |||||
]; | ]; | ||||
} | } | ||||
} | } |
<?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]); | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?php | <?php | ||||
namespace common\services; | |||||
namespace common\services\UserProducer; | |||||
use common\helpers\MeanPayment; | 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\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() | 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) { | if ($userProducer) { | ||||
$oldCredit = $userProducer->credit; | |||||
$oldCredit = $userProducer->getCredit(); | |||||
$this->deductCredit($userProducer, $creditHistory); | $this->deductCredit($userProducer, $creditHistory); | ||||
$this->initMeanPaymentOrder($creditHistory); | $this->initMeanPaymentOrder($creditHistory); | ||||
} | } | ||||
} | } | ||||
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(); | $userProducer->save(); | ||||
public function isCreditLimitCrossed($oldCredit, $newCredit) | public function isCreditLimitCrossed($oldCredit, $newCredit) | ||||
{ | { | ||||
$creditLimitReminder = Producer::getConfig('credit_limit_reminder'); | |||||
$creditLimitReminder = ProducerModel::getConfig('credit_limit_reminder'); | |||||
return !is_null($creditLimitReminder) && | return !is_null($creditLimitReminder) && | ||||
$oldCredit > $creditLimitReminder | $oldCredit > $creditLimitReminder |
<?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(); | |||||
} | |||||
} |
* termes. | * termes. | ||||
*/ | */ | ||||
namespace common\models; | |||||
namespace common\logic\UserProducer; | |||||
use common\logic\Producer\ProducerModel; | |||||
use common\logic\User\UserModel; | |||||
use Yii; | use Yii; | ||||
use common\components\ActiveRecordCommon; | 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 | * @inheritdoc | ||||
*/ | */ | ||||
public function getProducer() | public function getProducer() | ||||
{ | { | ||||
return $this->hasOne(Producer::className(), ['id' => 'id_producer']); | |||||
return $this->hasOne(ProducerModel::class, ['id' => 'id_producer']); | |||||
} | } | ||||
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||||
return $this->hasOne(UserModel::class, ['id' => 'id_user']); | |||||
} | } | ||||
/** | /** |
<?php | <?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) | public function getOne($idUser, $idProducer) | ||||
{ | { | ||||
return UserProducer::searchOne([ | |||||
return UserProducerModel::searchOne([ | |||||
'id_user' => $idUser, | 'id_user' => $idUser, | ||||
'id_producer' => $idProducer | 'id_producer' => $idProducer | ||||
]); | ]); | ||||
public function getBy($idUser, $active = 1, $bookmark = 1) | public function getBy($idUser, $active = 1, $bookmark = 1) | ||||
{ | { | ||||
return UserProducer::find() | |||||
return UserProducerModel::find() | |||||
->with(['producer']) | ->with(['producer']) | ||||
->where([ | ->where([ | ||||
'id_user' => $idUser, | 'id_user' => $idUser, |
<?php | |||||
namespace common\logic; | |||||
interface UtilsInterface | |||||
{ | |||||
} |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
/* @var $this yii\web\View */ | /* @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]); | $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]); | ||||
?> | ?> |
*/ | */ | ||||
/* @var $this yii\web\View */ | /* @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]); | $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]); | ||||
?> | ?> |
*/ | */ | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
use common\helpers\Url ; | use common\helpers\Url ; | ||||
?> | ?> | ||||
<p>Voici votre identifiant de connexion : <br /> | <p>Voici votre identifiant de connexion : <br /> | ||||
<strong><?= Html::encode($user->email) ?></strong></p> | <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 | <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> | en place votre système de réservation.</p> | ||||
<?php else: ?> | <?php else: ?> |
termes. | termes. | ||||
*/ | */ | ||||
use common\models\User ; | |||||
use common\models\UserModel ; | |||||
use common\helpers\Url ; | use common\helpers\Url ; | ||||
?> | ?> | ||||
Voici votre identifiant de connexion : | Voici votre identifiant de connexion : | ||||
<?= $user->email ?> | <?= $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 : | 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']); ?> | <?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?> | ||||
<?php else: ?> | <?php else: ?> |
$userProducer = false; | $userProducer = false; | ||||
if(isset($order->user) && $order->user) { | if(isset($order->user) && $order->user) { | ||||
$user = $order->user; | $user = $order->user; | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'id_producer' => $order->distribution->id_producer | 'id_producer' => $order->distribution->id_producer | ||||
]) ; | ]) ; |
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||||
return $this->hasOne(UserModel::className(), ['id' => 'id_user']); | |||||
} | } | ||||
public function getProducer() | public function getProducer() |
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||||
return $this->hasOne(UserModel::className(), ['id' => 'id_user']); | |||||
} | } | ||||
public function getProductOrder() | public function getProductOrder() | ||||
$amountPaid, | $amountPaid, | ||||
GlobalParam::getCurrentProducerId(), | GlobalParam::getCurrentProducerId(), | ||||
$this->id_user, | $this->id_user, | ||||
User::getCurrentId() | |||||
UserModel::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
public function addOrderStatusHistory($newStatus, $origin) | public function addOrderStatusHistory($newStatus, $origin) | ||||
{ | { | ||||
$orderStatusHistory = new OrderStatusHistory(); | $orderStatusHistory = new OrderStatusHistory(); | ||||
$orderStatusHistory->id_user = User::getCurrentId(); | |||||
$orderStatusHistory->id_user = UserModel::getCurrentId(); | |||||
$orderStatusHistory->id_order = $this->id; | $orderStatusHistory->id_order = $this->id; | ||||
$orderStatusHistory->status = $newStatus; | $orderStatusHistory->status = $newStatus; | ||||
$orderStatusHistory->origin = $origin; | $orderStatusHistory->origin = $origin; | ||||
$creditHistory->id_producer = $idProducer; | $creditHistory->id_producer = $idProducer; | ||||
$creditHistory->id_user_action = $idUserAction; | $creditHistory->id_user_action = $idUserAction; | ||||
$creditHistory->populateRelation('order', $this); | $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); | $creditHistoryService->save($creditHistory); | ||||
} | } | ||||
$amount, | $amount, | ||||
GlobalParam::getCurrentProducerId(), | GlobalParam::getCurrentProducerId(), | ||||
$this->id_user, | $this->id_user, | ||||
User::getCurrentId() | |||||
UserModel::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
} | } |
public function getOrder() | public function getOrder() | ||||
{ | { | ||||
return $this->hasOne(User::className(), ['id' => 'id_order']); | |||||
return $this->hasOne(UserModel::className(), ['id' => 'id_order']); | |||||
} | } | ||||
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||||
return $this->hasOne(UserModel::className(), ['id' => 'id_user']); | |||||
} | } | ||||
/** | /** |
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasOne( | return $this->hasOne( | ||||
User::className(), | |||||
UserModel::className(), | |||||
['id' => 'id_user'] | ['id' => 'id_user'] | ||||
) ; | ) ; | ||||
} | } | ||||
if (is_array($this->users) && count($this->users)) { | if (is_array($this->users) && count($this->users)) { | ||||
foreach ($this->users as $key => $val) { | foreach ($this->users as $key => $val) { | ||||
$user = User::findOne($val); | |||||
$user = UserModel::findOne($val); | |||||
if ($user) { | if ($user) { | ||||
$userPointSale = new UserPointSale; | $userPointSale = new UserPointSale; | ||||
$userPointSale->id_user = $val; | $userPointSale->id_user = $val; | ||||
{ | { | ||||
if (isset($this->userPointSale)) { | if (isset($this->userPointSale)) { | ||||
foreach ($this->userPointSale as $userPointSale) { | foreach ($this->userPointSale as $userPointSale) { | ||||
if ($userPointSale->id_user == User::getCurrentId()) { | |||||
if ($userPointSale->id_user == UserModel::getCurrentId()) { | |||||
return $userPointSale->comment; | return $userPointSale->comment; | ||||
} | } | ||||
} | } |
$userProducer = null; | $userProducer = null; | ||||
if ($user) { | if ($user) { | ||||
$userProducer = UserProducer::searchOne([ | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
]); | ]); | ||||
} | } |
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasOne( | return $this->hasOne( | ||||
User::className(), | |||||
UserModel::className(), | |||||
['id' => 'id_user'] | ['id' => 'id_user'] | ||||
); | ); | ||||
} | } |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\models\PointSale; | use common\models\PointSale; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use Yii; | use Yii; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||||
return $this->hasOne(UserModel::className(), ['id' => 'id_user']); | |||||
} | } | ||||
public function getProducer() | public function getProducer() | ||||
$user = false; | $user = false; | ||||
if ($this->id_user) { | 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'); | $order->date = date('Y-m-d H:i:s'); | ||||
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) { | } elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) { | ||||
$order->auto_payment = 1; | $order->auto_payment = 1; | ||||
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) { | } 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_user' => $order->id_user, | ||||
'id_producer' => $distribution->id_producer | 'id_producer' => $distribution->id_producer | ||||
]); | ]); | ||||
$theOrder->getAmount(Order::AMOUNT_PAID), | $theOrder->getAmount(Order::AMOUNT_PAID), | ||||
$theOrder->distribution->id_producer, | $theOrder->distribution->id_producer, | ||||
$theOrder->id_user, | $theOrder->id_user, | ||||
User::getCurrentId() | |||||
UserModel::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
namespace common\models; | namespace common\models; | ||||
use common\helpers\GlobalParam; | 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 $id_point_sale; | ||||
var $subscribers; | var $subscribers; | ||||
{ | { | ||||
$optionsSearch = self::defaultOptionsSearch(); | $optionsSearch = self::defaultOptionsSearch(); | ||||
$query = User::find() | |||||
$query = UserModel::find() | |||||
->select( | ->select( | ||||
'`user`.id, ' | '`user`.id, ' | ||||
. '`user`.username,' | . '`user`.username,' |
<?php | |||||
namespace common\repositories; | |||||
use common\models\ProducerPriceRange; | |||||
class ProducerPriceRangeRepository | |||||
{ | |||||
public function query() | |||||
{ | |||||
return ProducerPriceRange::find()->orderBy('range_begin ASC'); | |||||
} | |||||
} |
<?php | |||||
namespace common\repositories; | |||||
use common\models\User; | |||||
class UserRepository | |||||
{ | |||||
public function getOneById($id) | |||||
{ | |||||
return User::searchOne(['id' => $id]); | |||||
} | |||||
} |
<?php | |||||
namespace common\services; | |||||
use common\helpers\Password; | |||||
use common\models\Producer; | |||||
use common\models\UserProducer; | |||||
class ProducerPriceRangeService | |||||
{ | |||||
} |
<?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(); | |||||
} | |||||
} |
->all(); | ->all(); | ||||
foreach($pointsSaleArray as $pointSale) { | foreach($pointsSaleArray as $pointSale) { | ||||
$usersArray = common\models\User::find()->innerJoin( | |||||
$usersArray = common\models\UserModel::find()->innerJoin( | |||||
'order', | 'order', | ||||
'user.id = order.id_user AND order.id_point_sale = :id_point_sale', | 'user.id = order.id_user AND order.id_point_sale = :id_point_sale', | ||||
[':id_point_sale' => $pointSale->id] | [':id_point_sale' => $pointSale->id] |
namespace frontend\controllers; | namespace frontend\controllers; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use frontend\forms\ProducerCodeForm; | use frontend\forms\ProducerCodeForm; | ||||
use Yii; | use Yii; | ||||
use frontend\forms\PasswordResetRequestForm; | use frontend\forms\PasswordResetRequestForm; | ||||
*/ | */ | ||||
public function actionError() | public function actionError() | ||||
{ | { | ||||
$exception = Yii::$app->errorHandler->exception; | |||||
$exception = \Yii::$app->errorHandler->exception; | |||||
if ($exception->getMessage() == 'Producteur introuvable' | 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]); | return $this->render('error-404-producer', ['exception' => $exception]); | ||||
} | } | ||||
public function actionLogin() | public function actionLogin() | ||||
{ | { | ||||
if (!\Yii::$app->user->isGuest) { | if (!\Yii::$app->user->isGuest) { | ||||
return Yii::$app->getResponse()->redirect(['site/index']); | |||||
return \Yii::$app->getResponse()->redirect(['site/index']); | |||||
} | } | ||||
$model = new LoginForm(); | $model = new LoginForm(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->login()) { | 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) { | if ($returnUrl) { | ||||
return $this->redirect($returnUrl); | return $this->redirect($returnUrl); | ||||
$userProducerArray = $this->getLogic() | $userProducerArray = $this->getLogic() | ||||
->getUserProducerContainer() | ->getUserProducerContainer() | ||||
->getRepository() | ->getRepository() | ||||
->getBy(User::getCurrentId()); | |||||
->getBy(UserModel::getCurrentId()); | |||||
if ($userProducerArray | if ($userProducerArray | ||||
&& is_array($userProducerArray) | && is_array($userProducerArray) | ||||
*/ | */ | ||||
public function actionLogout() | public function actionLogout() | ||||
{ | { | ||||
Yii::$app->user->logout(); | |||||
\Yii::$app->user->logout(); | |||||
return $this->goHome(); | return $this->goHome(); | ||||
} | } | ||||
public function actionSignup() | public function actionSignup() | ||||
{ | { | ||||
$model = new SignupForm(); | $model = new SignupForm(); | ||||
$producerRepository = Yii::$app->logic->getProducerContainer()->getRepository(); | |||||
$producerRepository = \Yii::$app->logic->getProducerContainer()->getRepository(); | |||||
if ($model->load(Yii::$app->request->post())) { | if ($model->load(Yii::$app->request->post())) { | ||||
$user = $model->signup(); | $user = $model->signup(); | ||||
if ($producerCodeForm->load($this->getRequest()->post()) | if ($producerCodeForm->load($this->getRequest()->post()) | ||||
&& $producerCodeForm->validate()) { | && $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])); | $this->redirect($this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); | ||||
} | } | ||||
if ($this->getUser()->isGuest) { | if ($this->getUser()->isGuest) { | ||||
if ($loginForm->load($this->getRequest()->post()) && $loginForm->login()) { | if ($loginForm->load($this->getRequest()->post()) && $loginForm->login()) { | ||||
if (!strlen($producer->code)) { | if (!strlen($producer->code)) { | ||||
$producerContainer->getService()->addUser(User::getCurrentId(), $id); | |||||
$producerContainer->getService()->addUser(UserModel::getCurrentId(), $id); | |||||
} | } | ||||
$this->redirect($returnUrl); | $this->redirect($returnUrl); |
namespace frontend\controllers; | namespace frontend\controllers; | ||||
use Yii; | use Yii; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
use yii\web\Controller; | use yii\web\Controller; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
*/ | */ | ||||
public function actionUpdate() | public function actionUpdate() | ||||
{ | { | ||||
$idUser = User::getCurrentId(); | |||||
$idUser = UserModel::getCurrentId(); | |||||
$model = $this->findModel($idUser); | $model = $this->findModel($idUser); | ||||
if ($model->load($this->getRequest()->post()) | if ($model->load($this->getRequest()->post()) | ||||
// modification du mot de passe | // modification du mot de passe | ||||
if (strlen($model->password_new)) { | 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_old = ''; | ||||
$model->password_new = ''; | $model->password_new = ''; | ||||
* Finds the User model based on its primary key value. | * Finds the User model based on its primary key value. | ||||
* If the model is not found, a 404 HTTP exception will be thrown. | * If the model is not found, a 404 HTTP exception will be thrown. | ||||
* @param integer $id | * @param integer $id | ||||
* @return User the loaded model | |||||
* @return UserModel the loaded model | |||||
* @throws NotFoundHttpException if the model cannot be found | * @throws NotFoundHttpException if the model cannot be found | ||||
*/ | */ | ||||
protected function findModel($id) | protected function findModel($id) |
namespace frontend\forms; | namespace frontend\forms; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use yii\base\Model; | use yii\base\Model; | ||||
use yii; | use yii; | ||||
['email', 'required'], | ['email', 'required'], | ||||
['email', 'email'], | ['email', 'email'], | ||||
['email', 'exist', | ['email', 'exist', | ||||
'targetClass' => '\common\models\User', | |||||
'targetClass' => '\common\models\UserModel', | |||||
'message' => 'There is no user with such email.' | 'message' => 'There is no user with such email.' | ||||
], | ], | ||||
]; | ]; | ||||
*/ | */ | ||||
public function sendEmail() | public function sendEmail() | ||||
{ | { | ||||
/* @var $user User */ | |||||
$user = User::findOne([ | |||||
/* @var $user UserModel */ | |||||
$user = UserModel::findOne([ | |||||
'email' => $this->email, | 'email' => $this->email, | ||||
]); | ]); | ||||
if ($user) { | if ($user) { | ||||
if (!User::isPasswordResetTokenValid($user->password_reset_token)) { | |||||
if (!UserModel::isPasswordResetTokenValid($user->password_reset_token)) { | |||||
$user->generatePasswordResetToken(); | $user->generatePasswordResetToken(); | ||||
} | } | ||||
if ($user->save()) { | 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']) | ->setFrom(['contact@opendistrib.net' => 'distrib']) | ||||
->setTo($this->email) | ->setTo($this->email) | ||||
->setSubject('[distrib] Mot de passe oublié') | ->setSubject('[distrib] Mot de passe oublié') |
namespace frontend\forms; | namespace frontend\forms; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use yii\base\InvalidParamException; | use yii\base\InvalidParamException; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use Yii; | use Yii; | ||||
public $password; | public $password; | ||||
/** | /** | ||||
* @var \common\models\User | |||||
* @var \common\models\UserModel | |||||
*/ | */ | ||||
private $_user; | private $_user; | ||||
if (empty($token) || !is_string($token)) { | if (empty($token) || !is_string($token)) { | ||||
throw new InvalidParamException('Password reset token cannot be blank.'); | throw new InvalidParamException('Password reset token cannot be blank.'); | ||||
} | } | ||||
$this->_user = User::findByPasswordResetToken($token); | |||||
$this->_user = UserModel::findByPasswordResetToken($token); | |||||
if (!$this->_user) { | if (!$this->_user) { | ||||
throw new InvalidParamException('Wrong password reset token.'); | throw new InvalidParamException('Wrong password reset token.'); | ||||
} | } |
namespace frontend\forms; | namespace frontend\forms; | ||||
use Yii; | use Yii; | ||||
use common\models\User; | |||||
use common\models\UserModel; | |||||
use common\models\Producer; | use common\models\Producer; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use common\models\UserProducer; | |||||
use common\models\UserProducerModel; | |||||
use common\helpers\Password; | use common\helpers\Password; | ||||
/** | /** | ||||
['email', function ($attribute, $params) { | ['email', function ($attribute, $params) { | ||||
$email = $this->$attribute; | $email = $this->$attribute; | ||||
$userExist = User::searchOne([ | |||||
$userExist = UserModel::searchOne([ | |||||
'type' => 'individual', | 'type' => 'individual', | ||||
'email' => $email | 'email' => $email | ||||
]); | ]); | ||||
/** | /** | ||||
* Signs user up. | * 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() | 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()) { | if ($this->validate()) { | ||||
public function processFormProducer($user) | 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 | // Création du producteur | ||||
$producer = $producerContainer->getService()->createInstance(); | $producer = $producerContainer->getService()->createInstance(); | ||||
public function populateUser($user) | public function populateUser($user) | ||||
{ | { | ||||
$userContainer = Yii::$app->logic->getUserContainer(); | |||||
$userContainer = \Yii::$app->logic->getUserContainer(); | |||||
$user->username = $this->email; | $user->username = $this->email; | ||||
$user->email = $this->email; | $user->email = $this->email; |
use yii\widgets\Breadcrumbs; | use yii\widgets\Breadcrumbs; | ||||
use common\widgets\Alert; | use common\widgets\Alert; | ||||
use common\helpers\Url; | use common\helpers\Url; | ||||
use common\logic\Producer\ProducerModel; | |||||
use common\logic\User\UserModel; | |||||
/* @var $this \yii\web\View */ | /* @var $this \yii\web\View */ | ||||
/* @var $content string */ | /* @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); | \common\assets\CommonAsset::register($this); | ||||
\frontend\assets\AppAsset::register($this); | \frontend\assets\AppAsset::register($this); | ||||
$producer = null; | $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]); | |||||
} | } | ||||
?> | ?> | ||||
<meta name="viewport" content="width=device-width, initial-scale=1"> | <meta name="viewport" content="width=device-width, initial-scale=1"> | ||||
<?= Html::csrfMetaTags() ?> | <?= Html::csrfMetaTags() ?> | ||||
<link rel="icon" type="image/png" href="<?= $this->getUrlManager()->getBaseUrl(); ?>/img/favicon-distrib.png"/> | <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() ?> | <?php $this->head() ?> | ||||
<!--[if lt IE 9]> | <!--[if lt IE 9]> | ||||
<script src="<?= $this->getUrlManager()->getBaseUrl(); ?>/js/html5shiv.min.js"></script> | <script src="<?= $this->getUrlManager()->getBaseUrl(); ?>/js/html5shiv.min.js"></script> | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-log-in"></span> Connexion', | 'label' => '<span class="glyphicon glyphicon-log-in"></span> Connexion', | ||||
'url' => $this->getUrlManager()->createUrl(['site/login']), | 'url' => $this->getUrlManager()->createUrl(['site/login']), | ||||
'visible' => Yii::$app->user->isGuest, | |||||
'visible' => \Yii::$app->user->isGuest, | |||||
'active' => $this->getControllerAction() == 'site/login' | 'active' => $this->getControllerAction() == 'site/login' | ||||
], | ], | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-user"></span> Inscription', | 'label' => '<span class="glyphicon glyphicon-user"></span> Inscription', | ||||
'url' => $this->getUrlManager()->createUrl(['site/signup']), | 'url' => $this->getUrlManager()->createUrl(['site/signup']), | ||||
'visible' => Yii::$app->user->isGuest, | |||||
'visible' => \Yii::$app->user->isGuest, | |||||
'active' => $this->getControllerAction() == 'site/signup' | 'active' => $this->getControllerAction() == 'site/signup' | ||||
], | ], | ||||
[ | [ | ||||
<section id="bookmarked-producers"> | <section id="bookmarked-producers"> | ||||
<div class="container"> | <div class="container"> | ||||
<?php | <?php | ||||
$producersArray = Producer::find() | |||||
$producersArray = ProducerModel::find() | |||||
->joinWith(['userProducer user_producer']) | ->joinWith(['userProducer user_producer']) | ||||
->where([ | ->where([ | ||||
'user_producer.id_user' => User::getCurrentId(), | |||||
'user_producer.id_user' => UserModel::getCurrentId(), | |||||
'user_producer.bookmark' => 1, | 'user_producer.bookmark' => 1, | ||||
]) | ]) | ||||
->all(); | ->all(); | ||||
?> | ?> | ||||
<?php if (count($producersArray)): ?> | <?php if (count($producersArray)): ?> | ||||
<h2>Mes producteurs ></h2> | <h2>Mes producteurs ></h2> | ||||
<div id="producers"> | <div id="producers"> | ||||
<?php foreach ($producersArray as $producer): ?> | <?php foreach ($producersArray as $producer): ?> | ||||
<a class="btn btn-xs btn-default" | <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; ?> | <?php endforeach; ?> | ||||
</div> | </div> | ||||
<?php else: ?> | <?php else: ?> | ||||
<section class="container" id="content"> | <section class="container" id="content"> | ||||
<?php if (Yii::$app->session->hasFlash('error')): ?> | <?php if (Yii::$app->session->hasFlash('error')): ?> | ||||
<div class="alert alert-danger" role="alert"> | <div class="alert alert-danger" role="alert"> | ||||
<?= Yii::$app->session->getFlash('error') ?> | |||||
<?= \Yii::$app->session->getFlash('error') ?> | |||||
</div> | </div> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<?php if (Yii::$app->session->hasFlash('success')): ?> | <?php if (Yii::$app->session->hasFlash('success')): ?> | ||||
<div class="alert alert-success" role="alert"> | <div class="alert alert-success" role="alert"> | ||||
<?= Yii::$app->session->getFlash('success') ?> | |||||
<?= \Yii::$app->session->getFlash('success') ?> | |||||
</div> | </div> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
* termes. | * termes. | ||||
*/ | */ | ||||
use yii\grid\GridView; | |||||
?> | ?> | ||||
<div class="alert alert-warning" role="alert"> | <div class="alert alert-warning" role="alert"> | ||||
]); | ]); | ||||
?> | ?> | ||||
<?php if (!isset($noButton)){ ?> | <?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 } ?> | <?php } ?> | ||||
<div class="panel panel-default"> | <div class="panel panel-default"> | ||||
<div class="panel-heading"> | <div class="panel-heading"> | ||||
<h2 class="panel-title"> | <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> | <span class="the-title">Producteurs</span> | ||||
</h2> | </h2> | ||||
</div> | </div> | ||||
<div class="panel-body"> | <div class="panel-body"> | ||||
<p class="presentation">Simplifiez la distribution de vos produits<br /> avec des outils adaptés.</p> | <p class="presentation">Simplifiez la distribution de vos produits<br /> avec des outils adaptés.</p> | ||||
<?php if(Yii::$app->user->isGuest): ?> | <?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; ?> | <?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> | </div> | ||||
</div> | </div> | ||||
<div class="panel panel-default"> | <div class="panel panel-default"> | ||||
<div class="panel-heading"> | <div class="panel-heading"> | ||||
<h2 class="panel-title"> | <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> | <span class="the-title">Clients</span> | ||||
</h2> | </h2> | ||||
</div> | </div> | ||||
<p class="presentation">Réservez vos produits en ligne et récupérez votre commande | <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> | chez votre producteur ou dans un dépôt près de chez vous.</p> | ||||
<?php if(Yii::$app->user->isGuest): ?> | <?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; ?> | <?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> | </div> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<div class="panel-body"> | <div class="panel-body"> | ||||
<div class="block block-order col-md-6"> | <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> | <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 class="clr"></div> | ||||
</div> | </div> | ||||
<div class="block block-payment col-md-6"> | <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> | <p>Système de crédit permettant la comptabilisation des paiements.</p> | ||||
<div class="clr"></div> | <div class="clr"></div> | ||||
</div> | </div> | ||||
<div class="clr"></div> | <div class="clr"></div> | ||||
<div class="block block-points-sale-products col-md-6"> | <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> | <p>Gestion des différents points de vente et produits.</p> | ||||
<div class="clr"></div> | <div class="clr"></div> | ||||
</div> | </div> | ||||
<div class="block block-subscriptions col-md-6"> | <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> | <p>Gestion des abonnement.</p> | ||||
<div class="clr"></div> | <div class="clr"></div> | ||||
</div> | </div> | ||||
<div class="clr"></div> | <div class="clr"></div> | ||||
<div class="block block-communication col-md-6"> | <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> | <p>Communication simplifiée avec les clients.</p> | ||||
<div class="clr"></div> | <div class="clr"></div> | ||||
</div> | </div> | ||||
<div class="block block-evolution col-md-6"> | <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 class="clr"></div> | ||||
</div> | </div> | ||||
</div> | </div> |