mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,30 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
* User
|
||||
* User.
|
||||
*
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="users")
|
||||
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="acl_cache_region")
|
||||
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "user"=User::class
|
||||
* "user": User::class
|
||||
* })
|
||||
*/
|
||||
class User implements AdvancedUserInterface {
|
||||
|
||||
class User implements AdvancedUserInterface
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
@@ -33,28 +39,18 @@ class User implements AdvancedUserInterface {
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* Array where SAML attributes's data are stored.
|
||||
*
|
||||
* @ORM\Column(type="string", length=80)
|
||||
* @var array
|
||||
*
|
||||
* @ORM\Column(type="json", nullable=true)
|
||||
*/
|
||||
private $username;
|
||||
private $attributes;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(
|
||||
* type="string",
|
||||
* length=80,
|
||||
* unique=true,
|
||||
* nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity=Location::class)
|
||||
*/
|
||||
private $usernameCanonical;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=200)
|
||||
* @Serializer\Groups({"docgen:read"})
|
||||
*/
|
||||
private string $label = '';
|
||||
private ?Location $currentLocation = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -71,35 +67,12 @@ class User implements AdvancedUserInterface {
|
||||
* type="string",
|
||||
* length=150,
|
||||
* nullable=true,
|
||||
* unique=true)
|
||||
* unique=true)
|
||||
*/
|
||||
private $emailCanonical;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255)
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @internal must be set to null if we use bcrypt
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $salt = null;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*
|
||||
* @ORM\Column(type="boolean")
|
||||
* sf4 check: in yml was false by default !?
|
||||
*/
|
||||
private $locked = true;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
@@ -110,43 +83,74 @@ class User implements AdvancedUserInterface {
|
||||
*
|
||||
* @ORM\ManyToMany(
|
||||
* targetEntity="Chill\MainBundle\Entity\GroupCenter",
|
||||
* inversedBy="users")
|
||||
* inversedBy="users")
|
||||
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
|
||||
*/
|
||||
private $groupCenters;
|
||||
|
||||
/**
|
||||
* Array where SAML attributes's data are stored
|
||||
* @var array
|
||||
*
|
||||
* @ORM\Column(type="json", nullable=true)
|
||||
* @ORM\Column(type="string", length=200)
|
||||
* @Serializer\Groups({"docgen:read"})
|
||||
*/
|
||||
private $attributes;
|
||||
private string $label = '';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*
|
||||
* @ORM\Column(type="boolean")
|
||||
* sf4 check: in yml was false by default !?
|
||||
*/
|
||||
private $locked = true;
|
||||
|
||||
/**
|
||||
* @var Center|null
|
||||
* @ORM\ManyToOne(targetEntity=Center::class)
|
||||
* @Serializer\Groups({"docgen:read"})
|
||||
*/
|
||||
private ?Center $mainCenter = null;
|
||||
|
||||
/**
|
||||
* @var Scope|null
|
||||
* @ORM\ManyToOne(targetEntity=Scope::class)
|
||||
*/
|
||||
private ?Scope $mainScope = null;
|
||||
|
||||
/**
|
||||
* @var UserJob|null
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255)
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @internal must be set to null if we use bcrypt
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $salt;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=UserJob::class)
|
||||
*/
|
||||
private ?UserJob $userJob = null;
|
||||
|
||||
/**
|
||||
* @var Location|null
|
||||
* @ORM\ManyToOne(targetEntity=Location::class)
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=80)
|
||||
*/
|
||||
private ?Location $currentLocation = null;
|
||||
private $username;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(
|
||||
* type="string",
|
||||
* length=80,
|
||||
* unique=true,
|
||||
* nullable=true)
|
||||
*/
|
||||
private $usernameCanonical;
|
||||
|
||||
/**
|
||||
* User constructor.
|
||||
@@ -165,85 +169,38 @@ class User implements AdvancedUserInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
* @param \Chill\MainBundle\Entity\GroupCenter $groupCenter
|
||||
*
|
||||
* @return integer
|
||||
* @return \Chill\MainBundle\Entity\User
|
||||
*/
|
||||
public function getId()
|
||||
public function addGroupCenter(GroupCenter $groupCenter)
|
||||
{
|
||||
$this->groupCenters->add($groupCenter);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function eraseCredentials()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set username
|
||||
* Get attributes.
|
||||
*
|
||||
* @param string $name
|
||||
* @return Agent
|
||||
* @return array
|
||||
*/
|
||||
public function setUsername($name)
|
||||
public function getAttributes()
|
||||
{
|
||||
$this->username = $name;
|
||||
|
||||
if (empty($this->getLabel())) {
|
||||
$this->setLabel($name);
|
||||
if (null === $this->attributes) {
|
||||
$this->attributes = [];
|
||||
}
|
||||
|
||||
return $this;
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername()
|
||||
public function getCurrentLocation(): ?Location
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function eraseCredentials() {}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return ['ROLE_USER'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getSalt()
|
||||
{
|
||||
return $this->salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $usernameCanonical
|
||||
* @return $this
|
||||
*/
|
||||
public function setUsernameCanonical($usernameCanonical)
|
||||
{
|
||||
$this->usernameCanonical = $usernameCanonical;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUsernameCanonical()
|
||||
{
|
||||
return $this->usernameCanonical;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
* @return $this
|
||||
*/
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
return $this->currentLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,17 +211,6 @@ class User implements AdvancedUserInterface {
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $emailCanonical
|
||||
* @return $this
|
||||
*/
|
||||
public function setEmailCanonical($emailCanonical)
|
||||
{
|
||||
$this->emailCanonical = $emailCanonical;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -274,14 +220,36 @@ class User implements AdvancedUserInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $password
|
||||
* @return $this
|
||||
* @return GroupCenter
|
||||
*/
|
||||
function setPassword($password)
|
||||
public function getGroupCenters()
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this->groupCenters;
|
||||
}
|
||||
|
||||
return $this;
|
||||
/**
|
||||
* Get id.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function getMainCenter(): ?Center
|
||||
{
|
||||
return $this->mainCenter;
|
||||
}
|
||||
|
||||
public function getMainScope(): ?Scope
|
||||
{
|
||||
return $this->mainScope;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,14 +260,38 @@ class User implements AdvancedUserInterface {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $salt
|
||||
* @return $this
|
||||
*/
|
||||
function setSalt($salt)
|
||||
public function getRoles(): array
|
||||
{
|
||||
$this->salt = $salt;
|
||||
return $this;
|
||||
return ['ROLE_USER'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSalt()
|
||||
{
|
||||
return $this->salt;
|
||||
}
|
||||
|
||||
public function getUserJob(): ?UserJob
|
||||
{
|
||||
return $this->userJob;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUsernameCanonical()
|
||||
{
|
||||
return $this->usernameCanonical;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,46 +326,6 @@ class User implements AdvancedUserInterface {
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function setEnabled($enabled)
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GroupCenter
|
||||
*/
|
||||
public function getGroupCenters()
|
||||
{
|
||||
return $this->groupCenters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Chill\MainBundle\Entity\GroupCenter $groupCenter
|
||||
* @return \Chill\MainBundle\Entity\User
|
||||
*/
|
||||
public function addGroupCenter(GroupCenter $groupCenter)
|
||||
{
|
||||
$this->groupCenters->add($groupCenter);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Chill\MainBundle\Entity\GroupCenter $groupCenter
|
||||
* @throws \RuntimeException if the groupCenter is not in the collection
|
||||
*/
|
||||
public function removeGroupCenter(GroupCenter $groupCenter)
|
||||
{
|
||||
if ($this->groupCenters->removeElement($groupCenter) === FALSE) {
|
||||
throw new \RuntimeException(sprintf("The groupCenter could not be removed, "
|
||||
. "it seems not to be associated with the user. Aborting."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function check that groupCenter are present only once. The validator
|
||||
* use this function to avoid a user to be associated to the same groupCenter
|
||||
@@ -381,12 +333,12 @@ class User implements AdvancedUserInterface {
|
||||
*/
|
||||
public function isGroupCenterPresentOnce(ExecutionContextInterface $context)
|
||||
{
|
||||
$groupCentersIds = array();
|
||||
$groupCentersIds = [];
|
||||
|
||||
foreach ($this->getGroupCenters() as $groupCenter) {
|
||||
if (in_array($groupCenter->getId(), $groupCentersIds)) {
|
||||
$context->buildViolation("The user has already those permissions")
|
||||
->addViolation();
|
||||
|
||||
$context->buildViolation('The user has already those permissions')
|
||||
->addViolation();
|
||||
} else {
|
||||
$groupCentersIds[] = $groupCenter->getId();
|
||||
}
|
||||
@@ -394,7 +346,20 @@ class User implements AdvancedUserInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attributes
|
||||
* @param \Chill\MainBundle\Entity\GroupCenter $groupCenter
|
||||
*
|
||||
* @throws RuntimeException if the groupCenter is not in the collection
|
||||
*/
|
||||
public function removeGroupCenter(GroupCenter $groupCenter)
|
||||
{
|
||||
if ($this->groupCenters->removeElement($groupCenter) === false) {
|
||||
throw new RuntimeException(sprintf('The groupCenter could not be removed, '
|
||||
. 'it seems not to be associated with the user. Aborting.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attributes.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
@@ -407,107 +372,126 @@ class User implements AdvancedUserInterface {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
if ($this->attributes === null) {
|
||||
$this->attributes = [];
|
||||
}
|
||||
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
* @return User
|
||||
*/
|
||||
public function setLabel(string $label): User
|
||||
{
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Center|null
|
||||
*/
|
||||
public function getMainCenter(): ?Center
|
||||
{
|
||||
return $this->mainCenter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Center|null $mainCenter
|
||||
* @return User
|
||||
*/
|
||||
public function setMainCenter(?Center $mainCenter): User
|
||||
{
|
||||
$this->mainCenter = $mainCenter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Scope|null
|
||||
*/
|
||||
public function getMainScope(): ?Scope
|
||||
{
|
||||
return $this->mainScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Scope|null $mainScope
|
||||
* @return User
|
||||
*/
|
||||
public function setMainScope(?Scope $mainScope): User
|
||||
{
|
||||
$this->mainScope = $mainScope;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UserJob|null
|
||||
*/
|
||||
public function getUserJob(): ?UserJob
|
||||
{
|
||||
return $this->userJob;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserJob|null $userJob
|
||||
* @return User
|
||||
*/
|
||||
public function setUserJob(?UserJob $userJob): User
|
||||
{
|
||||
$this->userJob = $userJob;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Location|null
|
||||
*/
|
||||
public function getCurrentLocation(): ?Location
|
||||
{
|
||||
return $this->currentLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Location|null $location
|
||||
* @return User
|
||||
*/
|
||||
public function setCurrentLocation(?Location $currentLocation): User
|
||||
{
|
||||
$this->currentLocation = $currentLocation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $emailCanonical
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEmailCanonical($emailCanonical)
|
||||
{
|
||||
$this->emailCanonical = $emailCanonical;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function setEnabled($enabled)
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): User
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMainCenter(?Center $mainCenter): User
|
||||
{
|
||||
$this->mainCenter = $mainCenter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMainScope(?Scope $mainScope): User
|
||||
{
|
||||
$this->mainScope = $mainScope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $password
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $salt
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSalt($salt)
|
||||
{
|
||||
$this->salt = $salt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setUserJob(?UserJob $userJob): User
|
||||
{
|
||||
$this->userJob = $userJob;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set username.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Agent
|
||||
*/
|
||||
public function setUsername($name)
|
||||
{
|
||||
$this->username = $name;
|
||||
|
||||
if (empty($this->getLabel())) {
|
||||
$this->setLabel($name);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $usernameCanonical
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUsernameCanonical($usernameCanonical)
|
||||
{
|
||||
$this->usernameCanonical = $usernameCanonical;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user