<?php
/**
* Created by PhpStorm.
* User: audri
* Date: 26/02/15
* Time: 15:12
*/
namespace App\Entity\Users;
use App\Entity\Users\Child as Student;
use App\Entity\Users\StudentsParents;
use Bo\SubscriptionBundle\Entity\Offer;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Users\User;
/**
* Class teacher
* @package Bo\UserBundle\Entity
* @ORM\Entity(repositoryClass="App\Repository\Users\ParentsRepository")
*
*/
class Parents extends User
{
/**
* @var string
* @ORM\Column(name="code_sponsonring",nullable=true,type="string",length=255,unique=true)
*/
private $codeSponsonring;
/**
* @var string
* @ORM\Column(name="point_sponsonring",nullable=true,type="integer",options={"default":0})
*/
private $pointSponsonring;
/**
* @var boolean
* @ORM\Column(type="boolean",name="popin_change_offer",options={"default":false})
*/
private $popinChangeOffer;
/**************** Associations *******************/
/**
* @var ArrayCollection $children
* @ORM\OneToMany(targetEntity="StudentsParents",mappedBy="parents" ,cascade={"persist"})
*
*/
private $childrens;
/*
* @ORM\OneToMany(targetEntity="\Bo\StudentBundle\Entity\SessionStudent",mappedBy="guardiant")
*/
private $guardiantSession;
/*
* @ORM\OneToMany(targetEntity="Bo\SubscriptionBundle\Entity\KnowUs",mappedBy="user",cascade={"persist","remove"})
*/
private $knowUs;
/**************** Fin ***************************/
private $childrenForm;
public function __construct()
{
parent::__construct();
//To validate Form subscription Child
//$this->setFirstname('parent');
/************* fin *******************/
$this->childrens = new ArrayCollection();
$this->guardiantSession = new ArrayCollection();
$this->knowUs = new ArrayCollection();
$this->pointSponsonring = 0;
$this->setNewDashboardWelcomeMessage(false);
$this->popinChangeOffer = false;
$this->childrenForm = new ArrayCollection();
}
/**
* @return ArrayCollection
*/
public function getChildrens()
{
if(!is_null($this->childrens)){
// !! Reverse pour recupérer les lien les plus récents !!
$childrensList = array_reverse($this->childrens->toArray());
// PATCH pour recupéré les enfants sans doublon
$filteredChildrensList = [];
$studentList = [];
/** @var StudentsParents $studentsParents */
foreach ($childrensList as $studentsParents) {
$studentId = $studentsParents->getStudent()->getId();
if (!in_array($studentId, $studentList)) {
$studentList[] = $studentId;
$filteredChildrensList[] = $studentsParents;
}
}
return new ArrayCollection($filteredChildrensList);
}
}
/**
* @param Student $childrens
*/
public function setChildrens($childrens)
{
$this->childrens = $childrens;
}
/**
* @param $child
*/
public function addChildrens(Student $child)
{
if (!$this->childrens->contains($child)) {
$this->childrens->add($child);
}
}
/**
* @param $student
* @return bool
*/
public function isMychild($student)
{
if (!$this->childrens->isEmpty()) {
foreach ($this->childrens as $item) {
if ($student->getId() == $item->getStudent()->getId()) {
return true;
}
}
}
return false;
}
/**
* @return mixed
*/
public function getGuardiantSession()
{
return $this->guardiantSession;
}
/**
* @param mixed $guardiantSession
*/
public function setGuardiantSession($guardiantSession)
{
$this->guardiantSession = $guardiantSession;
}
/**
* @param mixed $guardiantSession
*/
public function addGuardiantSession($guardiantSession)
{
$this->guardiantSession[] = $guardiantSession;
}
/**
* @return mixed
*/
public function getKnowUs()
{
return $this->knowUs;
}
/**
* @param mixed $knowUs
*/
public function setKnowUs($knowUs)
{
$this->knowUs = $knowUs;
}
/**
* @param mixed $knowUs
*/
public function addKnowUs($knowUs)
{
$this->knowUs[] = $knowUs;
}
/**
* @return string
*/
public function getCodeSponsonring()
{
return $this->codeSponsonring;
}
/**
* @param string $codeSponsonring
*/
public function setCodeSponsonring($codeSponsonring)
{
$this->codeSponsonring = $codeSponsonring;
}
/**
* @return string
*/
public function getPointSponsonring()
{
return $this->pointSponsonring;
}
/**
* @param string $pointSponsonring
*/
public function setPointSponsonring($pointSponsonring)
{
$this->pointSponsonring = $pointSponsonring;
}
public function addSponsonringPoint()
{
$this->pointSponsonring = $this->pointSponsonring + 10;
}
public function getDiscr()
{
return User::DISCR_PARENT;
}
/**
* @return bool
*/
public function isPopinChangeOffer()
{
return $this->popinChangeOffer;
}
/**
* @param bool $popinChangeOffer
*/
public function setPopinChangeOffer(bool $popinChangeOffer): void
{
$this->popinChangeOffer = $popinChangeOffer;
}
/**
* @return mixed
*/
public function getChildrenForm()
{
return $this->childrenForm;
}
/**
* @param mixed $childrenForm
*/
public function setChildrenForm($childrenForm): void
{
$this->childrenForm = $childrenForm;
}
/**
* @param mixed $childrenForm
*/
public function addChildrenForm($childrenForm): void
{
$this->childrenForm[] = $childrenForm;
}
}