src/Entity/Training/Training.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Training;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Image;
  5. use App\Entity\Schoolyear;
  6. use App\Repository\Training\TrainingRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use App\Traits\Actions;
  11. use Doctrine\ORM\Mapping\Column;
  12. use Doctrine\ORM\Mapping\OneToMany;
  13. use Doctrine\ORM\Mapping\OrderBy;
  14. #[ORM\Entity(repositoryClassTrainingRepository::class)]
  15. #[ORM\Table(name'hs_tc_training_training')]
  16. #[ApiResource]
  17. class Training implements \Stringable
  18. {
  19.     use Actions;
  20.     #[ORM\Column(name"pole"type"string"length255)]
  21.     private ?string $pole null;
  22.     #[ORM\Column(name"title"type"string"length255uniquetrue)]
  23.     private $title;
  24.     #[ORM\Column(name"title_ar"type"string"length255)]
  25.     private ?string $titleAr null;
  26.     #[ORM\Column(name"diploma"type"string"length255nullabletrue)]
  27.     private ?string $diploma;
  28.     #[ORM\Column(name"abbreviation"type"string"length255nullabletrue)]
  29.     private ?string $abbreviation;
  30.     #[ORM\Column(name"authorization_number"type"string"length255nullabletrue)]
  31.     private ?string $authorizationNumber;
  32.     #[ORM\Column(name"creation_year"type"string"length255nullabletrue)]
  33.     private ?string $creationYear;
  34.     #[ORM\Column(name"months"type"integer"nullabletrue)]
  35.     private ?int $months;
  36.     #[ORM\Column(type"integer"nullabletrue)]
  37.     private ?int $SchoolYearsNumber;
  38.     #[ORM\Column(name"monthly_payment"type"float"nullabletrue)]
  39.     private ?float $monthlyPayment;
  40.     #[ORM\Column(name"register_fees"type"float"nullabletrue)]
  41.     private ?float $registerFees;
  42.     #[ORM\Column(name"exam_fees"type"float"nullabletrue)]
  43.     private ?float $examFees;
  44.     #[ORM\Column(name"diploma_fees"type"float"nullabletrue)]
  45.     private ?float $diplomaFees;
  46.     #[ORM\Column(type"json"nullabletrue)]
  47.     private array $listMonths=[];
  48.     #[ORM\OneToMany(mappedBy"training"targetEntity"Module")]
  49.     #[ORM\OrderBy(["ref" => "ASC"])]
  50.     private ?Collection $modules null;
  51.     #[ORM\OneToMany(mappedBy"training"targetEntity"Groupe")]
  52.     private ?Collection $groupes null;
  53.     #[ORM\Column(name'forder'type'integer'nullabletrue)]
  54.     private ?int $forder;
  55.     #[ORM\OneToMany(mappedBy'training'targetEntityImage::class, cascade: ['all'])]
  56.     private ?Collection $images null;
  57.     private $file;
  58.     public function __construct()
  59.     {
  60.         // date_default_timezone_set('Africa/Casablanca');
  61.         $this->createAt=new \DateTime('now');
  62.         $this->published=true;
  63.         $this->modules = new ArrayCollection();
  64.         $this->images = new ArrayCollection();
  65.     }
  66.     /**
  67.      * @return string
  68.      */
  69.     public function getPole(): ?string
  70.     {
  71.         return $this->pole;
  72.     }
  73.     /**
  74.      * @param string $pole
  75.      */
  76.     public function setPole(?string $pole): Training
  77.     {
  78.         $this->pole $pole;
  79.         return $this;
  80.     }
  81.     /**
  82.      * Set title
  83.      *
  84.      * @param string $title
  85.      *
  86.      * @return Training
  87.      */
  88.     public function setTitle($title)
  89.     {
  90.         $this->title $title;
  91.         return $this;
  92.     }
  93.     /**
  94.      * Get title
  95.      *
  96.      * @return string
  97.      */
  98.     public function getTitle()
  99.     {
  100.         return $this->title;
  101.     }
  102.     /**
  103.      * @return string
  104.      */
  105.     public function getTitleAr(): ?string
  106.     {
  107.         return $this->titleAr;
  108.     }
  109.     /**
  110.      * @param string $titleAr
  111.      */
  112.     public function setTitleAr(?string $titleAr): Training
  113.     {
  114.         $this->titleAr $titleAr;
  115.         return $this;
  116.     }
  117.     /**
  118.      * Set diploma
  119.      *
  120.      * @param string $diploma
  121.      *
  122.      * @return Training
  123.      */
  124.     public function setDiploma($diploma)
  125.     {
  126.         $this->diploma $diploma;
  127.         return $this;
  128.     }
  129.     /**
  130.      * Get diploma
  131.      *
  132.      * @return string
  133.      */
  134.     public function getDiploma()
  135.     {
  136.         return $this->diploma;
  137.     }
  138.     /**
  139.      * Set authorizationNumber
  140.      *
  141.      * @param string $authorizationNumber
  142.      *
  143.      * @return Training
  144.      */
  145.     public function setAuthorizationNumber($authorizationNumber)
  146.     {
  147.         $this->authorizationNumber $authorizationNumber;
  148.         return $this;
  149.     }
  150.     /**
  151.      * Get authorizationNumber
  152.      *
  153.      * @return string
  154.      */
  155.     public function getAuthorizationNumber()
  156.     {
  157.         return $this->authorizationNumber;
  158.     }
  159.     /**
  160.      * @return string
  161.      */
  162.     public function getAbbreviation()
  163.     {
  164.         return $this->abbreviation;
  165.     }
  166.     /**
  167.      * @param string $abbreviation
  168.      */
  169.     public function setAbbreviation($abbreviation)
  170.     {
  171.         $this->abbreviation $abbreviation;
  172.     }
  173.     /**
  174.      * @return string
  175.      */
  176.     public function getCreationYear()
  177.     {
  178.         return $this->creationYear;
  179.     }
  180.     /**
  181.      * @param string $creationYear
  182.      * @return Training
  183.      */
  184.     public function setCreationYear($creationYear)
  185.     {
  186.         $this->creationYear $creationYear;
  187.         return $this;
  188.     }
  189.     /**
  190.      * @return int
  191.      */
  192.     public function getMonths()
  193.     {
  194.         return $this->months;
  195.     }
  196.     /**
  197.      * @param int $months
  198.      * @return Training
  199.      */
  200.     public function setMonths($months)
  201.     {
  202.         $this->months $months;
  203.         return $this;
  204.     }
  205.     /**
  206.      * @return float
  207.      */
  208.     public function getMonthlyPayment()
  209.     {
  210.         return $this->monthlyPayment;
  211.     }
  212.     public function getSchoolYearsNumber(): ?int
  213.     {
  214.         return $this->SchoolYearsNumber;
  215.     }
  216.     public function setSchoolYearsNumber(?int $SchoolYearsNumber): Training
  217.     {
  218.         $this->SchoolYearsNumber $SchoolYearsNumber;
  219.         return $this;
  220.     }
  221.     /**
  222.      * @param float $monthlyPayment
  223.      * @return Training
  224.      */
  225.     public function setMonthlyPayment($monthlyPayment)
  226.     {
  227.         $this->monthlyPayment $monthlyPayment;
  228.         return $this;
  229.     }
  230.     /**
  231.      * @return float
  232.      */
  233.     public function getRegisterFees()
  234.     {
  235.         return $this->registerFees;
  236.     }
  237.     /**
  238.      * @param float $registerFees
  239.      * @return Training
  240.      */
  241.     public function setRegisterFees($registerFees)
  242.     {
  243.         $this->registerFees $registerFees;
  244.         return $this;
  245.     }
  246.     /**
  247.      * @return float
  248.      */
  249.     public function getExamFees()
  250.     {
  251.         return $this->examFees;
  252.     }
  253.     /**
  254.      * @param float $examFees
  255.      * @return Training
  256.      */
  257.     public function setExamFees($examFees)
  258.     {
  259.         $this->examFees $examFees;
  260.         return $this;
  261.     }
  262.     /**
  263.      * @return float
  264.      */
  265.     public function getDiplomaFees()
  266.     {
  267.         return $this->diplomaFees;
  268.     }
  269.     /**
  270.      * @param float $diplomaFees
  271.      * @return Training
  272.      */
  273.     public function setDiplomaFees($diplomaFees)
  274.     {
  275.         $this->diplomaFees $diplomaFees;
  276.         return $this;
  277.     }
  278.     public function getNbrYears(){
  279.         if($this->getSchoolYearsNumber()==null)
  280.         return intdiv($this->months,10);
  281.         return $this->getSchoolYearsNumber();
  282.     }
  283.     public function getTrainingYears(){
  284.         $items=['first_year'];
  285.         if($this->getNbrYears()>=2$items[]='second_year';
  286.         if($this->getNbrYears()>=3$items[]='third_year';
  287.         return $items;
  288.     }
  289.     public function __toString(): string
  290.     {
  291.         return (string) $this->title;
  292.     }
  293.     public function getName(){
  294.         return $this->diploma.' en '.$this->title;
  295.     }
  296.     /**
  297.      * Add module
  298.      *
  299.      *
  300.      * @return Training
  301.      */
  302.     public function addModule(Module $module)
  303.     {
  304.         $module->setTraining($this);
  305.         $this->modules[] = $module;
  306.         return $this;
  307.     }
  308.     /**
  309.      * Remove module
  310.      */
  311.     public function removeModule(Module $module)
  312.     {
  313.         $this->modules->removeElement($module);
  314.     }
  315.     /**
  316.      * Get modules
  317.      *
  318.      * @return \Doctrine\Common\Collections\Collection
  319.      */
  320.     public function getModules()
  321.     {
  322.         return $this->modules;
  323.     }
  324.     /**
  325.      * Add groupe
  326.      *
  327.      *
  328.      * @return Training
  329.      */
  330.     public function addGroupe(Groupe $groupe)
  331.     {
  332.         $groupe->setTraining($this);
  333.         $this->groupes[] = $groupe;
  334.         return $this;
  335.     }
  336.     /**
  337.      * Remove groupe
  338.      */
  339.     public function removeGroupe(Groupe $groupe)
  340.     {
  341.         $this->groupes->removeElement($groupe);
  342.     }
  343.     /**
  344.      * Get groupes
  345.      *
  346.      * @return \Doctrine\Common\Collections\Collection
  347.      */
  348.     public function getGroupes()
  349.     {
  350.         return $this->groupes;
  351.     }
  352.     public function getListMonths(): array
  353.     {
  354.         return $this->listMonths;
  355.     }
  356.     public function setListMonths(array $listMmonths): Training
  357.     {
  358.         $this->listMonths $listMmonths;
  359.         return $this;
  360.     }
  361.     /**
  362.      * @return mixed
  363.      */
  364.     public function getForder()
  365.     {
  366.         return $this->forder;
  367.     }
  368.     /**
  369.      * @return Training
  370.      */
  371.     public function setForder(mixed $forder)
  372.     {
  373.         $this->forder $forder;
  374.         return $this;
  375.     }
  376.     /**
  377.      * Add image
  378.      *
  379.      *
  380.      * @return Training
  381.      */
  382.     public function addImage(Image $image)
  383.     {
  384.         $this->images[] = $image;
  385.         return $this;
  386.     }
  387.     /**
  388.      * Remove image
  389.      */
  390.     public function removeImage(Image $image)
  391.     {
  392.         $this->images->removeElement($image);
  393.     }
  394.     /**
  395.      * Get images
  396.      *
  397.      * @return Collection
  398.      */
  399.     public function getImages()
  400.     {
  401.         return $this->images;
  402.     }
  403.     /**
  404.      * @return mixed
  405.      */
  406.     public function getFile()
  407.     {
  408.         return $this->file;
  409.     }
  410.     /**
  411.      * @param mixed $file
  412.      * @return Training
  413.      */
  414.     public function setFile($file)
  415.     {
  416.         $this->file $file;
  417.         return $this;
  418.     }
  419.     public function getModulesByLevel($level)
  420.     {
  421.         return $this->modules->filter(function (Module $module) use ($level) {
  422.             return $module->getLevel()==$level;
  423.         });
  424.     }
  425.     public function getGroupesBySY(SchoolYear $schoolYear)
  426.     {
  427.         $items=[];
  428.         /** @var Groupe $group */
  429.         foreach ($this->getGroupes() as $group) {
  430.             if($group->getSchoolyear1() === $schoolYear){
  431.                 $items[]=$group;
  432.             }
  433.         }
  434.         return $items;
  435.     }
  436. }