You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 line
1.6KB

  1. <?php
  2. namespace common\logic\Feature\FeatureProducer;
  3. use common\logic\AbstractBuilder;
  4. use common\logic\Feature\Feature\Feature;
  5. class FeatureProducerBuilder extends AbstractBuilder
  6. {
  7. protected FeatureProducerRepository $featureProducerRepository;
  8. public function loadDependencies(): void
  9. {
  10. $this->featureProducerRepository = $this->loadService(FeatureProducerRepository::class);
  11. }
  12. public function instanciateFeatureProducer(
  13. Feature $feature,
  14. bool $status = null
  15. ): FeatureProducer
  16. {
  17. $featureProducer = new FeatureProducer();
  18. $featureProducer->populateFeature($feature);
  19. $featureProducer->populateProducer($this->getProducerContext());
  20. $featureProducer->status = $status;
  21. return $featureProducer;
  22. }
  23. public function createFeatureProducer(
  24. Feature $feature,
  25. bool $status = null
  26. ): FeatureProducer
  27. {
  28. $featureProducer = $this->featureProducerRepository->findOneFeatureProducer($feature);
  29. if(!$featureProducer) {
  30. $featureProducer = $this->instanciateFeatureProducer($feature, $status);
  31. $this->create($featureProducer);
  32. }
  33. return $featureProducer;
  34. }
  35. public function updateStatus(FeatureProducer $featureProducer, bool $status = null)
  36. {
  37. $featureProducer->status = $status;
  38. $this->update($featureProducer);
  39. }
  40. public function updateStatusByFeature(Feature $feature, bool $status = null)
  41. {
  42. $featureProducer = $this->createFeatureProducer($feature, $status);
  43. $this->updateStatus($featureProducer, $status);
  44. }
  45. }