latest updates, towns and regions
[namibia] / module / User / src / User / Entity / AuthenticationLog.php
1 <?php
2 namespace User\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * Authentication logs.
10  * @ORM\Entity
11  * @ORM\HasLifecycleCallbacks
12  * @ORM\Table(name="lib_authentication_log")
13  */
14 class AuthenticationLog
15 {
16
17         /**
18          * Can archive records.
19          */
20         const ARCHIVE = false;
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\ManyToOne(targetEntity="Profile", inversedBy="logins")
39          * @ORM\JoinColumn(nullable=true, name="profile_id", referencedColumnName="id")
40          **/
41         protected $profile;
42
43         /**
44          * @ORM\Column(type="string", nullable=true, length=100, name="ip_address")
45          */
46         protected $ipAddress;
47
48         /**
49          * @ORM\Column(type="datetime");
50          */
51         protected $created;
52
53
54         /**
55          * Magic getter to expose protected properties.
56          * @param string $property
57          * @return mixed
58          */
59         public function __get($property)
60         {
61                 return $this->$property;
62         }
63
64         /**
65          * Magic setter to save protected properties.
66          * @param string $property
67          * @param mixed $value
68          */
69         public function __set($property, $value)
70         {
71                 $this->$property = $value;
72         }
73
74         /**
75          * @ORM\PrePersist
76          */
77         public function setCreateTime()
78         {
79                 $this->created = new \DateTime("now");
80         }
81
82         /**
83          * Convert the object to an array.
84          * @param array $expand
85          * @param array $intersect
86          * @return array
87          */
88         public function toArray(array $expand = array('attachment'), array $intersect = array())
89         {
90                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
91                 $includeAll = empty($intersect);
92                 $data = array();
93                 ($includeAll || isset($intersect['id']))
94                         && $data['id'] = $this->id;
95                 ($includeAll || isset($intersect['profile']))
96                         && $data['profile'] = in_array('profile', $expand)
97                                                                         && !is_null($this->profile)
98                                 ? $this->profile->toArray($expand, $intersect)
99                                 : null;
100                 ($includeAll || isset($intersect['ipAddress']))
101                         && $data['ipAddress'] = $this->ipAddress;
102                 ($includeAll || isset($intersect['created']))
103                         && $data['created'] = !is_null($this->created)
104                                 ? $this->created->format($dateTimeFormat)
105                                 : null;
106                 return $data;
107         }
108
109         /**
110          * Populate from an array.
111          * @param array $data
112          */
113         public function fromArray($data = array())
114         {
115                 isset($data['id'])
116                         && $this->id = $data['id'];
117                 isset($data['profile'])
118                         && $this->profile = $data['profile'];
119                 isset($data['ipAddress'])
120                         && $this->ipAddress = $data['ipAddress'];
121         }
122
123 }