src/Entity/Training/Module.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Training;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\Training\ModuleRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping\Entity;
  8. use Doctrine\ORM\Mapping\ManyToOne;
  9. use Doctrine\ORM\Mapping\JoinColumn;
  10. use App\Traits\Actions;
  11. use Doctrine\ORM\Mapping as ORM;
  12. #[Entity(repositoryClassModuleRepository::class)]
  13. #[ORM\Table(name'hs_tc_training_module')]
  14. #[ApiResource]
  15. class Module implements \Stringable
  16. {
  17.     use Actions;
  18.     #[ORM\Column(name"ref"type"string"length255)]
  19.     private ?string $ref null;
  20.     #[ORM\Column(name"name"type"string"length255)]
  21.     private $name;
  22.     #[ManyToOne(targetEntity"Training"inversedBy"modules")]
  23.     #[JoinColumn(nullablefalse)]
  24.     private ?Training $training null;
  25.     #[ORM\Column(name"coefficient"type"integer"length255)]
  26.     private ?int $coefficient null;
  27.     #[ORM\Column(name"semester"type"string"length255)]
  28.     private ?string $semester null;
  29.     #[ORM\OneToMany(mappedBy"module"targetEntity"Assignation")]
  30.     private ?Collection $assignations null;
  31.     #[ORM\OneToMany(mappedBy"module"targetEntityNotemodule::class, cascade: ["all"])]
  32.     private ?Collection $notes null;
  33.     #[ORM\Column()]
  34.     private ?int $hourlyVolume null;
  35.     public function __construct()
  36.     {
  37.         // date_default_timezone_set('Africa/Casablanca');
  38.         $this->createAt=new \DateTime('now');
  39.         $this->published=false;
  40.         $this->notes=new ArrayCollection();
  41.         $note3=new Notemodule();
  42.         $note3->setGenre('controle')->setName('c1');
  43.         $this->addNote($note3);
  44.         $note4=new Notemodule();
  45.         $note4->setGenre('controle')->setName('c2');
  46.         $this->addNote($note4);
  47.         $note1=new Notemodule();
  48.         $note1->setGenre('examen')->setName('ep');
  49.         $this->addNote($note1);
  50.         $note2=new Notemodule();
  51.         $note2->setGenre('examen')->setName('et');
  52.         $this->addNote($note2);
  53.     }
  54.     /**
  55.      * @return string
  56.      */
  57.     public function getRef(): ?string
  58.     {
  59.         return $this->ref;
  60.     }
  61.     /**
  62.      * @param string $ref
  63.      */
  64.     public function setRef(?string $ref): Module
  65.     {
  66.         $this->ref $ref;
  67.         return $this;
  68.     }
  69.     /**
  70.      * Set nom
  71.      *
  72.      * @param string $name
  73.      * @return Module
  74.      */
  75.     public function setName($name)
  76.     {
  77.         $this->name $name;
  78.         return $this;
  79.     }
  80.     /**
  81.      * Get name
  82.      *
  83.      * @return string
  84.      */
  85.     public function getName()
  86.     {
  87.         return $this->name;
  88.     }
  89.     function __toString(): string
  90.     {
  91.         return (string) $this->name;
  92.     }
  93.     /**
  94.      * @return Training
  95.      */
  96.     public function getTraining(): ?Training
  97.     {
  98.         return $this->training;
  99.     }
  100.     /**
  101.      * @param Training $training
  102.      */
  103.     public function setTraining(?Training $training): Module
  104.     {
  105.         $this->training $training;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return integer
  110.      */
  111.     public function getCoefficient(): ?int
  112.     {
  113.         return $this->coefficient;
  114.     }
  115.     /**
  116.      * @param integer $coefficient
  117.      */
  118.     public function setCoefficient(?int $coefficient): Module
  119.     {
  120.         $this->coefficient $coefficient;
  121.         return $this;
  122.     }
  123.     /**
  124.      * @return string
  125.      */
  126.     public function getSemester(): ?string
  127.     {
  128.         return $this->semester;
  129.     }
  130.     /**
  131.      * @param string $semester
  132.      */
  133.     public function setSemester(?string $semester): Module
  134.     {
  135.         $this->semester $semester;
  136.         return $this;
  137.     }
  138.     /**
  139.      * Add assignation
  140.      *
  141.      *
  142.      * @return Module
  143.      */
  144.     public function addAssignation(Assignation $assignation)
  145.     {
  146.         $assignation->setModule($this);
  147.         $this->assignations[] = $assignation;
  148.         return $this;
  149.     }
  150.     /**
  151.      * Remove assignation
  152.      */
  153.     public function removeAssignation(Assignation $assignation)
  154.     {
  155.         $this->assignations->removeElement($assignation);
  156.     }
  157.     /**
  158.      * Get assignations
  159.      *
  160.      * @return Collection
  161.      */
  162.     public function getAssignations()
  163.     {
  164.         return $this->assignations;
  165.     }
  166.     /**
  167.      * Add note
  168.      *
  169.      *
  170.      * @return Module
  171.      */
  172.     public function addNote(Notemodule $note)
  173.     {
  174.         $note->setModule($this);
  175.         $this->notes->add($note);
  176.         return $this;
  177.     }
  178.     /**
  179.      * Remove note
  180.      */
  181.     public function removeNote(Notemodule $note)
  182.     {
  183.         $this->notes->removeElement($note);
  184.     }
  185.     /**
  186.      * Get notes
  187.      *
  188.      * @return ArrayCollection
  189.      */
  190.     public function getNotes()
  191.     {
  192.         return $this->notes;
  193.     }
  194.     public function getHourlyVolume(): ?int
  195.     {
  196.         return $this->hourlyVolume;
  197.     }
  198.     public function setHourlyVolume(?int $hourlyVolume): void
  199.     {
  200.         $this->hourlyVolume $hourlyVolume;
  201.     }
  202.     public function getFormerGroupe(Groupe $groupe): ?\App\Entity\Training\Former{
  203.         $former=null;
  204.         /** @var Assignation $assignation */
  205.         foreach ($this->getAssignations() as $assignation){
  206.             if($assignation->getGroupe()===$groupe$former=$assignation->getFormer();
  207.         }
  208.         return $former;
  209.     }
  210.     public function getPCInput(Groupe $groupe){
  211.         $sm=0;
  212.         $nbr=0;
  213.         /** @var Assignation $assign */
  214.         foreach ($this->assignations as $assign){
  215.             if($assign->getGroupe()===$groupe){
  216.                 foreach ($assign->getModule()->getNotes() as $note){
  217.                     $sm+=$note->getPCInput($groupe);
  218.                     $nbr++;
  219.                 }
  220.             }
  221.         }
  222.         if($nbr==0) return 0;
  223.         return floor($sm/$nbr);
  224.     }
  225.     public function getNbrCC(){
  226.         $i=0;
  227.         /** @var Notemodule $note */
  228.         foreach ($this->getNotes() as $note){
  229.             if($note->getGenre()=='controle'$i++;
  230.         }
  231.         return $i;
  232.     }
  233.     public function getLevel(){
  234.         return match ($this->semester) {
  235.             'Semestre 2''Semestre 1' => 'first_year',
  236.             'Semestre 3''Semestre 4' => 'second_year',
  237.             'Semestre 5''Semestre 6' => 'third_year',
  238.             default => '',
  239.         };
  240.     }
  241.     public function getSchoolyearGroupe(Groupe $groupe){
  242.         return match ($this->getTrainingYear()) {
  243.             'first_year' => $groupe->getSchoolyear1(),
  244.             'second_year' => $groupe->getSchoolyear2(),
  245.             'third_year' => $groupe->getSchoolyear3(),
  246.             default => null,
  247.         };
  248.     }
  249.     public function hasCC(){
  250.         $rep=false;
  251.         /** @var Notemodule $note */
  252.         foreach ($this->getNotes() as $note){
  253.             if($note->getGenre()=='controle'$rep=true;
  254.         }
  255.         return $rep;
  256.     }
  257. }