mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-25 16:14:59 +00:00
fix directory structure for branch 1.5 & bundle ChillMain
This commit is contained in:
288
src/Bundle/ChillMainBundle/Entity/User.php
Normal file
288
src/Bundle/ChillMainBundle/Entity/User.php
Normal file
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
* User
|
||||
*/
|
||||
class User implements AdvancedUserInterface {
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $username;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $usernameCanonical;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $emailCanonical;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
* @internal must be set to null if we use bcrypt
|
||||
*/
|
||||
private $salt = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $locked = true;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $enabled = true;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Collection
|
||||
*/
|
||||
private $groupCenters;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->groupCenters = new ArrayCollection();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set username
|
||||
*
|
||||
* @param string $name
|
||||
* @return Agent
|
||||
*/
|
||||
public function setUsername($name)
|
||||
{
|
||||
$this->username = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return $this->getUsername();
|
||||
}
|
||||
|
||||
public function eraseCredentials()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function getRoles()
|
||||
{
|
||||
return array('ROLE_USER');
|
||||
}
|
||||
|
||||
public function getSalt()
|
||||
{
|
||||
return $this->salt;
|
||||
}
|
||||
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getUsernameCanonical()
|
||||
{
|
||||
return $this->usernameCanonical;
|
||||
}
|
||||
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function getEmailCanonical()
|
||||
{
|
||||
return $this->emailCanonical;
|
||||
}
|
||||
|
||||
public function setUsernameCanonical($usernameCanonical)
|
||||
{
|
||||
$this->usernameCanonical = $usernameCanonical;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEmailCanonical($emailCanonical)
|
||||
{
|
||||
$this->emailCanonical = $emailCanonical;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
function setSalt($salt)
|
||||
{
|
||||
$this->salt = $salt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAccountNonExpired()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
*/
|
||||
public function isAccountNonLocked()
|
||||
{
|
||||
return $this->locked;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isCredentialsNonExpired()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
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
|
||||
* more than once.
|
||||
*/
|
||||
public function isGroupCenterPresentOnce(ExecutionContextInterface $context)
|
||||
{
|
||||
$groupCentersIds = array();
|
||||
foreach ($this->getGroupCenters() as $groupCenter) {
|
||||
if (in_array($groupCenter->getId(), $groupCentersIds)) {
|
||||
$context->buildViolation("The user has already those permissions")
|
||||
->addViolation();
|
||||
|
||||
} else {
|
||||
$groupCentersIds[] = $groupCenter->getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user