src/Entity/Olympiad/Olympiad.php line 26

  1. <?php
  2. namespace App\Entity\Olympiad;
  3. use App\Entity\Common\DateInterval;
  4. use App\Entity\Common\File;
  5. use App\Entity\Organisation\Organisation;
  6. use App\Entity\Organisation\SuccessHistory;
  7. use App\Entity\Organisation\University\OlympPrivilegy;
  8. use App\Entity\Scholar\Profile;
  9. use App\Entity\Traits\ActiveTrait;
  10. use App\Entity\Traits\TrackerFields;
  11. use App\Entity\Traits\UserCreatedInterface;
  12. use App\Entity\Traits\UserUpdatedInterface;
  13. use App\Entity\UUID\HaveUuidInterface;
  14. use App\Entity\UUID\UuidTrait;
  15. use App\Model\Translation\TranslatableTrait;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  20. #[ORM\Table(name'olympiad')]
  21. #[ORM\Entity(repositoryClass\App\Repository\Olympiad\OlympiadRepository::class)]
  22. #[ORM\HasLifecycleCallbacks]
  23. class Olympiad implements UserCreatedInterfaceUserUpdatedInterface,
  24.     HaveUuidInterfaceTranslatableInterface
  25. {
  26.     use TrackerFields;
  27.     use ActiveTrait;
  28.     use UuidTrait;
  29.     use TranslatableTrait;
  30.     #[ORM\Id]
  31.     #[ORM\GeneratedValue(strategy'AUTO')]
  32.     #[ORM\Column(type'integer')]
  33.     private ?int $id null;
  34.     /**
  35.      * @var string|null
  36.      */
  37.     #[ORM\Column(type'string'nullabletrue)]
  38.     private $caption;
  39.     /**
  40.      * @var string|null
  41.      */
  42.     #[ORM\Column(type'string'nullabletrue)]
  43.     private $subtitle;
  44.     /**
  45.      * @var bool
  46.      */
  47.     #[ORM\Column(type'boolean'options: ['default' => 0])]
  48.     private $mainpage false;
  49.     /**
  50.      * @var Collection|Discipline[]
  51.      */
  52.     #[ORM\JoinTable(name'olympiad_discipline_relation')]
  53.     #[ORM\ManyToMany(targetEntity'App\Entity\Olympiad\Discipline'inversedBy'olympiads')]
  54.     private $disciplines;
  55.     /**
  56.      * @var  Collection|Grade[]
  57.      *
  58.      */
  59.     #[ORM\JoinTable(name'olympiad_grade_relation')]
  60.     #[ORM\ManyToMany(targetEntity'App\Entity\Olympiad\Grade'inversedBy'olympiads')]
  61.     private $grades;
  62.     /**
  63.      * @var  Collection|Stage[]
  64.      *
  65.      */
  66.     #[ORM\OneToMany(targetEntity'App\Entity\Olympiad\Stage'mappedBy'olympiad')]
  67.     private $stages;
  68.     /**
  69.      * @var Level|null
  70.      */
  71.     #[ORM\ManyToOne(targetEntity'App\Entity\Olympiad\Level'inversedBy'olympiads')]
  72.     #[ORM\JoinColumn(nullablefalse)]
  73.     private $level;
  74.     /**
  75.      * @var string|null
  76.      */
  77.     #[ORM\Column(type'text'nullabletrue)]
  78.     private ?string $description null;
  79.     #[ORM\Column(type'text'nullabletrue)]
  80.     private ?string $results null;
  81.     /**
  82.      * @var Collection|Organisation
  83.      */
  84.     #[ORM\JoinTable(name'olympiad_organisation_relation')]
  85.     #[ORM\ManyToMany(targetEntity'App\Entity\Organisation\Organisation'inversedBy'olympiads')]
  86.     private $organisations;
  87.     /**
  88.      * @var DateInterval
  89.      */
  90.     #[ORM\Embedded(class: \App\Entity\Common\DateInterval::class)]
  91.     private $interval;
  92.     /**
  93.      * @var File|null
  94.      */
  95.     #[ORM\ManyToOne(targetEntity'App\Entity\Common\File'cascade: ['remove''persist'])]
  96.     private $logo;
  97.     /**
  98.      * @var ArrayCollection|OlympPrivilegy[]
  99.      *
  100.      */
  101.     #[ORM\OneToMany(targetEntity'App\Entity\Organisation\University\OlympPrivilegy'mappedBy'olympiad')]
  102.     private $privileges;
  103.     /**
  104.      * @var ArrayCollection|Profile[]
  105.      */
  106.     #[ORM\ManyToMany(targetEntity'App\Entity\Scholar\Profile'mappedBy'olympiads')]
  107.     private $scholar_profiles;
  108.     /**
  109.      * @var ArrayCollection|SuccessHistory[]
  110.      */
  111.     #[ORM\ManyToMany(targetEntity'App\Entity\Organisation\SuccessHistory'mappedBy'olympiads')]
  112.     private $success_history;
  113.     public function __construct()
  114.     {
  115.         $this->interval = new DateInterval();
  116.         $this->disciplines = new ArrayCollection();
  117.         $this->stages = new ArrayCollection();
  118.         $this->grades = new ArrayCollection();
  119.         $this->scholar_profiles = new ArrayCollection();
  120.     }
  121.     /**
  122.      * @return int|null
  123.      */
  124.     public function getId(): ?int
  125.     {
  126.         return $this->id;
  127.     }
  128.     /**
  129.      * @param int|null $id
  130.      */
  131.     public function setId(?int $id): void
  132.     {
  133.         $this->id $id;
  134.     }
  135.     /**
  136.      * @return string|null
  137.      */
  138.     /*   public function getCaption(): ?string
  139.        {
  140.            return $this->caption;
  141.        }*/
  142.     /**
  143.      * @param string|null $caption
  144.      */
  145.     /* public function setCaption(?string $caption): void
  146.      {
  147.          $this->caption = $caption;
  148.      }*/
  149.     public function getElasticCategory()
  150.     {
  151.         $res = [];
  152.         foreach ($this->getDisciplines() as $disc) {
  153.             $res[] = $disc->getCategory()->getId();
  154.         }
  155.         return $res;
  156.     }
  157.     /**
  158.      * @return Discipline[]|Collection
  159.      */
  160.     public function getDisciplines()
  161.     {
  162.         return $this->disciplines;
  163.     }
  164.     /**
  165.      * @param Discipline[]|Collection $disciplines
  166.      */
  167.     public function setDisciplines(Collection $disciplines): void
  168.     {
  169. //        $this->disciplines->clear();
  170. //        dump($this->disciplines, $disciplines);
  171. //        $this->disciplines->clear();
  172.         if (!$this->disciplines) {
  173.             $this->disciplines = new ArrayCollection();
  174.         }
  175.         foreach ($this->disciplines as $d) {
  176.             if ($disciplines->contains($d)) {
  177.                 continue;
  178.             }
  179.             $this->disciplines->removeElement($d);
  180. //                $d->getOlympiads()->removeElement($this);
  181.         }
  182.         foreach ($disciplines as $d) {
  183.             if ($this->disciplines->contains($d)) {
  184.                 continue;
  185.             }
  186.             $this->disciplines->add($d);
  187.         }
  188.     }
  189.     /**
  190.      * @return Grade[]|Collection
  191.      */
  192.     public function getGrades()
  193.     {
  194.         return $this->grades;
  195.     }
  196.     /**
  197.      * @param Grade[]|Collection $grades
  198.      */
  199.     public function setGrades($grades): void
  200.     {
  201.         $this->grades $grades;
  202.     }
  203.     /**
  204.      * @return Level|null
  205.      */
  206.     public function getLevel(): ?Level
  207.     {
  208.         return $this->level;
  209.     }
  210.     /**
  211.      * @param Level|null $level
  212.      */
  213.     public function setLevel(?Level $level): void
  214.     {
  215.         $this->level $level;
  216.     }
  217.     /**
  218.      * @return string|null
  219.      */
  220.     /*  public function getDescription(): ?string
  221.       {
  222.           return $this->description;
  223.       }*/
  224.     /**
  225.      * @param string|null $description
  226.      */
  227.     /*   public function setDescription(?string $description): void
  228.        {
  229.            $this->description = $description;
  230.        }*/
  231.     /**
  232.      * @return string|null
  233.      */
  234.     /*   public function getResults(): ?string
  235.        {
  236.            return $this->results;
  237.        }*/
  238.     /**
  239.      * @param string|null $results
  240.      */
  241.     /*   public function setResults(?string $results): void
  242.        {
  243.            $this->results = $results;
  244.        }*/
  245.     public function getInterval(): DateInterval
  246.     {
  247.         return $this->interval;
  248.     }
  249.     public function setInterval(DateInterval $interval): void
  250.     {
  251.         $this->interval $interval;
  252.     }
  253.     /**
  254.      * @return File|null
  255.      */
  256.     public function getLogo(): ?File
  257.     {
  258.         return $this->logo;
  259.     }
  260.     /**
  261.      * @param File|null $logo
  262.      */
  263.     public function setLogo(?File $logo): void
  264.     {
  265.         $this->logo $logo;
  266.     }
  267.     /**
  268.      * @return Stage[]|Collection
  269.      */
  270.     public function getStages()
  271.     {
  272.         return $this->stages;
  273.     }
  274.     /**
  275.      * @param Stage[]|Collection $stages
  276.      */
  277.     public function setStages($stages): void
  278.     {
  279.         $this->stages $stages;
  280.     }
  281.     /**
  282.      * @return Profile[]|ArrayCollection
  283.      */
  284.     public function getScholarProfiles()
  285.     {
  286.         return $this->scholar_profiles;
  287.     }
  288.     /**
  289.      * @param Profile[]|ArrayCollection $scholar_profiles
  290.      */
  291.     public function setScholarProfiles($scholar_profiles): void
  292.     {
  293.         $this->scholar_profiles $scholar_profiles;
  294.     }
  295.     /**
  296.      * @return Organisation|Collection
  297.      */
  298.     public function getOrganisations()
  299.     {
  300.         return $this->organisations;
  301.     }
  302.     /**
  303.      * @param Organisation|Collection $organisations
  304.      */
  305.     public function setOrganisations($organisations): void
  306.     {
  307.         $this->organisations $organisations;
  308.     }
  309.     /**
  310.      * @return bool
  311.      */
  312.     public function isMainpage(): bool
  313.     {
  314.         return $this->mainpage;
  315.     }
  316.     /**
  317.      * @param bool $mainpage
  318.      */
  319.     public function setMainpage(bool $mainpage): void
  320.     {
  321.         $this->mainpage $mainpage;
  322.     }
  323. }