src/Entity/LineParticipant.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\LineParticipantRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassLineParticipantRepository::class)]
  9. class LineParticipant
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  16.     private ?string $description null;
  17.     #[ORM\Column(typeTypes::INTEGERnullabletrueoptions: ['default' => 0])]
  18.     private ?int $position 0;
  19.     #[ORM\ManyToOne(targetEntityLine::class, inversedBy'lineParticipants'cascade: ["persist"])]
  20.     // , "remove"
  21.     #[ORM\JoinColumn(nullabletrue)]
  22.     private ?Line $line;
  23.     /** @var Participant[]|ArrayCollection|Collection<int,Participant> */
  24.     #[ORM\ManyToMany(targetEntityParticipant::class, inversedBy'lineParticipants'cascade: ["persist"])] // , "remove"
  25.     #[ORM\JoinTable(name'line_participant_participant')]
  26.     #[ORM\JoinColumn(nullabletrueonDelete"RESTRICT")]
  27.     #[ORM\InverseJoinColumn(nullabletrueonDelete"RESTRICT")]
  28.     private $participants;
  29.     public function __construct()
  30.     {
  31.         $this->description null;
  32.         $this->line null;
  33.         $this->position 0;
  34.         $this->participants = new ArrayCollection();
  35.     }
  36.     public function getInfos(): string
  37.     {
  38.         return $this->description . ($this->line ' ' $this->line->getTheme() : '');
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getDescription(): ?string
  45.     {
  46.         return $this->description;
  47.     }
  48.     public function setDescription(?string $description): self
  49.     {
  50.         $this->description $description;
  51.         return $this;
  52.     }
  53.     /**
  54.      * Get the value of the line under which the presentation is held
  55.      */
  56.     public function getLine(): ?Line
  57.     {
  58.         return $this->line;
  59.     }
  60.     /**
  61.      * Set the value of line
  62.      *
  63.      * @return  self
  64.      */
  65.     public function setLine(?Line $line): self
  66.     {
  67.         $this->line $line;
  68.         return $this;
  69.     }
  70.     public function getListParticipants(): string
  71.     {
  72.         $list = [];
  73.         if ($this->participants) {
  74.             foreach ($this->participants as $participant) {
  75.                 if ($participant && $participant->getFullname()) {
  76.                     $list[] = $participant->getFullname();
  77.                 }
  78.             }
  79.             if ($list) {
  80.                 return implode(" / "$list);
  81.             }
  82.         }
  83.         return "";
  84.     }
  85.     /**
  86.      * returns an array of the ids of presenters
  87.      * @param int $event_id (optional) specify from which event to collect lines
  88.      * @return array
  89.      */
  90.     public function getListParticipantId($event_id null)
  91.     {
  92.         $list = [];
  93.         foreach ($this->participants as $participant) {
  94.             if ($event_id != null) {
  95.                 //collect only lines corresponding to $eventId
  96.                 if ($this->getLine()->getEvenement()->getId() == $event_id) {
  97.                     $list[] = $participant->getId();
  98.                 }
  99.             } else {
  100.                 //collect lines for all  events
  101.                 $list[] = $participant->getId();
  102.             }
  103.         }
  104.         return $list;
  105.     }
  106.     /**
  107.      * Get the value of participant
  108.      */
  109.     public function getParticipants()
  110.     {
  111.         return $this->participants;
  112.     }
  113.     /**
  114.      * Set the value of participant
  115.      *
  116.      * @return  self
  117.      */
  118.     public function setParticipants($participants): self
  119.     {
  120.         $this->participants $participants;
  121.         return $this;
  122.     }
  123.     public function addParticipant(Participant $participant): void
  124.     {
  125.         if (!$this->participants->contains($participant)) {
  126.             $participant->addLineParticipant($this);
  127.             $this->participants->add($participant);
  128.         }
  129.     }
  130.     public function removeParticipant(Participant $participant): void
  131.     {
  132.         if ($this->participants->contains($participant)) {
  133.             $participant->removeLineParticipant($this);
  134.             $this->participants->removeElement($participant);
  135.         }
  136.     }
  137. }