src/Entity/Users/Parents.php line 27

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: audri
  5.  * Date: 26/02/15
  6.  * Time: 15:12
  7.  */
  8. namespace App\Entity\Users;
  9. use App\Entity\Users\Child as Student;
  10. use App\Entity\Users\StudentsParents;
  11. use Bo\SubscriptionBundle\Entity\Offer;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Component\Config\Definition\Exception\Exception;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use App\Entity\Users\User;
  17. /**
  18.  * Class teacher
  19.  * @package Bo\UserBundle\Entity
  20.  * @ORM\Entity(repositoryClass="App\Repository\Users\ParentsRepository")
  21.  *
  22.  */
  23. class Parents extends User
  24. {
  25.     /**
  26.      * @var string
  27.      * @ORM\Column(name="code_sponsonring",nullable=true,type="string",length=255,unique=true)
  28.      */
  29.     private $codeSponsonring;
  30.     /**
  31.      * @var string
  32.      * @ORM\Column(name="point_sponsonring",nullable=true,type="integer",options={"default":0})
  33.      */
  34.     private $pointSponsonring;
  35.     /**
  36.      * @var boolean
  37.      * @ORM\Column(type="boolean",name="popin_change_offer",options={"default":false})
  38.      */
  39.     private $popinChangeOffer;
  40.     /**************** Associations *******************/
  41.     /**
  42.      * @var ArrayCollection $children
  43.      * @ORM\OneToMany(targetEntity="StudentsParents",mappedBy="parents" ,cascade={"persist"})
  44.      *
  45.      */
  46.     private $childrens;
  47.     /*
  48.      * @ORM\OneToMany(targetEntity="\Bo\StudentBundle\Entity\SessionStudent",mappedBy="guardiant")
  49.      */
  50.     private $guardiantSession;
  51.     /*
  52.      * @ORM\OneToMany(targetEntity="Bo\SubscriptionBundle\Entity\KnowUs",mappedBy="user",cascade={"persist","remove"})
  53.      */
  54.     private $knowUs;
  55.     /**************** Fin ***************************/
  56.     private $childrenForm;
  57.     public function __construct()
  58.     {
  59.         parent::__construct();
  60.         //To validate Form subscription Child
  61.         //$this->setFirstname('parent');
  62.         /************* fin *******************/
  63.         $this->childrens = new ArrayCollection();
  64.         $this->guardiantSession = new ArrayCollection();
  65.         $this->knowUs = new ArrayCollection();
  66.         $this->pointSponsonring = 0;
  67.         $this->setNewDashboardWelcomeMessage(false);
  68.         $this->popinChangeOffer = false;
  69.         $this->childrenForm = new ArrayCollection();
  70.     }
  71.     /**
  72.      * @return ArrayCollection
  73.      */
  74.     public function getChildrens()
  75.     {
  76.         if(!is_null($this->childrens)){
  77.             // !! Reverse pour recupérer les lien les plus récents !!
  78.             $childrensList = array_reverse($this->childrens->toArray());
  79.             // PATCH pour recupéré les enfants sans doublon
  80.             $filteredChildrensList = [];
  81.             $studentList = [];
  82.             /** @var StudentsParents $studentsParents */
  83.             foreach ($childrensList as $studentsParents) {
  84.                 $studentId = $studentsParents->getStudent()->getId();
  85.                 if (!in_array($studentId, $studentList)) {
  86.                     $studentList[] = $studentId;
  87.                     $filteredChildrensList[] = $studentsParents;
  88.                 }
  89.             }
  90.             return new ArrayCollection($filteredChildrensList);
  91.         }
  92.     }
  93.     /**
  94.      * @param Student $childrens
  95.      */
  96.     public function setChildrens($childrens)
  97.     {
  98.         $this->childrens = $childrens;
  99.     }
  100.     /**
  101.      * @param $child
  102.      */
  103.     public function addChildrens(Student $child)
  104.     {
  105.         if (!$this->childrens->contains($child)) {
  106.             $this->childrens->add($child);
  107.         }
  108.     }
  109.     /**
  110.      * @param $student
  111.      * @return bool
  112.      */
  113.     public function isMychild($student)
  114.     {
  115.         if (!$this->childrens->isEmpty()) {
  116.             foreach ($this->childrens as $item) {
  117.                 if ($student->getId() == $item->getStudent()->getId()) {
  118.                     return true;
  119.                 }
  120.             }
  121.         }
  122.         return false;
  123.     }
  124.     /**
  125.      * @return mixed
  126.      */
  127.     public function getGuardiantSession()
  128.     {
  129.         return $this->guardiantSession;
  130.     }
  131.     /**
  132.      * @param mixed $guardiantSession
  133.      */
  134.     public function setGuardiantSession($guardiantSession)
  135.     {
  136.         $this->guardiantSession = $guardiantSession;
  137.     }
  138.     /**
  139.      * @param mixed $guardiantSession
  140.      */
  141.     public function addGuardiantSession($guardiantSession)
  142.     {
  143.         $this->guardiantSession[] = $guardiantSession;
  144.     }
  145.     /**
  146.      * @return mixed
  147.      */
  148.     public function getKnowUs()
  149.     {
  150.         return $this->knowUs;
  151.     }
  152.     /**
  153.      * @param mixed $knowUs
  154.      */
  155.     public function setKnowUs($knowUs)
  156.     {
  157.         $this->knowUs = $knowUs;
  158.     }
  159.     /**
  160.      * @param mixed $knowUs
  161.      */
  162.     public function addKnowUs($knowUs)
  163.     {
  164.         $this->knowUs[] = $knowUs;
  165.     }
  166.     /**
  167.      * @return string
  168.      */
  169.     public function getCodeSponsonring()
  170.     {
  171.         return $this->codeSponsonring;
  172.     }
  173.     /**
  174.      * @param string $codeSponsonring
  175.      */
  176.     public function setCodeSponsonring($codeSponsonring)
  177.     {
  178.         $this->codeSponsonring = $codeSponsonring;
  179.     }
  180.     /**
  181.      * @return string
  182.      */
  183.     public function getPointSponsonring()
  184.     {
  185.         return $this->pointSponsonring;
  186.     }
  187.     /**
  188.      * @param string $pointSponsonring
  189.      */
  190.     public function setPointSponsonring($pointSponsonring)
  191.     {
  192.         $this->pointSponsonring = $pointSponsonring;
  193.     }
  194.     public function addSponsonringPoint()
  195.     {
  196.         $this->pointSponsonring = $this->pointSponsonring + 10;
  197.     }
  198.     public function getDiscr()
  199.     {
  200.         return User::DISCR_PARENT;
  201.     }
  202.     /**
  203.      * @return bool
  204.      */
  205.     public function isPopinChangeOffer()
  206.     {
  207.         return $this->popinChangeOffer;
  208.     }
  209.     /**
  210.      * @param bool $popinChangeOffer
  211.      */
  212.     public function setPopinChangeOffer(bool $popinChangeOffer): void
  213.     {
  214.         $this->popinChangeOffer = $popinChangeOffer;
  215.     }
  216.     /**
  217.      * @return mixed
  218.      */
  219.     public function getChildrenForm()
  220.     {
  221.         return $this->childrenForm;
  222.     }
  223.     /**
  224.      * @param mixed $childrenForm
  225.      */
  226.     public function setChildrenForm($childrenForm): void
  227.     {
  228.         $this->childrenForm = $childrenForm;
  229.     }
  230.     /**
  231.      * @param mixed $childrenForm
  232.      */
  233.     public function addChildrenForm($childrenForm): void
  234.     {
  235.         $this->childrenForm[] = $childrenForm;
  236.     }
  237. }