groupCenters = new ArrayCollection(); } /** * @return string */ public function __toString() { return $this->getLabel(); } /** * @param \Chill\MainBundle\Entity\GroupCenter $groupCenter * * @return \Chill\MainBundle\Entity\User */ public function addGroupCenter(GroupCenter $groupCenter) { $this->groupCenters->add($groupCenter); return $this; } public function eraseCredentials() { } public function getAbsenceStart(): ?DateTimeImmutable { return $this->absenceStart; } /** * Get attributes. * * @return array */ public function getAttributes() { if (null === $this->attributes) { $this->attributes = []; } return $this->attributes; } public function getCivility(): ?Civility { return $this->civility; } public function getCurrentLocation(): ?Location { return $this->currentLocation; } /** * @return string */ public function getEmail(): ?string { return $this->email; } /** * @return string */ public function getEmailCanonical() { return $this->emailCanonical; } /** * @return Collection */ public function getGroupCenters() { return $this->groupCenters; } /** * Get id. */ public function getId(): ?int { return $this->id; } public function getLabel(): string { return $this->label; } public function getMainCenter(): ?Center { return $this->mainCenter; } public function getMainLocation(): ?Location { return $this->mainLocation; } public function getMainScope(): ?Scope { return $this->mainScope; } /** * @return string */ public function getPassword() { return $this->password; } public function getRoles(): array { 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; } public function isAbsent(): bool { return null !== $this->getAbsenceStart() && $this->getAbsenceStart() <= new DateTimeImmutable('now'); } /** * @return bool */ public function isAccountNonExpired() { return true; } /** * @return bool */ public function isAccountNonLocked() { return $this->locked; } /** * @return bool */ public function isCredentialsNonExpired() { return true; } /** * @return bool */ public function isEnabled() { return $this->enabled; } /** * 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 = []; foreach ($this->getGroupCenters() as $groupCenter) { if (in_array($groupCenter->getId(), $groupCentersIds, true)) { $context->buildViolation('The user has already those permissions') ->addViolation(); } else { $groupCentersIds[] = $groupCenter->getId(); } } } /** * @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('The groupCenter could not be removed, ' . 'it seems not to be associated with the user. Aborting.'); } } public function setAbsenceStart(?DateTimeImmutable $absenceStart): void { $this->absenceStart = $absenceStart; } public function setAttributeByDomain(string $domain, string $key, $value): self { $this->attributes[$domain][$key] = $value; return $this; } /** * Merge the attributes with existing attributes. * * Only the key provided will be created or updated. For a two-level array, use @see{User::setAttributeByDomain} */ public function setAttributes(array $attributes): self { $this->attributes = array_merge($this->attributes, $attributes); return $this; } public function setCivility(?Civility $civility): User { $this->civility = $civility; return $this; } 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; } public function setEnabled(bool $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 setMainLocation(?Location $mainLocation): User { $this->mainLocation = $mainLocation; 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 User */ public function setUsername(?string $name) { $this->username = (string) $name; if ("" === trim($this->getLabel())) { $this->setLabel($name); } return $this; } /** * @param $usernameCanonical * * @return $this */ public function setUsernameCanonical($usernameCanonical) { $this->usernameCanonical = $usernameCanonical; return $this; } public function unsetAttribute($key): self { unset($this->attributes[$key]); return $this; } }