<?php
namespace CoreBundle\Entity;
use CoreBundle\Entity\Common\MmppUserInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;
/**
* Tutor
*
* @ORM\Table(name="tutor")
* @ORM\Entity(repositoryClass="CoreBundle\Repository\TutorRepository")
*/
#[Type]
class Tutor implements MmppUserInterface, \Serializable
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(type="string")
* @Assert\NotBlank
*/
private $login;
/**
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string")
* @Assert\NotBlank
*/
private $firstname;
/**
* @ORM\Column(type="string")
* @Assert\NotBlank
*/
private $lastname;
/**
* @ORM\Column(type="string")
* @Assert\NotBlank
* @Assert\Email
*/
private $email;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $avatar;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $admin;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $active;
/**
* @ORM\Column(type="datetimetz", name="logged_on", nullable=true)
*/
private $loggedOn;
/**
* @ORM\Column(type="datetimetz", name="last_activity", nullable=true)
*/
private $lastActivity;
/**
* @ORM\Column(type="string", length=32, nullable=true)
*/
private $token;
/**
* @todo à refaire
* 1 = centre, 2 = bordeaux, 3 = antilles
*
* @ORM\Column(type="integer")
* @var integer
*/
private $groupId;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": false})
* @var boolean
*/
private $apiAccess;
/**
* @ORM\OneToMany(targetEntity="Post", mappedBy="tutor")
* @ORM\OrderBy({"createdOn" = "DESC"})
*/
private $posts;
/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="tutorsConnected", )
* @ORM\JoinColumn(name="last_category_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $lastCategory;
/**
* @ORM\ManyToMany(targetEntity="GroupStudent", inversedBy="tutors")
* @ORM\JoinTable(name="tutor_group", inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")})
*/
private $groups;
/**
* @ORM\ManyToMany(targetEntity="Activity", inversedBy="tutors")
* @ORM\JoinTable(name="tutor_activity")
* @ORM\OrderBy({"name":"asc"})
*/
private $activities;
/**
* @ORM\ManyToMany(targetEntity="Module", inversedBy="tutors")
* @ORM\JoinTable(name="tutor_module")
* @ORM\OrderBy({"name":"asc"})
*/
private $modules;
/**
* @ORM\ManyToMany(targetEntity="Secteur", inversedBy="tutors")
* @ORM\JoinTable(name="tutor_secteur")
*/
private $secteurs;
/**
* Permet d'ajouter des droits d'accès supplémentaires à une catégory pour un tutor,
* sans passer par les branches/secteurs
*
* @ORM\ManyToMany(targetEntity="Category", inversedBy="tutors")
* @ORM\JoinTable(name="forum_tutors_categories")
*/
private $categories;
/**
* @ORM\OneToMany(targetEntity="QuestionnaireComment", mappedBy="tutor")
*/
private $comments;
/**
* @ORM\OneToMany(targetEntity="EdtLesson", mappedBy="tutor")
*/
private $edtLessons;
/**
* @ORM\OneToMany(targetEntity="QuestionnaireQcmQuestion", mappedBy="tutor")
*/
private $questions;
/**
* @ORM\OneToMany(targetEntity="Calendar", mappedBy="tutor")
*/
private $calendars;
/**
* @ORM\OneToMany(targetEntity="CalendarEvent", mappedBy="tutor")
*/
private $calendarEvents;
/**
* @ORM\OneToMany(targetEntity="QuestionnaireRangeQuestion", mappedBy="tutor")
*/
private $rangeQuestions;
/**
* @ORM\OneToMany(targetEntity="NoteTestGroup", mappedBy="tutor")
*/
private $noteTestGroups;
/**
* @ORM\OneToMany(targetEntity="NoteTestStudentLog", mappedBy="tutor")
*/
private $noteTestStudentLogs;
/**
* Pour faire la distinction entre tutor et student
* @var string
*/
public $class = 'tutor';
/**
* Pour le FormType
* @var string
*/
private $plainPassword;
/**
* @ORM\OneToMany(targetEntity="NoteTestStudent", mappedBy="tutor")
*/
private $noteTestStudents;
/**
* @ORM\Column(type="string", nullable=true)
* @var string
*/
#[Field]
private $firebaseToken;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
* @var \DateTimeImmutable
*/
#[Field]
private $firebaseTokenDate;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $qrCode;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private ?\DateTimeImmutable $qrCodeDate;
/**
* Constructor
*/
public function __construct()
{
$this->active = true;
$this->posts = new \Doctrine\Common\Collections\ArrayCollection();
$this->groups = new ArrayCollection();
$this->activities = new ArrayCollection();
$this->secteurs = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->edtLessons = new ArrayCollection();
$this->questions = new ArrayCollection();
$this->calendars = new ArrayCollection();
$this->calendarEvents = new ArrayCollection();
$this->rangeQuestions = new ArrayCollection();
$this->noteTestGroups = new ArrayCollection();
$this->modules = new ArrayCollection();
$this->noteTestStudents = new ArrayCollection();
$this->noteTestStudentLogs = new ArrayCollection();
}
/**
* Get id
*
* @return int
*/
#[Field(outputType: "ID")]
public function getId()
{
return $this->id;
}
public function getSalt()
{
// you *may* need a real salt depending on your encoder
// see section on salt below
return null;
}
public function getUsername()
{
return $this->login;
}
public function getUserIdentifier(): string
{
return $this->login;
}
public function getRoles()
{
if ($this->getAdmin()) {
return array('ROLE_ADMIN');
}
if ($this->getApiAccess()) {
return array('ROLE_API');
}
return array('ROLE_TUTOR');
}
public function eraseCredentials()
{
}
public function serialize()
{
return serialize(array(
$this->id,
$this->login,
$this->email,
$this->password,
));
}
public function unserialize($serialized)
{
list (
$this->id,
$this->login,
$this->email,
$this->password,
) = unserialize($serialized);
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
/**
* Set login
*
* @param string $login
*
* @return Tutor
*/
public function setLogin($login)
{
$this->login = $login;
return $this;
}
/**
* Get login
*
* @return string
*/
public function getLogin()
{
return $this->login;
}
#[Field]
public function getName(): string
{
return $this->firstname.' '.$this->lastname;
}
/**
* Set firstname
*
* @param string $firstname
*
* @return Tutor
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Get firstname
*
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set lastname
*
* @param string $lastname
*
* @return Tutor
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname
*
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set email
*
* @param string $email
*
* @return Tutor
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set phone
*
* @param string $phone
*
* @return Tutor
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Get disabled
*
* @return boolean
*/
public function getDisabled()
{
return !$this->active;
}
/**
* Set admin
*
* @param boolean $admin
*
* @return Tutor
*/
public function setAdmin($admin)
{
$this->admin = $admin;
return $this;
}
/**
* Get admin
*
* @return boolean
*/
#[Field]
public function getAdmin(): bool
{
return $this->admin ?? false;
}
/**
* Set loggedOn
*
* @param \DateTime $loggedOn
*
* @return Tutor
*/
public function setLoggedOn($loggedOn)
{
$this->loggedOn = $loggedOn;
return $this;
}
/**
* Get loggedOn
*
* @return \DateTime
*/
public function getLoggedOn()
{
return $this->loggedOn;
}
/**
* @return bool whether the user is active or not
*/
public function isActiveNow()
{
$delay = new \DateTime('20 minutes ago');
return ($this->getlastActivity()>$delay);
}
/**
* Set lastActivity
*
* @param \DateTime $lastActivity
*
* @return Tutor
*/
public function setLastActivity($lastActivity)
{
$this->lastActivity = $lastActivity;
return $this;
}
/**
* Get lastActivity
*
* @return \DateTime
*/
public function getLastActivity()
{
return $this->lastActivity;
}
/**
* Add post
*
* @param \CoreBundle\Entity\Post $post
*
* @return Tutor
*/
public function addPost(\CoreBundle\Entity\Post $post)
{
$this->posts[] = $post;
return $this;
}
/**
* Remove post
*
* @param \CoreBundle\Entity\Post $post
*/
public function removePost(\CoreBundle\Entity\Post $post)
{
$this->posts->removeElement($post);
}
/**
* Get posts
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPosts()
{
return $this->posts;
}
/**
* Set lastCategory
*
* @param \CoreBundle\Entity\Category $lastCategory
*
* @return Tutor
*/
public function setLastCategory(\CoreBundle\Entity\Category $lastCategory = null)
{
$this->lastCategory = $lastCategory;
return $this;
}
/**
* Get lastCategory
*
* @return \CoreBundle\Entity\Category
*/
public function getLastCategory()
{
return $this->lastCategory;
}
/**
* Add group
*
* @param \CoreBundle\Entity\GroupStudent $group
*
* @return Tutor
*/
public function addGroup(\CoreBundle\Entity\GroupStudent $group)
{
$this->groups[] = $group;
return $this;
}
/**
* Remove group
*
* @param \CoreBundle\Entity\GroupStudent $group
*/
public function removeGroup(\CoreBundle\Entity\GroupStudent $group)
{
$this->groups->removeElement($group);
}
/**
* Get groups
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getGroups()
{
return $this->groups;
}
/**
* Add activity
*
* @param \CoreBundle\Entity\Activity $activity
*
* @return Tutor
*/
public function addActivity(\CoreBundle\Entity\Activity $activity)
{
$this->activities[] = $activity;
return $this;
}
/**
* Remove activity
*
* @param \CoreBundle\Entity\Activity $activity
*/
public function removeActivity(\CoreBundle\Entity\Activity $activity)
{
$this->activities->removeElement($activity);
}
/**
* Get activities
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getActivities()
{
return $this->activities;
}
/**
* Set avatar
*
* @param string $avatar
*
* @return Tutor
*/
public function setAvatar($avatar)
{
$this->avatar = $avatar;
return $this;
}
/**
* Get avatar
*
* @return string
*/
public function getAvatar()
{
return $this->avatar;
}
/**
* Add category
*
* @param \CoreBundle\Entity\Category $category
*
* @return Tutor
*/
public function addCategory(\CoreBundle\Entity\Category $category)
{
$this->categories[] = $category;
return $this;
}
/**
* Remove category
*
* @param \CoreBundle\Entity\Category $category
*/
public function removeCategory(\CoreBundle\Entity\Category $category)
{
$this->categories->removeElement($category);
}
/**
* Get categories
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCategories()
{
return $this->categories;
}
public function addComment(QuestionnaireComment $comment)
{
$this->comments[] = $comment;
return $this;
}
public function removeComment(QuestionnaireComment $comment)
{
$this->comments->removeElement($comment);
}
public function getComments(): Collection
{
return $this->comments;
}
public function addQuestion(QuestionnaireQcmQuestion $question): self
{
$this->questions[] = $question;
return $this;
}
public function removeQuestion(QuestionnaireQcmQuestion $question)
{
$this->questions->removeElement($question);
}
public function getQuestions(): Collection
{
return $this->questions;
}
public function addRangeQuestion(QuestionnaireRangeQuestion $rangeQuestion): self
{
$this->rangeQuestions[] = $rangeQuestion;
return $this;
}
public function removeRangeQuestion(QuestionnaireRangeQuestion $rangeQuestion)
{
$this->rangeQuestions->removeElement($rangeQuestion);
}
public function getRangeQuestions(): Collection
{
return $this->rangeQuestions;
}
/**
* Set token
*
* @param string $token
*
* @return Tutor
*/
public function setToken($token)
{
$this->token = $token;
return $this;
}
/**
* Get token
*
* @return string
*/
public function getToken()
{
return $this->token;
}
/**
* Set groupId
*
* @param integer $groupId
*
* @return Tutor
*/
public function setGroupId($groupId)
{
$this->groupId = $groupId;
return $this;
}
/**
* Get groupId
*
* @return integer
*/
public function getGroupId()
{
return $this->groupId;
}
/**
* Add secteur
*
* @param \CoreBundle\Entity\Secteur $secteur
*
* @return Tutor
*/
public function addSecteur(\CoreBundle\Entity\Secteur $secteur)
{
$this->secteurs[] = $secteur;
return $this;
}
/**
* Remove secteur
*
* @param \CoreBundle\Entity\Secteur $secteur
*/
public function removeSecteur(\CoreBundle\Entity\Secteur $secteur)
{
$this->secteurs->removeElement($secteur);
}
/**
* Get secteurs
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getSecteurs()
{
return $this->secteurs;
}
/**
* @return string
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* @param string $plainPassword
*
* @return Tutor
*/
public function setPlainPassword($plainPassword)
{
$this->plainPassword = $plainPassword;
return $this;
}
/**
* Add edtLesson
*
* @param \CoreBundle\Entity\EdtLesson $edtLesson
*
* @return Tutor
*/
public function addEdtLesson(\CoreBundle\Entity\EdtLesson $edtLesson)
{
$this->edtLessons[] = $edtLesson;
return $this;
}
/**
* Remove edtLesson
*
* @param \CoreBundle\Entity\EdtLesson $edtLesson
*/
public function removeEdtLesson(\CoreBundle\Entity\EdtLesson $edtLesson)
{
$this->edtLessons->removeElement($edtLesson);
}
/**
* Get edtLessons
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getEdtLessons()
{
return $this->edtLessons;
}
/**
* Add calendar
*
* @param \CoreBundle\Entity\Calendar $calendar
*
* @return Tutor
*/
public function addCalendar(\CoreBundle\Entity\Calendar $calendar)
{
$this->calendars[] = $calendar;
return $this;
}
/**
* Remove calendar
*
* @param \CoreBundle\Entity\Calendar $calendar
*/
public function removeCalendar(\CoreBundle\Entity\Calendar $calendar)
{
$this->calendars->removeElement($calendar);
}
/**
* Get calendars
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCalendars()
{
return $this->calendars;
}
/**
* Add calendarEvent
*
* @param \CoreBundle\Entity\CalendarEvent $calendarEvent
*
* @return Tutor
*/
public function addCalendarEvent(\CoreBundle\Entity\CalendarEvent $calendarEvent)
{
$this->calendarEvents[] = $calendarEvent;
return $this;
}
/**
* Remove calendarEvent
*
* @param \CoreBundle\Entity\CalendarEvent $calendarEvent
*/
public function removeCalendarEvent(\CoreBundle\Entity\CalendarEvent $calendarEvent)
{
$this->calendarEvents->removeElement($calendarEvent);
}
/**
* Get calendarEvents
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCalendarEvents()
{
return $this->calendarEvents;
}
/**
* Add noteTestGroup
*
* @param \CoreBundle\Entity\NoteTestGroup $noteTestGroup
*
* @return Tutor
*/
public function addNoteTestGroup(\CoreBundle\Entity\NoteTestGroup $noteTestGroup)
{
$this->noteTestGroups[] = $noteTestGroup;
return $this;
}
/**
* Remove noteTestGroup
*
* @param \CoreBundle\Entity\NoteTestGroup $noteTestGroup
*/
public function removeNoteTestGroup(\CoreBundle\Entity\NoteTestGroup $noteTestGroup)
{
$this->noteTestGroups->removeElement($noteTestGroup);
}
/**
* Get noteTestGroups
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getNoteTestGroups()
{
return $this->noteTestGroups;
}
/**
* @return boolean
*/
public function getApiAccess()
{
return $this->apiAccess;
}
/**
* @param boolean $apiAccess
*
* @return Tutor
*/
public function setApiAccess($apiAccess)
{
$this->apiAccess = $apiAccess;
return $this;
}
/**
* @return mixed
*/
public function getActive(): ?bool
{
return $this->active;
}
/**
* @param mixed $active
*
* @return Tutor
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* @return Collection|Module[]
*/
public function getModules(): Collection
{
return $this->modules;
}
public function addModule(Module $module): self
{
if (!$this->modules->contains($module)) {
$this->modules[] = $module;
}
return $this;
}
public function removeModule(Module $module): self
{
$this->modules->removeElement($module);
return $this;
}
public function getNoteTestStudents()
{
return $this->noteTestStudents;
}
public function setNoteTestStudents($noteTestStudents)
{
$this->noteTestStudents = $noteTestStudents;
return $this;
}
public function addNoteTestStudent(NoteTestStudent $noteTestStudent): self
{
if (!$this->noteTestStudents->contains($noteTestStudent)) {
$this->noteTestStudents[] = $noteTestStudent;
$noteTestStudent->setTutor($this);
}
return $this;
}
public function removeNoteTestStudent(NoteTestStudent $noteTestStudent): self
{
if ($this->noteTestStudents->removeElement($noteTestStudent)) {
// set the owning side to null (unless already changed)
if ($noteTestStudent->getTutor() === $this) {
$noteTestStudent->setTutor(null);
}
}
return $this;
}
public function getFirebaseToken(): ?string
{
return $this->firebaseToken;
}
public function setFirebaseToken(?string $firebaseToken): self
{
$this->firebaseToken = $firebaseToken;
return $this;
}
public function getFirebaseTokenDate(): ?\DateTimeImmutable
{
return $this->firebaseTokenDate;
}
public function setFirebaseTokenDate(?\DateTimeImmutable $firebaseTokenDate): self
{
$this->firebaseTokenDate = $firebaseTokenDate;
return $this;
}
public function getQrCode(): ?string
{
return $this->qrCode;
}
public function setQrCode(?string $qrCode): self
{
$this->qrCode = $qrCode;
return $this;
}
public function getQrCodeDate(): ?\DateTimeImmutable
{
return $this->qrCodeDate;
}
public function setQrCodeDate(?\DateTimeImmutable $qrCodeDate): self
{
$this->qrCodeDate = $qrCodeDate;
return $this;
}
public function isAdmin(): ?bool
{
return $this->admin;
}
public function isActive(): ?bool
{
return $this->active;
}
public function isApiAccess(): ?bool
{
return $this->apiAccess;
}
/**
* @return Collection<int, NoteTestStudentLog>
*/
public function getNoteTestStudentLogs(): Collection
{
return $this->noteTestStudentLogs;
}
public function addNoteTestStudentLog(NoteTestStudentLog $noteTestStudentLog): self
{
if (!$this->noteTestStudentLogs->contains($noteTestStudentLog)) {
$this->noteTestStudentLogs->add($noteTestStudentLog);
$noteTestStudentLog->setTutor($this);
}
return $this;
}
public function removeNoteTestStudentLog(NoteTestStudentLog $noteTestStudentLog): self
{
if ($this->noteTestStudentLogs->removeElement($noteTestStudentLog)) {
// set the owning side to null (unless already changed)
if ($noteTestStudentLog->getTutor() === $this) {
$noteTestStudentLog->setTutor(null);
}
}
return $this;
}
}