<?php
namespace MCC\SocialCare\Component\User\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="user")
*/
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @var int
*/
protected $id;
/**
* @ORM\Column(name="first_name", type="string", nullable=true)
* @var string
*/
protected $firstName;
/**
* @ORM\Column(name="last_name", type="string", nullable=true)
* @var string
*/
protected $lastName;
/**
* @ORM\ManyToMany(targetEntity="Role", inversedBy="users", cascade={"persist"}, fetch="EAGER")
* @ORM\JoinTable(name="user_roles")
*
* @var Role[]|Collection
*/
protected $roles;
/**
* @ORM\ManyToMany(targetEntity="Group", inversedBy="users", cascade={"persist"}, fetch="EAGER")
* @ORM\JoinTable(name="user_groups")
*
* @var Group[]|Collection
*/
protected $groups;
/**
* @ORM\ManyToMany(targetEntity="MCC\SocialCare\Component\Team\Entity\Team", mappedBy="users")
*
* @var Team[]|Collection
*/
protected $teams;
/**
* @ORM\OneToMany(targetEntity="MCC\SocialCare\Component\Team\Entity\Team", mappedBy="manager")
*
* @var Team[]|Collection
*/
protected $managedTeams;
/**
* The cases in which the user is a key worker on.
*
* @ORM\OneToMany(
* targetEntity="MCC\SocialCare\Component\ServiceUserCase\Entity\ServiceUserCase",
* mappedBy="keyWorker"
* )
*
* @var ServiceUserCase[]|Collection
*/
protected $keyCases;
/**
* The cases the user is simply involved with.
*
* @ORM\ManyToMany(targetEntity="MCC\SocialCare\Component\ServiceUserCase\Entity\ServiceUserCase", mappedBy="users")
*
* @var Team[]|Collection
*/
protected $cases;
/**
* The users notifications.
*
* @ORM\OneToMany(
* targetEntity="MCC\SocialCare\Component\Notification\Entity\NotificationMessage",
* mappedBy="recipient",
* cascade={"persist"}
* )
*
* @var NotificationMessage[]|Collection
*/
protected $notifications;
public function __construct()
{
parent::__construct();
$this->roles = new ArrayCollection();
$this->groups = new ArrayCollection();
$this->teams = new ArrayCollection();
$this->managedTeams = new ArrayCollection();
$this->keyCases = new ArrayCollection();
$this->cases = new ArrayCollection();
$this->notifications = new ArrayCollection();
}
/**
* @return string
*/
public function getFullName()
{
return $this->firstName.' '.$this->lastName;
}
/**
* {@inheritdoc}
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
* {@inheritdoc}
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* {@inheritdoc}
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
* {@inheritdoc}
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param string|Role $role
* @return User
*/
public function addRole($role)
{
if (!$role instanceof Role) {
$role = (new Role)->setRole($role);
}
if (!$this->hasRole($role)) {
$this->roles->add($role);
}
return $this;
}
/**
* @param string|Role $role
* @return User
*/
public function removeRole($role)
{
if ($role instanceof Role) {
$this->roles->removeElement($role);
return $this;
}
foreach ($this->roles as $r) {
if ($r->getRole() === $role) {
$this->roles->removeElement($r);
}
}
return $this;
}
/**
* @param string|Role $role
* @return bool
*/
public function hasRole($role)
{
if ($role instanceof Role) {
$role = $role->getRole();
}
return $this->roles->exists(function ($key, Role $element) use ($role) {
return $role === $element->getRole();
});
}
/**
* @return Role[]
*/
public function getRoles()
{
$roles = $this->roles->toArray();
foreach ($this->getGroups() as $group) {
$roles = array_merge($roles, $group->getRoles());
}
return $roles;
}
/**
* @param GroupInterface $group
* @return User
*/
public function addGroup(GroupInterface $group)
{
if (!$this->hasGroup($group)) {
$this->groups[] = $group;
}
return $this;
}
/**
* @param GroupInterface $group
* @return User
*/
public function removeGroup(GroupInterface $group)
{
$this->groups->removeElement($group);
return $this;
}
/**
* @param string|GroupInterface $group
* @return bool
*/
public function hasGroup($group)
{
if ($group instanceof GroupInterface) {
return $this->groups->contains($group);
}
return $this->groups->exists(function ($key, GroupInterface $element) use ($group) {
return $group === $element->getName();
});
}
/**
* @return Collection|Group[]
*/
public function getGroups()
{
return $this->groups;
}
/**
* @param Team $team
* @return $this
*/
public function addTeam(Team $team)
{
if (!$this->hasTeam($team)) {
$this->teams->add($team);
$team->addUser($this);
}
return $this;
}
/**
* @param Team $team
* @return $this
*/
public function removeTeam(Team $team)
{
if ($this->hasTeam($team)) {
$this->teams->removeElement($team);
$team->removeUser($this);
}
return $this;
}
/**
* @param Team $team
* @return bool
*/
public function hasTeam(Team $team)
{
return $this->teams->contains($team);
}
/**
* @return Collection|Team[]
*/
public function getTeams()
{
return $this->teams;
}
/**
* @param Team $team
* @return $this
*/
public function addManagedTeam(Team $team)
{
if (!$this->hasManagedTeam($team)) {
$this->managedTeams->add($team);
$team->setManager($this);
}
return $this;
}
/**
* @param Team $team
* @return $this
*/
public function removeManagedTeam(Team $team)
{
if ($this->hasManagedTeam($team)) {
$this->managedTeams->removeElement($team);
$team->setManager(null);
}
return $this;
}
/**
* @param Team $team
* @return bool
*/
public function hasManagedTeam(Team $team)
{
return $this->managedTeams->contains($team);
}
/**
* @return Collection|Team[]
*/
public function getManagedTeams()
{
return $this->managedTeams;
}
/**
* @param ServiceUserCase $keyCase
* @return $this
*/
public function addKeyCase(ServiceUserCase $keyCase)
{
if (!$this->hasKeyCase($keyCase)) {
$this->keyCases->add($keyCase);
$keyCase->setKeyWorker($this);
}
return $this;
}
/**
* @param ServiceUserCase $keyCase
* @return $this
*/
public function removeKeyCase(ServiceUserCase $keyCase)
{
if ($this->hasKeyCase($keyCase)) {
$this->keyCases->removeElement($keyCase);
$keyCase->setKeyWorker(null);
}
return $this;
}
/**
* @param ServiceUserCase $keyCase
* @return bool
*/
public function hasKeyCase(ServiceUserCase $keyCase)
{
return $this->keyCases->contains($keyCase);
}
/**
* @return Collection|ServiceUserCase[]
*/
public function getKeyCases()
{
return $this->keyCases;
}
/**
* @param ServiceUserCase $case
* @return $this
*/
public function addCase(ServiceUserCase $case)
{
if (!$this->hasCase($case)) {
$this->cases->add($case);
$case->addUser($this);
}
return $this;
}
/**
* @param ServiceUserCase $case
* @return $this
*/
public function removeCase(ServiceUserCase $case)
{
if ($this->hasCase($case)) {
$this->cases->removeElement($case);
$case->removeUser($this);
}
return $this;
}
/**
* @param ServiceUserCase $case
* @return bool
*/
public function hasCase(ServiceUserCase $case)
{
return $this->cases->contains($case);
}
/**
* @return Collection|ServiceUserCase[]
*/
public function getCases()
{
return $this->cases;
}
/**
* @param NotificationMessage $message
* @return $this
*/
public function addNotification(NotificationMessage $message)
{
if (!$this->hasNotification($message)) {
$message->setRecipient($this);
$this->notifications->add($message);
}
return $this;
}
/**
* @param NotificationMessage $message
* @return $this
*/
public function removeNotfication(NotificationMessage $message)
{
if ($this->hasNotification($message)) {
$this->notifications->removeElement($message);
$message->setRecipient(null);
}
return $this;
}
/**
* @param NotificationMessage $message
* @return bool
*/
public function hasNotification(NotificationMessage $message)
{
return $this->notifications->contains($message);
}
/**
* @return Collection|NotificationMessage[]
*/
public function getNotifications()
{
return $this->notifications;
}
/**
* Get unread notification messages
*
* @return Collection|NotificationMessage[]
*/
public function getUnreadNotifications()
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq('read', false));
return $this->notifications->matching($criteria);
}
/**
* Serializes the user.
*
* The serialized data have to contain the fields used by the equals method and the username.
*
* @return string
*/
public function serialize()
{
return serialize(array(
$this->password,
$this->salt,
$this->usernameCanonical,
$this->username,
$this->expired,
$this->locked,
$this->credentialsExpired,
$this->enabled,
$this->id,
));
}
/**
* Unserializes the user.
*
* @param string $serialized
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
// add a few extra elements in the array to ensure that we have enough keys when unserializing
// older data which does not include all properties.
$data = array_merge($data, array_fill(0, 2, null));
list(
$this->password,
$this->salt,
$this->usernameCanonical,
$this->username,
$this->expired,
$this->locked,
$this->credentialsExpired,
$this->enabled,
$this->id
) = $data;
}
}
var_dump( unserialize('a:4:{i:0;C:41:"MCC\SocialCare\Component\User\Entity\User":206:{a:9:{i:0;s:60:"$2y$15$2m55uqgw1dc0488k0k44kuj5jlsY5zHjNX/WlJ75iKn1NgPX6rcMS";i:1;s:31:"2m55uqgw1dc0488k0k44k0co8wk8csw";i:2;s:10:"superadmin";i:3;s:10:"superadmin";i:4;b:0;i:5;b:0;i:6;b:0;i:7;b:1;i:8;i:12;}}i:1;b:1;i:2;a:2:{i:0;C:41:"MCC\SocialCare\Component\User\Entity\Role":42:{a:2:{i:0;i:3;i:1;s:16:"ROLE_SUPER_ADMIN";}}i:1;r:16;}i:3;a:0:{}}') );
- Output for git.master, git.master_jit, rfc.property-hooks
- Fatal error: Cannot use "parent" when current class scope has no parent in /in/vYbuc on line 102
Process exited with code 255.
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches
Archived branches
Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:
35.61 ms | 401 KiB | 8 Q