src/Entity/Student.php line 563

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Mark;
  4. use App\Entity\Payment;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Entity\Traits\TimeStampable;
  8. use App\Repository\StudentRepository;
  9. use App\Entity\Traits\HasUploadableField;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. /**
  16.  * @ORM\Entity(repositoryClass=StudentRepository::class)
  17.  * @UniqueEntity(fields={"matricule"}, message="There is already an account with this matricule")
  18.  * @ORM\HasLifecycleCallbacks
  19.  * @Vich\Uploadable
  20.  * 
  21.  */
  22. class Student
  23. {
  24.     use TimeStampable;
  25.     use HasUploadableField;
  26.     /**
  27.      * @ORM\Id
  28.      * @ORM\GeneratedValue
  29.      * @ORM\Column(type="integer")
  30.      */
  31.     private $id;
  32.     /**
  33.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  34.      * 
  35.      * @Vich\UploadableField(mapping="student_image", fileNameProperty="imageName")
  36.      * @Assert\File(
  37.      *     maxSize = "6024k",
  38.      *     mimeTypes = {"image/bmp", "image/gif", "image/x-icon", "image/jpeg", "image/png", "image/svg+xml"},
  39.      *     mimeTypesMessage = "Please upload a valid image(bmp,gif,jpg,jpeg,png,svg)"
  40.      * )
  41.      * 
  42.      * @var File|null
  43.      */
  44.     private $imageFile;
  45.     /**
  46.      * @ORM\Column(type="string", length=255)
  47.      */
  48.     private $matricule;
  49.     /**
  50.      * @var string
  51.      *
  52.      * @ORM\Column(name="firstname", type="string", length=255, nullable=true)
  53.      */
  54.     private $firstname;
  55.     /**
  56.      * @var string
  57.      *
  58.      * @ORM\Column(name="lastname", type="string", length=255)
  59.      */
  60.     private $lastname;
  61.     /**
  62.      * @var string
  63.      *
  64.      * @ORM\Column(name="particular_disease", type="string", length=255, nullable=true)
  65.      */
  66.     private $particularDisease;
  67.     /**
  68.      * @var string
  69.      *
  70.      * @ORM\Column(name="father_name", type="string", length=255)
  71.      */
  72.     private $fatherName;
  73.     /**
  74.      * @var string
  75.      *
  76.      * @ORM\Column(name="mother_name", type="string", length=255)
  77.      */
  78.     private $motherName;
  79.     /**
  80.      * @var string
  81.      *
  82.      * @ORM\Column(name="primary_contact", type="string", length=255, nullable=true)
  83.      */
  84.     private $primaryContact;
  85.     /**
  86.      * @var string
  87.      *
  88.      * @ORM\Column(name="residence", type="string", length=255, nullable=true)
  89.      */
  90.     private $residence;
  91.     /**
  92.      * @var string
  93.      *
  94.      * @ORM\Column(name="secondary_contact", type="string", length=255, nullable=true)
  95.      */
  96.     private $secondaryContact;
  97.     /**
  98.      * @var string
  99.      *
  100.      * @ORM\Column(name="other_informations", type="text", nullable=true)
  101.      */
  102.     private $otherInformations;
  103.     /**
  104.      * @var \DateTime
  105.      *
  106.      * @ORM\Column(name="birthday", type="date", nullable=false)
  107.      */
  108.     private $birthday;
  109.     /** @ORM\Column(name="gender", nullable=false, unique=false, length=10)
  110.      * @Assert\Choice(
  111.      * choices = { "0", "1" },
  112.      * message = "précisez le sexe")
  113.      */
  114.     private $gender;
  115.     /**
  116.      * @var string
  117.      *
  118.      * @ORM\Column(name="birthplace", type="string", length=255)
  119.      */
  120.     private $birthplace;
  121.     /**
  122.      * @var boolean
  123.      *
  124.      * @ORM\Column(name="enrolled", type="boolean", options={"default":false})
  125.      */
  126.     private $enrolled false;
  127.     /**
  128.      * @ORM\OneToMany(targetEntity=Subscription::class, mappedBy="student")
  129.      */
  130.     private $subscriptions;
  131.     /**
  132.      * @ORM\OneToMany(targetEntity=Payment::class, mappedBy="student",cascade={"persist"})
  133.      * @ORM\JoinColumn(nullable=true)
  134.      *
  135.      * */
  136.     private $payments;
  137.     /**
  138.      * Get updated
  139.      *
  140.      * @return \DateTime
  141.      */
  142.     public function getUpdated()
  143.     {
  144.         return $this->updated;
  145.     }
  146.     public function getId(): ?int
  147.     {
  148.         return $this->id;
  149.     }
  150.     /**
  151.      *
  152.      * @return string
  153.      */
  154.     public function __toString()
  155.     {
  156.         $lastname = (is_null($this->getLastName())) ? "" $this->getLastName();
  157.         $firstname = (is_null($this->getFirstName())) ? "" $this->getFirstName();
  158.         $matricule = (is_null($this->getMatricule())) ? "" $this->getMatricule();
  159.         return  $lastname " " $firstname " " $matricule;
  160.     }
  161.     
  162.     /**
  163.      *
  164.      * @return string
  165.      */
  166.     public function fullName()
  167.     {
  168.         $lastname = (is_null($this->getLastName())) ? "" $this->getLastName();
  169.         $firstname = (is_null($this->getFirstName())) ? "" $this->getFirstName();
  170.         return  $lastname " " $firstname ;
  171.     }
  172.     /**
  173.      * Set matricule
  174.      *
  175.      * @param string $matricule
  176.      *
  177.      * @return Student
  178.      */
  179.     public function setMatricule($matricule)
  180.     {
  181.         $this->matricule $matricule;
  182.         return $this;
  183.     }
  184.     /**
  185.      * Get matricule
  186.      *
  187.      * @return string
  188.      */
  189.     public function getMatricule()
  190.     {
  191.         return $this->matricule;
  192.     }
  193.     /**
  194.      * Set particularDisease
  195.      *
  196.      * @param string $particularDisease
  197.      *
  198.      * @return Student
  199.      */
  200.     public function setParticularDisease($particularDisease)
  201.     {
  202.         $this->particularDisease $particularDisease;
  203.         return $this;
  204.     }
  205.     /**
  206.      * Get particularDisease
  207.      *
  208.      * @return string
  209.      */
  210.     public function getParticularDisease()
  211.     {
  212.         return $this->particularDisease;
  213.     }
  214.     /**
  215.      * Set fatherName
  216.      *
  217.      * @param string $fatherName
  218.      *
  219.      * @return Student
  220.      */
  221.     public function setFatherName($fatherName)
  222.     {
  223.         $this->fatherName $fatherName;
  224.         return $this;
  225.     }
  226.     /**
  227.      * Get fatherName
  228.      *
  229.      * @return string
  230.      */
  231.     public function getFatherName()
  232.     {
  233.         return $this->fatherName;
  234.     }
  235.     /**
  236.      * Set motherName
  237.      *
  238.      * @param string $motherName
  239.      *
  240.      * @return Student
  241.      */
  242.     public function setMotherName($motherName)
  243.     {
  244.         $this->motherName $motherName;
  245.         return $this;
  246.     }
  247.     /**
  248.      * Get motherName
  249.      *
  250.      * @return string
  251.      */
  252.     public function getMotherName()
  253.     {
  254.         return $this->motherName;
  255.     }
  256.     /**
  257.      * Set primaryContact
  258.      *
  259.      * @param string $primaryContact
  260.      *
  261.      * @return Student
  262.      */
  263.     public function setPrimaryContact($primaryContact)
  264.     {
  265.         $this->primaryContact $primaryContact;
  266.         return $this;
  267.     }
  268.     /**
  269.      * Get primaryContact
  270.      *
  271.      * @return string
  272.      */
  273.     public function getPrimaryContact()
  274.     {
  275.         return $this->primaryContact;
  276.     }
  277.     /**
  278.      * Set secondaryContact
  279.      *
  280.      * @param string $secondaryContact
  281.      *
  282.      * @return Student
  283.      */
  284.     public function setSecondaryContact($secondaryContact)
  285.     {
  286.         $this->secondaryContact $secondaryContact;
  287.         return $this;
  288.     }
  289.     /**
  290.      * Get secondaryContact
  291.      *
  292.      * @return string
  293.      */
  294.     public function getSecondaryContact()
  295.     {
  296.         return $this->secondaryContact;
  297.     }
  298.     /**
  299.      * Set otherInformations
  300.      *
  301.      * @param string $otherInformations
  302.      *
  303.      * @return Student
  304.      */
  305.     public function setOtherInformations($otherInformations)
  306.     {
  307.         $this->otherInformations $otherInformations;
  308.         return $this;
  309.     }
  310.     /**
  311.      * Get otherInformations
  312.      *
  313.      * @return string
  314.      */
  315.     public function getOtherInformations()
  316.     {
  317.         return $this->otherInformations;
  318.     }
  319.     /**
  320.      * Set gender
  321.      *
  322.      * @param string $gender
  323.      *
  324.      * @return Student
  325.      */
  326.     public function setGender($gender)
  327.     {
  328.         $this->gender $gender;
  329.         return $this;
  330.     }
  331.     /**
  332.      * Get gender
  333.      *
  334.      * @return string
  335.      */
  336.     public function getGender()
  337.     {
  338.         return $this->gender;
  339.     }
  340.     /**
  341.      * Set birthplace
  342.      *
  343.      * @param string $birthplace
  344.      *
  345.      * @return Student
  346.      */
  347.     public function setBirthplace($birthplace)
  348.     {
  349.         $this->birthplace $birthplace;
  350.         return $this;
  351.     }
  352.     /**
  353.      * Get birthplace
  354.      *
  355.      * @return string
  356.      */
  357.     public function getBirthplace()
  358.     {
  359.         return $this->birthplace;
  360.     }
  361.     /**
  362.      * Set level
  363.      *
  364.      * @param \AppBundle\Entity\Level $level
  365.      *
  366.      * @return Student
  367.      */
  368.     public function setLevel(Level $level)
  369.     {
  370.         $this->level $level;
  371.         return $this;
  372.     }
  373.     /**
  374.      * Get level
  375.      *
  376.      * @return \AppBundle\Entity\Level
  377.      */
  378.     public function getLevel()
  379.     {
  380.         return $this->level;
  381.     }
  382.     /**
  383.      * Set updated
  384.      *
  385.      * @param \DateTime $updated
  386.      *
  387.      * @return Student
  388.      */
  389.     public function setUpdated($updated)
  390.     {
  391.         $this->updated $updated;
  392.         return $this;
  393.     }
  394.     /**
  395.      * Class where the student is enrolled in a given school year
  396.      *
  397.      * @return ClassRoom
  398.      */
  399.     public function getClassRoom(SchoolYear $year)
  400.     {
  401.         $subscribtion $em->getRepository('AppBundle:Subscription')->findBy(array('schoolYear' => $year'student' => $std));
  402.         return $subscribtion->getClassRoom();
  403.     }
  404.      /**
  405.      * Tuition fees already paid by the student in a given school year
  406.      *
  407.      * @return int
  408.      */
  409.     public function getPaymentsSum(SchoolYear $year)
  410.     {
  411.         $sum 0;
  412.         foreach ($this->payments as $p) {
  413.             if($p->getSchoolYear() == $year){
  414.                  $sum += $p->getAmount();
  415.             }
  416.         }
  417.         return $sum;
  418.     }
  419.     /**
  420.      * Set birthday
  421.      *
  422.      * @param \DateTime $birthday
  423.      *
  424.      * @return Student
  425.      */
  426.     public function setBirthday($birthday)
  427.     {
  428.         $this->birthday $birthday;
  429.         return $this;
  430.     }
  431.     /**
  432.      * Get birthday
  433.      *
  434.      * @return \DateTime
  435.      */
  436.     public function getBirthday()
  437.     {
  438.         return $this->birthday;
  439.     }
  440.     /**
  441.      * Set firstname
  442.      *
  443.      * @param string $firstname
  444.      *
  445.      * @return Student
  446.      */
  447.     public function setFirstname($firstname)
  448.     {
  449.         $this->firstname $firstname;
  450.         return $this;
  451.     }
  452.     /**
  453.      * Get firstname
  454.      *
  455.      * @return string
  456.      */
  457.     public function getFirstname()
  458.     {
  459.         return $this->firstname;
  460.     }
  461.     /**
  462.      * Set lastname
  463.      *
  464.      * @param string $lastname
  465.      *
  466.      * @return Student
  467.      */
  468.     public function setLastname($lastname)
  469.     {
  470.         $this->lastname $lastname;
  471.         return $this;
  472.     }
  473.     /**
  474.      * Get lastname
  475.      *
  476.      * @return string
  477.      */
  478.     public function getLastname()
  479.     {
  480.         return $this->lastname;
  481.     }
  482.     /**
  483.      * Constructor
  484.      */
  485.     public function __construct()
  486.     {
  487.         $this->setEnrolled(false);
  488.         $this->marks = new \Doctrine\Common\Collections\ArrayCollection();
  489.         $this->subscriptions = new \Doctrine\Common\Collections\ArrayCollection();
  490.         $this->payments = new ArrayCollection();
  491.     }
  492.     public function addMark(Mark $mark)
  493.     {
  494.         $this->marks[] = $mark;
  495.         return $this;
  496.     }
  497.     public function removeMark(Mark $mark)
  498.     {
  499.         $this->marks->removeElement($mark);
  500.     }
  501.     /**
  502.      * Get marks
  503.      *
  504.      * @return \Doctrine\Common\Collections\Collection
  505.      */
  506.     public function getMarks()
  507.     {
  508.         return $this->marks;
  509.     }
  510.     /**
  511.      * Set profileImagePath
  512.      *
  513.      * @param string $profileImagePath
  514.      *
  515.      * @return Student
  516.      */
  517.     public function setProfileImagePath($profileImagePath)
  518.     {
  519.         $this->profileImagePath $profileImagePath;
  520.         return $this;
  521.     }
  522.     /**
  523.      * Get profileImagePath
  524.      *
  525.      * @return string
  526.      */
  527.     public function getProfileImagePath()
  528.     {
  529.         return $this->profileImagePath;
  530.     }
  531.     /**
  532.      * Set residence
  533.      *
  534.      * @param string $residence
  535.      *
  536.      * @return Student
  537.      */
  538.     public function setResidence($residence)
  539.     {
  540.         $this->residence $residence;
  541.         return $this;
  542.     }
  543.     /**
  544.      * Get residence
  545.      *
  546.      * @return string
  547.      */
  548.     public function getResidence()
  549.     {
  550.         return $this->residence;
  551.     }
  552.     /**
  553.      * @return Collection|Subscription[]
  554.      */
  555.     public function getSubscriptions(): Collection
  556.     {
  557.         return $this->subscriptions;
  558.     }
  559.     public function addSubscription(Subscription $subscription): self
  560.     {
  561.         if (!$this->subscriptions->contains($subscription)) {
  562.             $this->subscriptions[] = $subscription;
  563.             $subscription->setStudent($this);
  564.         }
  565.         return $this;
  566.     }
  567.     public function removeSubscription(Subscription $subscription): self
  568.     {
  569.         if ($this->subscriptions->removeElement($subscription)) {
  570.             // set the owning side to null (unless already changed)
  571.             if ($subscription->getStudent() === $this) {
  572.                 $subscription->setStudent(null);
  573.             }
  574.         }
  575.         return $this;
  576.     }
  577.     /**
  578.      * Set enrolled
  579.      *
  580.      * @param boolean $enrolled
  581.      *
  582.      * @return Student
  583.      */
  584.     public function setEnrolled($enrolled)
  585.     {
  586.         $this->enrolled $enrolled;
  587.         return $this;
  588.     }
  589.     /**
  590.      * Get enrolled
  591.      *
  592.      * @return boolean
  593.      */
  594.     public function getEnrolled()
  595.     {
  596.         return $this->enrolled;
  597.     }
  598.     public function addPayment(Payment $payment)
  599.     {
  600.         $this->payments[] = $payment;
  601.         return $this;
  602.     }
  603.     public function removePayment(Payment $payment)
  604.     {
  605.         $this->payments->removeElement($payment);
  606.     }
  607.     /**
  608.      * Get payments
  609.      *
  610.      * @return \Doctrine\Common\Collections\Collection
  611.      */
  612.     public function getPayments()
  613.     {
  614.         return $this->payments;
  615.     }
  616.     public function isEnrolled(): ?bool
  617.     {
  618.         return $this->enrolled;
  619.     }
  620. }