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.

81 lines
2.3KB

  1. <?php
  2. namespace Lc\PietroBundle\Solver\Workshop;
  3. use Lc\PietroBundle\Model\Workshop\WorkshopInterface;
  4. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  5. class WorkshopSolver
  6. {
  7. protected ParameterBagInterface $parameterBag;
  8. public function __construct(ParameterBagInterface $parameterBag)
  9. {
  10. $this->parameterBag = $parameterBag;
  11. }
  12. public function isComplete(WorkshopInterface $workshop): bool
  13. {
  14. $gauge = $this->parameterBag->get('app.workshop.gauge');
  15. $countEntriesRegistered = $this->countEntriesRegistered($workshop);
  16. return $countEntriesRegistered >= $gauge;
  17. }
  18. public function getRemainingPlaces(WorkshopInterface $workshop)
  19. {
  20. $gauge = $this->parameterBag->get('app.workshop.gauge');
  21. $countEntriesRegistered = $this->countEntriesRegistered($workshop);
  22. return $gauge - $countEntriesRegistered;
  23. }
  24. public function countEntriesAnimators(WorkshopInterface $workshop): int
  25. {
  26. return count($this->getEntriesByIsAnimator($workshop, true));
  27. }
  28. public function countEntriesRegistered(WorkshopInterface $workshop): int
  29. {
  30. return count($this->getEntriesByIsAnimator($workshop, false));
  31. }
  32. public function getEntriesRegistered(WorkshopInterface $workshop)
  33. {
  34. return $this->getEntriesByIsAnimator($workshop, false);
  35. }
  36. public function hasEntryAnimator(WorkshopInterface $workshop): bool
  37. {
  38. return $this->countEntriesAnimators($workshop) > 0;
  39. }
  40. public function getEntriesAnimators(WorkshopInterface $workshop)
  41. {
  42. return $this->getEntriesByIsAnimator($workshop, true);
  43. }
  44. public function getOneEntryAnimator(WorkshopInterface $workshop)
  45. {
  46. $entriesAnimatorArray = $this->getEntriesByIsAnimator($workshop, true);
  47. if($entriesAnimatorArray && count($entriesAnimatorArray) > 0) {
  48. return $entriesAnimatorArray[0];
  49. }
  50. return false;
  51. }
  52. public function getEntriesByIsAnimator(WorkshopInterface $workshop, bool $isAnimator): array
  53. {
  54. $entryArray = [];
  55. foreach($workshop->getEntries() as $entry) {
  56. if($entry->isAnimator() == $isAnimator) {
  57. $entryArray[] = $entry;
  58. }
  59. }
  60. return $entryArray;
  61. }
  62. }