src/Entity/Formation/Participant.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Formation;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\Formation\ParticipantRepository;
  5. use App\Traits\Actions;
  6. use App\Entity\User;
  7. use DateTime;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  12. use Symfony\Component\HttpFoundation\File\UploadedFile;
  13. #[ORM\Entity(repositoryClassParticipantRepository::class)]
  14. #[ORM\Table(name'hs_tc_formation_participant')]
  15. #[ApiResource]
  16. class Participant implements \Stringable
  17. {
  18.     use Actions;
  19.     final public const SERVER_PATH_TO_IMAGE_FOLDER 'uploads/images/participant';
  20.     #[ORM\OneToOne(inversedBy"participant"targetEntityUser::class, cascade: ["persist"])]
  21.     #[ORM\JoinColumn(nullabletrue)]
  22.     private ?User $user null;
  23.     #[ORM\ManyToOne(targetEntity"Classe"inversedBy"participants")]
  24.     #[ORM\JoinColumn(nullabletrue)]
  25.     private ?Classe $classe null;
  26.     #[ORM\Column(name"first_name"type"string"length255)]
  27.     private $firstName;
  28.     #[ORM\Column(name"last_name"type"string"length255)]
  29.     private $lastName;
  30.     #[ORM\Column(name"first_name_ar"type"string"length255nullabletrue)]
  31.     private ?string $firstNameAr null;
  32.     #[ORM\Column(name"last_name_ar"type"string"length255nullabletrue)]
  33.     private ?string $lastNameAr null;
  34.     #[ORM\Column(name"cin"type"string"length255nullabletrue)]
  35.     private $cin;
  36.     #[ORM\Column(name"gender"type"string"length255nullabletrue)]
  37.     private $gender;
  38.     #[ORM\Column(name"birth_in"type"string"length255nullabletrue)]
  39.     private $birthIn;
  40.     #[ORM\Column(name"birth_in_ar"type"string"length255nullabletrue)]
  41.     private ?string $birthInAr null;
  42.     #[ORM\Column(name"birth_at"type"datetime"nullabletrue)]
  43.     private $birthAt;
  44.     #[ORM\Column(name"nationality"type"string"length255nullabletrue)]
  45.     private string $nationality "Marocaine";
  46.     #[ORM\Column(name"phone"type"string"length255nullabletrue)]
  47.     private $phone;
  48.     #[ORM\Column(name"phone2"type"string"length255nullabletrue)]
  49.     private $phone2;
  50.     #[ORM\Column(name'wp'type'string'length255nullabletrue)]
  51.     private ?string $wp null;
  52.     #[ORM\Column(name"email"type"string"length255nullabletrue)]
  53.     private $email;
  54.     #[ORM\Column(name"address"type"string"length255nullabletrue)]
  55.     private $address;
  56.     #[ORM\Column(name"address_ar"type"string"length255nullabletrue)]
  57.     private ?string $addressAr null;
  58.     #[ORM\Column(name"city"type"string"length255nullabletrue)]
  59.     private $city;
  60.     #[ORM\Column(name"school_level"type"string"length255nullabletrue)]
  61.     private $schoolLevel;
  62.     #[ORM\Column(name"school_last"type"string"length255nullabletrue)]
  63.     private $schoolLast;
  64.     #[ORM\Column(name"registration_number"type"string"length255nullabletrue)]
  65.     private $regNumber;
  66.     #[ORM\Column(name"serie_number"type"string"length255nullabletrue)]
  67.     private ?string $serieNumber null;
  68.     #[ORM\Column(name"id_massar"type"string"length255nullabletrue)]
  69.     private ?string $idMassar null;
  70.     #[ORM\Column(name"diplome_number"type"string"length255nullabletrue)]
  71.     private ?string $diplomeNumber null;
  72.     #[ORM\Column(name:"registration_at"type:"datetime"nullable:true)]
  73.     private \DateTime $registrationAt;
  74.     #[ORM\Column(name"status"type"string"length255nullabletrue)]
  75.     private $status;
  76.     #[ORM\Column(name"status_at"type"datetime"nullabletrue)]
  77.     private ?\DateTime $statusAt null;
  78.     #[ORM\Column(name"image_name"type"string"length255nullabletrue)]
  79.     protected $imageName 'photo.jpg';
  80.     protected $imageFile;
  81.     #[ORM\Column(name"cin_image"type"string"length255nullabletrue)]
  82.     protected $cinImage 'cin.png';
  83.     protected $cinImageFile;
  84.     #[ORM\Column(name"school_level_image"type"string"length255nullabletrue)]
  85.     protected $schoolLevelImage 'attestation.png';
  86.     protected $schoolLevelImageFile;
  87.     #[ORM\Column(name"monthly_payment"type"float"nullabletrue)]
  88.     private ?float $monthlyPayment null;
  89.     #[ORM\Column(name"register_costs"type"float"nullabletrue)]
  90.     private ?float $registerCosts null;
  91.     #[ORM\Column(name"other_costs"type"string"nullabletrue)]
  92.     private ?string $otherCosts null;
  93.     #[ORM\Column(name"diploma_costs"type"float"nullabletrue)]
  94.     private ?float $diplomaCosts null;
  95.     #[ORM\Column(name"discount"type"boolean")]
  96.     private $discount;
  97.     #[ORM\OneToMany(mappedBy"participant"targetEntityApayment::class)]
  98.     #[ORM\OrderBy(["createAt" => "ASC"])]
  99.     private ?Collection $payments null;
  100.     #[ORM\OneToMany(mappedBy"participant"targetEntity"Cost"cascade: ["persist"], orphanRemovaltrue)]
  101.     #[ORM\OrderBy(["datePaie" => "ASC"])]
  102.     private ?Collection $costs null;
  103.     #[ORM\OneToMany(mappedBy"participant"targetEntityAabsence::class, cascade: ["persist"], orphanRemovaltrue)]
  104.     private ?Collection $aabsences null;
  105.     #[ORM\Column(length255nullabletrue)]
  106.     private ?string $plainPassword null;
  107.     #[ORM\Column(name"training_duration"type"string"length255nullabletrue)]
  108.     private ?string $trainingDuration null;
  109.     public function __construct()
  110.     {
  111.         // date_default_timezone_set('Africa/Casablanca');
  112.         $this->createAt=new \DateTime('now');
  113.         $this->registrationAt=new \DateTime('now');
  114.         $this->published=true;
  115.         $this->payments=new ArrayCollection();
  116.         $this->discount=false;
  117.         $this->wp="212";
  118.     }
  119.     /**
  120.      * Set user
  121.      *
  122.      *
  123.      * @return Participant
  124.      */
  125.     public function setUser(User $user)
  126.     {
  127.         $this->user $user;
  128.         return $this;
  129.     }
  130.     /**
  131.      * Get user
  132.      *
  133.      * @return User
  134.      */
  135.     public function getUser()
  136.     {
  137.         return $this->user;
  138.     }
  139.     /**
  140.      * Set classe
  141.      *
  142.      *
  143.      * @return Participant
  144.      */
  145.     public function setClasse(Classe $classe)
  146.     {
  147.         $this->classe $classe;
  148.         return $this;
  149.     }
  150.     /**
  151.      * Get classe
  152.      *
  153.      * @return Classe
  154.      */
  155.     public function getClasse()
  156.     {
  157.         return $this->classe;
  158.     }
  159.     /**
  160.      * @return string
  161.      */
  162.     public function getFirstName()
  163.     {
  164.         return $this->firstName;
  165.     }
  166.     /**
  167.      * @param string $firstName
  168.      * @return Participant
  169.      */
  170.     public function setFirstName($firstName)
  171.     {
  172.         $this->firstName $firstName;
  173.         return $this;
  174.     }
  175.     /**
  176.      * @return string
  177.      */
  178.     public function getLastName()
  179.     {
  180.         return $this->lastName;
  181.     }
  182.     /**
  183.      * @param string $lastName
  184.      * @return Participant
  185.      */
  186.     public function setLastName($lastName)
  187.     {
  188.         $this->lastName $lastName;
  189.         return $this;
  190.     }
  191.     /**
  192.      * @return \DateTime
  193.      */
  194.     public function getBirthAt()
  195.     {
  196.         return $this->birthAt;
  197.     }
  198.     /**
  199.      * @param \DateTime $birthAt
  200.      * @return Participant
  201.      */
  202.     public function setBirthAt($birthAt)
  203.     {
  204.         $this->birthAt $birthAt;
  205.         return $this;
  206.     }
  207.     /**
  208.      * @return string
  209.      */
  210.     public function getPhone()
  211.     {
  212.         return $this->phone;
  213.     }
  214.     /**
  215.      * @param string $phone
  216.      * @return Participant
  217.      */
  218.     public function setPhone($phone)
  219.     {
  220.         $this->phone $phone;
  221.         return $this;
  222.     }
  223.     public function getWp(): ?string
  224.     {
  225.         return $this->wp;
  226.     }
  227.     public function setWp(?string $wp): void
  228.     {
  229.         $this->wp $wp;
  230.     }
  231.     /**
  232.      * @return string
  233.      */
  234.     public function getPhone2()
  235.     {
  236.         return $this->phone2;
  237.     }
  238.     /**
  239.      * @param string $phone2
  240.      * @return Participant
  241.      */
  242.     public function setPhone2($phone2)
  243.     {
  244.         $this->phone2 $phone2;
  245.         return $this;
  246.     }
  247.     /**
  248.      * @return string
  249.      */
  250.     public function getEmail()
  251.     {
  252.         return $this->email;
  253.     }
  254.     /**
  255.      * @param string $email
  256.      * @return Participant
  257.      */
  258.     public function setEmail($email)
  259.     {
  260.         $this->email $email;
  261.         return $this;
  262.     }
  263.     /**
  264.      * @return string
  265.      */
  266.     public function getAddress()
  267.     {
  268.         return $this->address;
  269.     }
  270.     /**
  271.      * @param string $address
  272.      * @return Participant
  273.      */
  274.     public function setAddress($address)
  275.     {
  276.         $this->address $address;
  277.         return $this;
  278.     }
  279.     /**
  280.      * @return string
  281.      */
  282.     public function getCity()
  283.     {
  284.         return $this->city;
  285.     }
  286.     /**
  287.      * @param string $city
  288.      * @return Participant
  289.      */
  290.     public function setCity($city)
  291.     {
  292.         $this->city $city;
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return string
  297.      */
  298.     public function getSchoolLevel()
  299.     {
  300.         return $this->schoolLevel;
  301.     }
  302.     /**
  303.      * @param string $schoolLevel
  304.      * @return Participant
  305.      */
  306.     public function setSchoolLevel($schoolLevel)
  307.     {
  308.         $this->schoolLevel $schoolLevel;
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return string
  313.      */
  314.     public function getCin()
  315.     {
  316.         return $this->cin;
  317.     }
  318.     /**
  319.      * @param string $cin
  320.      * @return Participant
  321.      */
  322.     public function setCin($cin)
  323.     {
  324.         $this->cin $cin;
  325.         return $this;
  326.     }
  327.     /**
  328.      * @return string
  329.      */
  330.     public function getGender()
  331.     {
  332.         return $this->gender;
  333.     }
  334.     /**
  335.      * @param string $gender
  336.      * @return Participant
  337.      */
  338.     public function setGender($gender)
  339.     {
  340.         $this->gender $gender;
  341.         return $this;
  342.     }
  343.     /**
  344.      * @return string
  345.      */
  346.     public function getBirthIn()
  347.     {
  348.         return $this->birthIn;
  349.     }
  350.     /**
  351.      * @param string $birthIn
  352.      * @return Participant
  353.      */
  354.     public function setBirthIn($birthIn)
  355.     {
  356.         $this->birthIn $birthIn;
  357.         return $this;
  358.     }
  359.     /**
  360.      * @return string
  361.      */
  362.     public function getNationality()
  363.     {
  364.         return $this->nationality;
  365.     }
  366.     /**
  367.      * @param string $nationality
  368.      * @return Participant
  369.      */
  370.     public function setNationality($nationality)
  371.     {
  372.         $this->nationality $nationality;
  373.         return $this;
  374.     }
  375.     /**
  376.      * @return string
  377.      */
  378.     public function getSchoolLast()
  379.     {
  380.         return $this->schoolLast;
  381.     }
  382.     /**
  383.      * @param string $schoolLast
  384.      * @return Participant
  385.      */
  386.     public function setSchoolLast($schoolLast)
  387.     {
  388.         $this->schoolLast $schoolLast;
  389.         return $this;
  390.     }
  391.     /**
  392.      * @return string
  393.      */
  394.     public function getRegNumber()
  395.     {
  396.         return $this->regNumber;
  397.     }
  398.     /**
  399.      * @param string $regNumber
  400.      * @return Participant
  401.      */
  402.     public function setRegNumber($regNumber)
  403.     {
  404.         $this->regNumber $regNumber;
  405.         return $this;
  406.     }
  407.     /**
  408.      * @return string
  409.      */
  410.     public function getSerieNumber(): ?string
  411.     {
  412.         return $this->serieNumber;
  413.     }
  414.     /**
  415.      * @param string $serieNumber
  416.      */
  417.     public function setSerieNumber(?string $serieNumber): Participant
  418.     {
  419.         $this->serieNumber $serieNumber;
  420.         return $this;
  421.     }
  422.     /**
  423.      * @return string
  424.      */
  425.     public function getDiplomeNumber(): ?string
  426.     {
  427.         return $this->diplomeNumber;
  428.     }
  429.     /**
  430.      * @param string $diplomeNumber
  431.      */
  432.     public function setDiplomeNumber(?string $diplomeNumber): Participant
  433.     {
  434.         $this->diplomeNumber $diplomeNumber;
  435.         return $this;
  436.     }
  437.     /**
  438.      * @return string
  439.      */
  440.     public function getIdMassar(): ?string
  441.     {
  442.         return $this->idMassar;
  443.     }
  444.     /**
  445.      * @param string $idMassar
  446.      */
  447.     public function setIdMassar(?string $idMassar): Participant
  448.     {
  449.         $this->idMassar $idMassar;
  450.         return $this;
  451.     }
  452.     /**
  453.      * @return string
  454.      */
  455.     public function getStatus()
  456.     {
  457.         return $this->status;
  458.     }
  459.     /**
  460.      * @param string $status
  461.      * @return Participant
  462.      */
  463.     public function setStatus($status)
  464.     {
  465.         $this->status $status;
  466.         // date_default_timezone_set('Africa/Casablanca');
  467.         $this->statusAt=new \DateTime('now');
  468.         return $this;
  469.     }
  470.     /**
  471.      * @return \DateTime
  472.      */
  473.     public function getStatusAt()
  474.     {
  475.         return $this->statusAt;
  476.     }
  477.     /**
  478.      * @param \DateTime $statusAt
  479.      * @return Participant
  480.      */
  481.     public function setStatusAt($statusAt)
  482.     {
  483.         $this->statusAt $statusAt;
  484.         return $this;
  485.     }
  486.     public function getTrainingDuration(): ?string
  487.     {
  488.         return $this->trainingDuration;
  489.     }
  490.     public function setTrainingDuration(?string $trainingDuration): void
  491.     {
  492.         $this->trainingDuration $trainingDuration;
  493.     }
  494.     /**
  495.      * @return string
  496.      */
  497.     public function getCinImage()
  498.     {
  499.         return $this->cinImage;
  500.     }
  501.     /**
  502.      * @param string $cinImage
  503.      * @return Participant
  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 Participant
  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 Participant
  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 Participant
  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 Participant
  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 Participant
  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): Participant
  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): Participant
  614.     {
  615.         $this->monthlyPayment $monthlyPayment;
  616.         return $this;
  617.     }
  618.     /**
  619.      * @return float
  620.      */
  621.     public function getRegisterCosts(): ?float
  622.     {
  623.         return $this->registerCosts;
  624.     }
  625.     /**
  626.      * @param float $registerCosts
  627.      */
  628.     public function setRegisterCosts(?float $registerCosts): Participant
  629.     {
  630.         $this->registerCosts $registerCosts;
  631.         return $this;
  632.     }
  633.     /**
  634.      * @return string
  635.      */
  636.     public function getOtherCosts(): ?string
  637.     {
  638.         return $this->otherCosts;
  639.     }
  640.     /**
  641.      * @param string $otherCosts
  642.      */
  643.     public function setOtherCosts(?string $otherCosts): Participant
  644.     {
  645.         $this->otherCosts $otherCosts;
  646.         return $this;
  647.     }
  648.     /**
  649.      * @return float
  650.      */
  651.     public function getDiplomaCosts(): ?float
  652.     {
  653.         return $this->diplomaCosts;
  654.     }
  655.     /**
  656.      * @param float $diplomaCosts
  657.      */
  658.     public function setDiplomaCosts(?float $diplomaCosts): Participant
  659.     {
  660.         $this->diplomaCosts $diplomaCosts;
  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): Participant
  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): Participant
  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): Participant
  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): Participant
  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 Participant
  733.      */
  734.     public function setDiscount($discount)
  735.     {
  736.         $this->discount $discount;
  737.         return $this;
  738.     }
  739.     /**
  740.      * Add payment
  741.      *
  742.      *
  743.      * @return Participant
  744.      */
  745.     public function addPayment(Apayment $payment)
  746.     {
  747.         $payment->setParticipant($this);
  748.         $this->payments[] = $payment;
  749.         return $this;
  750.     }
  751.     /**
  752.      * Remove payment
  753.      */
  754.     public function removePayment(Apayment $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.     public function addCost(Cost $cost)
  768.     {
  769.         $cost->setParticipant($this);
  770.         $this->costs[] = $cost;
  771.         return $this;
  772.     }
  773.     /**
  774.      * Remove cost
  775.      */
  776.     public function removeCost(Cost $cost)
  777.     {
  778.         $this->costs->removeElement($cost);
  779.     }
  780.     /**
  781.      * Get costs
  782.      *
  783.      * @return Collection
  784.      */
  785.     public function getCosts()
  786.     {
  787.         return $this->costs;
  788.     }
  789.     /**
  790.      * Add aabsence
  791.      *
  792.      *
  793.      * @return Participant
  794.      */
  795.     public function addAabsence(Aabsence $aabsence)
  796.     {
  797.         $aabsence->setParticipant($this);
  798.         $this->aabsences[] = $aabsence;
  799.         return $this;
  800.     }
  801.     /**
  802.      * Remove aabsence
  803.      */
  804.     public function removeAabsence(Aabsence $aabsence)
  805.     {
  806.         $this->aabsences->removeElement($aabsence);
  807.     }
  808.     /**
  809.      * Get aabsences
  810.      *
  811.      * @return Collection
  812.      */
  813.     public function getAabsences()
  814.     {
  815.         return $this->aabsences;
  816.     }
  817.     public function getAabsencesByTimetableItemAndPeriod(Timetableitem $timetableitem$start$end){
  818.         $startDate =DateTime::createFromFormat('d-m-Y H:i'$start.' 00:00');
  819.         $endDate =DateTime::createFromFormat('d-m-Y H:i'$end.' 23:59');
  820.         /** @var Aabsence $aabsence */
  821.         foreach ($this->aabsences as $aabsence){
  822.             if($aabsence->getAseance()->getTimetableitem()===$timetableitem && $aabsence->getAseance()->getTakesplaceOn() >= $startDate && $aabsence->getAseance()->getTakesplaceOn() <= $endDate) return $aabsence;
  823.         }
  824.         return null;
  825.     }
  826.     public function getAbsencesByPeriod($start$end)
  827.     {
  828.         $startDate =DateTime::createFromFormat('d-m-Y H:i'$start.' 00:00');
  829.         $endDate =DateTime::createFromFormat('d-m-Y H:i'$end.' 23:59');
  830.         $absences=[];
  831.         /** @var Aabsence $absence */
  832.         foreach ($this->aabsences as $absence){
  833.             if($absence->getAseance()->getTakesplaceOn() >= $startDate && $absence->getAseance()->getTakesplaceOn() <= $endDate && $absence->isPublished()) {
  834.                 $absences[]=$absence;
  835.             }
  836.         }
  837. //        usort($absences, function (Absence $a, Absence $b) {
  838. //            return $a->getSeance()->getTakesplaceOn() <=> $b->getSeance()->getTakesplaceOn();
  839. //        });
  840.         return $absences;
  841.     }
  842.     public function getLastAbsentSeance(): ?Aseance
  843.     {
  844.         $lastAbsence null;
  845.         /** @var Aabsence $absence */
  846.         foreach ($this->getAabsences() as $absence) {
  847.             if (($lastAbsence === null || $absence->getAseance()->getTakesplaceOn() > $lastAbsence->getAseance()->getTakesplaceOn()) && $absence->isPublished()) {
  848.                 $lastAbsence $absence;
  849.             }
  850.         }
  851.         return $lastAbsence $lastAbsence->getAseance() : null;
  852.     }
  853.     public function monthStart($month){
  854.         // date_default_timezone_set('Africa/Casablanca');
  855.         $format 'd/m/y H:i:s';
  856.         $date\DateTime::createFromFormat($format'1/'.$month.' 00:00:00');
  857.         if($date && $date->format('m/y')==$month) return $date;
  858.         else return \DateTime::createFromFormat($format'01/07/16 00:00:00');
  859.     }
  860.     public function monthEnd($month){
  861.         // date_default_timezone_set('Africa/Casablanca');
  862.         $format 'd/m/y H:i:s';
  863.         return \DateTime::createFromFormat($format$this->monthStart($month)->format('t/m/y').' 23:59:59');
  864.     }
  865.     public function isAbandonedMonth($month){
  866.         if($this->status=='AbandonnĂ©' && $this->monthStart($month)>$this->statusAt) return true;
  867.         return false;
  868.     }
  869.     public function getCostByTypeName($type$name){
  870.         /** @var Cost $cost */
  871.         foreach ($this->costs as $cost){
  872.             if($cost->getName()==$name && $cost->getType()==$type) return $cost;
  873.         }
  874.         return null;
  875.     }
  876.     public function getCostsTraining(){
  877.         return $this->monthlyPayment ?? $this->classe->getMonthlyPayment();
  878.     }
  879.     public function getCostsRegister(){
  880.         return $this->registerCosts ?? $this->classe->getRegisterCosts();
  881.     }
  882.     public function getCostsByType($type)
  883.     {
  884.         $costs=[];
  885.         foreach ($this->costs as $cost){
  886.             if($cost->getType()==$type){
  887.                 $costs[]=$cost;
  888.             }
  889.         }
  890.         return $costs;
  891.     }
  892.     public function getToPay($type){
  893.         $mCosts=0;
  894.         if($type=='all'){
  895.             /** @var Cost $cost */
  896.             foreach ($this->costs as $cost){
  897.                 if($cost->isCounted()) $mCosts+=$cost->getMontant();
  898.             }
  899.         }
  900.         else{
  901.             /** @var Cost $cost */
  902.             foreach ($this->costs as $cost){
  903.                 if($cost->getType()==$type && $cost->isCounted()) $mCosts+=$cost->getMontant();
  904.             }
  905.         }
  906.         return $mCosts;
  907.     }
  908.     public function getOutDate($type$year=null){
  909.         $mCosts=0;
  910.         if($type=='all' && $year==null){
  911.             /** @var Cost $cost */
  912.             foreach ($this->costs as $cost){
  913.                 if($cost->isExpired()) $mCosts+=$cost->getMontant();
  914.             }
  915.         }
  916.         elseif($year==null){
  917.             /** @var Cost $cost */
  918.             foreach ($this->costs as $cost){
  919.                 if($cost->getType()==$type && $cost->isExpired()) $mCosts+=$cost->getMontant();
  920.             }
  921.         }
  922.         elseif($type=='all'){
  923.             /** @var Cost $cost */
  924.             foreach ($this->costs as $cost){
  925.                 if($cost->getActivityYear()==$year && $cost->isExpired()) $mCosts+=$cost->getMontant();
  926.             }
  927.         }
  928.         else{
  929.             /** @var Cost $cost */
  930.             foreach ($this->costs as $cost){
  931.                 if($cost->getType()==$type && $cost->getActivityYear()==$year && $cost->isExpired()) $mCosts+=$cost->getMontant();
  932.             }
  933.         }
  934.         return $mCosts;
  935.     }
  936.     public function getTotalPay($costs){
  937.         $m=0;
  938.         if($costs=='all'){
  939.             /** @var Apayment $payment */
  940.             foreach ($this->payments as $payment){
  941.                 /** @var Apayline $item */
  942.                 foreach ($payment->getItems() as $item){
  943.                     $m+=$item->getAmount();
  944.                 }
  945.             }
  946.         }
  947.         elseif ($costs!=="registerCosts" && $costs!=="monthlyPayment"){
  948.             /** @var Apayment $payment */
  949.             foreach ($this->payments as $payment){
  950.                 /** @var Apayline $item */
  951.                 foreach ($payment->getItems() as $item){
  952.                     if($item->getCost()->getName()==$costs$m+=$item->getAmount();
  953.                 }
  954.             }
  955.         }
  956.         else{
  957.             /** @var Apayment $payment */
  958.             foreach ($this->payments as $payment){
  959.                 /** @var Apayline $item */
  960.                 foreach ($payment->getItems() as $item){
  961.                     if($item->getCost()->getType()==$costs$m+=$item->getAmount();
  962.                 }
  963.             }
  964.         }
  965.         return $m;
  966.     }
  967.     public function getRestPay($costs){
  968.         return ($this->getToPay($costs)-$this->getTotalPay($costs)>0)?($this->getToPay($costs)-$this->getTotalPay($costs)):0;
  969.     }
  970.     public function getAdvance($costs){
  971.         return ($this->getToPay($costs)-$this->getTotalPay($costs)<0)?-($this->getToPay($costs)-$this->getTotalPay($costs)):0;
  972.     }
  973.     public function getPayByMonth($month)
  974.     {
  975.     }
  976.     public function getPcPay($costs){
  977.         if($this->getToPay($costs)!=0)
  978.             return round($this->getTotalPay($costs)/$this->getToPay($costs)*100,0);
  979.         else
  980.             return -1;
  981.     }
  982.     public function getCostByMonth($month)
  983.     {
  984.         /** @var Cost $cost */
  985.         foreach ($this->costs as $cost)
  986.         if ($cost->getType()=='monthlyPayment' && $cost->getName()==$month) {
  987.             return $cost;
  988.         }
  989.         return null;
  990.     }
  991.     public function getBgClassCosts(Cost $cost){
  992.         if($cost->isPaied()) return 'bg-green';
  993.         elseif ($cost->amountPaied()>0) return 'bg-light-blue';
  994.         else return $this->classe->getBgClass($cost->getName());
  995.     }
  996.     public function getBgClass($m){
  997.         if(in_array($m,$this->getMonthsPaid('short'),true)){
  998.             return 'bg-green';
  999.         }
  1000.         elseif($m==$this->getMonthPaidPartially('short'))
  1001.             return  'bg-light-blue';
  1002.         else return $this->classe->getBgClass($m);
  1003.     }
  1004. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1005. /*
  1006.  *  *        *       *      * * * * *   * * * *
  1007.  *  * *      *    *     *       *       *
  1008.  *  *   *    *   *       *      *       * * * *
  1009.  *  *     *  *    *     *       *       *
  1010.  *  *        *       *          *       * * * *
  1011.  * */
  1012.     public function __toString(): string
  1013.     {
  1014.         return $this->getLastName().' '.$this->getFirstName();
  1015.     }
  1016.     public function getName(): string
  1017.     {
  1018.         return $this->getLastName().' '.$this->getFirstName();
  1019.     }
  1020.     public function getRegistrationAt(): DateTime
  1021.     {
  1022.         return $this->registrationAt;
  1023.     }
  1024.     public function setRegistrationAt(DateTime $registrationAt): Participant
  1025.     {
  1026.         $this->registrationAt $registrationAt;
  1027.         return $this;
  1028.     }
  1029.     public function createAvatar(ParameterBagInterface $parameterBag)
  1030.     {
  1031.         $thumbWidth 70;
  1032.         $sourceImagePath $parameterBag->get('kernel.project_dir') . '/public/images/participant/';
  1033.         $sourceImage imagecreatefromjpeg($sourceImagePath.$this->imageName);
  1034.         $destImagePath $sourceImagePath 'thumbs/'.$this->imageName;
  1035.         $orgWidth imagesx($sourceImage);
  1036.         $orgHeight imagesy($sourceImage);
  1037.         $thumbHeight floor($orgHeight * ($thumbWidth $orgWidth));
  1038.         $destImage imagecreatetruecolor($thumbWidth$thumbHeight);
  1039.         imagecopyresampled($destImage$sourceImage0000$thumbWidth$thumbHeight$orgWidth$orgHeight);
  1040.         imagejpeg($destImage$destImagePath);
  1041.         imagedestroy($sourceImage);
  1042.         imagedestroy($destImage);
  1043.     }
  1044. }