Advertisement
Guest User

Untitled

a guest
May 27th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.44 KB | None | 0 0
  1. <?php
  2. namespace App\Model;
  3.  
  4. use \Doctrine\ORM\Mapping as ORM;
  5.  
  6. /**
  7.  * @ORM\Entity
  8.  * @ORM\Table(name="users")
  9.  */
  10. class User {
  11.    
  12.     /** @const */
  13.     const ROLE_ADMIN = 'ADMIN',
  14.             ROLE_MANAGER = 'MANAGER',
  15.             ROLE_CLIENT = 'CLIENT';
  16.    
  17.     /** @const */
  18.     const STATUS_LOGIN = true,
  19.             STATUS_LOGOUT = false;
  20.  
  21.     /** @const */
  22.     const FLAG_ACTIVE = 'ACTIVE',
  23.             FLAG_INACTIVE = 'INACTIVE';
  24.    
  25.     /**
  26.      * @var array
  27.      */
  28.     public static $roles = [
  29.         self::ROLE_ADMIN => 'Administrátor',
  30.         self::ROLE_MANAGER => 'Manažér',
  31.         self::ROLE_CLIENT => 'Klient'
  32.     ];
  33.    
  34.     /**
  35.      * @var array
  36.      */
  37.     public static $flags = [
  38.         self::FLAG_ACTIVE => 'Aktivní',
  39.         self::FLAG_INACTIVE => 'Neaktivní'
  40.     ];
  41.    
  42.    
  43.     use \Kdyby\Doctrine\Entities\MagicAccessors;
  44.  
  45.     /**
  46.      * @ORM\Id
  47.      * @ORM\Column(type="integer")
  48.      * @ORM\GeneratedValue
  49.      */
  50.     protected $id;
  51.    
  52.     /**
  53.      * @ORM\Column(unique=true)
  54.      */
  55.     protected $username;
  56.    
  57.     /**
  58.      * @ORM\Column
  59.      */
  60.     protected $email;
  61.    
  62.     /**
  63.      * @ORM\Column
  64.      */
  65.     protected $password;
  66.  
  67.     /**
  68.      * @ORM\Column(type="boolean")
  69.      */
  70.     protected $is_company;
  71.  
  72.     /**
  73.      * @ORM\Column(nullable=true)
  74.      */
  75.     protected $company_name;
  76.    
  77.     /**
  78.      * @ORM\Column(nullable=true)
  79.      */
  80.     protected $ico;
  81.    
  82.     /**
  83.      * @ORM\Column(nullable=true)
  84.      */
  85.     protected $dic;
  86.    
  87.     /**
  88.      * @ORM\Column(nullable=true)
  89.      */
  90.     protected $icdph;
  91.    
  92.     /**
  93.      * @ORM\Column
  94.      */
  95.     protected $name;
  96.    
  97.     /**
  98.      * @ORM\ManyToOne(targetEntity="\App\Model\Enum\District", inversedBy="users")
  99.      */
  100.     protected $district;
  101.    
  102.     /**
  103.      * @ORM\ManyToOne(targetEntity="\App\Model\Enum\Region", inversedBy="users")
  104.      */
  105.     protected $township;
  106.    
  107.     /**
  108.      * @ORM\Column
  109.      */
  110.     protected $street;
  111.    
  112.     /**
  113.      * @ORM\Column
  114.      */
  115.     protected $psc;
  116.    
  117.     /**
  118.      * @ORM\Column(nullable=true)
  119.      */
  120.     protected $phone;
  121.    
  122.     /**
  123.      * @ORM\Column(nullable=true)
  124.      */
  125.     protected $phone2;
  126.    
  127.     /**
  128.      * @ORM\Column(nullable=true)
  129.      */
  130.     protected $mobile_phone;
  131.    
  132.     /**
  133.      * @ORM\Column(nullable=true)
  134.      */
  135.     protected $mobile_phone2;
  136.    
  137.     /**
  138.      * @ORM\Column(nullable=true)
  139.      */
  140.     protected $fax;
  141.    
  142.     /**
  143.      * @ORM\Column(nullable=true)
  144.      */
  145.     protected $email2;
  146.    
  147.     /**
  148.      * @ORM\Column(nullable=true)
  149.      */
  150.     protected $web;
  151.    
  152.     /**
  153.      * @ORM\Column(nullable=true)
  154.      */
  155.     protected $skype;
  156.    
  157.     /**
  158.      * @ORM\Column(type="string", columnDefinition="ENUM('ADMIN', 'MANAGER', 'CLIENT') DEFAULT 'CLIENT'", nullable=FALSE)
  159.      * @var string
  160.      */
  161.     protected $role = self::ROLE_CLIENT;
  162.    
  163.     /**
  164.      * @ORM\Column(type="boolean")
  165.      */
  166.     protected $status;
  167.    
  168.     /**
  169.      * @ORM\Column(type="string", columnDefinition="ENUM('ACTIVE', 'INACTIVE') DEFAULT 'INACTIVE'", nullable=FALSE)
  170.      */
  171.     protected $flag = self::FLAG_INACTIVE;
  172.    
  173.     /**
  174.      * @ORM\Column(type="datetime")
  175.      */
  176.     protected $reg_time;
  177.    
  178.     /**
  179.      * @ORM\Column(type="datetime")
  180.      */
  181.     protected $last_time;
  182.    
  183.     /**
  184.      * @ORM\Column(type="datetime")
  185.      */
  186.     protected $last_activity;
  187.    
  188.     /**
  189.      * @ORM\Column(type="text", nullable=true)
  190.      */
  191.     protected $access_token;
  192.    
  193.     /**
  194.      * @ORM\Column(type="datetime", nullable=true)
  195.      */
  196.     protected $access_token_created;
  197.    
  198.     /**
  199.      * @ORM\Column(type="date", nullable=true)
  200.      */
  201.     protected $date_of_signature;
  202.    
  203.     /**
  204.      * @ORM\Column(type="date", nullable=true)
  205.      */
  206.     protected $date_end;
  207.    
  208.     /**
  209.      * @ORM\ManyToOne(targetEntity="User", inversedBy="managers")
  210.      */
  211.     protected $manager;
  212.    
  213.     /**
  214.      * @ORM\Column(type="float")
  215.      */
  216.     protected $credit;
  217.    
  218.     /**
  219.      * @ORM\Column(type="float")
  220.      */
  221.     protected $credit_trust;
  222.    
  223.     /**
  224.      * @ORM\Column(type="float")
  225.      */
  226.     protected $credit_blocking;
  227.    
  228.     /**
  229.      * @ORM\Column(type="float")
  230.      */
  231.     protected $credit_debit;
  232.    
  233.     /**
  234.      * @ORM\Column(nullable=true)
  235.      */
  236.     protected $contact_name;
  237.    
  238.     /**
  239.      * @ORM\Column(nullable=true)
  240.      */
  241.     protected $contact_mobile;
  242.    
  243.     /**
  244.      * @ORM\Column(nullable=true)
  245.      */
  246.     protected $contact_phone;
  247.    
  248.     /**
  249.      * @ORM\Column(nullable=true)
  250.      */
  251.     protected $contact_email;
  252.    
  253.     /**
  254.      * @ORM\Column(type="text", nullable=true)
  255.      */
  256.     protected $note;
  257.    
  258.     /**
  259.      * @ORM\Column(type="integer")
  260.      */
  261.     protected $sort_logo;
  262.    
  263.     /**
  264.      * @ORM\Column(type="text", nullable=true)
  265.      */
  266.     protected $logo;
  267.    
  268.     /**
  269.      * @ORM\Column(type="text", nullable=true)
  270.      */
  271.     protected $inter_note;
  272.    
  273.     /**
  274.      * @ORM\OneToMany(targetEntity="User", mappedBy="manager")
  275.      */
  276.     protected $managers;
  277.    
  278.     /**
  279.      * @ORM\OneToMany(targetEntity="Item", mappedBy="user")
  280.      */
  281.     protected $items;
  282.    
  283.     /**
  284.      * @ORM\OneToMany(targetEntity="Shop", mappedBy="buyer")
  285.      */
  286.     protected $buyer_shops;
  287.    
  288.     /**
  289.      * @ORM\OneToMany(targetEntity="Shop", mappedBy="seller")
  290.      */
  291.     protected $seller_shops;
  292.    
  293.    
  294.  
  295.     public function __construct() {
  296.         $this->last_time = new \DateTime();
  297.         $this->reg_time = new \DateTime();
  298.         $this->last_activity = new \DateTime();
  299.         $this->credit = 0;
  300.         $this->credit_blocking = 0;
  301.         $this->credit_debit = 0;
  302.         $this->credit_trust = 0;
  303.         $this->sort_logo = 0;
  304.        
  305.         $this->managers = new \Doctrine\Common\Collections\ArrayCollection();
  306.         $this->items = new \Doctrine\Common\Collections\ArrayCollection();
  307.         $this->buyer_shops = new \Doctrine\Common\Collections\ArrayCollection();
  308.         $this->seller_shops = new \Doctrine\Common\Collections\ArrayCollection();
  309.     }
  310.    
  311.     /**
  312.      * @param string $role
  313.      * @return \App\Model\User
  314.      */
  315.     public function setRole($role) {
  316.         if (!in_array($role, [self::ROLE_ADMIN, self::ROLE_MANAGER, self::ROLE_CLIENT]))
  317.             throw new \InvalidArgumentException("Zle nastavená role: '$role'.");
  318.        
  319.         $this->role = $role;
  320.         return $this;
  321.     }
  322.    
  323.     /**
  324.      * @return string
  325.      */
  326.     public function getRoleName() {
  327.         if(!isset(self::$roles[$this->role])) {
  328.             throw new \InvalidArgumentException("Zle požádané role: '$this->role'.");
  329.         }
  330.        
  331.         return self::$roles[$this->role];
  332.     }
  333.    
  334.     /**
  335.      * @return string
  336.      */
  337.     public function getFlagName() {
  338.         if(!isset(self::$flags[$this->flag])) {
  339.             throw new \InvalidArgumentException("Zle požádaný flag: '$this->flag'.");
  340.         }
  341.        
  342.         return self::$flags[$this->flag];
  343.     }
  344.    
  345.     /**
  346.      * @return string
  347.      */
  348.     public function getFullname() {
  349.         if(!\Nette\Utils\Validators::isNone($this->company_name)) {
  350.             return $this->company_name;
  351.         } else if (!\Nette\Utils\Validators::isNone($this->name)) {
  352.             return $this->name;
  353.         } else {
  354.             return $this->username;
  355.         }
  356.     }
  357. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement