|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
-
- namespace common\logic\Feature\FeatureProducer;
-
- use common\logic\AbstractBuilder;
- use common\logic\Feature\Feature\Feature;
-
- class FeatureProducerBuilder extends AbstractBuilder
- {
- protected FeatureProducerRepository $featureProducerRepository;
-
- public function loadDependencies(): void
- {
- $this->featureProducerRepository = $this->loadService(FeatureProducerRepository::class);
- }
-
- public function instanciateFeatureProducer(
- Feature $feature,
- bool $status = null
- ): FeatureProducer
- {
- $featureProducer = new FeatureProducer();
- $featureProducer->populateFeature($feature);
- $featureProducer->populateProducer($this->getProducerContext());
- $featureProducer->status = $status;
-
- return $featureProducer;
- }
-
- public function createFeatureProducer(
- Feature $feature,
- bool $status = null
- ): FeatureProducer
- {
- $featureProducer = $this->featureProducerRepository->findOneFeatureProducer($feature);
- if(!$featureProducer) {
- $featureProducer = $this->instanciateFeatureProducer($feature, $status);
- $this->create($featureProducer);
- }
-
- return $featureProducer;
- }
-
- public function updateStatus(FeatureProducer $featureProducer, bool $status = null)
- {
- $featureProducer->status = $status;
- $this->update($featureProducer);
- }
-
- public function updateStatusByFeature(Feature $feature, bool $status = null)
- {
- $featureProducer = $this->createFeatureProducer($feature, $status);
- $this->updateStatus($featureProducer, $status);
- }
- }
|