<?php
namespace App\Entity\Training;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Image;
use App\Entity\Schoolyear;
use App\Repository\Training\TrainingRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Traits\Actions;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OrderBy;
#[ORM\Entity(repositoryClass: TrainingRepository::class)]
#[ORM\Table(name: 'hs_tc_training_training')]
#[ApiResource]
class Training implements \Stringable
{
use Actions;
#[ORM\Column(name: "pole", type: "string", length: 255)]
private ?string $pole = null;
#[ORM\Column(name: "title", type: "string", length: 255, unique: true)]
private $title;
#[ORM\Column(name: "title_ar", type: "string", length: 255)]
private ?string $titleAr = null;
#[ORM\Column(name: "diploma", type: "string", length: 255, nullable: true)]
private ?string $diploma;
#[ORM\Column(name: "abbreviation", type: "string", length: 255, nullable: true)]
private ?string $abbreviation;
#[ORM\Column(name: "authorization_number", type: "string", length: 255, nullable: true)]
private ?string $authorizationNumber;
#[ORM\Column(name: "creation_year", type: "string", length: 255, nullable: true)]
private ?string $creationYear;
#[ORM\Column(name: "months", type: "integer", nullable: true)]
private ?int $months;
#[ORM\Column(type: "integer", nullable: true)]
private ?int $SchoolYearsNumber;
#[ORM\Column(name: "monthly_payment", type: "float", nullable: true)]
private ?float $monthlyPayment;
#[ORM\Column(name: "register_fees", type: "float", nullable: true)]
private ?float $registerFees;
#[ORM\Column(name: "exam_fees", type: "float", nullable: true)]
private ?float $examFees;
#[ORM\Column(name: "diploma_fees", type: "float", nullable: true)]
private ?float $diplomaFees;
#[ORM\Column(type: "json", nullable: true)]
private array $listMonths=[];
#[ORM\OneToMany(mappedBy: "training", targetEntity: "Module")]
#[ORM\OrderBy(["ref" => "ASC"])]
private ?Collection $modules = null;
#[ORM\OneToMany(mappedBy: "training", targetEntity: "Groupe")]
private ?Collection $groupes = null;
#[ORM\Column(name: 'forder', type: 'integer', nullable: true)]
private ?int $forder;
#[ORM\OneToMany(mappedBy: 'training', targetEntity: Image::class, cascade: ['all'])]
private ?Collection $images = null;
private $file;
public function __construct()
{
// date_default_timezone_set('Africa/Casablanca');
$this->createAt=new \DateTime('now');
$this->published=true;
$this->modules = new ArrayCollection();
$this->images = new ArrayCollection();
}
/**
* @return string
*/
public function getPole(): ?string
{
return $this->pole;
}
/**
* @param string $pole
*/
public function setPole(?string $pole): Training
{
$this->pole = $pole;
return $this;
}
/**
* Set title
*
* @param string $title
*
* @return Training
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @return string
*/
public function getTitleAr(): ?string
{
return $this->titleAr;
}
/**
* @param string $titleAr
*/
public function setTitleAr(?string $titleAr): Training
{
$this->titleAr = $titleAr;
return $this;
}
/**
* Set diploma
*
* @param string $diploma
*
* @return Training
*/
public function setDiploma($diploma)
{
$this->diploma = $diploma;
return $this;
}
/**
* Get diploma
*
* @return string
*/
public function getDiploma()
{
return $this->diploma;
}
/**
* Set authorizationNumber
*
* @param string $authorizationNumber
*
* @return Training
*/
public function setAuthorizationNumber($authorizationNumber)
{
$this->authorizationNumber = $authorizationNumber;
return $this;
}
/**
* Get authorizationNumber
*
* @return string
*/
public function getAuthorizationNumber()
{
return $this->authorizationNumber;
}
/**
* @return string
*/
public function getAbbreviation()
{
return $this->abbreviation;
}
/**
* @param string $abbreviation
*/
public function setAbbreviation($abbreviation)
{
$this->abbreviation = $abbreviation;
}
/**
* @return string
*/
public function getCreationYear()
{
return $this->creationYear;
}
/**
* @param string $creationYear
* @return Training
*/
public function setCreationYear($creationYear)
{
$this->creationYear = $creationYear;
return $this;
}
/**
* @return int
*/
public function getMonths()
{
return $this->months;
}
/**
* @param int $months
* @return Training
*/
public function setMonths($months)
{
$this->months = $months;
return $this;
}
/**
* @return float
*/
public function getMonthlyPayment()
{
return $this->monthlyPayment;
}
public function getSchoolYearsNumber(): ?int
{
return $this->SchoolYearsNumber;
}
public function setSchoolYearsNumber(?int $SchoolYearsNumber): Training
{
$this->SchoolYearsNumber = $SchoolYearsNumber;
return $this;
}
/**
* @param float $monthlyPayment
* @return Training
*/
public function setMonthlyPayment($monthlyPayment)
{
$this->monthlyPayment = $monthlyPayment;
return $this;
}
/**
* @return float
*/
public function getRegisterFees()
{
return $this->registerFees;
}
/**
* @param float $registerFees
* @return Training
*/
public function setRegisterFees($registerFees)
{
$this->registerFees = $registerFees;
return $this;
}
/**
* @return float
*/
public function getExamFees()
{
return $this->examFees;
}
/**
* @param float $examFees
* @return Training
*/
public function setExamFees($examFees)
{
$this->examFees = $examFees;
return $this;
}
/**
* @return float
*/
public function getDiplomaFees()
{
return $this->diplomaFees;
}
/**
* @param float $diplomaFees
* @return Training
*/
public function setDiplomaFees($diplomaFees)
{
$this->diplomaFees = $diplomaFees;
return $this;
}
public function getNbrYears(){
if($this->getSchoolYearsNumber()==null)
return intdiv($this->months,10);
return $this->getSchoolYearsNumber();
}
public function getTrainingYears(){
$items=['first_year'];
if($this->getNbrYears()>=2) $items[]='second_year';
if($this->getNbrYears()>=3) $items[]='third_year';
return $items;
}
public function __toString(): string
{
return (string) $this->title;
}
public function getName(){
return $this->diploma.' en '.$this->title;
}
/**
* Add module
*
*
* @return Training
*/
public function addModule(Module $module)
{
$module->setTraining($this);
$this->modules[] = $module;
return $this;
}
/**
* Remove module
*/
public function removeModule(Module $module)
{
$this->modules->removeElement($module);
}
/**
* Get modules
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getModules()
{
return $this->modules;
}
/**
* Add groupe
*
*
* @return Training
*/
public function addGroupe(Groupe $groupe)
{
$groupe->setTraining($this);
$this->groupes[] = $groupe;
return $this;
}
/**
* Remove groupe
*/
public function removeGroupe(Groupe $groupe)
{
$this->groupes->removeElement($groupe);
}
/**
* Get groupes
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getGroupes()
{
return $this->groupes;
}
public function getListMonths(): array
{
return $this->listMonths;
}
public function setListMonths(array $listMmonths): Training
{
$this->listMonths = $listMmonths;
return $this;
}
/**
* @return mixed
*/
public function getForder()
{
return $this->forder;
}
/**
* @return Training
*/
public function setForder(mixed $forder)
{
$this->forder = $forder;
return $this;
}
/**
* Add image
*
*
* @return Training
*/
public function addImage(Image $image)
{
$this->images[] = $image;
return $this;
}
/**
* Remove image
*/
public function removeImage(Image $image)
{
$this->images->removeElement($image);
}
/**
* Get images
*
* @return Collection
*/
public function getImages()
{
return $this->images;
}
/**
* @return mixed
*/
public function getFile()
{
return $this->file;
}
/**
* @param mixed $file
* @return Training
*/
public function setFile($file)
{
$this->file = $file;
return $this;
}
public function getModulesByLevel($level)
{
return $this->modules->filter(function (Module $module) use ($level) {
return $module->getLevel()==$level;
});
}
public function getGroupesBySY(SchoolYear $schoolYear)
{
$items=[];
/** @var Groupe $group */
foreach ($this->getGroupes() as $group) {
if($group->getSchoolyear1() === $schoolYear){
$items[]=$group;
}
}
return $items;
}
}