| Current Path : /var/www/v3.cesa.co.za/src/UserBundle/Entity/ |
| Current File : /var/www/v3.cesa.co.za/src/UserBundle/Entity/UserList.php |
<?php
namespace App\UserBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* UserList
*
* @ORM\Table(name="user_list")
* @ORM\Entity(repositoryClass="App\UserBundle\Repository\UserListRepository")
* @ORM\HasLifecycleCallbacks
*/
class UserList implements UserInterface, PasswordAuthenticatedUserInterface, EquatableInterface
{
/**
* @ORM\Id
* @ORM\Column(type="string", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private $username;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $algorithm;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $salt;
/**
* @ORM\Column(type="string", length=255)
*/
private $password;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $last_login;
/**
* @ORM\Column(type="boolean", options={"default": 1})
*/
private $is_active;
/**
* @ORM\Column(type="boolean", options={"default": 0})
*/
private $is_super_admin;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $first_name_string;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $last_name_string;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $e_mail_address_string;
/**
* @ORM\Column(type="boolean", options={"default": 0})
*/
private $e_mail_address_subscribed;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $mobile_number;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $company_name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $company_vat;
/**
* @ORM\Column(type="boolean", options={"default": 0})
*/
private $deleted;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $date_of_birth;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $id_number;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $passport_number;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $debit_order_day;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $referred_by;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $short_code;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $id_doc_file_id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $created_by;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\Column(type="datetime")
*/
private $updated_at;
/**
* @ORM\ManyToMany(targetEntity="App\UserBundle\Entity\UserLevel", inversedBy="user_list")
* @ORM\JoinTable(name="user_list_user_level",
* joinColumns={@ORM\JoinColumn(name="user_list_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="user_level_id", referencedColumnName="id")}
* )
*/
private $user_level;
/**
* @var array
*/
private $roles = [];
/**
* @var string|null
*/
private $plain_password;
public function __construct()
{
$this->user_level = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): static
{
$this->username = $username;
return $this;
}
public function getAlgorithm(): ?string
{
return $this->algorithm;
}
public function setAlgorithm(?string $algorithm): static
{
$this->algorithm = $algorithm;
return $this;
}
public function getSalt(): ?string
{
return $this->salt;
}
public function setSalt(?string $salt): static
{
$this->salt = $salt;
return $this;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
/**
* Set plain password for form
*/
public function setPlainPassword($plainPassword)
{
$this->plain_password = $plainPassword;
return $this;
}
/**
* Get plain password for form
*/
public function getPlainPassword()
{
return $this->plain_password;
}
public function getLastLogin(): ?\DateTimeInterface
{
return $this->last_login;
}
public function setLastLogin(?\DateTimeInterface $last_login): static
{
$this->last_login = $last_login;
return $this;
}
public function isIsActive(): ?bool
{
return $this->is_active;
}
public function setIsActive(bool $is_active): static
{
$this->is_active = $is_active;
return $this;
}
public function isIsSuperAdmin(): ?bool
{
return $this->is_super_admin;
}
public function setIsSuperAdmin(bool $is_super_admin): static
{
$this->is_super_admin = $is_super_admin;
return $this;
}
public function getFirstNameString(): ?string
{
return $this->first_name_string;
}
public function setFirstNameString(?string $first_name_string): static
{
$this->first_name_string = $first_name_string;
return $this;
}
public function getLastNameString(): ?string
{
return $this->last_name_string;
}
public function setLastNameString(?string $last_name_string): static
{
$this->last_name_string = $last_name_string;
return $this;
}
public function isDeleted(): ?bool
{
return $this->deleted;
}
public function setDeleted(bool $deleted): static
{
$this->deleted = $deleted;
return $this;
}
public function getDateOfBirth(): ?\DateTimeInterface
{
return $this->date_of_birth;
}
public function setDateOfBirth(?\DateTimeInterface $date_of_birth): static
{
$this->date_of_birth = $date_of_birth;
return $this;
}
public function getIdNumber(): ?string
{
return $this->id_number;
}
public function setIdNumber(?string $id_number): static
{
$this->id_number = $id_number;
return $this;
}
public function getPassportNumber(): ?string
{
return $this->passport_number;
}
public function setPassportNumber(?string $passport_number): static
{
$this->passport_number = $passport_number;
return $this;
}
public function getDebitOrderDay(): ?int
{
return $this->debit_order_day;
}
public function setDebitOrderDay(?int $debit_order_day): static
{
$this->debit_order_day = $debit_order_day;
return $this;
}
public function getReferredBy(): ?string
{
return $this->referred_by;
}
public function setReferredBy(?string $referred_by): static
{
$this->referred_by = $referred_by;
return $this;
}
public function getShortCode(): ?string
{
return $this->short_code;
}
public function setShortCode(?string $short_code): static
{
$this->short_code = $short_code;
return $this;
}
public function getIdDocFileId(): ?string
{
return $this->id_doc_file_id;
}
public function setIdDocFileId(?string $id_doc_file_id): static
{
$this->id_doc_file_id = $id_doc_file_id;
return $this;
}
public function getCreatedBy(): ?string
{
return $this->created_by;
}
public function setCreatedBy(?string $created_by): static
{
$this->created_by = $created_by;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): static
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(\DateTimeInterface $updated_at): static
{
$this->updated_at = $updated_at;
return $this;
}
/**
* Get user roles
*
* @return array
*/
public function getRoles(): array
{
if (is_array($this->roles) && count($this->roles) > 0) {
return $this->roles;
}
$arrOut = array('ROLE_LOGGED_IN', 'ROLE_MY_DETAILS', 'ROLE_USER', 'ROLE_REPORTS_ONLY', 'IS_AUTHENTICATED_FULLY');
if (strlen($this->getId()) <= 0) {
return array();
}
if (!$this->isIsActive()) {
return array('NONE');
} elseif ($this->isIsSuperAdmin()) {
$arrOut[] = 'ROLE_SONATA_ADMIN';
$arrOut[] = 'ROLE_ADMIN';
$arrOut[] = 'ROLE_REPORTS_ONLY';
$arrOut[] = 'ROLE_SUPER_ADMINISTRATOR';
$arrOut[] = 'ROLE_SUPER_ADMIN';
} else {
$arrOut[] = 'ROLE_FRONTEND_USER';
}
foreach ($this->getUserLevel() as $userLevel) {
$roles = explode(',', $userLevel->getRoles());
foreach ($roles as $role) {
$arrOut[] = 'ROLE_' . strtoupper($role);
}
}
$this->roles = array_unique($arrOut);
// var_dump($this->roles);
// exit;
return $this->roles;
}
/**
* Check if user has role
*
* @param string $roleName
* @return boolean
*/
public function getGranted($roleName)
{
return in_array($roleName, $this->getRoles());
}
public function eraseCredentials(): void {}
public function equals(UserInterface $user)
{
return $user->getUserIdentifier() == $this->getUserIdentifier();
}
public function __sleep()
{
return array('id');
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
if (is_null($this->getCreatedAt())) {
$this->setCreatedAt(new \DateTime());
}
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function setUpdatedAtValue()
{
$this->setUpdatedAt(new \DateTime());
}
public function getUserIdentifier(): string
{
return $this->getId();
}
public function getPassword(): ?string
{
return $this->password;
}
public function getEMailAddressString(): ?string
{
return $this->e_mail_address_string;
}
public function setEMailAddressString(?string $e_mail_address_string): static
{
$this->e_mail_address_string = $e_mail_address_string;
return $this;
}
public function isEMailAddressSubscribed(): ?bool
{
return $this->e_mail_address_subscribed;
}
public function setEMailAddressSubscribed(bool $e_mail_address_subscribed): static
{
$this->e_mail_address_subscribed = $e_mail_address_subscribed;
return $this;
}
public function getMobileNumber(): ?string
{
return $this->mobile_number;
}
public function setMobileNumber(?string $mobile_number): static
{
$this->mobile_number = $mobile_number;
return $this;
}
public function getCompanyName(): ?string
{
return $this->company_name;
}
public function setCompanyName(?string $company_name): static
{
$this->company_name = $company_name;
return $this;
}
public function getCompanyVat(): ?string
{
return $this->company_vat;
}
public function setCompanyVat(?string $company_vat): static
{
$this->company_vat = $company_vat;
return $this;
}
/**
* @return Collection<int, UserLevel>
*/
public function getUserLevel(): Collection
{
return $this->user_level;
}
public function addUserLevel(UserLevel $userLevel): static
{
if (!$this->user_level->contains($userLevel)) {
$this->user_level->add($userLevel);
}
return $this;
}
public function removeUserLevel(UserLevel $userLevel): static
{
$this->user_level->removeElement($userLevel);
return $this;
}
public function __toString()
{
return $this->getUsername();
}
public function serialize()
{
return serialize(array(
$this->id,
$this->password,
$this->e_mail_address_string,
$this->username,
));
}
public function unserialize($serialized)
{
list(
$this->id,
$this->password,
$this->e_mail_address_string,
$this->username,
) = unserialize($serialized, array('allowed_classes' => false));
}
public function isEqualTo(UserInterface $user): bool
{
if ($user instanceof PasswordAuthenticatedUserInterface && $this->password !== $user->getPassword()) {
// return false;
}
if ($this->username !== $user->getUserIdentifier()) {
// echo $this->id . ' ' . $this->username . ' !== ' . $user->getUserIdentifier() . '<br />';
// return false;
}
if ($this->id !== $user->getUserIdentifier()) {
return false;
}
return true;
}
public function getFullNameString()
{
$return = trim($this->getFirstNameString()) . ' ';
$return .= trim($this->getLastNameString());
return trim($return) . ' (' . $this->getUsername() . ')';
}
/**
* Get full number to send
*
* @return string
*/
public function getFullNumberToSend()
{
$return = '';
if ($this->getMobileNumber() == 'Not Listed') {
return $return;
}
if (strlen($this->getMobileNumber()) > 0) {
$return .= trim($this->getMobileNumber());
}
if (substr($return, 0, 5) == '+2727') {
$return = '+27' . substr($return, 5);
}
if (substr($return, 0, 4) == '+270') {
$return = '+27' . substr($return, 4);
}
$return = str_replace('+27+27', '+27', $return);
$return = str_replace('(', '', $return);
$return = str_replace(')', '', $return);
if (strlen($return) <= 3) {
$return = '';
}
return str_replace(' ', '', $return);
}
public function isActive(): ?bool
{
return $this->is_active;
}
public function isSuperAdmin(): ?bool
{
return $this->is_super_admin;
}
}