src/Entity/Training/Trainee.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Training;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Training\Fee;
  5. use App\Repository\Training\TraineeRepository;
  6. use App\Traits\Actions;
  7. use App\Entity\Schoolyear;
  8. use App\Entity\User;
  9. use DateTime;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  14. use Symfony\Component\HttpFoundation\File\UploadedFile;
  15. #[ORM\Entity(repositoryClassTraineeRepository::class)]
  16. #[ORM\Table(name'hs_tc_training_trainee')]
  17. #[ApiResource]
  18. class Trainee implements \Stringable
  19. {
  20.     use Actions;
  21.     final public const SERVER_PATH_TO_IMAGE_FOLDER 'uploads/images/trainee';
  22.     #[ORM\OneToOne(inversedBy"trainee"targetEntityUser::class, cascade: ["persist"])]
  23.     #[ORM\JoinColumn(nullabletrue)]
  24.     private ?User $user null;
  25.     #[ORM\ManyToOne(targetEntity"Groupe"inversedBy"trainees")]
  26.     #[ORM\JoinColumn(nullabletrue)]
  27.     private ?Groupe $groupe null;
  28.     #[ORM\Column(name"first_name"type"string"length255)]
  29.     private $firstName;
  30.     #[ORM\Column(name"last_name"type"string"length255)]
  31.     private $lastName;
  32.     #[ORM\Column(name"first_name_ar"type"string"length255nullabletrue)]
  33.     private ?string $firstNameAr null;
  34.     #[ORM\Column(name"last_name_ar"type"string"length255nullabletrue)]
  35.     private ?string $lastNameAr null;
  36.     #[ORM\Column(name"cin"type"string"length255nullabletrue)]
  37.     private $cin;
  38.     #[ORM\Column(name"gender"type"string"length255nullabletrue)]
  39.     private $gender;
  40.     #[ORM\Column(name"birth_in"type"string"length255nullabletrue)]
  41.     private $birthIn;
  42.     #[ORM\Column(name"birth_in_ar"type"string"length255nullabletrue)]
  43.     private ?string $birthInAr null;
  44.     #[ORM\Column(name"birth_at"type"datetime"nullabletrue)]
  45.     private $birthAt;
  46.     #[ORM\Column(name"nationality"type"string"length255nullabletrue)]
  47.     private string $nationality "Marocaine";
  48.     #[ORM\Column(name"phone"type"string"length255nullabletrue)]
  49.     private $phone;
  50.     #[ORM\Column(name"phone2"type"string"length255nullabletrue)]
  51.     private $phone2;
  52.     #[ORM\Column(name'wp'type'string'length255nullabletrue)]
  53.     private ?string $wp null;
  54.     #[ORM\Column(name"email"type"string"length255nullabletrue)]
  55.     private $email;
  56.     #[ORM\Column(name"address"type"string"length255nullabletrue)]
  57.     private $address;
  58.     #[ORM\Column(name"address_ar"type"string"length255nullabletrue)]
  59.     private ?string $addressAr null;
  60.     #[ORM\Column(name"city"type"string"length255nullabletrue)]
  61.     private $city;
  62.     #[ORM\Column(name"school_level"type"string"length255nullabletrue)]
  63.     private $schoolLevel;
  64.     #[ORM\Column(name"school_last"type"string"length255nullabletrue)]
  65.     private $schoolLast;
  66.     #[ORM\Column(name"registration_number"type"string"length255nullabletrue)]
  67.     private $regNumber;
  68.     #[ORM\Column(name"serie_number"type"string"length255nullabletrue)]
  69.     private ?string $serieNumber null;
  70.     #[ORM\Column(name"id_massar"type"string"length255nullabletrue)]
  71.     private ?string $idMassar null;
  72.     #[ORM\Column(name"diplome_number"type"string"length255nullabletrue)]
  73.     private ?string $diplomeNumber null;
  74.     #[ORM\Column(name:"registration_at"type:"datetime"nullable:true)]
  75.     private \DateTime $registrationAt;
  76.     #[ORM\Column(name"status"type"string"length255nullabletrue)]
  77.     private $status;
  78.     #[ORM\Column(name"status_at"type"datetime"nullabletrue)]
  79.     private ?\DateTime $statusAt null;
  80.     #[ORM\Column(name"image_name"type"string"length255nullabletrue)]
  81.     protected $imageName 'photo.jpg';
  82.     protected $imageFile;
  83.     #[ORM\Column(name"cin_image"type"string"length255nullabletrue)]
  84.     protected $cinImage 'cin.png';
  85.     protected $cinImageFile;
  86.     #[ORM\Column(name"school_level_image"type"string"length255nullabletrue)]
  87.     protected $schoolLevelImage 'attestation.png';
  88.     protected $schoolLevelImageFile;
  89.     #[ORM\Column(name"monthly_payment"type"float"nullabletrue)]
  90.     private ?float $monthlyPayment null;
  91.     #[ORM\Column(name"register_fees"type"float"nullabletrue)]
  92.     private ?float $registerFees null;
  93.     #[ORM\Column(name"exam_fees"type"float"nullabletrue)]
  94.     private ?float $examFees null;
  95.     #[ORM\Column(name"diploma_fees"type"float"nullabletrue)]
  96.     private ?float $diplomaFees null;
  97.     #[ORM\Column(name"discount"type"boolean")]
  98.     private $discount;
  99.     #[ORM\OneToMany(mappedBy"trainee"targetEntityFpayment::class)]
  100.     #[ORM\OrderBy(["createAt" => "ASC"])]
  101.     private ?Collection $payments null;
  102.     #[ORM\OneToMany(mappedBy"trainee"targetEntityNote::class, cascade: ["persist"], orphanRemovaltrue)]
  103.     private ?Collection $notes null;
  104.     #[ORM\OneToMany(mappedBy"trainee"targetEntity"Nsti"cascade: ["persist"], orphanRemovaltrue)]
  105.     private ?Collection $nstis;
  106.     #[ORM\OneToMany(mappedBy"trainee"targetEntity"Fee"cascade: ["persist"], orphanRemovaltrue)]
  107.     #[ORM\OrderBy(["datePaie" => "ASC"])]
  108.     private ?Collection $fees null;
  109.     #[ORM\OneToMany(mappedBy"trainee"targetEntityAbsence::class, cascade: ["persist"], orphanRemovaltrue)]
  110.     private ?Collection $absences null;
  111.     #[ORM\Column(length255nullabletrue)]
  112.     private ?string $plainPassword null;
  113.     public function __construct()
  114.     {
  115.         // date_default_timezone_set('Africa/Casablanca');
  116.         $this->createAt=new \DateTime('now');
  117.         $this->registrationAt=new \DateTime('now');
  118.         $this->published=true;
  119.         $this->nstis=new ArrayCollection();
  120.         $this->payments=new ArrayCollection();
  121.         $this->notes=new ArrayCollection();
  122.         $this->fees=new ArrayCollection();
  123.         $this->wp="212";
  124.         $this->status="En cours";
  125.         $this->discount=true;
  126.     }
  127.     /**
  128.      * Set user
  129.      *
  130.      *
  131.      * @return Trainee
  132.      */
  133.     public function setUser(User $user)
  134.     {
  135.         $this->user $user;
  136.         return $this;
  137.     }
  138.     /**
  139.      * Get user
  140.      *
  141.      * @return User
  142.      */
  143.     public function getUser()
  144.     {
  145.         return $this->user;
  146.     }
  147.     /**
  148.      * Set groupe
  149.      *
  150.      *
  151.      * @return Trainee
  152.      */
  153.     public function setGroupe(Groupe $groupe)
  154.     {
  155.         $this->groupe $groupe;
  156.         return $this;
  157.     }
  158.     /**
  159.      * Get groupe
  160.      *
  161.      * @return Groupe
  162.      */
  163.     public function getGroupe()
  164.     {
  165.         return $this->groupe;
  166.     }
  167.     /**
  168.      * @return string
  169.      */
  170.     public function getFirstName()
  171.     {
  172.         return $this->firstName;
  173.     }
  174.     /**
  175.      * @param string $firstName
  176.      * @return Trainee
  177.      */
  178.     public function setFirstName($firstName)
  179.     {
  180.         $this->firstName $firstName;
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return string
  185.      */
  186.     public function getLastName()
  187.     {
  188.         return $this->lastName;
  189.     }
  190.     /**
  191.      * @param string $lastName
  192.      * @return Trainee
  193.      */
  194.     public function setLastName($lastName)
  195.     {
  196.         $this->lastName $lastName;
  197.         return $this;
  198.     }
  199.     /**
  200.      * @return \DateTime
  201.      */
  202.     public function getBirthAt()
  203.     {
  204.         return $this->birthAt;
  205.     }
  206.     /**
  207.      * @param \DateTime $birthAt
  208.      * @return Trainee
  209.      */
  210.     public function setBirthAt($birthAt)
  211.     {
  212.         $this->birthAt $birthAt;
  213.         return $this;
  214.     }
  215.     /**
  216.      * @return string
  217.      */
  218.     public function getPhone()
  219.     {
  220.         return $this->phone;
  221.     }
  222.     /**
  223.      * @param string $phone
  224.      * @return Trainee
  225.      */
  226.     public function setPhone($phone)
  227.     {
  228.         $this->phone $phone;
  229.         return $this;
  230.     }
  231.     public function getWp(): ?string
  232.     {
  233.         return $this->wp;
  234.     }
  235.     public function setWp(?string $wp): void
  236.     {
  237.         $this->wp $wp;
  238.     }
  239.     /**
  240.      * @return string
  241.      */
  242.     public function getPhone2()
  243.     {
  244.         return $this->phone2;
  245.     }
  246.     /**
  247.      * @param string $phone2
  248.      * @return Trainee
  249.      */
  250.     public function setPhone2($phone2)
  251.     {
  252.         $this->phone2 $phone2;
  253.         return $this;
  254.     }
  255.     /**
  256.      * @return string
  257.      */
  258.     public function getEmail()
  259.     {
  260.         return $this->email;
  261.     }
  262.     /**
  263.      * @param string $email
  264.      * @return Trainee
  265.      */
  266.     public function setEmail($email)
  267.     {
  268.         $this->email $email;
  269.         return $this;
  270.     }
  271.     /**
  272.      * @return string
  273.      */
  274.     public function getAddress()
  275.     {
  276.         return $this->address;
  277.     }
  278.     /**
  279.      * @param string $address
  280.      * @return Trainee
  281.      */
  282.     public function setAddress($address)
  283.     {
  284.         $this->address $address;
  285.         return $this;
  286.     }
  287.     /**
  288.      * @return string
  289.      */
  290.     public function getCity()
  291.     {
  292.         return $this->city;
  293.     }
  294.     /**
  295.      * @param string $city
  296.      * @return Trainee
  297.      */
  298.     public function setCity($city)
  299.     {
  300.         $this->city $city;
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return string
  305.      */
  306.     public function getSchoolLevel()
  307.     {
  308.         return $this->schoolLevel;
  309.     }
  310.     /**
  311.      * @param string $schoolLevel
  312.      * @return Trainee
  313.      */
  314.     public function setSchoolLevel($schoolLevel)
  315.     {
  316.         $this->schoolLevel $schoolLevel;
  317.         return $this;
  318.     }
  319.     /**
  320.      * @return string
  321.      */
  322.     public function getCin()
  323.     {
  324.         return $this->cin;
  325.     }
  326.     /**
  327.      * @param string $cin
  328.      * @return Trainee
  329.      */
  330.     public function setCin($cin)
  331.     {
  332.         $this->cin $cin;
  333.         return $this;
  334.     }
  335.     /**
  336.      * @return string
  337.      */
  338.     public function getGender()
  339.     {
  340.         return $this->gender;
  341.     }
  342.     /**
  343.      * @param string $gender
  344.      * @return Trainee
  345.      */
  346.     public function setGender($gender)
  347.     {
  348.         $this->gender $gender;
  349.         return $this;
  350.     }
  351.     /**
  352.      * @return string
  353.      */
  354.     public function getBirthIn()
  355.     {
  356.         return $this->birthIn;
  357.     }
  358.     /**
  359.      * @param string $birthIn
  360.      * @return Trainee
  361.      */
  362.     public function setBirthIn($birthIn)
  363.     {
  364.         $this->birthIn $birthIn;
  365.         return $this;
  366.     }
  367.     /**
  368.      * @return string
  369.      */
  370.     public function getNationality()
  371.     {
  372.         return $this->nationality;
  373.     }
  374.     /**
  375.      * @param string $nationality
  376.      * @return Trainee
  377.      */
  378.     public function setNationality($nationality)
  379.     {
  380.         $this->nationality $nationality;
  381.         return $this;
  382.     }
  383.     /**
  384.      * @return string
  385.      */
  386.     public function getSchoolLast()
  387.     {
  388.         return $this->schoolLast;
  389.     }
  390.     /**
  391.      * @param string $schoolLast
  392.      * @return Trainee
  393.      */
  394.     public function setSchoolLast($schoolLast)
  395.     {
  396.         $this->schoolLast $schoolLast;
  397.         return $this;
  398.     }
  399.     /**
  400.      * @return string
  401.      */
  402.     public function getRegNumber()
  403.     {
  404.         return $this->regNumber;
  405.     }
  406.     /**
  407.      * @param string $regNumber
  408.      * @return Trainee
  409.      */
  410.     public function setRegNumber($regNumber)
  411.     {
  412.         $this->regNumber $regNumber;
  413.         return $this;
  414.     }
  415.     /**
  416.      * @return string
  417.      */
  418.     public function getSerieNumber(): ?string
  419.     {
  420.         return $this->serieNumber;
  421.     }
  422.     /**
  423.      * @param string $serieNumber
  424.      */
  425.     public function setSerieNumber(?string $serieNumber): Trainee
  426.     {
  427.         $this->serieNumber $serieNumber;
  428.         return $this;
  429.     }
  430.     /**
  431.      * @return string
  432.      */
  433.     public function getDiplomeNumber(): ?string
  434.     {
  435.         return $this->diplomeNumber;
  436.     }
  437.     /**
  438.      * @param string $diplomeNumber
  439.      */
  440.     public function setDiplomeNumber(?string $diplomeNumber): Trainee
  441.     {
  442.         $this->diplomeNumber $diplomeNumber;
  443.         return $this;
  444.     }
  445.     /**
  446.      * @return string
  447.      */
  448.     public function getIdMassar(): ?string
  449.     {
  450.         return $this->idMassar;
  451.     }
  452.     /**
  453.      * @param string $idMassar
  454.      */
  455.     public function setIdMassar(?string $idMassar): Trainee
  456.     {
  457.         $this->idMassar $idMassar;
  458.         return $this;
  459.     }
  460.     /**
  461.      * @return string
  462.      */
  463.     public function getStatus()
  464.     {
  465.         return $this->status;
  466.     }
  467.     /**
  468.      * @param string $status
  469.      * @return Trainee
  470.      */
  471.     public function setStatus($status)
  472.     {
  473.         $this->status $status;
  474.         // date_default_timezone_set('Africa/Casablanca');
  475.         $this->statusAt=new \DateTime('now');
  476.         return $this;
  477.     }
  478.     /**
  479.      * @return \DateTime
  480.      */
  481.     public function getStatusAt()
  482.     {
  483.         return $this->statusAt;
  484.     }
  485.     /**
  486.      * @param \DateTime $statusAt
  487.      * @return Trainee
  488.      */
  489.     public function setStatusAt($statusAt)
  490.     {
  491.         $this->statusAt $statusAt;
  492.         return $this;
  493.     }
  494.     /**
  495.      * @return string
  496.      */
  497.     public function getCinImage()
  498.     {
  499.         return $this->cinImage;
  500.     }
  501.     /**
  502.      * @param string $cinImage
  503.      * @return Trainee
  504.      */
  505.     public function setCinImage($cinImage)
  506.     {
  507.         $this->cinImage $cinImage;
  508.         return $this;
  509.     }
  510.     /**
  511.      * @return mixed
  512.      */
  513.     public function getCinImageFile()
  514.     {
  515.         return $this->cinImageFile;
  516.     }
  517.     /**
  518.      * @return Trainee
  519.      */
  520.     public function setCinImageFile(mixed $cinImageFile)
  521.     {
  522.         $this->cinImageFile $cinImageFile;
  523.         return $this;
  524.     }
  525.     /**
  526.      * @return string
  527.      */
  528.     public function getSchoolLevelImage()
  529.     {
  530.         return $this->schoolLevelImage;
  531.     }
  532.     /**
  533.      * @param string $schoolLevelImage
  534.      * @return Trainee
  535.      */
  536.     public function setSchoolLevelImage($schoolLevelImage)
  537.     {
  538.         $this->schoolLevelImage $schoolLevelImage;
  539.         return $this;
  540.     }
  541.     /**
  542.      * @return mixed
  543.      */
  544.     public function getSchoolLevelImageFile()
  545.     {
  546.         return $this->schoolLevelImageFile;
  547.     }
  548.     /**
  549.      * @return Trainee
  550.      */
  551.     public function setSchoolLevelImageFile(mixed $schoolLevelImageFile)
  552.     {
  553.         $this->schoolLevelImageFile $schoolLevelImageFile;
  554.         return $this;
  555.     }
  556.     /**
  557.      * @return string
  558.      */
  559.     public function getImageName()
  560.     {
  561.         return $this->imageName;
  562.     }
  563.     /**
  564.      * @param string $imageName
  565.      * @return Trainee
  566.      */
  567.     public function setImageName($imageName)
  568.     {
  569.         $this->imageName $imageName;
  570.         return $this;
  571.     }
  572.     /**
  573.      * @return mixed
  574.      */
  575.     public function getImageFile()
  576.     {
  577.         return $this->imageFile;
  578.     }
  579.     /**
  580.      * @param mixed $imageFile
  581.      * @return Trainee
  582.      */
  583.     public function setImageFile(UploadedFile $imageFile=null)
  584.     {
  585.         $this->imageFile $imageFile;
  586.         return $this;
  587.     }
  588.     public function getPhoto(){
  589.         return "<img src='../../../../".self::SERVER_PATH_TO_IMAGE_FOLDER.'/'.$this->imageName."' style='width: 100px;'>";
  590.     }
  591.     public function getCompletName(){
  592.         return $this->gender.' '.$this->lastName.' '.$this->firstName;
  593.     }
  594.     public function getPlainPassword(): ?string
  595.     {
  596.         return $this->plainPassword;
  597.     }
  598.     public function setPlainPassword(?string $plainPassword): Trainee
  599.     {
  600.         $this->plainPassword $plainPassword;
  601.         return $this;
  602.     }
  603.     /**
  604.      * @return float
  605.      */
  606.     public function getMonthlyPayment(): ?float
  607.     {
  608.         return $this->monthlyPayment;
  609.     }
  610.     /**
  611.      * @param float $monthlyPayment
  612.      */
  613.     public function setMonthlyPayment(?float $monthlyPayment): Trainee
  614.     {
  615.         $this->monthlyPayment $monthlyPayment;
  616.         return $this;
  617.     }
  618.     /**
  619.      * @return float
  620.      */
  621.     public function getRegisterFees(): ?float
  622.     {
  623.         return $this->registerFees;
  624.     }
  625.     /**
  626.      * @param float $registerFees
  627.      */
  628.     public function setRegisterFees(?float $registerFees): Trainee
  629.     {
  630.         $this->registerFees $registerFees;
  631.         return $this;
  632.     }
  633.     /**
  634.      * @return float
  635.      */
  636.     public function getExamFees(): ?float
  637.     {
  638.         return $this->examFees;
  639.     }
  640.     /**
  641.      * @param float $examFees
  642.      */
  643.     public function setExamFees(?float $examFees): Trainee
  644.     {
  645.         $this->examFees $examFees;
  646.         return $this;
  647.     }
  648.     /**
  649.      * @return float
  650.      */
  651.     public function getDiplomaFees(): ?float
  652.     {
  653.         return $this->diplomaFees;
  654.     }
  655.     /**
  656.      * @param float $diplomaFees
  657.      */
  658.     public function setDiplomaFees(?float $diplomaFees): Trainee
  659.     {
  660.         $this->diplomaFees $diplomaFees;
  661.         return $this;
  662.     }
  663.     /**
  664.      * @return string
  665.      */
  666.     public function getFirstNameAr(): ?string
  667.     {
  668.         return $this->firstNameAr;
  669.     }
  670.     /**
  671.      * @param string $firstNameAr
  672.      */
  673.     public function setFirstNameAr(?string $firstNameAr): Trainee
  674.     {
  675.         $this->firstNameAr $firstNameAr;
  676.         return $this;
  677.     }
  678.     /**
  679.      * @return string
  680.      */
  681.     public function getLastNameAr(): ?string
  682.     {
  683.         return $this->lastNameAr;
  684.     }
  685.     /**
  686.      * @param string $lastNameAr
  687.      */
  688.     public function setLastNameAr(?string $lastNameAr): Trainee
  689.     {
  690.         $this->lastNameAr $lastNameAr;
  691.         return $this;
  692.     }
  693.     /**
  694.      * @return string
  695.      */
  696.     public function getBirthInAr(): ?string
  697.     {
  698.         return $this->birthInAr;
  699.     }
  700.     /**
  701.      * @param string $birthInAr
  702.      */
  703.     public function setBirthInAr(?string $birthInAr): Trainee
  704.     {
  705.         $this->birthInAr $birthInAr;
  706.         return $this;
  707.     }
  708.     /**
  709.      * @return string
  710.      */
  711.     public function getAddressAr(): ?string
  712.     {
  713.         return $this->addressAr;
  714.     }
  715.     /**
  716.      * @param string $addressAr
  717.      */
  718.     public function setAddressAr(?string $addressAr): Trainee
  719.     {
  720.         $this->addressAr $addressAr;
  721.         return $this;
  722.     }
  723.     /**
  724.      * @return bool
  725.      */
  726.     public function isDiscount()
  727.     {
  728.         return $this->discount;
  729.     }
  730.     /**
  731.      * @param bool $discount
  732.      * @return Trainee
  733.      */
  734.     public function setDiscount($discount)
  735.     {
  736.         $this->discount $discount;
  737.         return $this;
  738.     }
  739.     /**
  740.      * Add payment
  741.      *
  742.      *
  743.      * @return Trainee
  744.      */
  745.     public function addPayment(Fpayment $payment)
  746.     {
  747.         $payment->setTrainee($this);
  748.         $this->payments[] = $payment;
  749.         return $this;
  750.     }
  751.     /**
  752.      * Remove payment
  753.      */
  754.     public function removePayment(Fpayment $payment)
  755.     {
  756.         $this->payments->removeElement($payment);
  757.     }
  758.     /**
  759.      * Get payments
  760.      *
  761.      * @return Collection
  762.      */
  763.     public function getPayments()
  764.     {
  765.         return $this->payments;
  766.     }
  767.     /**
  768.      * Add note
  769.      *
  770.      *
  771.      * @return Trainee
  772.      */
  773.     public function addNote(Note $note)
  774.     {
  775.         $note->setTrainee($this);
  776.         $this->notes[] = $note;
  777.         return $this;
  778.     }
  779.     /**
  780.      * Remove note
  781.      */
  782.     public function removeNote(Note $note)
  783.     {
  784.         $this->notes->removeElement($note);
  785.     }
  786.     /**
  787.      * Get notes
  788.      *
  789.      * @return Collection
  790.      */
  791.     public function getNotes()
  792.     {
  793.         return $this->notes;
  794.     }
  795.     /**
  796.      * Add nsti
  797.      *
  798.      *
  799.      * @return Trainee
  800.      */
  801.     public function addNsti(Nsti $nsti)
  802.     {
  803.         $nsti->setTrainee($this);
  804.         $this->nstis[] = $nsti;
  805.         return $this;
  806.     }
  807.     /**
  808.      * Remove nsti
  809.      */
  810.     public function removeNsti(Nsti $nsti)
  811.     {
  812.         $this->nstis->removeElement($nsti);
  813.     }
  814.     /**
  815.      * Get nstis
  816.      *
  817.      * @return Collection
  818.      */
  819.     public function getNstis()
  820.     {
  821.         return $this->nstis;
  822.     }
  823.     public function getNsti(Creval $creval$jury){
  824.         /** @var Nsti $nsti */
  825.         foreach ($this->nstis as $nsti){
  826.             if($nsti->getCreval()===$creval && $nsti->getJury()===$jury) return $nsti;
  827.         }
  828.         return null;
  829.     }
  830.     public function getNstiByJury($jury){
  831.         $m=0;
  832.         $c=0;
  833.         /** @var Nsti $nsti */
  834.         foreach ($this->nstis as $nsti){
  835.             if($jury==$nsti->getJury()){
  836.                 $m+=$nsti->getVal()*$nsti->getCreval()->getCoefficient();
  837.                 $c+=$nsti->getCreval()->getCoefficient();
  838.             }
  839.         }
  840.         return ($c!=0?$m/$c:0)*4;
  841.     }
  842.     public function getMNsti(){
  843.         $m=0;
  844.         $c=0;
  845.         /** @var Nsti $nsti */
  846.         foreach ($this->nstis as $nsti){
  847.             $m+=$nsti->getVal()*$nsti->getCreval()->getCoefficient();
  848.             $c+=$nsti->getCreval()->getCoefficient();
  849.         }
  850.         return ($c!=0?$m/$c:0)*4;
  851.     }
  852.     /**
  853.      * Add fee
  854.      *
  855.      *
  856.      * @return Trainee
  857.      */
  858.     public function addFee(Fee $fee)
  859.     {
  860.         $fee->setTrainee($this);
  861.         $this->fees[] = $fee;
  862.         return $this;
  863.     }
  864.     /**
  865.      * Remove fee
  866.      */
  867.     public function removeFee(Fee $fee)
  868.     {
  869.         $this->fees->removeElement($fee);
  870.     }
  871.     /**
  872.      * Get fees
  873.      *
  874.      * @return Collection
  875.      */
  876.     public function getFees()
  877.     {
  878.         return $this->fees;
  879.     }
  880.     /**
  881.      * Add absence
  882.      *
  883.      *
  884.      * @return Trainee
  885.      */
  886.     public function addAbsence(Absence $absence)
  887.     {
  888.         $absence->setTrainee($this);
  889.         $this->absences[] = $absence;
  890.         return $this;
  891.     }
  892.     /**
  893.      * Remove absence
  894.      */
  895.     public function removeAbsence(Absence $absence)
  896.     {
  897.         $this->absences->removeElement($absence);
  898.     }
  899.     /**
  900.      * Get absences
  901.      *
  902.      * @return Collection
  903.      */
  904.     public function getAbsences()
  905.     {
  906.         return $this->absences;
  907.     }
  908.     public function getAbsencesByScheduleItemAndPeriod(Scheduleitem $scheduleitem$start$end){
  909.         $startDate =DateTime::createFromFormat('d-m-Y H:i'$start.' 00:00');
  910.         $endDate =DateTime::createFromFormat('d-m-Y H:i'$end.' 23:59');
  911.         /** @var Absence $absence */
  912.         foreach ($this->absences as $absence){
  913.             if($absence->getSeance()->getScheduleitem()===$scheduleitem && $absence->getSeance()->getTakesplaceOn() >= $startDate && $absence->getSeance()->getTakesplaceOn() <= $endDate) return $absence;
  914.         }
  915.         return null;
  916.     }
  917.     public function getAbsencesByPeriod($start$end)
  918.     {
  919.         $startDate =DateTime::createFromFormat('d-m-Y H:i'$start.' 00:00');
  920.         $endDate =DateTime::createFromFormat('d-m-Y H:i'$end.' 23:59');
  921.         $absences=[];
  922.         /** @var Absence $absence */
  923.         foreach ($this->absences as $absence){
  924.             if($absence->getSeance()->getTakesplaceOn() >= $startDate && $absence->getSeance()->getTakesplaceOn() <= $endDate && $absence->isPublished()) {
  925.                 $absences[]=$absence;
  926.             }
  927.         }
  928. //        usort($absences, function (Absence $a, Absence $b) {
  929. //            return $a->getSeance()->getTakesplaceOn() <=> $b->getSeance()->getTakesplaceOn();
  930. //        });
  931.         return $absences;
  932.     }
  933.     public function getLastAbsentSeance(): ?Seance
  934.     {
  935.         $lastAbsence null;
  936.         /** @var Absence $absence */
  937.         foreach ($this->getAbsences() as $absence) {
  938.             if (($lastAbsence === null || $absence->getSeance()->getTakesplaceOn() > $lastAbsence->getSeance()->getTakesplaceOn()) && $absence->isPublished()) {
  939.                 $lastAbsence $absence;
  940.             }
  941.         }
  942.         return $lastAbsence $lastAbsence->getSeance() : null;
  943.     }
  944.     /**
  945.      * Add schedule
  946.      *
  947.      *
  948.      * @return Trainee
  949.      */
  950.     public function getFeeByTypeNameSy($type$name$sy){
  951.         /** @var Fee $fee */
  952.         foreach ($this->fees as $fee){
  953.             if($fee->getName()==$name && $fee->getTrainingYear()==$sy && $fee->getType()==$type) return $fee;
  954.         }
  955.         return null;
  956.     }
  957.     public function getFeesTraining(){
  958.         return $this->monthlyPayment ?? $this->groupe->getTraining()->getMonthlyPayment();
  959.     }
  960.     public function getFeesRegister(){
  961.         return $this->registerFees ?? $this->groupe->getTraining()->getRegisterFees();
  962.     }
  963.     public function getFeesExam(){
  964.         return $this->examFees ?? $this->groupe->getTraining()->getExamFees();
  965.     }
  966.     public function getFeesDiploma(){
  967.         return $this->diplomaFees ?? $this->groupe->getTraining()->getDiplomaFees();
  968.     }
  969.     public function getTrainingYear(Schoolyear $schoolyear){
  970.         if($this->getGroupe()->getSchoolyear3()===$schoolyear) return '3eme Année';
  971.         elseif($this->getGroupe()->getSchoolyear2()===$schoolyear) return '2eme Année';
  972.         elseif($this->getGroupe()->getSchoolyear1()===$schoolyear) return '1ier Année';
  973.         else return '-';
  974.     }
  975.     public function monthStart($month){
  976.         // date_default_timezone_set('Africa/Casablanca');
  977.         $format 'd/m/y H:i:s';
  978.         //$month=$this->groupe->getMonth($this->groupe->getIndexMonth($month), 'number');
  979.         $date\DateTime::createFromFormat($format'1/'.$month.' 00:00:00');
  980.         if($date && $date->format('m/y')==$month) return $date;
  981.         else return \DateTime::createFromFormat($format'01/07/16 00:00:00');
  982.     }
  983.     public function monthEnd($month){
  984.         // date_default_timezone_set('Africa/Casablanca');
  985.         $format 'd/m/y H:i:s';
  986.         return \DateTime::createFromFormat($format$this->monthStart($month)->format('t/m/y').' 23:59:59');
  987.     }
  988.     public function isAbandoned(){
  989.         return $this->status=='Abandonné';
  990.     }
  991.     public function isAbandonedMonth($month){
  992.         if($this->status=='Abandonné' && $this->monthStart($month)>$this->statusAt) return true;
  993.         return false;
  994.     }
  995.     public function isAbandonedSY(Schoolyear $schoolyear){
  996.         if($this->status=='Abandonné' && $schoolyear->getStartAt()>$this->statusAt) return true;
  997.         return false;
  998.     }
  999.     public function isEncours(Schoolyear $schoolyear){
  1000.         if($this->status==='En cours' && in_array($schoolyear$this->getGroupe()->getTrainingYears()) ) return true;
  1001.         return false;
  1002.     }
  1003.     public function getMonthsPassed($format='long'){
  1004.         $items=[];
  1005.         foreach ($this->groupe->getMonthsPassed($format) as $month){
  1006.             if($this->isAbandonedMonth($month)) continue;
  1007.             $items[]=$month;
  1008.         }
  1009.         return $items;
  1010.     }
  1011.     public function getNbrMonthsPassed(){
  1012.         return is_countable($this->getMonthsPassed()) ? count($this->getMonthsPassed()) : 0;
  1013.     }
  1014.     public function getMonthsPassedByYear($year$format='long'){
  1015.         $items=[];
  1016.         foreach ($this->groupe->getMonthsPassedByYear($year'number') as $month){
  1017.             if($this->status=='Abandonné' && $this->monthStart($month)>$this->statusAt) continue;
  1018.             $items[]=$this->groupe->getMonth($this->groupe->getIndexMonth($month), $format);
  1019.         }
  1020.         return $items;
  1021.     }
  1022.     public function getNbrMonthsPassedByYear($year){
  1023.         return is_countable($this->getMonthsPassedByYear($year)) ? count($this->getMonthsPassedByYear($year)) : 0;
  1024.     }
  1025.     public function getTotalFees($type$year=null)
  1026.     {
  1027.         $mFees=0;
  1028.         if($type=='all' && $year==null){
  1029.             /** @var Fee $fee */
  1030.             foreach ($this->fees as $fee){
  1031.                 if($fee->isNotAbandoned()) $mFees+=$fee->getMontant();
  1032.             }
  1033.         }
  1034.         elseif($year==null){
  1035.             /** @var Fee $fee */
  1036.             foreach ($this->fees as $fee){
  1037.                 if($fee->getType()==$type && $fee->isNotAbandoned()) $mFees+=$fee->getMontant();
  1038.             }
  1039.         }
  1040.         elseif($type=='all'){
  1041.             /** @var Fee $fee */
  1042.             foreach ($this->fees as $fee){
  1043.                 if($fee->getTrainingYear()==$year && $fee->isNotAbandoned()) $mFees+=$fee->getMontant();
  1044.             }
  1045.         }
  1046.         else{
  1047.             /** @var Fee $fee */
  1048.             foreach ($this->fees as $fee){
  1049.                 if($fee->getType()==$type && $fee->getTrainingYear()==$year && $fee->isNotAbandoned()) $mFees+=$fee->getMontant();
  1050.             }
  1051.         }
  1052.         return $mFees;
  1053.     }
  1054.     public function getToPay($type='all'$year=null){
  1055.         $mFees=0;
  1056.         if($type=='all' && $year==null){
  1057.             /** @var Fee $fee */
  1058.             foreach ($this->fees as $fee){
  1059.                 if($fee->isCounted()) $mFees+=$fee->getMontant();
  1060.             }
  1061.         }
  1062.         elseif($year==null){
  1063.             /** @var Fee $fee */
  1064.             foreach ($this->fees as $fee){
  1065.                 if($fee->getType()==$type && $fee->isCounted()) $mFees+=$fee->getMontant();
  1066.             }
  1067.         }
  1068.         elseif($type=='all'){
  1069.             /** @var Fee $fee */
  1070.             foreach ($this->fees as $fee){
  1071.                 if($fee->getTrainingYear()==$year && $fee->isCounted()) $mFees+=$fee->getMontant();
  1072.             }
  1073.         }
  1074.         else{
  1075.             /** @var Fee $fee */
  1076.             foreach ($this->fees as $fee){
  1077.                 if($fee->getType()==$type && $fee->getTrainingYear()==$year && $fee->isCounted()) $mFees+=$fee->getMontant();
  1078.             }
  1079.         }
  1080.         return $mFees;
  1081.     }
  1082.     public function isExempt($type$year=null)
  1083.     {
  1084.         $i=0;
  1085.         $mFees=0;
  1086.         if($type=='all' && $year==null){
  1087.             /** @var Fee $fee */
  1088.             foreach ($this->fees as $fee){
  1089.                 if($fee->isCounted()) {
  1090.                     $i++;
  1091.                     $mFees+=$fee->getMontant();
  1092.                 }
  1093.             }
  1094.         }
  1095.         elseif($year==null){
  1096.             /** @var Fee $fee */
  1097.             foreach ($this->fees as $fee){
  1098.                 if($fee->getType()==$type && $fee->isCounted()) {
  1099.                     $i++;
  1100.                     $mFees+=$fee->getMontant();
  1101.                 }
  1102.             }
  1103.         }
  1104.         elseif($type=='all'){
  1105.             /** @var Fee $fee */
  1106.             foreach ($this->fees as $fee){
  1107.                 if($fee->getTrainingYear()==$year && $fee->isCounted()) {
  1108.                     $i++;
  1109.                     $mFees+=$fee->getMontant();
  1110.                 }
  1111.             }
  1112.         }
  1113.         else{
  1114.             /** @var Fee $fee */
  1115.             foreach ($this->fees as $fee){
  1116.                 if($fee->getType()==$type && $fee->getTrainingYear()==$year && $fee->isCounted()) {
  1117.                     $i++;
  1118.                     $mFees+=$fee->getMontant();
  1119.                 }
  1120.             }
  1121.         }
  1122.         return $i>&& $mFees==0;
  1123.     }
  1124.     public function getOutDate($type$year=null){
  1125.         $mFees=0;
  1126.         if($type=='all' && $year==null){
  1127.             /** @var Fee $fee */
  1128.             foreach ($this->fees as $fee){
  1129.                 if($fee->isExpired()) $mFees+=$fee->getMontant();
  1130.             }
  1131.         }
  1132.         elseif($year==null){
  1133.             /** @var Fee $fee */
  1134.             foreach ($this->fees as $fee){
  1135.                 if($fee->getType()==$type && $fee->isExpired()) $mFees+=$fee->getMontant();
  1136.             }
  1137.         }
  1138.         elseif($type=='all'){
  1139.             /** @var Fee $fee */
  1140.             foreach ($this->fees as $fee){
  1141.                 if($fee->getTrainingYear()==$year && $fee->isExpired()) $mFees+=$fee->getMontant();
  1142.             }
  1143.         }
  1144.         else{
  1145.             /** @var Fee $fee */
  1146.             foreach ($this->fees as $fee){
  1147.                 if($fee->getType()==$type && $fee->getTrainingYear()==$year && $fee->isExpired()) $mFees+=$fee->getMontant();
  1148.             }
  1149.         }
  1150.         return $mFees;
  1151.     }
  1152.     public function getToPayByYear($fees$year){
  1153.         $mFees = match ($fees) {
  1154.             'monthlyPayment' => $this->getFeesTraining()*(is_countable($this->groupe->getMonthsPassed('number')) ? count($this->groupe->getMonthsPassed('number')) : 0),
  1155.             'registerFees' => $this->getFeesRegister(),
  1156.             'examFees' => $this->getFeesExam(),
  1157.             'all' => $this->getToPay('monthlyPayment')+$this->getToPay('registerFees')+$this->getToPay('examFees')+$this->getToPay('diplomaFees'),
  1158.             default => 0,
  1159.         };
  1160.         return $mFees;
  1161.     }
  1162.     public function getTotalPay(string $fees$year null): float
  1163.     {
  1164.         $m 0.0;
  1165.         if ($fees === 'all' && $year === null) {
  1166.             /** @var Fpayment $payment */
  1167.             foreach ($this->payments as $payment) {
  1168.                 $m += (float)$payment->getAmount();
  1169.             }
  1170.         } elseif ($fees === 'all') {
  1171.             /** @var Fpayment $payment */
  1172.             foreach ($this->payments as $payment) {
  1173.                 /** @var Fpayline $item */
  1174.                 foreach ($payment->getItems() as $item) {
  1175.                     $fee $item->getFee();
  1176.                     if ($fee && $fee->getTrainingYear() == $year) {
  1177.                         $m += (float)$item->getAmount();
  1178.                     }
  1179.                 }
  1180.             }
  1181.         } elseif ($year === null) {
  1182.             /** @var Fpayment $payment */
  1183.             foreach ($this->payments as $payment) {
  1184.                 /** @var Fpayline $item */
  1185.                 foreach ($payment->getItems() as $item) {
  1186.                     $fee $item->getFee();
  1187.                     if ($fee && $fee->getType() == $fees) {
  1188.                         $m += (float)$item->getAmount();
  1189.                     }
  1190.                 }
  1191.             }
  1192.         } else {
  1193.             /** @var Fpayment $payment */
  1194.             foreach ($this->payments as $payment) {
  1195.                 /** @var Fpayline $item */
  1196.                 foreach ($payment->getItems() as $item) {
  1197.                     $fee $item->getFee();
  1198.                     if ($fee && $fee->getType() == $fees && $fee->getTrainingYear() == $year) {
  1199.                         $m += (float)$item->getAmount();
  1200.                     }
  1201.                 }
  1202.             }
  1203.         }
  1204.         return $m;
  1205.     }
  1206.     /**
  1207.      * Calcule le reste Ã  payer pour le stagiaire selon le type de frais et l'année.
  1208.      * Amélioration : typage strict, robustesse.
  1209.      */
  1210.     public function getRestPay(string $fees$year null): float
  1211.     {
  1212.         $toPay = (float)$this->getToPay($fees$year);
  1213.         $totalPay = (float)$this->getTotalPay($fees$year);
  1214.         $rest $toPay $totalPay;
  1215.         return $rest $rest 0.0;
  1216.     }
  1217.     /**
  1218.      * Calcule l'avance de paiement pour le stagiaire selon le type de frais et l'année.
  1219.      * Amélioration : typage strict, robustesse, float.
  1220.      */
  1221.     public function getAdvance(string $fees$year null): float
  1222.     {
  1223.         $toPay = (float)$this->getToPay($fees$year);
  1224.         $totalPay = (float)$this->getTotalPay($fees$year);
  1225.         $advance $totalPay $toPay;
  1226.         return $advance $advance 0.0;
  1227.     }
  1228.     public function getLatePaid($fees$year=null){
  1229.         return ($this->getOutDate($fees$year)-$this->getTotalPay($fees$year)>0)?($this->getOutDate($fees$year)-$this->getTotalPay($fees$year)):0;
  1230.     }
  1231.     public function getLateAdvance($fees$year=null){
  1232.         return ($this->getOutDate($fees$year)-$this->getTotalPay($fees$year)<0)?-($this->getOutDate($fees$year)-$this->getTotalPay($fees$year)):0;
  1233.     }
  1234.     public function getPcPay($fees$year=null){
  1235.         if($this->getToPay($fees$year)!=0)
  1236.             return round($this->getTotalPay($fees$year)/$this->getToPay($fees$year)*100,0);
  1237.         else
  1238.             return -1;
  1239.     }
  1240.     public function getToPayFeesTraining(){
  1241.         return $this->getFeesTraining()*(is_countable($this->groupe->getMonthsPassed('number')) ? count($this->groupe->getMonthsPassed('number')) : 0);
  1242.     }
  1243.     public function getBgClassFess(Fee $fee){
  1244.         if($fee->isPaied()) return 'bg-green';
  1245.         elseif ($fee->amountPaied()>0) return 'bg-light-blue';
  1246.         else return $this->groupe->getBgClass($fee->getName());
  1247.     }
  1248.     public function getBgClass($m){
  1249.         if(in_array($m,$this->getMonthsPaid('short'),true)){
  1250.             return 'bg-green';
  1251.         }
  1252.         elseif($m==$this->getMonthPaidPartially('short'))
  1253.             return  'bg-light-blue';
  1254.         else return $this->groupe->getBgClass($m);
  1255.     }
  1256. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1257. /*
  1258.  *  *        *       *      * * * * *   * * * *
  1259.  *  * *      *    *     *       *       *
  1260.  *  *   *    *   *       *      *       * * * *
  1261.  *  *     *  *    *     *       *       *
  1262.  *  *        *       *          *       * * * *
  1263.  * */
  1264.     public function getNoteVal(Noteassign $noteassign){
  1265.         /** @var Note $ligne */
  1266.         foreach ($this->getNotes() as $ligne){
  1267.             if($ligne->getNoteassign()===$noteassign) return $ligne;
  1268.         }
  1269.         return null;
  1270.     }
  1271.     public function getNoteValByName(Module $module$note){
  1272.         /** @var Note $n */
  1273.         foreach ($this->getNotes() as $n){
  1274.             if($n->getNoteassign()->getAssignation()->getModule()===$module && $n->getNoteassign()->getNotemodule()->getName()==$note) return $n->getVal();
  1275.         }
  1276.         return -1;
  1277.     }
  1278.     public function getNoteObsByName(Module $module$note){
  1279.         /** @var Note $n */
  1280.         foreach ($this->getNotes() as $n){
  1281.             if($n->getNoteassign()->getAssignation()->getModule()===$module && $n->getNoteassign()->getNotemodule()->getName()==$note) return $n->getRemarque();
  1282.         }
  1283.         return '';
  1284.     }
  1285.     public function getNoteByNoteModule(Notemodule $notemodule)
  1286.     {
  1287.         foreach ($this->getNotes() as $n){
  1288.             if($n->getNoteassign()->getNotemodule()==$notemodule) return $n;
  1289.         }
  1290.         return null;
  1291.     }
  1292.     public function getMoyenCC(Module $module){
  1293.         if($module->hasCC()){
  1294.             $sum=0;
  1295.             $nbr=1;
  1296.             /** @var Note $n */
  1297.             foreach ($this->getNotes() as $n){
  1298.                 if(
  1299.                     $n->getNoteassign()->getAssignation()->getModule()===$module &&
  1300.                     $n->getNoteassign()->getNotemodule()->getGenre()=='controle' &&
  1301.                     $n->getVal()!=null
  1302.                 )  {
  1303.                     $sum+=$n->getVal();
  1304.                     $nbr=$n->getNoteassign()->getAssignation()->getNbrControle();
  1305.                 }
  1306.             }
  1307.             if($module->getNbrCC()!=0) return $sum/$nbr;
  1308.         }
  1309.         return '';
  1310.     }
  1311.     public function getNotePratique(Module $module){
  1312.         /** @var Note $n */
  1313.         foreach ($this->getNotes() as $n){
  1314.             if($n->getNoteassign()->getAssignation()->getModule()===$module && $n->getNoteassign()->getNotemodule()->getName()=='ep')  return $n->getVal();
  1315.         }
  1316.         return 0;
  1317.     }
  1318.     public function getNotetheorique(Module $module){
  1319.         /** @var Note $n */
  1320.         foreach ($this->getNotes() as $n){
  1321.             if($n->getNoteassign()->getAssignation()->getModule()===$module && $n->getNoteassign()->getNotemodule()->getName()=='et')  return $n->getVal();
  1322.         }
  1323.         return 0;
  1324.     }
  1325.     public function getMoyen(Module $module){
  1326.         if($module->hasCC())
  1327.             return ($this->getMoyenCC($module)*3+$this->getNotePratique($module)*3+$this->getNotetheorique($module)*2)/8;
  1328.         else
  1329.             return ($this->getNotePratique($module)*3+$this->getNotetheorique($module)*2)/5;
  1330.     }
  1331.     public function getMGCC($type){
  1332.         $sumCof=0;
  1333.         $sumNote=0;
  1334.         switch ($type){
  1335.             case 'semestre1':
  1336.                 /** @var Module $module */
  1337.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1338.                     if($module->getSemester()=='Semestre 1'){
  1339.                         $sumCof+=$module->getCoefficient();
  1340.                         $sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
  1341.                     }
  1342.                 }
  1343.                 break;
  1344.             case 'semestre2':
  1345.                 /** @var Module $module */
  1346.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1347.                     if($module->getSemester()=='Semestre 2'){
  1348.                         $sumCof+=$module->getCoefficient();
  1349.                         $sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
  1350.                     }
  1351.                 }
  1352.                 break;
  1353.             case 'semestre3':
  1354.                 /** @var Module $module */
  1355.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1356.                     if($module->getSemester()=='Semestre 3'){
  1357.                         $sumCof+=$module->getCoefficient();
  1358.                         $sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
  1359.                     }
  1360.                 }
  1361.                 break;
  1362.             case 'semestre4':
  1363.                 /** @var Module $module */
  1364.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1365.                     if($module->getSemester()=='Semestre 4'){
  1366.                         $sumCof+=$module->getCoefficient();
  1367.                         $sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
  1368.                     }
  1369.                 }
  1370.                 break;
  1371.             case 'semestre5':
  1372.                 /** @var Module $module */
  1373.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1374.                     if($module->getSemester()=='Semestre 5'){
  1375.                         $sumCof+=$module->getCoefficient();
  1376.                         $sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
  1377.                     }
  1378.                 }
  1379.                 break;
  1380.             case 'semestre6':
  1381.                 /** @var Module $module */
  1382.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1383.                     if($module->getSemester()=='Semestre 6'){
  1384.                         $sumCof+=$module->getCoefficient();
  1385.                         $sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
  1386.                     }
  1387.                 }
  1388.                 break;
  1389.             case 'first_year':
  1390.                 /** @var Module $module */
  1391.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1392.                     if($module->getSemester()=='Semestre 1' || $module->getSemester()=='Semestre 2'){
  1393.                         if($module->hasCC()){
  1394.                             $sumCof+=$module->getCoefficient();
  1395.                             $sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
  1396.                         }
  1397.                     }
  1398.                 }
  1399.                 break;
  1400.             case 'second_year':
  1401.                 /** @var Module $module */
  1402.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1403.                     if($module->getSemester()=='Semestre 3' || $module->getSemester()=='Semestre 4'){
  1404.                         if($module->hasCC()){
  1405.                             $sumCof+=$module->getCoefficient();
  1406.                             $sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
  1407.                         }
  1408.                     }
  1409.                 }
  1410.                 break;
  1411.             case 'third_year':
  1412.                 /** @var Module $module */
  1413.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1414.                     if($module->getSemester()=='Semestre 5' || $module->getSemester()=='Semestre 6'){
  1415.                         if($module->hasCC()){
  1416.                             $sumCof+=$module->getCoefficient();
  1417.                             $sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
  1418.                         }
  1419.                     }
  1420.                 }
  1421.                 break;
  1422.             default:
  1423.                 if($this->getGroupe()->getTraining()->getNbrYears()==3)
  1424.                     return (round($this->getMGCC('first_year'),2)+round($this->getMGCC('second_year'),2)+round($this->getMGCC('third_year'),2))/3;
  1425.                 elseif($this->getGroupe()->getTraining()->getNbrYears()==2)
  1426.                     return (round($this->getMGCC('first_year'),2)+round($this->getMGCC('second_year'),2))/2;
  1427.                 else return $this->getMGCC('first_year');
  1428.         }
  1429.         if($sumCof!=0){
  1430.             return $sumNote/$sumCof;
  1431.         }
  1432.         return 0;
  1433.     }
  1434.     public function getMGPratique($type){
  1435.         $sumCof=0;
  1436.         $sumNote=0;
  1437.         switch ($type){
  1438.             case 'semestre1':
  1439.                 /** @var Module $module */
  1440.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1441.                     if($module->getSemester()=='Semestre 1'){
  1442.                         $sumCof+=$module->getCoefficient();
  1443.                         $sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
  1444.                     }
  1445.                 }
  1446.                 break;
  1447.             case 'semestre2':
  1448.                 /** @var Module $module */
  1449.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1450.                     if($module->getSemester()=='Semestre 2'){
  1451.                         $sumCof+=$module->getCoefficient();
  1452.                         $sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
  1453.                     }
  1454.                 }
  1455.                 break;
  1456.             case 'semestre3':
  1457.                 /** @var Module $module */
  1458.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1459.                     if($module->getSemester()=='Semestre 3'){
  1460.                         $sumCof+=$module->getCoefficient();
  1461.                         $sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
  1462.                     }
  1463.                 }
  1464.                 break;
  1465.             case 'semestre4':
  1466.                 /** @var Module $module */
  1467.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1468.                     if($module->getSemester()=='Semestre 4'){
  1469.                         $sumCof+=$module->getCoefficient();
  1470.                         $sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
  1471.                     }
  1472.                 }
  1473.                 break;
  1474.             case 'semestre5':
  1475.                 /** @var Module $module */
  1476.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1477.                     if($module->getSemester()=='Semestre 5'){
  1478.                         $sumCof+=$module->getCoefficient();
  1479.                         $sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
  1480.                     }
  1481.                 }
  1482.                 break;
  1483.             case 'semestre6':
  1484.                 /** @var Module $module */
  1485.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1486.                     if($module->getSemester()=='Semestre 6'){
  1487.                         $sumCof+=$module->getCoefficient();
  1488.                         $sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
  1489.                     }
  1490.                 }
  1491.                 break;
  1492.             case 'first_year':
  1493.                 /** @var Module $module */
  1494.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1495.                     if($module->getSemester()=='Semestre 1' || $module->getSemester()=='Semestre 2'){
  1496.                         $sumCof+=$module->getCoefficient();
  1497.                         $sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
  1498.                     }
  1499.                 }
  1500.                 break;
  1501.             case 'second_year':
  1502.                 /** @var Module $module */
  1503.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1504.                     if($module->getSemester()=='Semestre 3' || $module->getSemester()=='Semestre 4'){
  1505.                         $sumCof+=$module->getCoefficient();
  1506.                         $sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
  1507.                     }
  1508.                 }
  1509.                 break;
  1510.             case 'third_year':
  1511.                 /** @var Module $module */
  1512.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1513.                     if($module->getSemester()=='Semestre 5' || $module->getSemester()=='Semestre 6'){
  1514.                         $sumCof+=$module->getCoefficient();
  1515.                         $sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
  1516.                     }
  1517.                 }
  1518.                 break;
  1519.             default:
  1520.                 if($this->getGroupe()->getTraining()->getNbrYears()==3)
  1521.                     return (round($this->getMGPratique('first_year'),2)+round($this->getMGPratique('second_year'),2)+round($this->getMGPratique('third_year'),2))/3;
  1522.                 elseif($this->getGroupe()->getTraining()->getNbrYears()==2)
  1523.                     return (round($this->getMGPratique('first_year'),2)+round($this->getMGPratique('second_year'),2))/2;
  1524.                 else return $this->getMGPratique('first_year');
  1525.         }
  1526.         if($sumCof!=0){
  1527.             return $sumNote/$sumCof;
  1528.         }
  1529.         return 0;
  1530.     }
  1531.     public function getMGTheorique($type){
  1532.         $sumCof=0;
  1533.         $sumNote=0;
  1534.         switch ($type){
  1535.             case 'semestre1':
  1536.                 /** @var Module $module */
  1537.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1538.                     if($module->getSemester()=='Semestre 1'){
  1539.                         $sumCof+=$module->getCoefficient();
  1540.                         $sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
  1541.                     }
  1542.                 }
  1543.                 break;
  1544.             case 'semestre2':
  1545.                 /** @var Module $module */
  1546.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1547.                     if($module->getSemester()=='Semestre 2'){
  1548.                         $sumCof+=$module->getCoefficient();
  1549.                         $sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
  1550.                     }
  1551.                 }
  1552.                 break;
  1553.             case 'semestre3':
  1554.                 /** @var Module $module */
  1555.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1556.                     if($module->getSemester()=='Semestre 3'){
  1557.                         $sumCof+=$module->getCoefficient();
  1558.                         $sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
  1559.                     }
  1560.                 }
  1561.                 break;
  1562.             case 'semestre4':
  1563.                 /** @var Module $module */
  1564.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1565.                     if($module->getSemester()=='Semestre 4'){
  1566.                         $sumCof+=$module->getCoefficient();
  1567.                         $sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
  1568.                     }
  1569.                 }
  1570.                 break;
  1571.             case 'semestre5':
  1572.                 /** @var Module $module */
  1573.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1574.                     if($module->getSemester()=='Semestre 5'){
  1575.                         $sumCof+=$module->getCoefficient();
  1576.                         $sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
  1577.                     }
  1578.                 }
  1579.                 break;
  1580.             case 'semestre6':
  1581.                 /** @var Module $module */
  1582.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1583.                     if($module->getSemester()=='Semestre 6'){
  1584.                         $sumCof+=$module->getCoefficient();
  1585.                         $sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
  1586.                     }
  1587.                 }
  1588.                 break;
  1589.             case 'first_year':
  1590.                 /** @var Module $module */
  1591.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1592.                     if($module->getSemester()=='Semestre 1' || $module->getSemester()=='Semestre 2'){
  1593.                         $sumCof+=$module->getCoefficient();
  1594.                         $sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
  1595.                     }
  1596.                 }
  1597.                 break;
  1598.             case 'second_year':
  1599.                 /** @var Module $module */
  1600.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1601.                     if($module->getSemester()=='Semestre 3' || $module->getSemester()=='Semestre 4'){
  1602.                         $sumCof+=$module->getCoefficient();
  1603.                         $sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
  1604.                     }
  1605.                 }
  1606.                 break;
  1607.             case 'third_year':
  1608.                 /** @var Module $module */
  1609.                 foreach ($this->getGroupe()->getTraining()->getModules() as $module){
  1610.                     if($module->getSemester()=='Semestre 5' || $module->getSemester()=='Semestre 6'){
  1611.                         $sumCof+=$module->getCoefficient();
  1612.                         $sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
  1613.                     }
  1614.                 }
  1615.                 break;
  1616.             default:
  1617.                 if($this->getGroupe()->getTraining()->getNbrYears()==3)
  1618.                     return (round($this->getMGTheorique('first_year'),2)+round($this->getMGTheorique('second_year'),2)+round($this->getMGTheorique('third_year'),2))/3;
  1619.                 elseif($this->getGroupe()->getTraining()->getNbrYears()==2)
  1620.                     return (round($this->getMGTheorique('first_year'),2)+round($this->getMGTheorique('second_year'),2))/2;
  1621.                 else return $this->getMGTheorique('first_year');
  1622.         }
  1623.         if($sumCof!=0){
  1624.             return $sumNote/$sumCof;
  1625.         }
  1626.         return 0;
  1627.     }
  1628.     public function getMG($type){
  1629.         return ($this->getMGCC($type)*3+$this->getMGPratique($type)*3+$this->getMGTheorique($type)*2)/8;
  1630.     }
  1631.     public function getJuryDecisionPassage($type){
  1632.         if($this->getMG($type)<8.5) return 'Redoublant';
  1633.         elseif ($this->getMG($type)<10) return 'Admis par Rachtage';
  1634.         else return 'Admis';
  1635.     }
  1636.     public function getClassement($note){
  1637.         $i=1;
  1638.         /** @var Trainee $trainee */
  1639.         foreach ($this->getGroupe()->getTraineesSorted($note) as $trainee){
  1640.             if($trainee===$this) return $i;
  1641.             $i++;
  1642.         }
  1643.     }
  1644.     public function getMoyenneGeneral(){
  1645.         return (
  1646.                 $this->getMGCC('training')*3
  1647.                 +
  1648.                 $this->getMGPratique('training')*3
  1649.                 +
  1650.                 $this->getMGTheorique('training')*2
  1651.                 +
  1652.                 $this->getMNsti()*2
  1653.             )/10;
  1654.     }
  1655.     public function __toString(): string
  1656.     {
  1657.         return $this->getLastName().' '.$this->getFirstName();
  1658.     }
  1659.     public function getRegistrationAt(): DateTime
  1660.     {
  1661.         return $this->registrationAt;
  1662.     }
  1663.     public function setRegistrationAt(DateTime $registrationAt): Trainee
  1664.     {
  1665.         $this->registrationAt $registrationAt;
  1666.         return $this;
  1667.     }
  1668.     public function createAvatar(ParameterBagInterface $parameterBag)
  1669.     {
  1670.         $thumbWidth 70;
  1671.         $sourceImagePath $parameterBag->get('kernel.project_dir') . '/public/images/trainee/';
  1672.         $sourceImage imagecreatefromjpeg($sourceImagePath.$this->imageName);
  1673.         $destImagePath $sourceImagePath 'thumbs/'.$this->imageName;
  1674.         $orgWidth imagesx($sourceImage);
  1675.         $orgHeight imagesy($sourceImage);
  1676.         $thumbHeight floor($orgHeight * ($thumbWidth $orgWidth));
  1677.         $destImage imagecreatetruecolor($thumbWidth$thumbHeight);
  1678.         imagecopyresampled($destImage$sourceImage0000$thumbWidth$thumbHeight$orgWidth$orgHeight);
  1679.         imagejpeg($destImage$destImagePath);
  1680.         imagedestroy($sourceImage);
  1681.         imagedestroy($destImage);
  1682.     }
  1683. }