Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Model;
- use \Doctrine\ORM\Mapping as ORM;
- /**
- * @ORM\Entity
- * @ORM\Table(name="users")
- */
- class User {
- /** @const */
- const ROLE_ADMIN = 'ADMIN',
- ROLE_MANAGER = 'MANAGER',
- ROLE_CLIENT = 'CLIENT';
- /** @const */
- const STATUS_LOGIN = true,
- STATUS_LOGOUT = false;
- /** @const */
- const FLAG_ACTIVE = 'ACTIVE',
- FLAG_INACTIVE = 'INACTIVE';
- /**
- * @var array
- */
- public static $roles = [
- self::ROLE_ADMIN => 'Administrátor',
- self::ROLE_MANAGER => 'Manažér',
- self::ROLE_CLIENT => 'Klient'
- ];
- /**
- * @var array
- */
- public static $flags = [
- self::FLAG_ACTIVE => 'Aktivní',
- self::FLAG_INACTIVE => 'Neaktivní'
- ];
- use \Kdyby\Doctrine\Entities\MagicAccessors;
- /**
- * @ORM\Id
- * @ORM\Column(type="integer")
- * @ORM\GeneratedValue
- */
- protected $id;
- /**
- * @ORM\Column(unique=true)
- */
- protected $username;
- /**
- * @ORM\Column
- */
- protected $email;
- /**
- * @ORM\Column
- */
- protected $password;
- /**
- * @ORM\Column(type="boolean")
- */
- protected $is_company;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $company_name;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $ico;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $dic;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $icdph;
- /**
- * @ORM\Column
- */
- protected $name;
- /**
- * @ORM\ManyToOne(targetEntity="\App\Model\Enum\District", inversedBy="users")
- */
- protected $district;
- /**
- * @ORM\ManyToOne(targetEntity="\App\Model\Enum\Region", inversedBy="users")
- */
- protected $township;
- /**
- * @ORM\Column
- */
- protected $street;
- /**
- * @ORM\Column
- */
- protected $psc;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $phone;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $phone2;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $mobile_phone;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $mobile_phone2;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $fax;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $email2;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $web;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $skype;
- /**
- * @ORM\Column(type="string", columnDefinition="ENUM('ADMIN', 'MANAGER', 'CLIENT') DEFAULT 'CLIENT'", nullable=FALSE)
- * @var string
- */
- protected $role = self::ROLE_CLIENT;
- /**
- * @ORM\Column(type="boolean")
- */
- protected $status;
- /**
- * @ORM\Column(type="string", columnDefinition="ENUM('ACTIVE', 'INACTIVE') DEFAULT 'INACTIVE'", nullable=FALSE)
- */
- protected $flag = self::FLAG_INACTIVE;
- /**
- * @ORM\Column(type="datetime")
- */
- protected $reg_time;
- /**
- * @ORM\Column(type="datetime")
- */
- protected $last_time;
- /**
- * @ORM\Column(type="datetime")
- */
- protected $last_activity;
- /**
- * @ORM\Column(type="text", nullable=true)
- */
- protected $access_token;
- /**
- * @ORM\Column(type="datetime", nullable=true)
- */
- protected $access_token_created;
- /**
- * @ORM\Column(type="date", nullable=true)
- */
- protected $date_of_signature;
- /**
- * @ORM\Column(type="date", nullable=true)
- */
- protected $date_end;
- /**
- * @ORM\ManyToOne(targetEntity="User", inversedBy="managers")
- */
- protected $manager;
- /**
- * @ORM\Column(type="float")
- */
- protected $credit;
- /**
- * @ORM\Column(type="float")
- */
- protected $credit_trust;
- /**
- * @ORM\Column(type="float")
- */
- protected $credit_blocking;
- /**
- * @ORM\Column(type="float")
- */
- protected $credit_debit;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $contact_name;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $contact_mobile;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $contact_phone;
- /**
- * @ORM\Column(nullable=true)
- */
- protected $contact_email;
- /**
- * @ORM\Column(type="text", nullable=true)
- */
- protected $note;
- /**
- * @ORM\Column(type="integer")
- */
- protected $sort_logo;
- /**
- * @ORM\Column(type="text", nullable=true)
- */
- protected $logo;
- /**
- * @ORM\Column(type="text", nullable=true)
- */
- protected $inter_note;
- /**
- * @ORM\OneToMany(targetEntity="User", mappedBy="manager")
- */
- protected $managers;
- /**
- * @ORM\OneToMany(targetEntity="Item", mappedBy="user")
- */
- protected $items;
- /**
- * @ORM\OneToMany(targetEntity="Shop", mappedBy="buyer")
- */
- protected $buyer_shops;
- /**
- * @ORM\OneToMany(targetEntity="Shop", mappedBy="seller")
- */
- protected $seller_shops;
- public function __construct() {
- $this->last_time = new \DateTime();
- $this->reg_time = new \DateTime();
- $this->last_activity = new \DateTime();
- $this->credit = 0;
- $this->credit_blocking = 0;
- $this->credit_debit = 0;
- $this->credit_trust = 0;
- $this->sort_logo = 0;
- $this->managers = new \Doctrine\Common\Collections\ArrayCollection();
- $this->items = new \Doctrine\Common\Collections\ArrayCollection();
- $this->buyer_shops = new \Doctrine\Common\Collections\ArrayCollection();
- $this->seller_shops = new \Doctrine\Common\Collections\ArrayCollection();
- }
- /**
- * @param string $role
- * @return \App\Model\User
- */
- public function setRole($role) {
- if (!in_array($role, [self::ROLE_ADMIN, self::ROLE_MANAGER, self::ROLE_CLIENT]))
- throw new \InvalidArgumentException("Zle nastavená role: '$role'.");
- $this->role = $role;
- return $this;
- }
- /**
- * @return string
- */
- public function getRoleName() {
- if(!isset(self::$roles[$this->role])) {
- throw new \InvalidArgumentException("Zle požádané role: '$this->role'.");
- }
- return self::$roles[$this->role];
- }
- /**
- * @return string
- */
- public function getFlagName() {
- if(!isset(self::$flags[$this->flag])) {
- throw new \InvalidArgumentException("Zle požádaný flag: '$this->flag'.");
- }
- return self::$flags[$this->flag];
- }
- /**
- * @return string
- */
- public function getFullname() {
- if(!\Nette\Utils\Validators::isNone($this->company_name)) {
- return $this->company_name;
- } else if (!\Nette\Utils\Validators::isNone($this->name)) {
- return $this->name;
- } else {
- return $this->username;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement