|
- <?php
-
- namespace common\logic\PointSale\UserPointSale;
-
- use common\logic\BaseService;
- use common\logic\BuilderInterface;
- use common\logic\PointSale\PointSale\PointSale;
- use common\logic\User\User\User;
-
- class UserPointSaleBuilder extends BaseService implements BuilderInterface
- {
- public function instanciateUserPointSale(User $user, PointSale $pointSale, string $comment = null): UserPointSale
- {
- $userPointSale = new UserPointSale();
-
- $userPointSale->id_user = $user->id;
- $userPointSale->populateRelation('user', $user);
- $userPointSale->id_point_sale = $pointSale->id;
- $userPointSale->populateRelation('pointSale', $pointSale);
-
- if($comment) {
- $userPointSale->comment = $comment;
- }
-
- return $userPointSale;
- }
-
- public function createUserPointSale(User $user, PointSale $pointSale, string $comment = null): UserPointSale
- {
- $userPointSale = $this->instanciateUserPointSale($user, $pointSale, $comment);
- $userPointSale->save();
-
- return $userPointSale;
- }
-
- public function deleteByPointSale(PointSale $pointSale): void
- {
- UserPointSale::deleteAll(['id_point_sale' => $pointSale->id]);
- }
- }
|