@@ -43,6 +43,8 @@ class BusinessLogic | |||
$this->getPointSaleModule(), | |||
$this->getSharedPointSaleModule(), | |||
$this->getProductModule(), | |||
$this->getRotatingProductModule(), | |||
$this->getRotatingModule(), | |||
$this->getProductOrderModule(), | |||
$this->getOrderStatusModule(), | |||
$this->getOrderStatusHistoryModule(), | |||
@@ -51,6 +53,7 @@ class BusinessLogic | |||
$this->getDeliveryNoteModule(), | |||
$this->getDocumentModule(), | |||
$this->getSubscriptionModule(), | |||
$this->getDistributionRotatingModule(), | |||
$this->getDistributionModule(), | |||
$this->getProducerModule(), | |||
$this->getOrderModule(), |
@@ -6,6 +6,7 @@ use domain\Communication\Email\EmailModule; | |||
use domain\Config\TaxRate\TaxRateModule; | |||
use domain\Config\Unit\UnitModule; | |||
use domain\Distribution\Distribution\DistributionModule; | |||
use domain\Distribution\DistributionRotating\DistributionRotatingModule; | |||
use domain\Distribution\PointSaleDistribution\PointSaleDistributionModule; | |||
use domain\Distribution\ProductDistribution\ProductDistributionModule; | |||
use domain\Document\DeliveryNote\DeliveryNoteModule; | |||
@@ -32,6 +33,8 @@ use domain\Product\ProductAccessory\ProductAccessoryModule; | |||
use domain\Product\ProductCategory\ProductCategoryModule; | |||
use domain\Product\ProductPointSale\ProductPointSaleModule; | |||
use domain\Product\ProductPrice\Module\ProductPriceModule; | |||
use domain\Product\Rotating\RotatingModule; | |||
use domain\Product\RotatingProduct\RotatingProductModule; | |||
use domain\Setting\SettingModule; | |||
use domain\Subscription\ProductSubscription\ProductSubscriptionModule; | |||
use domain\Subscription\Subscription\SubscriptionModule; | |||
@@ -46,6 +49,21 @@ use domain\User\UserUserGroup\UserUserGroupModule; | |||
trait BusinessLogicTrait | |||
{ | |||
public function getDistributionRotatingModule(): DistributionRotatingModule | |||
{ | |||
return DistributionRotatingModule::getInstance(); | |||
} | |||
public function getRotatingProductModule(): RotatingProductModule | |||
{ | |||
return RotatingProductModule::getInstance(); | |||
} | |||
public function getRotatingModule(): RotatingModule | |||
{ | |||
return RotatingModule::getInstance(); | |||
} | |||
public function getEmailModule(): EmailModule | |||
{ | |||
return EmailModule::getInstance(); |
@@ -0,0 +1,61 @@ | |||
<?php | |||
use yii\db\Migration; | |||
use yii\db\Schema; | |||
/** | |||
* Class m240702_142432_create_tables_rotating_product | |||
*/ | |||
class m240702_142432_create_tables_rotating_product extends Migration | |||
{ | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function safeUp() | |||
{ | |||
$this->createTable('rotating', [ | |||
'id' => 'pk', | |||
'id_producer' => Schema::TYPE_INTEGER.' NOT NULL', | |||
'name' => Schema::TYPE_STRING.' NOT NULL', | |||
'day' => Schema::TYPE_INTEGER.' NOT NULL', | |||
'status' => Schema::TYPE_INTEGER.' NOT NULL', | |||
]); | |||
$this->addForeignKey('rotating_fk_id_producer', 'rotating', 'id_producer', 'producer', 'id'); | |||
$this->createTable('rotating_product', [ | |||
'id' => 'pk', | |||
'id_rotating' => Schema::TYPE_INTEGER.' NOT NULL', | |||
'id_product' => Schema::TYPE_INTEGER.' NOT NULL', | |||
'position' => Schema::TYPE_INTEGER.' NOT NULL', | |||
'status' => Schema::TYPE_INTEGER.' NOT NULL', | |||
]); | |||
$this->addForeignKey('rotating_product_fk_id_rotating', 'rotating_product', 'id_rotating', 'rotating', 'id'); | |||
$this->addForeignKey('rotating_product_fk_id_product', 'rotating_product', 'id_product', 'product', 'id'); | |||
$this->createTable('distribution_rotating', [ | |||
'id' => 'pk', | |||
'id_distribution' => Schema::TYPE_INTEGER.' NOT NULL', | |||
'id_rotating' => Schema::TYPE_INTEGER.' NOT NULL', | |||
'id_rotating_product' => Schema::TYPE_INTEGER, | |||
'status' => Schema::TYPE_INTEGER.' NOT NULL', | |||
]); | |||
$this->addForeignKey('distribution_rotating_fk_id_distribution', 'distribution_rotating', 'id_distribution', 'distribution', 'id'); | |||
$this->addForeignKey('distribution_rotating_fk_id_rotating', 'distribution_rotating', 'id_rotating', 'rotating', 'id'); | |||
$this->addForeignKey('distribution_rotating_fk_id_rotating_product', 'distribution_rotating', 'id_rotating_product', 'rotating_product', 'id'); | |||
$this->addColumn('product_subscription', 'id_rotating', Schema::TYPE_INTEGER); | |||
$this->addForeignKey('product_subscription_fk_id_rotating', 'product_subscription', 'id_rotating', 'rotating', 'id'); | |||
} | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function safeDown() | |||
{ | |||
$this->dropTable('rotating'); | |||
$this->dropTable('rotating_product'); | |||
$this->dropTable('distribution_rotating'); | |||
$this->dropColumn('product_subscription', 'id_rotating'); | |||
} | |||
} |
@@ -0,0 +1,99 @@ | |||
<?php | |||
namespace domain\Distribution\DistributionRotating; | |||
use common\components\ActiveRecordCommon; | |||
use domain\Distribution\Distribution\Distribution; | |||
use domain\Product\Rotating\Rotating; | |||
use domain\Product\RotatingProduct\RotatingProduct; | |||
use yii\db\ActiveQuery; | |||
class DistributionRotating extends ActiveRecordCommon | |||
{ | |||
public static function tableName() | |||
{ | |||
return 'distribution_rotating'; | |||
} | |||
public function rules() | |||
{ | |||
return [ | |||
[['id_distribution', 'id_rotating'], 'required'], | |||
[['id_distribution', 'id_rotating', 'id_rotating_product', 'status'], 'integer'], | |||
]; | |||
} | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'id_distribution' => 'Distribution', | |||
'id_rotating' => 'Produit tournant', | |||
'id_rotating_product' => 'Produit', | |||
'status' => 'Statut', | |||
]; | |||
} | |||
/* Getters / Setters */ | |||
public function getDistribution(): Distribution | |||
{ | |||
return $this->distributionRelation; | |||
} | |||
public function setDistribution(Distribution $distribution): self | |||
{ | |||
$this->populateFieldObject('id_distribution', 'distributionRelation', $distribution); | |||
return $this; | |||
} | |||
public function getRotating(): Rotating | |||
{ | |||
return $this->rotatingRelation; | |||
} | |||
public function setRotating(Rotating $rotating): self | |||
{ | |||
$this->populateFieldObject('id_rotating', 'rotatingRelation', $rotating); | |||
return $this; | |||
} | |||
public function getRotatingProduct(): RotatingProduct | |||
{ | |||
return $this->rotatingProductRelation; | |||
} | |||
public function setRotatingProduct(RotatingProduct $rotatingProduct): self | |||
{ | |||
$this->populateFieldObject('id_rotating_product', 'rotatingProductRelation', $rotatingProduct); | |||
return $this; | |||
} | |||
public function getStatus(): int | |||
{ | |||
return $this->status; | |||
} | |||
public function setStatus(int $status): self | |||
{ | |||
$this->status = $status; | |||
return $this; | |||
} | |||
/* Relations */ | |||
public function getDistributionRelation(): ActiveQuery | |||
{ | |||
return $this->hasOne(Distribution::class, ['id' => 'id_distribution']); | |||
} | |||
public function getRotatingRelation(): ActiveQuery | |||
{ | |||
return $this->hasOne(Rotating::class, ['id' => 'id_rotating']); | |||
} | |||
public function getRotatingProductRelation(): ActiveQuery | |||
{ | |||
return $this->hasOne(RotatingProduct::class, ['id' => 'id_rotating_product']); | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
<?php | |||
namespace domain\Distribution\DistributionRotating; | |||
use domain\_\AbstractBuilder; | |||
use domain\_\StatusInterface; | |||
class DistributionRotatingBuilder extends AbstractBuilder | |||
{ | |||
public function instanciateDistributionRotating(): DistributionRotating | |||
{ | |||
$distributionRotating = new DistributionRotating(); | |||
$distributionRotating->setStatus(StatusInterface::STATUS_ONLINE); | |||
return $distributionRotating; | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
<?php | |||
namespace domain\Distribution\DistributionRotating; | |||
use domain\_\AbstractDefinition; | |||
class DistributionRotatingDefinition extends AbstractDefinition | |||
{ | |||
public function getEntityFqcn(): string | |||
{ | |||
return DistributionRotating::class; | |||
} | |||
} |
@@ -0,0 +1,26 @@ | |||
<?php | |||
namespace domain\Distribution\DistributionRotating; | |||
use domain\_\AbstractManager; | |||
use domain\Distribution\Distribution\Distribution; | |||
use domain\Product\RotatingProduct\RotatingProduct; | |||
class DistributionRotatingManager extends AbstractManager | |||
{ | |||
protected DistributionRotatingBuilder $distributionRotatingBuilder; | |||
public function loadDependencies(): void | |||
{ | |||
$this->distributionRotatingBuilder = $this->loadService(DistributionRotatingBuilder::class); | |||
} | |||
public function createDistributionRotating(Distribution $distribution, RotatingProduct $rotatingProduct): DistributionRotating | |||
{ | |||
$distributionRotating = $this->distributionRotatingBuilder->instanciateDistributionRotating(); | |||
$distributionRotating | |||
->setDistribution($distribution) | |||
->setRotatingProduct($rotatingProduct); | |||
return $distributionRotating; | |||
} | |||
} |
@@ -0,0 +1,32 @@ | |||
<?php | |||
namespace domain\Distribution\DistributionRotating; | |||
use domain\_\AbstractModule; | |||
class DistributionRotatingModule extends AbstractModule | |||
{ | |||
public function getServices(): array | |||
{ | |||
return [ | |||
DistributionRotatingDefinition::class, | |||
DistributionRotatingRepository::class, | |||
DistributionRotatingBuilder::class, | |||
]; | |||
} | |||
public function getDefinition(): DistributionRotatingDefinition | |||
{ | |||
return DistributionRotatingDefinition::getInstance(); | |||
} | |||
public function getRepository(): DistributionRotatingRepository | |||
{ | |||
return DistributionRotatingRepository::getInstance(); | |||
} | |||
public function getBuilder(): DistributionRotatingBuilder | |||
{ | |||
return DistributionRotatingBuilder::getInstance(); | |||
} | |||
} |
@@ -0,0 +1,25 @@ | |||
<?php | |||
namespace domain\Distribution\DistributionRotating; | |||
use domain\_\AbstractRepository; | |||
class DistributionRotatingRepository extends AbstractRepository | |||
{ | |||
protected DistributionRotatingRepositoryQuery $query; | |||
public function loadDependencies(): void | |||
{ | |||
$this->loadQuery(DistributionRotatingRepositoryQuery::class); | |||
} | |||
public function getDefaultOptionsSearch(): array | |||
{ | |||
return [ | |||
self::WITH => [], | |||
self::JOIN_WITH => ['rotatingRelation'], | |||
self::ORDER_BY => 'rotating.name ASC', | |||
self::ATTRIBUTE_ID_PRODUCER => '' | |||
]; | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
<?php | |||
namespace domain\Distribution\DistributionRotating; | |||
use domain\_\AbstractRepositoryQuery; | |||
class DistributionRotatingRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
protected DistributionRotatingDefinition $definition; | |||
public function loadDependencies(): void | |||
{ | |||
$this->loadDefinition(DistributionRotatingDefinition::class); | |||
} | |||
} |
@@ -0,0 +1,93 @@ | |||
<?php | |||
namespace domain\Product\Rotating; | |||
use common\components\ActiveRecordCommon; | |||
use domain\Producer\Producer\Producer; | |||
use yii\db\ActiveQuery; | |||
class Rotating extends ActiveRecordCommon | |||
{ | |||
public static function tableName() | |||
{ | |||
return 'rotating'; | |||
} | |||
public function rules() | |||
{ | |||
return [ | |||
[['id_producer', 'name', 'day'], 'required'], | |||
[['name'], 'string', 'max' => 255], | |||
[['id_producer', 'day', 'status'], 'integer'], | |||
]; | |||
} | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'id_producer' => 'Producteur', | |||
'name' => 'Nom', | |||
'day' => 'Jour', | |||
'status' => 'Statut', | |||
]; | |||
} | |||
/* Getters / Setters */ | |||
public function getId(): ?int | |||
{ | |||
return $this->id; | |||
} | |||
public function getProducer(): Producer | |||
{ | |||
return $this->producerRelation; | |||
} | |||
public function setProducer(Producer $producer): self | |||
{ | |||
$this->populateFieldObject('id_producer', 'producerRelation', $producer); | |||
return $this; | |||
} | |||
public function getName(): string | |||
{ | |||
return $this->name; | |||
} | |||
public function setName(string $name): self | |||
{ | |||
$this->name = $name; | |||
return $this; | |||
} | |||
public function getDay(): int | |||
{ | |||
return $this->day; | |||
} | |||
public function setDay(int $day): self | |||
{ | |||
$this->day = $day; | |||
return $this; | |||
} | |||
public function getStatus(): int | |||
{ | |||
return $this->status; | |||
} | |||
public function setStatus(int $status): self | |||
{ | |||
$this->status = $status; | |||
return $this; | |||
} | |||
/* Relations */ | |||
public function getProducerRelation(): ActiveQuery | |||
{ | |||
return $this->hasOne(Producer::class, ['id' => 'id_producer']); | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
<?php | |||
namespace domain\Product\Rotating; | |||
use domain\_\AbstractBuilder; | |||
use domain\_\StatusInterface; | |||
use domain\Producer\Producer\Producer; | |||
class RotatingBuilder extends AbstractBuilder | |||
{ | |||
public function instanciateRotating(Producer $producer): Rotating | |||
{ | |||
$rotating = new Rotating(); | |||
$rotating->setProducer($producer); | |||
$rotating->setStatus(StatusInterface::STATUS_ONLINE); | |||
return $rotating; | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
<?php | |||
namespace domain\Product\Rotating; | |||
use domain\_\AbstractDefinition; | |||
class RotatingDefinition extends AbstractDefinition | |||
{ | |||
public function getEntityFqcn(): string | |||
{ | |||
return Rotating::class; | |||
} | |||
} |
@@ -0,0 +1,24 @@ | |||
<?php | |||
namespace domain\Product\Rotating; | |||
use domain\_\AbstractManager; | |||
use domain\Producer\Producer\Producer; | |||
class RotatingManager extends AbstractManager | |||
{ | |||
protected RotatingBuilder $rotatingBuilder; | |||
public function loadDependencies(): void | |||
{ | |||
$this->rotatingBuilder = $this->loadService(RotatingBuilder::class); | |||
} | |||
public function createRotating(Producer $producer, string $name, int $day): Rotating | |||
{ | |||
$rotating = $this->rotatingBuilder->instanciateRotating($producer, $name, $day); | |||
$rotating->setName($name); | |||
$rotating->setDay($day); | |||
return $rotating; | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
<?php | |||
namespace domain\Product\Rotating; | |||
use domain\_\AbstractModule; | |||
class RotatingModule extends AbstractModule | |||
{ | |||
public function getServices(): array | |||
{ | |||
return [ | |||
RotatingDefinition::class, | |||
RotatingBuilder::class, | |||
RotatingRepository::class, | |||
RotatingManager::class | |||
]; | |||
} | |||
public function getDefinition(): RotatingDefinition | |||
{ | |||
return RotatingDefinition::getInstance(); | |||
} | |||
public function getBuilder(): RotatingBuilder | |||
{ | |||
return RotatingBuilder::getInstance(); | |||
} | |||
public function getRepository(): RotatingRepository | |||
{ | |||
return RotatingRepository::getInstance(); | |||
} | |||
public function getManager(): RotatingManager | |||
{ | |||
return RotatingManager::getInstance(); | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
<?php | |||
namespace domain\Product\Rotating; | |||
use domain\_\AbstractRepository; | |||
use domain\_\RepositoryQueryInterface; | |||
class RotatingRepository extends AbstractRepository | |||
{ | |||
protected RotatingRepositoryQuery $query; | |||
public function loadDependencies(): void | |||
{ | |||
$this->loadQuery(RotatingRepositoryQuery::class); | |||
} | |||
public function getDefaultOptionsSearch(): array | |||
{ | |||
return [ | |||
self::WITH => [], | |||
self::JOIN_WITH => [], | |||
self::ORDER_BY => 'rotating.name ASC', | |||
self::ATTRIBUTE_ID_PRODUCER => 'rotating.id_producer' | |||
]; | |||
} | |||
public function queryRotatings(): RepositoryQueryInterface | |||
{ | |||
return $this->createDefaultQuery(); | |||
} | |||
public function findOneRotatingById(int $id): ?Rotating | |||
{ | |||
return $this->createDefaultQuery() | |||
->filterById($id) | |||
->findOne(); | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
<?php | |||
namespace domain\Product\Rotating; | |||
use domain\_\AbstractRepositoryQuery; | |||
class RotatingRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
protected RotatingDefinition $definition; | |||
public function loadDependencies(): void | |||
{ | |||
$this->loadDefinition(RotatingDefinition::class); | |||
} | |||
} |
@@ -0,0 +1,98 @@ | |||
<?php | |||
namespace domain\Product\RotatingProduct; | |||
use common\components\ActiveRecordCommon; | |||
use domain\Product\Product\Product; | |||
use domain\Product\Rotating\Rotating; | |||
use yii\db\ActiveQuery; | |||
class RotatingProduct extends ActiveRecordCommon | |||
{ | |||
public static function tableName() | |||
{ | |||
return 'rotating_product'; | |||
} | |||
public function rules() | |||
{ | |||
return [ | |||
[['id_rotating', 'id_product'], 'required'], | |||
[['id_rotating', 'id_product', 'position', 'status'], 'integer'], | |||
]; | |||
} | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'id_rotating' => 'Produit tournant', | |||
'id_product' => 'Product', | |||
'position' => 'Position', | |||
'status' => 'Statut', | |||
]; | |||
} | |||
/* Getters / Setters */ | |||
public function getId(): ?int | |||
{ | |||
return $this->id; | |||
} | |||
public function getRotating(): Rotating | |||
{ | |||
return $this->rotatingRelation; | |||
} | |||
public function setRotating(Rotating $rotating): self | |||
{ | |||
$this->populateFieldObject('id_rotating', 'rotatingRelation', $rotating); | |||
return $this; | |||
} | |||
public function getProduct(): Product | |||
{ | |||
return $this->productRelation; | |||
} | |||
public function setProduct(Product $product): self | |||
{ | |||
$this->populateFieldObject('id_product', 'productRelation', $product); | |||
return $this; | |||
} | |||
public function getPosition(): int | |||
{ | |||
return $this->position; | |||
} | |||
public function setPosition(int $position): self | |||
{ | |||
$this->position = $position; | |||
return $this; | |||
} | |||
public function getStatus(): int | |||
{ | |||
return $this->status; | |||
} | |||
public function setStatus(int $status): self | |||
{ | |||
$this->status = $status; | |||
return $this; | |||
} | |||
/* Relations */ | |||
public function getRotatingRelation(): ActiveQuery | |||
{ | |||
return $this->hasOne(Rotating::class, ['id' => 'id_rotating']); | |||
} | |||
public function getProductRelation(): ActiveQuery | |||
{ | |||
return $this->hasOne(Product::class, ['id' => 'id_product']); | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
<?php | |||
namespace domain\Product\RotatingProduct; | |||
use domain\_\AbstractBuilder; | |||
use domain\_\StatusInterface; | |||
use domain\Product\Rotating\Rotating; | |||
class RotatingProductBuilder extends AbstractBuilder | |||
{ | |||
protected RotatingProductRepository $rotatingProductRepository; | |||
public function loadDependencies(): void | |||
{ | |||
$this->rotatingProductRepository = $this->loadService(RotatingProductRepository::class); | |||
} | |||
public function instanciateRotatingProduct(Rotating $rotating): RotatingProduct | |||
{ | |||
$rotatingProduct = new RotatingProduct(); | |||
$rotatingProduct | |||
->setRotating($rotating) | |||
->setStatus(StatusInterface::STATUS_ONLINE); | |||
return $rotatingProduct; | |||
} | |||
public function initRotatingProductPosition(RotatingProduct $rotatingProduct): RotatingProduct | |||
{ | |||
$lastRotatingProduct = $this->rotatingProductRepository->findOneLastRotatingProduct($rotatingProduct->getRotating()); | |||
$rotatingProduct->setPosition($lastRotatingProduct->getPosition() + 1); | |||
return $rotatingProduct; | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
<?php | |||
namespace domain\Product\RotatingProduct; | |||
use domain\_\AbstractDefinition; | |||
class RotatingProductDefinition extends AbstractDefinition | |||
{ | |||
public function getEntityFqcn(): string | |||
{ | |||
return RotatingProduct::class; | |||
} | |||
} |
@@ -0,0 +1,28 @@ | |||
<?php | |||
namespace domain\Product\RotatingProduct; | |||
use domain\_\AbstractManager; | |||
use domain\_\StatusInterface; | |||
use domain\Product\Product\Product; | |||
use domain\Product\Rotating\Rotating; | |||
class RotatingProductManager extends AbstractManager | |||
{ | |||
protected RotatingProductBuilder $rotatingProductBuilder; | |||
public function loadDependencies(): void | |||
{ | |||
$this->rotatingProductBuilder = $this->loadService(RotatingProductBuilder::class); | |||
} | |||
public function createRotatingProduct(Rotating $rotating, Product $product): RotatingProduct | |||
{ | |||
$rotatingProduct = $this->rotatingProductBuilder->instanciateRotatingProduct($rotating); | |||
$rotatingProduct->setProduct($product); | |||
$this->rotatingProductBuilder->initRotatingProductPosition($rotatingProduct); | |||
$rotatingProduct->save(); | |||
return $rotatingProduct; | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
<?php | |||
namespace domain\Product\RotatingProduct; | |||
use domain\_\AbstractModule; | |||
class RotatingProductModule extends AbstractModule | |||
{ | |||
public function getServices(): array | |||
{ | |||
return [ | |||
RotatingProductDefinition::class, | |||
RotatingProductBuilder::class, | |||
RotatingProductRepository::class, | |||
RotatingProductManager::class | |||
]; | |||
} | |||
public function getDefinition(): RotatingProductDefinition | |||
{ | |||
return RotatingProductDefinition::getInstance(); | |||
} | |||
public function getBuilder(): RotatingProductBuilder | |||
{ | |||
return RotatingProductBuilder::getInstance(); | |||
} | |||
public function getRepository(): RotatingProductRepository | |||
{ | |||
return RotatingProductRepository::getInstance(); | |||
} | |||
public function getManager(): RotatingProductManager | |||
{ | |||
return RotatingProductManager::getInstance(); | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
<?php | |||
namespace domain\Product\RotatingProduct; | |||
use domain\_\AbstractRepository; | |||
use domain\Product\Rotating\Rotating; | |||
class RotatingProductRepository extends AbstractRepository | |||
{ | |||
protected RotatingProductRepositoryQuery $query; | |||
public function loadDependencies(): void | |||
{ | |||
$this->loadQuery(RotatingProductRepositoryQuery::class); | |||
} | |||
public function getDefaultOptionsSearch(): array | |||
{ | |||
return [ | |||
self::WITH => [], | |||
self::JOIN_WITH => [], | |||
self::ORDER_BY => 'rotating_product.position ASC', | |||
self::ATTRIBUTE_ID_PRODUCER => '' | |||
]; | |||
} | |||
public function findOneLastRotatingProduct(Rotating $rotating): ?RotatingProduct | |||
{ | |||
return $this->createQuery() | |||
->filterByRotating($rotating) | |||
->orderBy('rotating_product.position DESC') | |||
->findOne(); | |||
} | |||
} |
@@ -0,0 +1,22 @@ | |||
<?php | |||
namespace domain\Product\RotatingProduct; | |||
use domain\_\AbstractRepositoryQuery; | |||
use domain\Product\Rotating\Rotating; | |||
class RotatingProductRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
protected RotatingProductDefinition $definition; | |||
public function loadDependencies(): void | |||
{ | |||
$this->loadDefinition(RotatingProductDefinition::class); | |||
} | |||
public function filterByRotating(Rotating $rotating): self | |||
{ | |||
$this->andWhere(['rotating_product.id_rotating' => $rotating->getId()]); | |||
return $this; | |||
} | |||
} |
@@ -40,6 +40,8 @@ namespace domain\Subscription\ProductSubscription; | |||
use common\components\ActiveRecordCommon; | |||
use domain\Product\Product\Product; | |||
use domain\Product\Rotating\Rotating; | |||
use yii\db\ActiveQuery; | |||
/** | |||
* This is the model class for table "commande_auto_produit". | |||
@@ -60,8 +62,8 @@ class ProductSubscription extends ActiveRecordCommon | |||
public function rules() | |||
{ | |||
return [ | |||
[['id_subscription', 'id_product'], 'required'], | |||
[['id_subscription', 'id_product'], 'integer'], | |||
[['id_subscription'], 'required'], | |||
[['id_subscription', 'id_product', 'id_rotating'], 'integer'], | |||
[['quantity'], 'number'], | |||
]; | |||
} | |||
@@ -75,13 +77,30 @@ class ProductSubscription extends ActiveRecordCommon | |||
'id' => 'ID', | |||
'id_subscription' => 'Abonnement', | |||
'id_product' => 'Produit', | |||
'id_rotating' => 'Produit tournant', | |||
'quantity' => 'Quantité', | |||
]; | |||
} | |||
/* | |||
* Relations | |||
*/ | |||
/* Getters / setters */ | |||
public function getRotating(): ?Rotating | |||
{ | |||
return $this->rotatingRelation; | |||
} | |||
public function setRotating(Rotating $rotating): self | |||
{ | |||
$this->populateFieldObject('id_rotating', 'rotatingRelation', $rotating); | |||
return $this; | |||
} | |||
/* Relations */ | |||
public function getRotatingRelation(): ActiveQuery | |||
{ | |||
return $this->hasOne(Rotating::class, ['id' => 'id_rotating']); | |||
} | |||
public function getProduct() | |||
{ |