initial commit
[namibia] / module / Retail / src / Retail / Entity / Retail.php
1 <?php
2 namespace Retail\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * @ORM\Entity
10  * @ORM\HasLifecycleCallbacks
11  * @ORM\Table(name="retail", uniqueConstraints={@ORM\UniqueConstraint(name="unique_retailer", columns={"name"})})
12  */
13 class Retail
14 {
15
16         /**
17          * Can archive records.
18          */
19         const ARCHIVE = false;
20         /**
21          * Pull Synchronization Strategy for this table.
22          */
23         const PULL_SYNCH_STRATEGY = false;
24         /**
25          * Push Synchronization Strategy for this table.
26          */
27         const PUSH_SYNCH_STRATEGY = false;
28
29
30         /**
31          * @ORM\Id
32          * @ORM\Column(type="integer");
33          * @ORM\GeneratedValue(strategy="AUTO")
34          */
35         protected $id;
36
37         /**
38          * @ORM\Column(type="string", length=150, unique=true)
39          */
40         protected $name;
41
42         /**
43          * @ORM\Column(type="string", length=64, name="auth_token")
44          */
45         protected $authToken;
46
47         /**
48          * @ORM\Column(type="integer");
49          */
50         protected $requests = 0;
51
52         /**
53          * @ORM\Column(type="datetime");
54          */
55         protected $created;
56
57         /**
58          * @ORM\Column(type="datetime", nullable=true);
59          */
60         protected $updated;
61
62
63
64         /**
65          * Magic getter to expose protected properties.
66          * @param string $property
67          * @return mixed
68          */
69         public function __get($property)
70         {
71                 return $this->$property;
72         }
73
74         /**
75          * Magic setter to save protected properties.
76          * @param string $property
77          * @param mixed $value
78          */
79         public function __set($property, $value)
80         {
81                 $this->$property = $value;
82         }
83
84
85         /**
86          * @ORM\PrePersist
87          */
88         public function setCreateTime()
89         {
90                 $this->created = new \DateTime("now");
91         }
92
93         /**
94          * @ORM\PreUpdate
95          */
96         public function setUpdateTime()
97         {
98                 $this->updated = new \DateTime("now");
99         }
100
101         public function fromArray($data)
102         {
103                 isset($data['name'])
104                         && $this->name = $data['name'];
105                 isset($data['authToken'])
106                         && $this->authToken = $data['authToken'];
107                 isset($data['requests'])
108                         && $this->requests = $data['requests'];
109         }
110
111         public function toArray()
112         {
113                 return array(
114                         'id'   => $this->id,
115                         'name' => $this->name
116                 );
117         }
118 }