<?php
namespace App\Entity;
use App\Model\Uploadable;
use App\Service\KiboardToolsService;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* User
*
* @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\HasLifecycleCallbacks
* @UniqueEntity(fields="email", message="Cet email existe déjà")
*/
class User extends Uploadable implements UserInterface, PasswordAuthenticatedUserInterface, \Serializable
{
use TraitEntityAddons;
const DIRPATH = '../../data/';
const DIRNAME = 'pictures';
/**
* Civilities
*/
const CIV_MISTER = 1;
const CIV_MISS = 2;
const CIV_CONF = [
self::CIV_MISTER => [
'label' => 'M.',
'detail' => 'Monsieur',
'class' => 'dark',
'icon' => 'build/icon_men.png',
],
self::CIV_MISS => [
'label' => 'Mme',
'detail' => 'Madame',
'class' => 'dark',
'icon' => 'build/icon_women.png',
],
];
/**
* Types
*/
const TYPE_SALARIED = 1;
const TYPE_FREELANCE = 2;
const TYPE_CONF = [
self::TYPE_SALARIED => [
'label' => 'Salarié(e)',
'icon' => 'fa-building',
'class' => 'dark',
],
self::TYPE_FREELANCE => [
'label' => 'Indépendant(e)',
'icon' => 'fa-home',
'class' => 'info',
],
];
/**
* Roles
*/
const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
const ROLE_ADMIN = 'ROLE_ADMIN';
const ROLE_MANAGER = 'ROLE_MANAGER';
const ROLE_USER = 'ROLE_USER';
const ROLE_TELEMARKETING_MNG = 'ROLE_TELEMARKETING_MNG';
const ROLE_TELEMARKETING_USR = 'ROLE_TELEMARKETING_USR';
const ROLE_BIENPRETER_ADM = 'ROLE_BIENPRETER_ADM';
const ROLE_BIENPRETER_MNG = 'ROLE_BIENPRETER_MNG';
const ROLE_BIENPRETER_USR = 'ROLE_BIENPRETER_USR';
const ROLE_CONSULTING_ADM = 'ROLE_CONSULTING_ADM';
const ROLE_CONSULTING_MNG = 'ROLE_CONSULTING_MNG';
const ROLE_CONSULTING_USR = 'ROLE_CONSULTING_USR';
const ROLE_ADMINISTRATIVE_ADM = 'ROLE_ADMINISTRATIVE_ADM';
const ROLE_ADMINISTRATIVE_MNG = 'ROLE_ADMINISTRATIVE_MNG';
const ROLE_ADMINISTRATIVE_USR = 'ROLE_ADMINISTRATIVE_USR';
const ROLE_CONTRACT_PHOTOGRAPHER = 'ROLE_CONTRACT_PHOTOGRAPHER';
const ROLE_CONTRACT_WRITER = 'ROLE_CONTRACT_WRITER';
const ROLE_CONTRACT_LINKER = 'ROLE_CONTRACT_LINKER';
const ROLE_SPECIAL_HUMAN_RESOURCES = 'ROLE_SPECIAL_HUMAN_RESOURCES';
const ROLE_SPECIAL_ACCOUNTING = 'ROLE_SPECIAL_ACCOUNTING';
const ROLE_SPECIAL_LOGISTICS = 'ROLE_SPECIAL_LOGISTICS';
const ROLE_SPECIAL_DESIGNER = 'ROLE_SPECIAL_DESIGNER';
const ROLE_SPECIAL_LEGAL = 'ROLE_SPECIAL_LEGAL';
const ROLE_SPECIAL_SWISS_KNIFE = 'ROLE_SPECIAL_SWISS_KNIFE';
const ROLE_CONF = [
self::ROLE_SUPER_ADMIN => [
'label' => 'Super-Admin',
'class' => 'info',
],
self::ROLE_ADMIN => [
'label' => 'Administrateur',
'class' => 'info',
],
self::ROLE_MANAGER => [
'label' => 'Superviseur',
'class' => 'dark',
],
self::ROLE_USER => [
'label' => 'Utilisateur simple',
'class' => 'dark',
],
self::ROLE_TELEMARKETING_MNG => [
'label' => 'Téléprospection - Superviseur',
'class' => 'dark',
],
self::ROLE_TELEMARKETING_USR => [
'label' => 'Téléprospection',
'class' => 'light',
],
self::ROLE_BIENPRETER_ADM => [
'label' => 'Bienprêter - Superviseur',
'class' => 'dark',
],
self::ROLE_BIENPRETER_MNG => [
'label' => 'Bienprêter - Chargé d\'affaires',
'class' => 'dark',
],
self::ROLE_BIENPRETER_USR => [
'label' => 'Bienprêter',
'class' => 'dark',
],
self::ROLE_CONSULTING_ADM => [
'label' => 'Commercial - Directeur',
'class' => 'info',
],
self::ROLE_CONSULTING_MNG => [
'label' => 'Commercial - Superviseur',
'class' => 'dark',
],
self::ROLE_CONSULTING_USR => [
'label' => 'Commercial',
'class' => 'light',
],
self::ROLE_ADMINISTRATIVE_ADM => [
'label' => 'Administratif - Directeur',
'class' => 'info',
],
self::ROLE_ADMINISTRATIVE_MNG => [
'label' => 'Administratif - Superviseur',
'class' => 'dark',
],
self::ROLE_ADMINISTRATIVE_USR => [
'label' => 'Administratif - Suivi client',
'class' => 'light',
],
self::ROLE_CONTRACT_PHOTOGRAPHER => [
'label' => 'Contrat - Photographe',
'class' => 'dark',
],
self::ROLE_CONTRACT_WRITER => [
'label' => 'Contrat - Rédacteur',
'class' => 'dark',
],
self::ROLE_CONTRACT_LINKER => [
'label' => 'Contrat - Gestion des liens de diffusion',
'class' => 'dark',
],
self::ROLE_SPECIAL_HUMAN_RESOURCES => [
'label' => 'Ressources Humaines',
'class' => 'dark',
],
self::ROLE_SPECIAL_ACCOUNTING => [
'label' => 'Comptabilité',
'class' => 'dark',
],
self::ROLE_SPECIAL_LOGISTICS => [
'label' => 'Responsable Logistique',
'class' => 'dark',
],
self::ROLE_SPECIAL_DESIGNER => [
'label' => 'Graphiste / Gestion Front',
'class' => 'dark',
],
self::ROLE_SPECIAL_LEGAL => [
'label' => 'Juridique',
'class' => 'dark',
],
self::ROLE_SPECIAL_SWISS_KNIFE => [
'label' => 'Couteau suisse',
'class' => 'dark',
],
];
const EXTRA_ROLE_TELEMARKETING = 'EXTRA_ROLE_TELEMARKETING';
const EXTRA_ROLE_CONTRACT_VALIDATE = 'EXTRA_ROLE_CONTRACT_VALIDATE';
const EXTRA_ROLE_CONTRACT_CANCEL = 'EXTRA_ROLE_CONTRACT_CANCEL';
const EXTRA_ROLE_CONTRACT_PRICE = 'EXTRA_ROLE_CONTRACT_PRICE';
const EXTRA_ROLE_CONTRACT_YOUSIGN = 'EXTRA_ROLE_CONTRACT_YOUSIGN';
const EXTRA_ROLE_CONTRACT_ARCHIVED = 'EXTRA_ROLE_CONTRACT_ARCHIVED';
const EXTRA_ROLE_CONTRACT_NETTY = 'EXTRA_ROLE_CONTRACT_NETTY';
const EXTRA_ROLE_CONTRACT_PROMUP = 'EXTRA_ROLE_CONTRACT_PROMUP';
const EXTRA_ROLE_CONTRACT_KIMPLI = 'EXTRA_ROLE_CONTRACT_KIMPLI';
const EXTRA_ROLE_CONF = [
self::EXTRA_ROLE_TELEMARKETING => [
'label' => 'Téléprospection',
'class' => 'info',
],
self::EXTRA_ROLE_CONTRACT_VALIDATE => [
'label' => 'Validation des contrats',
'class' => 'info',
],
self::EXTRA_ROLE_CONTRACT_CANCEL => [
'label' => 'Annulation des contrats',
'class' => 'info',
],
self::EXTRA_ROLE_CONTRACT_PRICE => [
'label' => 'Modification du prix des contrats',
'class' => 'info',
],
self::EXTRA_ROLE_CONTRACT_YOUSIGN => [
'label' => 'Signature Yousign',
'class' => 'info',
],
self::EXTRA_ROLE_CONTRACT_ARCHIVED => [
'label' => 'Gestion des contrats archivés',
'class' => 'info',
],
self::EXTRA_ROLE_CONTRACT_NETTY => [
'label' => 'Gestion de la synchro Netty',
'class' => 'info',
],
self::EXTRA_ROLE_CONTRACT_PROMUP => [
'label' => 'Gestion de l\'interface Promup',
'class' => 'info',
],
self::EXTRA_ROLE_CONTRACT_KIMPLI => [
'label' => 'Gestion de l\'interface Kimpli',
'class' => 'info',
],
];
const UNIVERSE_BIENPRETER = 'UNIVERSE_BIENPRETER';
const UNIVERSE_PROMUP = 'UNIVERSE_PROMUP';
const UNIVERSE_KIMPLI = 'UNIVERSE_KIMPLI';
const UNIVERSE_CONF = [
self::UNIVERSE_BIENPRETER => [
'label' => 'Bienprêter',
'code' => 'bienpreter',
'class' => 'primary',
'logo' => 'build/logo_bienpreter.png',
'url_prod' => 'https://www.bienpreter.com',
'url_path' => '/connected',
'auto_login' => false,
'sync_users' => false,
],
self::UNIVERSE_PROMUP => [
'label' => 'Promup',
'code' => 'promup',
'class' => 'primary',
'logo' => 'build/logo_promup.png',
'url_prod' => 'https://www.promup.com',
'url_path' => KiboardToolsService::URL_AUTH,
'auto_login' => true,
'sync_users' => true,
],
self::UNIVERSE_KIMPLI => [
'label' => 'Kimpli',
'code' => 'kimpli',
'class' => 'primary',
'logo' => 'build/logo_kimpli.png',
'url_prod' => 'https://www.kimpli.com',
'url_path' => KiboardToolsService::URL_AUTH,
'auto_login' => true,
'sync_users' => true,
],
];
/**
* @var int|null
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
/**
* @var RefDepartment
*
* @ORM\OneToOne(targetEntity="RefDepartment", inversedBy="userConsulting", cascade={"persist"})
*/
private $exclusiveDepartment;
/**
* @var RefDepartment[]
*
* @ORM\OneToMany(targetEntity="RefDepartment", mappedBy="userCustomerService", cascade={"persist", "remove"})
*/
private $exclusiveDepartments;
/**
* @var Contract[]
* @ORM\OneToMany(targetEntity="Contract", mappedBy="userConsulting")
*/
private $contracts;
/**
* @var CustomerMessage[]
* @ORM\OneToMany(targetEntity="CustomerMessage", mappedBy="userCustomerService")
*/
private $messages;
/**
* @var UserActivity[]
* @ORM\OneToMany(targetEntity="UserActivity", mappedBy="user", cascade={"persist", "remove"})
*/
private $activities;
/**
* @var string
*
* @ORM\Column(name="filename", type="string", length=150, nullable=true, unique=true)
*/
protected $filename;
/**
* @var string
*
* @ORM\Column(name="address", type="text", nullable=true)
*/
private $address;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=150, unique=true)
* @Assert\Email()
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="slack_id", type="string", length=100, nullable=true)
*/
private $slackId;
/**
* @var string
*
* @ORM\Column(name="civility", type="integer", length=1)
*/
private $civility;
/**
* @var string
*
* @ORM\Column(name="first_name", type="string", length=100)
*/
private $firstName;
/**
* @var string
*
* @ORM\Column(name="last_name", type="string", length=100)
*/
private $lastName;
/**
* @var string
*
* @ORM\Column(name="email_home", type="string", length=150)
* @Assert\Email()
*/
private $emailHome;
/**
* @var string
*
* @ORM\Column(name="phone_home", type="string", nullable=true, length=50)
*/
private $phoneHome;
/**
* @var string
*
* @ORM\Column(name="phone_work", type="string", nullable=true, length=50)
*/
private $phoneWork;
/**
* @var int
*
* @ORM\Column(name="type", type="integer")
*/
private $type;
/**
* @var array
*
* @ORM\Column(name="roles", type="array")
*/
private $roles;
/**
* @var array
*
* @ORM\Column(name="extra_roles", type="array")
*/
private $extraRoles;
/**
* @var array
*
* @ORM\Column(name="universes", type="array")
*/
private $universes;
/**
* @var bool
*
* @ORM\Column(name="is_locked", type="boolean", options={"default": 0})
*/
private $isLocked;
/**
* @var array
*
* @ORM\Column(name="logs", type="array")
*/
private $logs;
/**
* @var \DateTime
*
* @ORM\Column(name="connected_at", type="datetime", nullable=true)
*/
private $connectedAt;
/**
* @param bool $bShowOnlyPublic
*
* @return array
*/
public function toArray(bool $bShowOnlyPublic = true): array
{
$aData = $this->buildArray([
'id', 'logs', 'activities', 'messages', 'password',
'contracts', 'documents', 'connectedAt', 'exclusiveDepartment', 'exclusiveDepartments',
]);
$aData['phone'] = $bShowOnlyPublic ? $this->phoneWork : $this->getPhone();
$aData['fullName'] = $this->getFullName();
$aData['halfName'] = $this->getHalfName();
if ($bShowOnlyPublic) {
$aAllowedFields = ['fullName', 'halfName', 'email', 'phone', 'civility'];
foreach ($aData as $sKey => $sField) {
if (!in_array($sKey, $aAllowedFields)) {
unset($aData[$sKey]);
}
}
}
return $aData;
}
/**
* @param User $oUser
* @param string $sMessage
* @param null $oDate
*
* @return self
* @throws \Exception
*/
public function addLog(User $oUser, string $sMessage, $oDate = null): User
{
$oDate = $oDate ?? new \DateTime();
$this->logs[] = implode(' ', ['['.$oDate->format('d/m/Y H:i').']', '['.$oUser->getHalfName().']', $sMessage]);
return $this;
}
/**
* @return string
*/
public function getExclusiveDepartmentsList(): string
{
$aCodes = [];
foreach ($this->exclusiveDepartments as $oDep) {
$aCodes[] = $oDep->getCode();
}
return implode(' - ', $aCodes);
}
public function getUser(): User
{
return $this;
}
public function getRole()
{
return $this->roles ? $this->roles[0] : null;
}
public function setRole($role): self
{
$this->roles = [$role];
return $this;
}
/**
* @return string
*/
public function getUsername(): ?string
{
return $this->getUserIdentifier();
}
/**
* @return string
*/
public function getUserIdentifier(): ?string
{
return $this->getEmail();
}
/**
* @return string
*/
public function getPassword(): ?string
{
return $this->password;
}
public function getSalt()
{
// you *may* need a real salt depending on your encoder
// see section on salt below
return null;
}
/**
* Get the user roles
*
* @return array
*/
public function getRoles(): array
{
return $this->roles;
}
public function eraseCredentials()
{
}
/**
* Constructor
*/
public function __construct()
{
$this->civility = self::CIV_MISTER;
$this->isLocked = false;
$this->logs = [];
$this->roles = $this->extraRoles = $this->universes = [];
$this->documents = new ArrayCollection();
$this->contracts = new ArrayCollection();
$this->messages = new ArrayCollection();
$this->exclusiveDepartments = new ArrayCollection();
$this->activities = new ArrayCollection();
}
/**
* @inheritDoc
*/
public function serialize()
{
return serialize(array(
$this->id,
$this->email,
$this->password
));
}
/**
* @inheritDoc
*/
public function unserialize($serialized)
{
[
$this->id,
$this->email,
$this->password,
] = unserialize($serialized);
}
/**
* @return string
*/
public function getName(): string
{
return $this->getFullName();
}
/**
* @return string|null
*/
public function getPhone(): ?string
{
return $this->phoneWork ? $this->phoneWork : $this->phoneHome;
}
/**
* @return string
*/
public function __toString(): string
{
return $this->getFullName();
}
/**
* @return string
*/
public function getHalfName(): string
{
return ucfirst($this->firstName) .' '. ($this->lastName ? mb_strtoupper($this->lastName[0]) : '') . '.';
}
/**
* @return string
*/
public function getFullName(): string
{
return ucfirst($this->firstName) .' '. mb_strtoupper($this->lastName);
}
/**
* @return string
*/
public function getReverseFullName(): string
{
return mb_strtoupper($this->lastName) .' '. ucfirst($this->firstName);
}
/**
* @return string
*/
public function getExtraFullName(): string
{
return $this->id . ' - ' . ucfirst($this->firstName) .' '. mb_strtoupper($this->lastName);
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function setPassword(?string $password): self
{
$this->password = $password;
return $this;
}
public function setRoles($roles): self
{
$this->roles = is_array($roles) ? $roles : [$roles];
return $this;
}
public function getIsLocked(): ?bool
{
return $this->isLocked;
}
public function setIsLocked(bool $isLocked): self
{
$this->isLocked = $isLocked;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getConnectedAt(): ?\DateTimeInterface
{
return $this->connectedAt;
}
public function setConnectedAt(\DateTimeInterface $connectedAt): self
{
$this->connectedAt = $connectedAt;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getCivility(): ?int
{
return $this->civility;
}
public function setCivility(int $civility): self
{
$this->civility = $civility;
return $this;
}
public function getPhoneHome(): ?string
{
return $this->phoneHome;
}
public function setPhoneHome(?string $phoneHome): self
{
$this->phoneHome = str_replace(['+33', ' '], ['0', ''], $phoneHome);
return $this;
}
public function getPhoneWork(): ?string
{
return $this->phoneWork;
}
public function setPhoneWork(?string $phoneWork): self
{
$this->phoneWork = str_replace(['+33', ' '], ['0', ''], $phoneWork);
return $this;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
public function getEmailHome(): ?string
{
return $this->emailHome;
}
public function setEmailHome(string $emailHome): self
{
$this->emailHome = $emailHome;
return $this;
}
public function getFilename(): ?string
{
return $this->filename;
}
public function setFilename(?string $filename): self
{
$this->filename = $filename;
return $this;
}
/**
* @return Collection|Contract[]
*/
public function getContracts(): Collection
{
return $this->contracts;
}
public function addContract(Contract $contract): self
{
if (!$this->contracts->contains($contract)) {
$this->contracts[] = $contract;
$contract->setUserConsulting($this);
}
return $this;
}
public function removeContract(Contract $contract): self
{
if ($this->contracts->contains($contract)) {
$this->contracts->removeElement($contract);
// set the owning side to null (unless already changed)
if ($contract->getUserConsulting() === $this) {
$contract->setUserConsulting(null);
}
}
return $this;
}
public function getExclusiveDepartment(): ?RefDepartment
{
return $this->exclusiveDepartment;
}
public function setExclusiveDepartment(?RefDepartment $exclusiveDepartment): self
{
$this->exclusiveDepartment = $exclusiveDepartment;
return $this;
}
public function getLogs(): ?array
{
return $this->logs;
}
public function setLogs(array $logs): self
{
$this->logs = $logs;
return $this;
}
/**
* @return Collection|CustomerMessage[]
*/
public function getMessages(): Collection
{
return $this->messages;
}
public function addMessage(CustomerMessage $message): self
{
if (!$this->messages->contains($message)) {
$this->messages[] = $message;
$message->setUserCustomerService($this);
}
return $this;
}
public function removeMessage(CustomerMessage $message): self
{
if ($this->messages->removeElement($message)) {
// set the owning side to null (unless already changed)
if ($message->getUserCustomerService() === $this) {
$message->setUserCustomerService(null);
}
}
return $this;
}
public function getExtraRoles(): ?array
{
return $this->extraRoles;
}
public function setExtraRoles(array $extraRoles): self
{
$this->extraRoles = $extraRoles;
return $this;
}
/**
* @return Collection|RefDepartment[]
*/
public function getExclusiveDepartments(): Collection
{
return $this->exclusiveDepartments;
}
public function syncExclusiveDepartments(array $aOldDeps): self
{
foreach ($aOldDeps as $oDep) {
if (!$this->exclusiveDepartments->contains($oDep) && ($oDep->getUserCustomerService() === $this)) {
$oDep->setUserCustomerService(null);
}
}
foreach ($this->exclusiveDepartments->toArray() as $oDep) {
$oDep->setUserCustomerService($this);
}
return $this;
}
public function addExclusiveDepartment(RefDepartment $exclusiveDepartment): self
{
if (!$this->exclusiveDepartments->contains($exclusiveDepartment)) {
$this->exclusiveDepartments[] = $exclusiveDepartment;
$exclusiveDepartment->setUserCustomerService($this);
}
return $this;
}
public function removeExclusiveDepartment(RefDepartment $exclusiveDepartment): self
{
if ($this->exclusiveDepartments->removeElement($exclusiveDepartment)) {
// set the owning side to null (unless already changed)
if ($exclusiveDepartment->getUserCustomerService() === $this) {
$exclusiveDepartment->setUserCustomerService(null);
}
}
return $this;
}
public function getSlackId(): ?string
{
return $this->slackId;
}
public function setSlackId(?string $slackId): self
{
$this->slackId = $slackId;
return $this;
}
public function getUniverses(): ?array
{
return $this->universes;
}
public function setUniverses(array $universes): self
{
$this->universes = $universes;
return $this;
}
public function isIsLocked(): ?bool
{
return $this->isLocked;
}
/**
* @return Collection<int, UserActivity>
*/
public function getActivities(): Collection
{
return $this->activities;
}
public function addActivity(UserActivity $activity): self
{
if (!$this->activities->contains($activity)) {
$this->activities[] = $activity;
$activity->setUser($this);
}
return $this;
}
public function removeActivity(UserActivity $activity): self
{
if ($this->activities->removeElement($activity)) {
// set the owning side to null (unless already changed)
if ($activity->getUser() === $this) {
$activity->setUser(null);
}
}
return $this;
}
}