src/Entity/Program.php line 92

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiSubresource;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  9. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use App\Repository\ProgramRepository;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Gedmo\Mapping\Annotation as Gedmo;
  15. use Symfony\Component\HttpFoundation\File\UploadedFile;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. /**
  19.  * @ORM\Entity(repositoryClass=ProgramRepository::class)
  20.  * @ApiResource(
  21.  *      normalizationContext={
  22.  *          "groups"={"program:read"}
  23.  *      },
  24.  *      denormalizationContext={
  25.  *          "groups"={"program:write"}
  26.  *      },
  27.  *      collectionOperations={
  28.  *          "get"={"security"="is_granted('ROLE_USER')"},
  29.  *          "post"={"security"="is_granted('ROLE_ADMIN')"},
  30.  *          "post_update"={
  31.  *              "security"="is_granted('ROLE_ADMIN')",
  32.  *              "path"="/programs/{id}",
  33.  *              "description"="Update a Program with method POST (using content-type: 'multipart')",
  34.  *              "method"="POST",
  35.  *              "controller"="App\Controller\Api\ProgramController::update"
  36.  *          },
  37.  *          "post_clone"={
  38.  *              "security"="is_granted('ROLE_ADMIN')",
  39.  *              "path"="/programs/{id}/clone",
  40.  *              "description"="Clone a program",
  41.  *              "method"="POST",
  42.  *              "deserialize"=false,
  43.  *              "controller"="App\Controller\Api\ProgramController::clone"
  44.  *          },
  45.  *          "vitality_balance_recommended_programs_by_client"={
  46.  *             "description"="Get vitality balance recommended programs by client.",
  47.  *             "path"="/clients/{id}/vitality-balance/recommended-programs",
  48.  *             "method"="GET",
  49.  *             "controller"="App\Controller\Api\VitalityBalanceController::getVitalityBalanceRecommandedProgramsByClient",
  50.  *             "security"="is_granted('ROLE_CLIENT')"
  51.  *          }
  52.  *      },
  53.  *      itemOperations={
  54.  *          "get"={"security"="is_granted('ROLE_USER')"},
  55.  *          "delete"={"security"="is_granted('ROLE_ADMIN')"},
  56.  *          "patch"={"security"="is_granted('ROLE_ADMIN')"},
  57.  *          "activate_program"={
  58.  *              "method"="GET",
  59.  *              "controller"="App\Controller\Api\ProgramController::activate",
  60.  *              "path"="/programs/{id}/activate",
  61.  *              "security"="is_granted('ROLE_ADMIN')",
  62.  *              "openapi_context"={"summary"="Activates a program"},
  63.  *           },
  64.  *           "deactivate_program"={
  65.  *              "method"="GET",
  66.  *              "controller"="App\Controller\Api\ProgramController::deactivate",
  67.  *              "path"="/programs/{id}/deactivate",
  68.  *              "security"="is_granted('ROLE_ADMIN')",
  69.  *              "openapi_context"={"summary"="Deactivates a program"},
  70.  *           }
  71.  *      }
  72.  * )
  73.  * @ORM\HasLifecycleCallbacks()
  74.  * @ApiFilter(OrderFilter::class, properties={"id", "name", "rank", "active", "daysCount", "status"})
  75.  * @ApiFilter(SearchFilter::class, properties={"name": "partial", "status", "active", "objectives.id": "exact", "reEducation"})
  76.  * @ApiFilter(GroupFilter::class, 
  77.  *      arguments={
  78.  *          "parameterName": "groups", 
  79.  *          "overrideDefaultGroups": true
  80.  *      }
  81.  * )
  82.  * @ApiFilter(PropertyFilter::class, 
  83.  *      arguments={
  84.  *          "parameterName"="fields", 
  85.  *          "overrideDefaultProperties"=true
  86.  *     }
  87.  * )
  88.  */
  89. class Program
  90. {
  91.     const STATUS_NEW 'new';
  92.     const STATUS_ACTIVE 'active';
  93.     const STATUS_DISABLED 'disabled';
  94.     const STATUSES = [
  95.         self::STATUS_NEW,
  96.         self::STATUS_ACTIVE,
  97.         self::STATUS_DISABLED,
  98.     ];
  99.     /**
  100.      * @ORM\Id
  101.      * @ORM\GeneratedValue
  102.      * @ORM\Column(type="integer")
  103.      * @Groups({"program:read", "program:read:id", "slide:read", "search_engine", "objective:read", "homepage:read", "day:read", "simple", "survey:read",
  104.      *     "program_list", "program_edit", "edit_day", "answer:read"})
  105.      */
  106.     private $id;
  107.     /**
  108.      * @ORM\Column(type="string", length=255)
  109.      * @Groups({"program:read", "program:read:name", "program:write", "search_engine", "objective:read", "slide:read", "homepage:read", "day:read", "simple",
  110.      *     "survey:read", "program_list", "program_edit", "edit_day", "answer:read", "objective_form_complete", "answer_recommended_objectives_edit"})
  111.      */
  112.     private $name;
  113.     /**
  114.      * @ORM\Column(type="text", nullable=true)
  115.      * @Groups({"program:read", "program:read:content", "program:write", "search_engine", "objective:read", "slide:read", "program_edit", "program_list"})
  116.      */
  117.     private $content null;
  118.     /**
  119.      * @ORM\Column(type="datetime")
  120.      * @Groups({"program:read", "program:read:createdAt", "program_list"})
  121.      * @Gedmo\Timestampable(on="create")
  122.      */
  123.     private $createdAt;
  124.     /**
  125.      * @ORM\Column(type="datetime")
  126.      * @Groups({"program:read", "program:read:updatedAt"})
  127.      * @Gedmo\Timestampable(on="update")
  128.      */
  129.     private $updatedAt;
  130.     /**
  131.      * @ORM\OneToMany(targetEntity=Day::class, mappedBy="program", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  132.      * @Groups({"program:read", "program:read:days"})
  133.      * @ApiSubresource(maxDepth=1)
  134.      */
  135.     private $days;
  136.     /**
  137.      * @ORM\Column(type="integer")
  138.      * @Groups({"program:read", "program:read:daysCount", "program:write", "search_engine", "objective:read", "slide:read", "program_list", "program_edit", "program_list"})
  139.      */
  140.     private $daysCount;
  141.     /**
  142.      * @ORM\Column(type="string", length=255)
  143.      * @Groups({"program:read", "program:read:status", "program_list", "program_list"})
  144.      */
  145.     private $status self::STATUS_NEW;
  146.     /**
  147.      * @ORM\Column(name="`rank`", type="integer")
  148.      * @Groups({"program:read", "program:read:rank", "program:write", "program_list"})
  149.      */
  150.     private $rank;
  151.     /**
  152.      * @ORM\Column(type="boolean", options={"default": "0"})
  153.      * @Groups({"program:read", "program:read:reEducation", "program:write"})
  154.      */
  155.     private $reEducation false;
  156.     /**
  157.      * @ORM\ManyToMany(targetEntity=Survey::class, mappedBy="programs", cascade={"persist", "refresh", "remove"})
  158.      * @Groups({"program:read", "program:read:survey"})
  159.      */
  160.     private $surveys;
  161.     /**
  162.      * @ORM\OneToMany(targetEntity=Slide::class, mappedBy="program")
  163.      */
  164.     private $slides;
  165.     /**
  166.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  167.      * @Groups({"program:read", "program:read:picture", "program:write", "slide:read", "search_engine", "objective:read", "homepage:read", "program_edit", "program_list"})
  168.      */
  169.     private $picture;
  170.     /**
  171.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  172.      * @Groups({"program:read", "program:read:avatar", "program:write", "search_engine", "objective:read", "homepage:read", "program_edit", "program_list"})
  173.      */
  174.     private $avatar;
  175.     /**
  176.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  177.      * @Groups({"program:read", "program:read:illustration", "program:write", "slide:read", "search_engine", "objective:read", "homepage:read", "program_edit", "program_list"})
  178.      */
  179.     private $illustration;
  180.     /**
  181.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  182.      * @Groups({"program:read", "program:read:tip", "program:write", "program_edit", "program_list"})
  183.      */
  184.     private $tip;
  185.     /**
  186.      * @ORM\Column(type="boolean", options={"default": "0"})
  187.      * @Groups({"program:read", "program:read:active", "program:write"})
  188.      */
  189.     private $active false;
  190.     /**
  191.      * @ORM\ManyToMany(targetEntity=TvTag::class)
  192.      * @Groups({"program:read", "program:read:tvTags", "program:write", "program_edit"})
  193.      */
  194.     private $tvTags;
  195.     /**
  196.      * @ORM\Column(type="text", nullable=true)
  197.      * @Groups({"program:read", "program:read:stringifyTags"})
  198.      */
  199.     private $stringifyTags '';
  200.     /**
  201.      * @ORM\ManyToOne(targetEntity=TvCompany::class, inversedBy="programs")
  202.      */
  203.     private $tvCompany;
  204.     /**
  205.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="programs")
  206.      * @Groups({"program:read", "program:read:company", "program:write", "program_edit"})
  207.      */
  208.     private $company;
  209.     
  210.     /**
  211.      * @ORM\OneToMany(targetEntity=ProgramEvent::class, mappedBy="program", cascade={"persist", "refresh", "remove"}, orphanRemoval=true)
  212.      */
  213.     private $programEvents;
  214.     /**
  215.      * @ORM\ManyToMany(targetEntity=Objective::class, mappedBy="programs")
  216.      */
  217.     private $objectives;
  218.     /**
  219.      * @ORM\Column(type="boolean", options={"default": 0})
  220.      * @Groups({"program:read", "program:read:itCanInterrest", "program:write"})
  221.      */
  222.     private $itCanInterrest false;
  223.     /**
  224.      * Custom field
  225.      * @var ArrayCollection|null
  226.      * Get experts from video's day
  227.      * @Groups({"program:read", "program:read:experts"})
  228.      */
  229.     private $experts null;
  230.     /**
  231.      * Custom field
  232.      * @var int|null
  233.      * @Groups({"program:read:expertsCount", "search_engine", "objective:read", "program_list"})
  234.      */
  235.     private $expertsCount null;
  236.     /**
  237.      * Custom field
  238.      * @var ArrayCollection|null
  239.      * Get videos from days
  240.      * @Groups({"program:read:videos"})
  241.      */
  242.     private $videos null;
  243.     /**
  244.      * Custom field
  245.      * @var int|null
  246.      * @Groups({"program:read:videosCount", "search_engine", "objective:read", "program_list"})
  247.      */
  248.     private $videosCount null;
  249.     /**
  250.      * Custom field
  251.      * @var ArrayCollection|null
  252.      * Get videos from days
  253.      * @Groups({"program:read:activeVideos"})
  254.      */
  255.     private $activeVideos null;
  256.     /**
  257.      * Custom field
  258.      * @var int|null
  259.      * @Groups({"program:read:activeVideosCount", "search_engine", "objective:read", "program_list"})
  260.      */
  261.     private $activeVideosCount null;
  262.     /**
  263.      * Custom field
  264.      * @var Day|null
  265.      * @Groups({"program:read", "program:read:currentDay"})
  266.      */
  267.     public $currentDay null;
  268.     /**
  269.      * Custom field
  270.      * @Groups({"program:read", "program:read:categories", "search_engine"})
  271.      */
  272.     public $categories null;
  273.     /**
  274.      * Custom field
  275.      * @var array
  276.      * @Groups({"program:read", "program:read:moodAfterPostResponses", "program_edit"})
  277.      */
  278.     public $moodAfterPostResponses null;
  279.     /**
  280.      * Custom field
  281.      * @Groups({"program:read", "program:read:flags", "program:write", "slide:read", "search_engine", "objective:read", "homepage:read"})
  282.      */
  283.     public $flags null;
  284.     /**
  285.      * Custom field
  286.      * @var ?int
  287.      * @Groups({"program:read", "program:read:daysCompletedCount", "program:write", "slide:read", "search_engine", "objective:read", "homepage:read"})
  288.      */
  289.     public $daysCompletedCount null;
  290.     public function __construct()
  291.     {
  292.         $this->days = new ArrayCollection();
  293.         $this->surveys = new ArrayCollection();
  294.         $this->slides = new ArrayCollection();
  295.         $this->tvTags = new ArrayCollection();
  296.         $this->programEvents = new ArrayCollection();
  297.         $this->objectives = new ArrayCollection();
  298.     }
  299.     public function __clone()
  300.     {
  301.         $this->id null;
  302.         $this->company null;
  303.         $this->status self::STATUS_NEW;
  304.         $this->slides = new ArrayCollection();
  305.         // $this->tvTags = new ArrayCollection();
  306.         $this->programEvents = new ArrayCollection();
  307.         $this->objectives = new ArrayCollection();
  308.         $this->createdAt = new \DateTime();
  309.         $this->updatedAt = new \DateTime();
  310.         $this->active false;
  311.         // Clone Days
  312.         $days = new ArrayCollection();
  313.         foreach ($this->days->toArray() as $day) {
  314.             $newDay = clone $day;
  315.             $newDay->setProgram($this);
  316.             $days->add($newDay);
  317.         }
  318.         $this->days $days;
  319.         
  320.         // Add This Program into TvTags
  321.         // foreach($this->tvTags->toArray() as $tvTag) {
  322.         //     $tvTag->addProgram($this);
  323.         // }
  324.         // @TODO : Dois-je copier les Questionnaires ?
  325.         $surveys = new ArrayCollection();
  326.         foreach($this->surveys->toArray() as $survey) {
  327.             $newSurvey = clone $survey;
  328.             $newSurvey->addProgram($this);
  329.             $surveys->add($newSurvey);
  330.         }
  331.         $this->surveys $surveys;
  332.         // Clone des MediaObject : Doit-on copier les images ?
  333.         // $this->picture = clone $this->picture;
  334.         // $this->avatar = clone $this->avatar;
  335.         // $this->illustration = clone $this->illustration;
  336.         // $this->tip = clone $this->tip;
  337.         $this->picture null;
  338.         $this->avatar null;
  339.         $this->illustration null;
  340.         $this->tip null;
  341.     }
  342.     public function getId(): ?int
  343.     {
  344.         return $this->id;
  345.     }
  346.     public function setId(?int $id): self
  347.     {
  348.         $this->id $id;
  349.         return $this;
  350.     }
  351.     public function getName(): ?string
  352.     {
  353.         return $this->name;
  354.     }
  355.     public function setName(string $name): self
  356.     {
  357.         $this->name $name;
  358.         return $this;
  359.     }
  360.     public function getContent(): ?string
  361.     {
  362.         return $this->content;
  363.     }
  364.     public function setContent(string $content): self
  365.     {
  366.         $this->content $content;
  367.         return $this;
  368.     }
  369.     public function getCreatedAt(): ?\DateTimeInterface
  370.     {
  371.         return $this->createdAt;
  372.     }
  373.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  374.     {
  375.         $this->createdAt $createdAt;
  376.         return $this;
  377.     }
  378.     public function getUpdatedAt(): ?\DateTimeInterface
  379.     {
  380.         return $this->updatedAt;
  381.     }
  382.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  383.     {
  384.         $this->updatedAt $updatedAt;
  385.         return $this;
  386.     }
  387.     /**
  388.      * @return Collection|Day[]
  389.      */
  390.     public function getDays(): Collection
  391.     {
  392.         return $this->days;
  393.     }
  394.     public function addDay(Day $day): self
  395.     {
  396.         if (!$this->days->contains($day)) {
  397.             $this->days[] = $day;
  398.             $day->setProgram($this);
  399.         }
  400.         return $this;
  401.     }
  402.     public function removeDay(Day $day): self
  403.     {
  404.         if ($this->days->removeElement($day)) {
  405.             // set the owning side to null (unless already changed)
  406.             if ($day->getProgram() === $this) {
  407.                 $day->setProgram(null);
  408.             }
  409.         }
  410.         return $this;
  411.     }
  412.     public function getDaysCount(): ?int
  413.     {
  414.         return $this->daysCount;
  415.     }
  416.     public function setDaysCount(int $daysCount): self
  417.     {
  418.         $this->daysCount $daysCount;
  419.         return $this;
  420.     }
  421.     /**
  422.      * Creates a single day
  423.      * @param int $rank
  424.      * @return Day
  425.      */
  426.     private function instantiateDay(int $rank 0): Day
  427.     {
  428.         $day = new Day();
  429.         $day->setName("Jour $rank du programme: '{$this->name}'");
  430.         $day->setContent("Descriptif du jour $rank du programme: '{$this->name}'");
  431.         $day->setRank($rank);
  432.         $day->setProgram($this);
  433.         $day->setStatus($this->status);
  434.         return $day;
  435.     }
  436.     /**
  437.      * Appends days to the list
  438.      * @param int $count
  439.      * @param int $addon
  440.      */
  441.     private function createDays(int $countint $addon 1){
  442.         $start = ($this->days->count() + $addon);
  443.         for ($n 0$n $count$n++) {
  444.             $this->addDay($this->instantiateDay($n $start));
  445.         }
  446.     }
  447.     private function deleteDays(int $count){
  448.         $start = ($this->days->count() - $count);
  449.         if ($start 0){
  450.             $start 0;
  451.         }
  452.         foreach ($this->days as $key=>$day) {
  453.             if ($key >= $start){
  454.                 $this->removeDay($day);
  455.             }
  456.         }
  457.     }
  458.     /**
  459.      * Instantiates the necessary number of days
  460.      */
  461.     public function instantiateDays()
  462.     {
  463.         if ($this->id == null) {
  464.             $this->createDays($this->daysCount0);
  465.         } elseif ($this->daysCount != $this->days->count()) { //this means it's an update event
  466.             if ($this->daysCount $this->days->count()){
  467.                 $this->createDays($this->daysCount $this->days->count());
  468.             }else{
  469.                 $this->deleteDays($this->days->count() - $this->daysCount);
  470.             }
  471.         }
  472.     }
  473.     public function getStatus(): ?string
  474.     {
  475.         return $this->status;
  476.     }
  477.     public function setStatus(string $status): self
  478.     {
  479.         $this->status $status;
  480.         if ($this->status == self::STATUS_ACTIVE) {
  481.             $this->active true;
  482.         } else {
  483.             $this->active false;
  484.         }
  485.         return $this;
  486.     }
  487.     public function getRank(): ?int
  488.     {
  489.         return $this->rank;
  490.     }
  491.     public function setRank(int $rank): self
  492.     {
  493.         $this->rank $rank;
  494.         return $this;
  495.     }
  496.     public function getReEducation(): ?bool
  497.     {
  498.         return $this->reEducation;
  499.     }
  500.     public function isReEducation(): ?bool
  501.     {
  502.         return $this->reEducation;
  503.     }
  504.     public function setReEducation(bool $reEducation): self
  505.     {
  506.         $this->reEducation $reEducation;
  507.         return $this;
  508.     }
  509.     /**
  510.      * @return Collection|Survey[]
  511.      */
  512.     public function getSurveys(): Collection
  513.     {
  514.         return $this->surveys;
  515.     }
  516.     public function addSurvey(Survey $survey): self
  517.     {
  518.         if (!$this->surveys->contains($survey)) {
  519.             $this->surveys[] = $survey;
  520.             $survey->addProgram($this);
  521.         }
  522.         return $this;
  523.     }
  524.     public function removeSurvey(Survey $survey): self
  525.     {
  526.         if ($this->surveys->removeElement($survey)) {
  527.             $survey->removeProgram($this);
  528.         }
  529.         return $this;
  530.     }
  531.     /**
  532.      * @return Collection|Slide[]
  533.      */
  534.     public function getSlides(): Collection
  535.     {
  536.         return $this->slides;
  537.     }
  538.     public function addSlide(Slide $slide): self
  539.     {
  540.         if (!$this->slides->contains($slide)) {
  541.             $this->slides[] = $slide;
  542.             $slide->setProgram($this);
  543.         }
  544.         return $this;
  545.     }
  546.     public function removeSlide(Slide $slide): self
  547.     {
  548.         if ($this->slides->removeElement($slide)) {
  549.             // set the owning side to null (unless already changed)
  550.             if ($slide->getProgram() === $this) {
  551.                 $slide->setProgram(null);
  552.             }
  553.         }
  554.         return $this;
  555.     }
  556.     public function getPicture(): ?MediaObject
  557.     {
  558.         return $this->picture;
  559.     }
  560.     public function setPicture(?MediaObject $picture): self
  561.     {
  562.         $this->picture $picture;
  563.         return $this;
  564.     }
  565.     /**
  566.      * @Groups({"program:write"})
  567.      */
  568.     public function setPictureFile($file null): self
  569.     {
  570.         if($file instanceof UploadedFile) {
  571.             $picture = empty($this->picture) ? new MediaObject $this->picture;
  572.             $picture->setFile($file);
  573.             $this->setPicture($picture);
  574.         }
  575.         return $this;
  576.     }
  577.     public function getAvatar(): ?MediaObject
  578.     {
  579.         return $this->avatar;
  580.     }
  581.     public function setAvatar(?MediaObject $avatar): self
  582.     {
  583.         $this->avatar $avatar;
  584.         return $this;
  585.     }
  586.     /**
  587.      * @Groups({"program:write"})
  588.      */
  589.     public function setAvatarFile($file null): self
  590.     {
  591.         if($file instanceof UploadedFile) {
  592.             $avatar = empty($this->avatar) ? new MediaObject $this->avatar;
  593.             $avatar->setFile($file);
  594.             $this->setAvatar($avatar);
  595.         }
  596.         return $this;
  597.     }
  598.     public function getIllustration(): ?MediaObject
  599.     {
  600.         return $this->illustration;
  601.     }
  602.     public function setIllustration(?MediaObject $illustration): self
  603.     {
  604.         $this->illustration $illustration;
  605.         return $this;
  606.     }
  607.     /**
  608.      * @Groups({"program:write"})
  609.      */
  610.     public function setIllustrationFile($file null): self
  611.     {
  612.         if($file instanceof UploadedFile) {
  613.             $illustration = empty($this->illustration) ? new MediaObject $this->illustration;
  614.             $illustration->setFile($file);
  615.             $this->setIllustration($illustration);
  616.         }
  617.         return $this;
  618.     }
  619.     public function getExperts(): ?Collection
  620.     {
  621.         $experts = new ArrayCollection;
  622.         foreach ($this->days as $day) {
  623.             foreach ($day->getPlaylist()->getVideos() as $video) {
  624.                 if($video->getActive()) {
  625.                     foreach ($video->getExperts() as $expert) {
  626.                         if(!$experts->contains($expert)) {
  627.                             $experts->add($expert);
  628.                         }
  629.                     }
  630.                 }
  631.             }
  632.         }
  633.         if(!$experts->isEmpty()) $this->experts $experts;
  634.         return $this->experts;
  635.     }
  636.     public function getExpertsCount(): ?int
  637.     {
  638.         if(!is_null($this->getExperts())) {
  639.             $this->expertsCount $this->getExperts()->count();
  640.         }
  641.         return $this->expertsCount;
  642.     }
  643.     public function getVideos(): ?Collection
  644.     {
  645.         $videos = new ArrayCollection;
  646.         foreach ($this->days as $day) {
  647.             foreach ($day->getPlaylist()->getVideos() as $video) {
  648.                 if(!$videos->contains($video)) {
  649.                     $videos->add($video);
  650.                 }
  651.             }
  652.         }
  653.         if(!$videos->isEmpty()) $this->videos $videos;
  654.         return $this->videos;
  655.     }
  656.     public function getVideosCount(): ?int
  657.     {
  658.         if(!is_null($this->getVideos())) {
  659.             $this->videosCount $this->getVideos()->count();
  660.         }
  661.         return $this->videosCount;
  662.     }
  663.     public function getActiveVideos(): ?Collection
  664.     {
  665.         $videos = new ArrayCollection;
  666.         foreach ($this->days as $day) {
  667.             foreach ($day->getPlaylist()->getVideos() as $video) {
  668.                 if($video->getActive() && !$videos->contains($video)) {
  669.                     $videos->add($video);
  670.                 }
  671.             }
  672.         }
  673.         if(!$videos->isEmpty()) $this->activeVideos $videos;
  674.         return $this->activeVideos;
  675.     }
  676.     public function getActiveVideosCount(): ?int
  677.     {
  678.         if(!is_null($this->getActiveVideos())) {
  679.             $this->activeVideosCount $this->getActiveVideos()->count();
  680.         }
  681.         return $this->activeVideosCount;
  682.     }
  683.     /**
  684.      * @Groups({"program:read", "program:read:tipsCount", "search_engine", "objective:read"}) 
  685.      */
  686.     public function getTipsCount(): int
  687.     {
  688.         $count 0;
  689.         foreach ($this->days as $day) {
  690.             foreach ($day->getPlaylist()->getVideos() as $video) {
  691.                 if ($video instanceof Video && $video->getTip() instanceof MediaObject) {
  692.                     $count++;
  693.                 }
  694.             }
  695.         }
  696.         return $count;
  697.     }
  698.     public function getTip(): ?MediaObject
  699.     {
  700.         return $this->tip;
  701.     }
  702.     public function setTip(?MediaObject $tip): self
  703.     {
  704.         $this->tip $tip;
  705.         return $this;
  706.     }
  707.     public function getActive(): ?bool
  708.     {
  709.         return $this->active;
  710.     }
  711.     public function setActive(bool $active): self
  712.     {
  713.         $this->active $active;
  714.         if ($this->active) {
  715.             $this->status self::STATUS_ACTIVE;
  716.         } else {
  717.             $this->status self::STATUS_DISABLED;
  718.         }
  719.         return $this;
  720.     }
  721.     /**
  722.      * @return Collection|TvTag[]
  723.      */
  724.     public function getTvTags(): Collection
  725.     {
  726.         return $this->tvTags;
  727.     }
  728.     /**
  729.      * @return Program
  730.      * @Groups({"program:write"})
  731.      */
  732.     public function setTvTags(Collection $tvTags): self
  733.     {
  734.         $this->tvTags $tvTags;
  735.         foreach ($this->tvTags as $tvTag) {
  736.             $this->stringifyTags .= "#".$tvTag->getName();
  737.         }
  738.         return $this;
  739.     }
  740.     public function addTvTag(TvTag $tvTag): self
  741.     {
  742.         if (!$this->tvTags->contains($tvTag)) {
  743.             $this->tvTags[] = $tvTag;
  744.         }
  745.         return $this;
  746.     }
  747.     public function removeTvTag(TvTag $tvTag): self
  748.     {
  749.         $this->tvTags->removeElement($tvTag);
  750.         return $this;
  751.     }
  752.     public function getStringifyTags(): ?string
  753.     {
  754.         return $this->stringifyTags;
  755.     }
  756.     public function setStringifyTags(?string $stringifyTags): self
  757.     {
  758.         $this->stringifyTags $stringifyTags;
  759.         return $this;
  760.     }
  761.     public function getTvCompany(): ?TvCompany
  762.     {
  763.         return $this->tvCompany;
  764.     }
  765.     public function setTvCompany(?TvCompany $tvCompany): self
  766.     {
  767.         $this->tvCompany $tvCompany;
  768.         return $this;
  769.     }
  770.     public function getCompany(): ?Company
  771.     {
  772.         return $this->company;
  773.     }
  774.     public function setCompany(?Company $company): self
  775.     {
  776.         $this->company $company;
  777.         return $this;
  778.     }
  779.     /**
  780.      * @return Collection|ProgramEvent[]
  781.      */
  782.     public function getProgramEvents(): Collection
  783.     {
  784.         return $this->programEvents;
  785.     }
  786.     public function addProgramEvent(ProgramEvent $programEvent): self
  787.     {
  788.         if (!$this->programEvents->contains($programEvent)) {
  789.             $this->programEvents[] = $programEvent;
  790.             $programEvent->setProgram($this);
  791.         }
  792.         return $this;
  793.     }
  794.     public function removeProgramEvent(ProgramEvent $programEvent): self
  795.     {
  796.         if ($this->programEvents->removeElement($programEvent)) {
  797.             // set the owning side to null (unless already changed)
  798.             if ($programEvent->getProgram() === $this) {
  799.                 $programEvent->setProgram(null);
  800.             }
  801.         }
  802.         return $this;
  803.     }
  804.     /**
  805.      * @return Collection|Objective[]
  806.      */
  807.     public function getObjectives(): Collection
  808.     {
  809.         return $this->objectives;
  810.     }
  811.     public function addObjective(Objective $objective): self
  812.     {
  813.         if (!$this->objectives->contains($objective)) {
  814.             $this->objectives[] = $objective;
  815.             $objective->addProgram($this);
  816.         }
  817.         return $this;
  818.     }
  819.     
  820.     public function removeObjective(Objective $objective): self
  821.     {
  822.         if ($this->objectives->removeElement($objective)) {
  823.             $objective->removeProgram($this);
  824.         }
  825.         return $this;
  826.     }
  827.     public function getItCanInterrest(): ?bool
  828.     {
  829.         return $this->itCanInterrest;
  830.     }
  831.     public function setItCanInterrest(bool $itCanInterrest): self
  832.     {
  833.         $this->itCanInterrest $itCanInterrest;
  834.         return $this;
  835.     }
  836. }