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