<?php
namespace App\Entity\Users;
use App\Model\TimestampableTrait;
use Bo\StudentBundle\Entity\OfferStudent;
use App\Entity\Users\Child as Student;
use Bo\SubscriptionBundle\Entity\OfferHistory;
use App\Validator\Constraints as UserAssert;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use ED\BlogBundle\Interfaces\Model\ArticleCommenterInterface;
use ED\BlogBundle\Interfaces\Model\BlogUserInterface;
use Exception;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Yaml\Parser;
// * @UniqueEntity(fields={"email"},message="blabli") @UniqueEntity(fields={"username"})
/**
* @ORM\Entity(repositoryClass="App\Repository\Users\UserRepository")
* @ORM\Table(name="aba_user",uniqueConstraints={@ORM\UniqueConstraint(columns={"email"})})
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"user"="User","parents"="Parents","teacher"="Teacher","admin"="Admin","student"="Child","guardiant"="Guardiant"})
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity(fields={"email"},repositoryMethod="findByUniqueCriteria",message="Cet email est déjà utilisé")
*
*/
//class User extends BaseUser implements BlogUserInterface, ArticleCommenterInterface, NotifiableInterface
class User implements UserInterface,EquatableInterface
{
const ID_LAURENCE = 212828;
const CIVILITY_MR = 'mr';
const CIVILITY_MRS = 'mrs';
const CIVILITY_MISS = 'miss';
const GENDER_MALE = 'male';
const GENDER_FEMALE = 'female';
const PROFIL_ELEVE = 'eleve';
const PROFIL_PARENT = 'parent';
const DISCR_PARENT = 'parents';
const DISCR_STUDENT = 'student';
const ORIGIN_SITE = 1;
const ORIGIN_MOBILE = 2;
use TimestampableTrait;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"api"})
*/
protected $id;
/**
* Required by BlogUserInterface
*
* @ORM\Column(name="blog_display_name", type="string",nullable=true)
*/
protected $blogDisplayName;
/**
* @var string $firstname
*
* @ORM\Column(name="firstname", type="string", length=255, nullable=false)
* @Assert\NotBlank(message="Vous devez renseigner votre prénom")
* @Groups({"api"})
*/
protected $firstname;
/**
* @ORM\Column(name="gender", type="string", nullable=true)
* Assert\NotBlank(message="Vous devez renseigner votre genre")
*/
protected $gender;
/**
* @var string
* @ORM\Column(name="registration_profile", nullable=true, type="string")
* Assert\NotBlank(message="Vous devez renseigner votre profil")
*/
private $registrationProfile;
/**
* @ORM\Column(name="civility", type="string", nullable=true)
* @Groups({"api"})
*/
protected $civility;
/**
* @ORM\Column(name="email", type="string",unique=true)
* @Assert\Email(message = "Merci d'indiquer un email valide.")
*
* @Groups({"api"})
*/
protected $email;
//@Assert\Email
/**
* @ORM\Column(type="string",nullable=true)
*
*/
protected $username;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
protected $enabled;
/**
* The salt to use for hashing.
*
* @ORM\Column(type="string",nullable=true)
*/
protected $salt;
/**
* Encrypted password. Must be persisted.
*
* @ORM\Column(type="string")
*/
protected $password;
/**
* @ORM\Column(type="CustomJsonType")
*/
protected $roles = [];
/**
*
* @Assert\NotBlank(groups={"registration"})
*/
protected $plainPassword;
/**
* @var \DateTime|null
*/
protected $lastLogin;
/**
* @var string $lastname
*
* @ORM\Column(name="lastname", type="string", length=255, nullable=true)
*
* @Groups({"api"})
*/
protected $lastname;
/**
* @var string $promoCode
*
* @ORM\Column(name="promo_code", type="string", length=255, nullable=true)
*
*/
protected $promoCode;
/**
* @var integer $endSubscriptionMailSended
*
* @ORM\Column(name="end_subscription_mail_sended", type="integer")
*/
protected $endSubscriptionMailSended = 0;
/**
* @var integer
*
* @ORM\Column(name="email_validation", type="integer")
*/
protected $emailValidation = 0;
/**
* @var string
*
* @ORM\Column(name="email_validation_token", type="string")
*/
protected $emailValidationToken;
/**
* @var string
*
* @ORM\Column(name="email_validation_token_requested_at", type="datetime")
*/
protected $emailValidationTokenRequestedAt;
/**
* @var string $facebookId
*
* @ORM\Column(name="facebook_id", type="string", length=255, nullable=true)
*
*/
protected $facebookId;
/**
* @var string $facebookAccessToken1
*
* @ORM\Column(name="facebook_access_token", type="string", length=255, nullable=true)
*
*/
protected $facebookAccessToken;
/**
* @var string $profilePicture
*
* @ORM\Column(name="profile_picture", type="string", length=255, nullable=true)
*/
protected $profilePicture;
/**
* @var
*/
protected $customRoles;
/**
* @var string $promoCode
*
* @ORM\Column(name="encoding_mdp", type="boolean", nullable=true)
*/
protected $encodingMdp;
/**
* @var boolean
* @ORM\Column(name="notif",type="boolean",nullable=true)
*/
protected $notif;
/**
* @var string
* @Assert\File(maxSize = "5M")
*/
protected $picture;
/**
* @var string
* @ORM\Column(name="picture", type="string", length=255, nullable=true)
*/
protected $path;
/**
* @var boolean
* @ORM\Column(name="credit_card",type="boolean",nullable=true)
*/
protected $creditCard;
/*
* @ORM\OneToMany(targetEntity="\Bo\StudentBundle\Entity\OfferStudent",mappedBy="student")
*
*/
protected $offers;
/*
* @ORM\OneToMany(targetEntity="\Bo\ReportBundle\Entity\Report",mappedBy="user")
*/
protected $reports;
/**
* @ORM\Column(name="is_newsletter",type="boolean",nullable=true)
*/
protected $isNewsletter;
/**
* @ORM\Column(name="is_cgu",type="boolean")
*
*/
protected $isCgu;
/**
* @ORM\Column(name="popin_share_good_deal", type="boolean")
*
*/
protected $popinShareGoodDeal;
/**
* @ORM\Column(name="stripe_id",type="string",nullable=true,length=255)
*
*/
protected $stripeId;
/**
* @ORM\Column(name="is_first_connection",type="boolean", options={"default":"1"})
*
*/
protected $isFirstConnection;
/*
* @ORM\OneToMany(targetEntity="\Bo\AdministratorsBundle\Entity\Assessment", mappedBy="student")
*/
protected $assessments;
/*
* @var OfferHistory
* @ORM\ManyToOne(targetEntity="Bo\SubscriptionBundle\Entity\OfferHistory", cascade={"persist"})
*/
protected $latestActiveOfferHistory;
/**
* @var int
* @ORM\Column(type="integer", options={"default":0})
*/
protected $status;
/**
* @var \DateTime
* @ORM\Column(name="date_sychronisation_intercom",type="datetime",nullable=true)
*/
protected $dateSychronisationIntercom;
/**
* @var integer $origin
*
* @ORM\Column(name="origin", type="integer")
*/
protected $origin;
/**
* @var boolean $legal_guardian_authorization
*
* @ORM\Column(name="legal_guardian_authorization", type="boolean")
*/
protected $legalGuardianAuthorization;
/**
* @var integer $parentEmail
* @Groups({"api"})
* @ORM\Column(name="parent_email", type="string")
*/
protected $parentEmail;
/**
* @var string $avatar
*
* @ORM\Column(type="string",nullable=true)
*/
protected $avatar;
/**
* @var boolean $isVerified
*
* @ORM\Column(type="boolean",nullable=true)
*/
protected $isVerified = false;
public $fileAvatar;
/**
* User constructor.
*/
public function __construct()
{
$this->encodingMdp = true;
$this->notif = false;
$this->username = $this->email;
$this->offers = new ArrayCollection();
$this->reports = new ArrayCollection();
$this->isFirstConnection = true;
$this->isNewsletter = false;
$this->isCgu = false;
$this->isFirstConnection = true;
$this->newDashboardWelcomeMessage = true;
//$this->status = OfferHistory::STATUS_NO_OFFER;
}
/**
* Return all the civilities
* @return array
*/
public static function getCivilities()
{
return [self::CIVILITY_MR, self::CIVILITY_MISS, self::CIVILITY_MRS];
}
/**
* @deprecated To remove when everything will good
* @return string
*/
public function getHistoryWording()
{
$res = "Inscrit sans abonnement";
if ($this->status != OfferHistory::STATUS_NO_OFFER && $this->getLatestActiveOfferHistory()) {
$res = $this->getLatestActiveOfferHistory()->getWording();
}
return $res;
}
/**
* @deprecated To remove when everything will good
* @return OfferHistory
*/
public function getLatestActiveOfferHistory()
{
return $this->latestActiveOfferHistory;
}
/**
* @deprecated To remove when everything will good
* @param OfferHistory|null $latestActiveOfferHistory
*/
public function setLatestActiveOfferHistory($latestActiveOfferHistory)
{
$this->latestActiveOfferHistory = $latestActiveOfferHistory;
if ($latestActiveOfferHistory) {
$this->setStatus($latestActiveOfferHistory->getStatus());
} else {
$this->setStatus(OfferHistory::STATUS_NO_OFFER);
}
}
/**
* @deprecated To remove when everything will good
* @return int
*/
public function getStatus()
{
if ($this->latestActiveOfferHistory) {
return $this->latestActiveOfferHistory->getStatus();
}
return $this->status;
}
/**
* @param int $status
*/
public function setStatus(int $status)
{
$this->status = $status;
}
/**
* @return mixed
*/
public function getBlogDisplayName()
{
return $this->blogDisplayName;
}
/**
* @param $blogDisplayName
* @return $this
*/
public function setBlogDisplayName($blogDisplayName)
{
$this->blogDisplayName = $blogDisplayName;
return $this;
}
/**
* @return mixed
*/
public function getCommenterDisplayName()
{
return $this->blogDisplayName;
}
/**
* @return string
*/
public function getEncodingMdp()
{
return $this->encodingMdp;
}
/**
* @param string $encodingMdp
*/
public function setEncodingMdp($encodingMdp)
{
$this->encodingMdp = $encodingMdp;
}
/*
public function serialize()
{
return serialize(array($this->facebookId, parent::serialize()));
}
public function unserialize($data)
{
[$this->facebookId, $parentData] = unserialize($data);
parent::unserialize($parentData);
}
*/
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
/**
* Get Uid
*
* @return string
*/
public function getUid()
{
return sha1($this->id);
}
/**
* Set firstname
*
* @param string $firstname
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
}
/**
* Get firstname
*
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set lastname
*
* @param string $lastname
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
}
/**
* Get lastname
*
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
public function getFullname()
{
return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
}
/**
* @param string $facebookId
* @return void
*/
public function setFacebookId($facebookId)
{
$this->facebookId = $facebookId;
}
/**
* @return string
*/
public function getFacebookId()
{
return $this->facebookId;
}
/**
* @return string
*/
public function getFacebookAccessToken()
{
return $this->facebookAccessToken;
}
/**
* @param string $facebookAccessToken
*/
public function setFacebookAccessToken($facebookAccessToken)
{
$this->facebookAccessToken = $facebookAccessToken;
}
/**
* @var string $phone
*
* @ORM\Column(name="phone", type="string", length=255, nullable=true)
* @Assert\Length(min = 5, max = 20, minMessage = "Numéro de telephone invalide", maxMessage = "Numéro de telephone invalide")
*
* @Groups({"api"})
*/
protected $phone;
/**
* @var string $street
*
* @ORM\Column(name="street", type="string", length=255, nullable=true)
*
*/
protected $street;
/**
* @var string $postalCode
*
* @ORM\Column(name="postal_code", type="string", length=255, nullable=true)
*
*/
protected $postalCode;
/**
* @var string $city
*
* @ORM\Column(name="city", type="string", length=255, nullable=true)
*
*/
protected $city;
/**
* @var string $country
*
* @ORM\Column(name="country", type="string", length=255, nullable=true)
* @Assert\NotBlank(groups={"registration_parent"})
*/
protected $country;
/**
* if the user allow to send promotion mails
* @var boolean $promo
*
* @ORM\Column(name="promo", type="boolean")
*/
protected $promo = false;
/**
* @var boolean $report
* @todo changeIt
*
* @ORM\Column(name="report", type="string", length=255)
* @Assert\Choice(
* callback = {"\aba\UserBundle\Entity\Report", "getPeriodicitiesValidation"},
* message = "Choose a valid periodicity.",
* groups={"registration_parent"}
* )
*/
protected $report = '';
/**
* if the user has validated the post registration form
* @var boolean $postRegistrationFormValidated
*
* @ORM\Column(name="post_registration_form_validated", type="boolean")
*/
protected $postRegistrationFormValidated = false;
/**
* @var string $from
*
* @ORM\Column(name="_from", type="string", length=255, nullable=true)
*/
protected $from;
/**
* @var boolean $newDashboardWelcomeMessage
* @ORM\Column(name="new_dashboard_welcome_message", type="boolean")
*/
private $newDashboardWelcomeMessage;
/**
* @return string
*/
public function getHmac()
{
return hash_hmac(
'sha256',
$this->id,
't4MwVPCbdgQXz03YIAL8kJ08O5z2O2vRaWkTcPFU'
);
}
/**
* Set phone
*
* @param string $phone
*/
public function setPhone($phone)
{
$this->phone = $phone;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set street
*
* @param string $street
*/
public function setStreet($street)
{
$this->street = $street;
}
/**
* Get street
*
* @return string
*/
public function getStreet()
{
return $this->street;
}
/**
* Set postalCode
*
* @param string $postalCode
*/
public function setPostalCode($postalCode)
{
$this->postalCode = $postalCode;
}
/**
* Get postalCode
*
* @return string
*/
public function getPostalCode()
{
return $this->postalCode;
}
/**
* Set city
*
* @param string $city
*/
public function setCity($city)
{
$this->city = $city;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set country
*
* @param string $country
*/
public function setCountry($country)
{
$this->country = $country;
}
/**
* Get country
*
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set promo
*
* @param boolean $promo
*/
public function setPromo($promo)
{
$this->promo = $promo;
}
/**
* Get promo
*
* @return boolean
*/
public function getPromo()
{
return $this->promo;
}
/**
* Set postRegistrationFormValidated
*
* @param boolean $postRegistrationFormValidated
*/
public function setPostRegistrationFormValidated($postRegistrationFormValidated)
{
$this->postRegistrationFormValidated = $postRegistrationFormValidated;
}
/**
* Get postRegistrationFormValidated
*
* @return boolean
*/
public function getPostRegistrationFormValidated()
{
return $this->postRegistrationFormValidated;
}
/**
* Set promoCode
*
* @param string $promoCode
*/
public function setPromoCode($promoCode)
{
$this->promoCode = $promoCode;
}
/**
* Get promoCode
*
* @return string
*/
public function getPromoCode()
{
return $this->promoCode;
}
/**
* Set report
*
* @param boolean $report
*/
public function setReport($report)
{
$this->report = $report;
}
/**
* Get report
*
* @return boolean
*/
public function getReport()
{
return $this->report;
}
/**
* Set from
*
* @param string $from
*/
public function setFrom($from)
{
$this->from = $from;
}
/**
* Get from
*
* @return string
*/
public function getFrom()
{
return $this->from;
}
/**
* Set course
*
* @param Course $course
*/
public function setCourse($course)
{
$this->course = $course;
}
/**
* Get course
*
* @return Course
*/
/**
* @param string $serie
*/
public function setSerie($serie)
{
$this->serie = $serie;
}
/**
* Set endSubscriptionMailSended
*
* @param integer $endSubscriptionMailSended
*/
public function setEndSubscriptionMailSended($endSubscriptionMailSended)
{
$this->endSubscriptionMailSended = $endSubscriptionMailSended;
}
/**
* Get endSubscriptionMailSended
*
* @return integer
*/
public function getEndSubscriptionMailSended()
{
return $this->endSubscriptionMailSended;
}
/**
* Return true if the user has ROLE_STUDENT_PAID credential
* NOT FUNCTIONAL
*/
public function isParent()
{
//return in_array(self::ROLE_PARENT, $this->getRoles());
}
/**
* @return string
*/
public function getCredentialsExpireAt()
{
return $this->credentialsExpireAt;
}
/*
* @param string $credentialsExpireAt
*
public function setCredentialsExpireAt($credentialsExpireAt)
{
$this->credentialsExpireAt = $credentialsExpireAt;
}*/
/**
* @return mixed
*/
public function getRoles()
{
return $this->roles;
}
/**
* @return mixed
*/
public function setRoles($roles)
{
$this->roles = $roles;
}
/**
* @return mixed
*/
public function addRoles(string $roles)
{
if(!in_array($roles,$this->roles)){
$this->roles[]= $roles;
}
}
/**
* @return string
*/
public function getInstance()
{
return $this->customInstanceof();
}
/**
* @return string
*/
public function customInstanceof()
{
if ($this instanceof Teacher) {
return "teacher";
}
if ($this instanceof Student) {
return "student";
}
if ($this instanceof Guardiant) {
return "guardiant";
}
if ($this instanceof Admin) {
return "admin";
}
if ($this instanceof Parents) {
return "parent";
}
return "user";
}
static private function convertRoleToLabel($role)
{
$roleDisplay = str_replace('ROLE_', '', $role);
$roleDisplay = str_replace('_', ' ', $roleDisplay);
return ucwords(strtolower($roleDisplay));
}
static function getRoleNames($front = false)
{
if (!$front) {
$pathToSecurity = __DIR__ . '/../../../..' . '/app/config/security.yml';
$yaml = new Parser();
$rolesArray = $yaml->parse(file_get_contents($pathToSecurity));
$arrayKeys = array();
foreach ($rolesArray['security']['role_hierarchy'] as $key => $value) {
//never allow assigning super admin
if ($key != 'ROLE_SUPER_ADMIN')
$arrayKeys[$key] = User::convertRoleToLabel($key);
//skip values that are arrays --- roles with multiple sub-roles
if (!is_array($value))
if ($value != 'ROLE_SUPER_ADMIN')
$arrayKeys[$value] = User::convertRoleToLabel($value);
}
//sort for display purposes
asort($arrayKeys);
return $arrayKeys;
}
return array("" => "select role", "ROLE_STUDENT" => "Eleve", "ROLE_PARENTS" => "Parents");
}
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function affectation_disc()
{
/* if(!in_array($this->customRoles, $this->roles) && $this->customRoles != null )
{
$this->roles[0] = $this->customRoles;
}*/
}
/**
* @return mixed
*/
public function getCustomRoles()
{
return $this->customRoles;
}
/**
* @param mixed $customRoles
*/
public function setCustomRoles($customRoles)
{
$this->customRoles = $customRoles;
}
/**
* @return bool
*/
public function flagNotice()
{
if ($this instanceof Student) {
foreach ($this->getParents() as $parent) {
if (!$parent->getEnabled()) {
return true;
}
}
}
return false;
}
/**
* @return mixed
*/
public function getEmail()
{
/*if(preg_match("/@test.com/",$this->email)){
return '[email protected]';
}*/
return $this->email;
}
/**
* @return mixed
*/
public function getNotif()
{
return $this->notif;
}
/**
* @param mixed $notif
*/
public function setNotif($notif)
{
$this->notif = $notif;
}
/**
* @return mixed
*/
public function getOffers()
{
return $this->offers;
}
/**
* @param mixed $offers
*/
public function setOffers($offers)
{
$this->offers = $offers;
}
public function addOffers($offers)
{
$this->offers[] = $offers;
}
/**
* @return mixed
*/
public function getReports()
{
return $this->reports;
}
/**
* @param mixed $reports
*/
public function setReports($reports)
{
$this->reports = $reports;
}
/**
* @param mixed $reports
*/
public function addReports($reports)
{
$this->reports[] = $reports;
}
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function prepersist()
{
$this->username;
}
public function setEmail($email)
{
$this->email = $email;
$this->username = $email;
}
/**
* @return int
*/
public function getOrigin()
{
return $this->origin;
}
/**
* @param int $origin
*/
public function setOrigin($origin)
{
$this->origin = $origin;
}
/**
* @return bool
*/
public function getLegalGuardianAuthorization()
{
return $this->legalGuardianAuthorization;
}
/**
* @param bool $legalGuardianAuthorization
*/
public function setLegalGuardianAuthorization($legalGuardianAuthorization)
{
$this->legalGuardianAuthorization = $legalGuardianAuthorization;
}
/**
* @return int
*/
public function getParentEmail()
{
return $this->parentEmail;
}
/**
* @param int $parentEmail
*/
public function setParentEmail($parentEmail)
{
$this->parentEmail = $parentEmail;
}
/**
* @return string
*/
public function getPicture()
{
return $this->picture;
}
/**
* @param string $picture
*/
public function setPicture($picture)
{
$this->picture = $picture;
}
/**
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* @param string $path
*/
public function setPath($path)
{
$this->path = $path;
}
public function getAbsolutePath()
{
return null === $this->path ? null : sprintf("%s/%s", $this->getUploadRootDir(), $this->path);
}
public function getWebPath()
{
return null === $this->path ? null : sprintf("/%s/%s", $this->getUploadDir(), $this->path);
}
protected function getUploadRootDir()
{
// le chemin absolu du répertoire où les documents uploadés doivent être sauvegardés
return __DIR__ . '/../../../../web/' . $this->getUploadDir();
}
protected function getUploadDir()
{
// on se débarrasse de « __DIR__ » afin de ne pas avoir de problème lorsqu'on affiche
// le document/image dans la vue.
return sprintf('ressources/avatars/%d/', $this->id);
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function PreUpdate()
{
if (null !== $this->picture) {
$this->removeUpload();
$this->path = sha1(uniqid(mt_rand(), true)) . '.' . $this->picture->guessExtension();
}
}
/**
* @ORM\PostPersist
* @ORM\PostUpdate
*/
public function PostUpdate()
{
if (null === $this->picture) {
return;
}
// s'il y a une erreur lors du déplacement du fichier, une exception
// va automatiquement être lancée par la méthode move(). Cela va empêcher
// proprement l'entité d'être persistée dans la base de données si
// erreur il y a
if (!is_dir($this->getUploadRootDir())) {
mkdir($this->getUploadRootDir(), '0755', true);
}
$this->picture->move($this->getUploadRootDir(), $this->path);
unset($this->picture);
}
/**
* @ORM\PostRemove()
*/
public function removeUpload()
{
$file = $this->getAbsolutePath();
if (is_file($file)) {
unlink($file);
}
}
public function getAvatar()
{
return $this->avatar;
}
public function setAvatar(?string $avatar)
{
$this->avatar = $avatar;
}
/**
* @return boolean
*/
public function isCreditCard()
{
return $this->creditCard;
}
/**
* @param boolean $creditCard
*/
public function setCreditCard($creditCard)
{
$this->creditCard = $creditCard;
}
/**
* @return mixed
*/
public function getIsNewsletter()
{
return $this->isNewsletter;
}
/**
* @param mixed $isNewsletter
*/
public function setIsNewsletter($isNewsletter)
{
$this->isNewsletter = $isNewsletter;
}
/**
* @return mixed
*/
public function getIsCgu()
{
return $this->isCgu;
}
/**
* @param mixed $isCgu
*/
public function setIsCgu($isCgu)
{
$this->isCgu = $isCgu;
}
public function hasRoleSubscription()
{
$Subscription = array('ROLE_REVISION', 'ROLE_ASSISTANCE','ROLE_NEW_OFFER', 'ROLE_ENCADREMENT');
foreach ($Subscription as $sub) {
if (in_array($sub, $this->getRoles())) {
return $sub;
}
}
return null;
}
/**
* @param $role
* @param User|null $user
* @return bool
*/
public function accessFonctionnality($role, User $user = null)
{
$hierachiqueRole = array(
'ROLE_REVISION' => array('ROLE_REVISION'),
'ROLE_NEW_OFFER' => ['ROLE_REVISION','ROLE_NEW_OFFER'],
'ROLE_ASSISTANCE' => array('ROLE_REVISION', 'ROLE_ASSISTANCE'),
'ROLE_ENCADREMENT' => array('ROLE_REVISION', 'ROLE_ASSISTANCE', 'ROLE_ENCADREMENT'));
if ($this instanceof Parents) {
if (!$this->getChildrens()->isEmpty() && $user instanceof Student) {
foreach ($this->getChildrens() as $cd) {
if ($cd->getStudent()->getId() === $user->getId()) {
$verif = $user->hasRoleSubscription();
if (!is_null($verif)) {
if (in_array($role, $hierachiqueRole[$verif])) {
return true;
}
}
}
}
}
return false;
}
if ($this instanceof Student) {
$verif = $this->hasRoleSubscription($role);
if (!is_null($verif)) {
if (in_array($role, $hierachiqueRole[$verif])) {
return true;
}
}
}
return false;
}
function getIsFirstConnection()
{
return $this->isFirstConnection;
}
function setIsFirstConnection($isFirstConnection)
{
$this->isFirstConnection = $isFirstConnection;
}
/**
* @return mixed
*/
public function getAssessments()
{
return $this->assessments;
}
/**
* @param mixed $assessments
*/
public function setAssessments($assessments)
{
$this->assessments = $assessments;
}
/**
* @param mixed $assessments
*/
public function addAssessments($assessments)
{
$this->assessments[] = $assessments;
}
/**
* @return mixed
*/
public function getStripeId()
{
return $this->stripeId;
}
/**
* @param mixed $stripeId
*/
public function setStripeId($stripeId)
{
$this->stripeId = $stripeId;
}
public function getCivility()
{
return $this->civility;
}
/**
* @param mixed $civility
*/
public function setCivility($civility)
{
$this->civility = $civility;
}
/**
* @return mixed
*/
public function getGender()
{
return $this->gender;
}
/**
* @param mixed $gender
*/
public function setGender($gender)
{
$this->gender = $gender;
}
/**
* @return string
*/
public function getRegistrationProfile()
{
return $this->registrationProfile;
}
/**
* @param string $registrationProfile
*/
public function setRegistrationProfile($registrationProfile)
{
$this->registrationProfile = $registrationProfile;
}
/**
* @return string
*/
public function getProfilePicture()
{
return $this->profilePicture;
}
/**
* @param string $profilePicture
*/
public function setProfilePicture($profilePicture)
{
$this->profilePicture = $profilePicture;
}
public function getCourse()
{
return null;
}
public function getSerie()
{
return null;
}
/**
* Get creditCard
*
* @return boolean
*/
public function getCreditCard()
{
return $this->creditCard;
}
/**
* Set newDashboardWelcomeMessage
*
* @param boolean $newDashboardWelcomeMessage
* @return User
*/
public function setNewDashboardWelcomeMessage($newDashboardWelcomeMessage)
{
$this->newDashboardWelcomeMessage = $newDashboardWelcomeMessage;
return $this;
}
/**
* Get newDashboardWelcomeMessage
*
* @return boolean
*/
public function getNewDashboardWelcomeMessage()
{
return $this->newDashboardWelcomeMessage;
}
/**
* @return int
*/
public function getEmailValidation()
{
return $this->emailValidation;
}
/**
* @param int $emailValidation
*/
public function setEmailValidation($emailValidation)
{
$this->emailValidation = $emailValidation;
}
/**
* @return string
*/
public function getEmailValidationToken()
{
return $this->emailValidationToken;
}
/**
* @param string $emailValidationToken
*/
public function setEmailValidationToken($emailValidationToken)
{
$this->emailValidationToken = $emailValidationToken;
}
/**
* @return string
*/
public function getEmailValidationTokenRequestedAt()
{
return $this->emailValidationTokenRequestedAt;
}
/**
* @param \DateTime $emailValidationTokenRequestedAt
*/
public function setEmailValidationTokenRequestedAt($emailValidationTokenRequestedAt)
{
$this->emailValidationTokenRequestedAt = $emailValidationTokenRequestedAt;
}
/**
* Add offers
*
* @param OfferStudent $offers
* @return User
*/
public function addOffer($offers)
{
$this->offers[] = $offers;
return $this;
}
/**
* Remove offers
*
* @param \Bo\StudentBundle\Entity\OfferStudent $offers
*/
public function removeOffer( $offers)
{
$this->offers->removeElement($offers);
}
/**
* @return null|Student
*/
public function getStudentEntity()
{
if ($this->offers->isEmpty() == false) {
$lastOfferStudent = $this->offers->last();
if ($lastOfferStudent) {
return $lastOfferStudent->getStudent();
}
}
return null;
}
/**
* @return null|Parents
*/
public function getParentEntity()
{
if ($this->offers->isEmpty() == false) {
$lastOfferStudent = $this->offers->last();
if ($lastOfferStudent) {
return $lastOfferStudent->getParent();
}
}
return null;
}
/**
* Add reports
*
* @param \Bo\ReportBundle\Entity\Report $reports
* @return User
*/
public function addReport( $reports)
{
$this->reports[] = $reports;
return $this;
}
/**
* Remove reports
*
* @param \Bo\ReportBundle\Entity\Report $reports
*/
public function removeReport( $reports)
{
$this->reports->removeElement($reports);
}
/**
* Add assessments
*
* @param \Bo\AdministratorsBundle\Entity\Assessment $assessments
* @return User
*/
public function addAssessment( $assessments)
{
$this->assessments[] = $assessments;
return $this;
}
/**
* Remove assessments
*
* @param \Bo\AdministratorsBundle\Entity\Assessment $assessments
*/
public function removeAssessment( $assessments)
{
$this->assessments->removeElement($assessments);
}
/**
* @return mixed
*/
public function getPopinShareGoodDeal()
{
return $this->popinShareGoodDeal;
}
/**
* @param mixed $popinShareGoodDeal
*/
public function setPopinShareGoodDeal($popinShareGoodDeal)
{
$this->popinShareGoodDeal = $popinShareGoodDeal;
}
/**
* @return string
*/
public function getDiscr()
{
return "other";
}
public function customCivility()
{
if ($this->civility == User::CIVILITY_MR) {
return "Monsieur";
}
return "Madame";
}
/**
* @return \DateTime
*/
public function getDateSychronisationIntercom()
{
return $this->dateSychronisationIntercom;
}
/**
* @param \DateTime $dateSychronisationIntercom
*/
public function setDateSychronisationIntercom(\DateTime $dateSychronisationIntercom): void
{
$this->dateSychronisationIntercom = $dateSychronisationIntercom;
}
/**
*
* Set civility by gender
* //NOTE : It's for student with gender but without civility
*
*/
public function setCivilityByGender()
{
if($this->civility === null and $this->gender !== null) {
switch ($this->gender) {
case self::GENDER_FEMALE :
$this->civility = self::CIVILITY_MISS;
break;
case self::GENDER_MALE :
$this->civility = self::CIVILITY_MR;
break;
}
}
}
public function getPassword() : string
{
return $this->password;
}
/**
* @param mixed $password
*/
public function setPassword($password): void
{
$this->password = $password;
}
public function getSalt()
{
return $this->salt;
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
$this->username = $username;
}
public function __call($name, $arguments)
{
// TODO: Implement @method string getUserIdentifier()
}
/**
* @return mixed
*/
public function getFileAvatar()
{
return $this->fileAvatar;
}
/**
* @param mixed $fileAvatar
*/
public function setFileAvatar($fileAvatar): void
{
$this->fileAvatar = $fileAvatar;
}
public function serialize($data, string $format, array $context = [])
{
// TODO: Implement serialize() method.
return serialize(array(
$this->id,
$this->password,
));
}
public function deserialize($data, string $type, string $format, array $context = [])
{
// TODO: Implement deserialize() method.
list (
$this->id,
$this->password,
) = unserialize($data, array('allowed_classes' => false));
}
public function getUserIdentifier(){
return $this->id;
}
public function isEqualTo(UserInterface $user)
{
// TODO: Implement isEqualTo() method.
return $user->getUserIdentifier() == $this->id;
}
/**
* @return mixed
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* @param mixed $enabled
*/
public function setEnabled($enabled): void
{
$this->enabled = $enabled;
}
public function setPlainPassword($password)
{
$this->plainPassword = $password;
return $this;
}
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* @return bool
*/
public function isVerified(): ?bool
{
return $this->isVerified;
}
/**
* @param bool $isVerified
*/
public function setIsVerified(bool $isVerified): void
{
$this->isVerified = $isVerified;
}
}