initial commit
[namibia] / module / Utility / src / Utility / Entity / ApiLog.php
1 <?php
2 namespace Utility\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * Notification logs.
10  * @ORM\Entity
11  * @ORM\HasLifecycleCallbacks
12  * @ORM\Table(name="lib_api_log")
13  */
14 class ApiLog
15 {
16
17         /**
18          * Can archive records.
19          */
20         const ARCHIVE = true;
21         /**
22          * Pull Synchronization Strategy for this table.
23          */
24         const PULL_SYNCH_STRATEGY = false;
25         /**
26          * Push Synchronization Strategy for this table.
27          */
28         const PUSH_SYNCH_STRATEGY = false;
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", nullable=true, length=250)
39          */
40         protected $service;
41
42         /**
43          * @ORM\Column(type="array", nullable=true)
44          */
45         protected $request;
46
47         /**
48          * @ORM\Column(type="array", nullable=true)
49          */
50         protected $response;
51
52         /**
53          * @ORM\Column(type="string", length=30, name="status")
54          */
55         protected $status;
56
57         /**
58          * @ORM\ManyToOne(targetEntity="\Company\Entity\Company")
59          * @ORM\JoinColumn(nullable=true, name="from_company_id")
60          **/
61         protected $fromCompany;
62
63         /**
64          * @ORM\ManyToOne(targetEntity="\User\Entity\Profile")
65          * @ORM\JoinColumn(nullable=true, name="from_profile_id")
66          **/
67         protected $fromProfile;
68
69         /**
70          * @ORM\Column(type="datetime");
71          */
72         protected $created;
73
74         /**
75          * @ORM\Column(type="datetime", nullable=true);
76          */
77         protected $updated;
78
79         /**
80          * @ORM\Column(type="boolean");
81          */
82         protected $archived = false;
83
84
85         /**
86          * Magic getter to expose protected properties.
87          * @param string $property
88          * @return mixed
89          */
90         public function __get($property)
91         {
92                 return $this->$property;
93         }
94
95         /**
96          * Magic setter to save protected properties.
97          * @param string $property
98          * @param mixed $value
99          */
100         public function __set($property, $value)
101         {
102                 $this->$property = $value;
103         }
104
105         /**
106          * @ORM\PrePersist
107          */
108         public function setCreateTime()
109         {
110                 $this->created = new \DateTime("now");
111         }
112
113         /**
114          * @ORM\PreUpdate
115          */
116         public function setUpdateTime()
117         {
118                 $this->updated = new \DateTime("now");
119         }
120
121         /**
122          * Convert the object to an array.
123          * @param array $expand
124          * @param array $intersect
125          * @return array
126          */
127         public function toArray(array $expand = array('attachment'), array $intersect = array())
128         {
129                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
130                 $includeAll = empty($intersect);
131                 $data = array();
132                 ($includeAll || isset($intersect['id']))
133                         && $data['id'] = $this->id;
134                 ($includeAll || isset($intersect['service']))
135                         && $data['service'] = $this->service;
136                 ($includeAll || isset($intersect['request']))
137                         && $data['request'] = $this->request;
138                 ($includeAll || isset($intersect['response']))
139                         && $data['response'] = $this->response;
140                 ($includeAll || isset($intersect['status']))
141                         && $data['status'] = $this->status;
142                 ($includeAll || isset($intersect['fromCompany']))
143                         && $data['fromCompany'] = in_array('fromCompany', $expand)
144                                                                         && !is_null($this->fromCompany)
145                                 ? $this->fromCompany->toArray($expand, $intersect)
146                                 : null;
147                 ($includeAll || isset($intersect['fromProfile']))
148                         && $data['fromProfile'] = in_array('fromProfile', $expand)
149                                                                         && !is_null($this->fromProfile)
150                                 ? $this->fromProfile->toArray($expand, $intersect)
151                                 : null;
152                 ($includeAll || isset($intersect['created']))
153                         && $data['created'] = !is_null($this->created)
154                                 ? $this->created->format($dateTimeFormat)
155                                 : null;
156                 ($includeAll || isset($intersect['updated']))
157                         && $data['updated'] = !is_null($this->updated)
158                                 ? $this->updated->format($dateTimeFormat)
159                                 : null;
160                 return $data;
161         }
162
163         /**
164          * Populate from an array.
165          * @param array $data
166          */
167         public function fromArray($data = array())
168         {
169                 isset($data['id'])
170                         && $this->id = $data['id'];
171                 isset($data['service'])
172                         && $this->service = $data['service'];
173                 isset($data['request'])
174                         && $this->request = $data['request'];
175                 isset($data['response'])
176                         && $this->response = $data['response'];
177                 isset($data['status'])
178                         && $this->status = $data['status'];
179                 isset($data['fromCompany'])
180                         && $this->fromCompany = $data['fromCompany'];
181                 isset($data['fromProfile'])
182                         && $this->fromProfile = $data['fromProfile'];
183         }
184
185 }