initial commit
[namibia] / module / Valuation / src / Valuation / Entity / XmlRpc.php
1 <?php
2 namespace Valuation\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * An xml-rpc client.
10  *
11  * @ORM\Entity
12  * @ORM\HasLifecycleCallbacks
13  * @ORM\Table(name="xmlrpc_auth")
14  */
15 class XmlRpc
16 {
17
18         /**
19          * Can archive records.
20          */
21         const ARCHIVE = true;
22         /**
23          * Pull Synchronization Strategy for this table.
24          */
25         const PULL_SYNCH_STRATEGY = false;
26         /**
27          * Push Synchronization Strategy for this table.
28          */
29         const PUSH_SYNCH_STRATEGY = false;
30
31
32
33         /* ------------------------------------ Identification ------------------------------------ */
34         /**
35          * @ORM\Id
36          * @ORM\Column(type="integer");
37          * @ORM\GeneratedValue(strategy="AUTO")
38          */
39         protected $id;
40
41         /**
42          * @ORM\Column(type="string", length=50, nullable=false, name="client_name");
43          */
44         protected $clientName;
45
46         /**
47          * @ORM\Column(type="string", length=42, nullable=false, name="client_api_id");
48          */
49         protected $clientApiId;
50
51         /**
52          * @ORM\Column(type="string", length=42, nullable=false, name="password_hash");
53          */
54         protected $passwordHash;
55
56         /**
57          * @ORM\Column(type="string", length=42, nullable=true, name="auth_token");
58          */
59         protected $authToken;
60
61         /**
62          * @ORM\Column(type="string", length=40, nullable=true, name="ip_address");
63          */
64         protected $ipAddress;
65
66         /**
67          * @ORM\Column(type="string", length=250, nullable=false, name="callback_url");
68          */
69         protected $callbackUrl;
70
71         /**
72          * @ORM\Column(type="boolean", name="trigger_sent_to_sales");
73          */
74         protected $triggerSentToSales = true;
75
76         /**
77          * @ORM\Column(type="datetime");
78          */
79         protected $created;
80
81         /**
82          * @ORM\Column(type="datetime", nullable=true);
83          */
84         protected $updated;
85
86         /**
87          * @ORM\Column(type="boolean");
88          */
89         protected $archived = false;
90
91
92
93         /**
94          * Magic getter to expose protected properties.
95          *
96          * @param string $property
97          * @return mixed
98          */
99         public function __get($property)
100         {
101                 return $this->$property;
102         }
103
104         /**
105          * Magic setter to save protected properties.
106          *
107          * @param string $property
108          * @param mixed $value
109          */
110         public function __set($property, $value)
111         {
112                 if ('password' == $property)
113                 {
114                         $this->passwordHash = md5($value);
115                         return;
116                 }
117                 if ('ipAddress' == $property)
118                 {
119                         $this->authToken = md5($this->clientApiId . time() . $this->passwordHash);
120                         $this->ipAddress = $value;
121                         return;
122                 }
123                 $this->$property = $value;
124         }
125
126         /**
127          * @ORM\PrePersist
128          */
129         public function setCreateTime()
130         {
131                 $this->created = new \DateTime("now");
132                 $this->clientApiId = md5(time() . 'xmlrpc-client');
133         }
134
135         /**
136          * @ORM\PreUpdate
137          */
138         public function setUpdateTime()
139         {
140                 $this->updated = new \DateTime("now");
141         }
142
143         /**
144          * Convert the object to an array.
145          * @param array $expand
146          * @param array $intersect
147          * @param boolean $showIdentifiers
148          * @param integer $expandAll
149          * @return array
150          */
151         public function toArray(
152                         array $expand = array(), array $intersect = array(),
153                         $showIdentifiers = false, $expandAll = 0
154                         )
155         {
156                 $intersect = array_flip($intersect);
157                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
158                 $includeAll = empty($intersect);
159                 $data = array();
160                 ($includeAll || isset($intersect['id']))
161                         && $data['id'] = $this->id;
162                 ($includeAll || isset($intersect['clientName']))
163                         && $data['clientName'] = $this->clientName;
164                 ($includeAll || isset($intersect['clientApiId']))
165                         && $data['clientApiId'] = $this->clientApiId;
166                 ($includeAll || isset($intersect['ipAddress']))
167                         && $data['ipAddress'] = $this->ipAddress;
168                 ($includeAll || isset($intersect['callbackUrl']))
169                         && $data['callbackUrl'] = $this->callbackUrl;
170                 ($includeAll || isset($intersect['triggerSentToSales']))
171                         && $data['triggerSentToSales'] = $this->triggerSentToSales;
172                 ($includeAll || isset($intersect['created']))
173                         && $data['created'] = !is_null($this->created)
174                                 ? $this->created->format($dateTimeFormat)
175                                 : null;
176                 ($includeAll || isset($intersect['updated']))
177                         && $data['updated'] = !is_null($this->updated)
178                                 ? $this->updated->format($dateTimeFormat)
179                                 : null;
180                 ($includeAll || isset($intersect['archived']))
181                         && $data['archived'] = $this->archived;
182                 return $data;
183         }
184
185         /**
186          * Populate from an array.
187          * @param array $data
188          */
189         public function fromArray($data = array())
190         {
191                 isset($data['id'])
192                         && $this->id = $data['id'];
193                 isset($data['clientName'])
194                         && $this->clientName = $data['clientName'];
195                 isset($data['password'])
196                         && $this->passwordHash = md5($data['password']);
197                 isset($data['callbackUrl'])
198                         && $this->callbackUrl = $data['callbackUrl'];
199                 isset($data['triggerSentToSales'])
200                         && $this->triggerSentToSales = $data['triggerSentToSales'];
201                 isset($data['ipAddress'])
202                         && $this->ipAddress = $data['ipAddress'];
203                 isset($data['ipAddress'])
204                         && $this->authToken = md5($this->clientApiId . time() . $this->passwordHash);
205         }
206
207
208
209 }
210