initial commit
[namibia] / module / Auction / src / Auction / Entity / Question.php
1 <?php
2 namespace Auction\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * A question concerning an item on auction..
10  *
11  * @ORM\Entity
12  * @ORM\HasLifecycleCallbacks
13  * @ORM\Table(name="auction_question")
14  */
15 class Question
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         /* ------------------------------------ Ownership ------------------------------------ */
43         /**
44          * @ORM\ManyToOne(targetEntity="Auction")
45          * @ORM\JoinColumn(nullable=false, name="auction_id")
46          **/
47         protected $auction;
48
49         /**
50          * @ORM\ManyToOne(targetEntity="\Company\Entity\Company")
51          * @ORM\JoinColumn(nullable=false, name="company_id")
52          **/
53         protected $company;
54
55         /**
56          * @ORM\ManyToOne(targetEntity="\User\Entity\Profile")
57          * @ORM\JoinColumn(nullable=false, name="profile_id")
58          **/
59         protected $profile;
60
61         /**
62          * @ORM\ManyToOne(targetEntity="Reply")
63          * @ORM\JoinColumn(nullable=true, name="auction_reply_id")
64          **/
65         protected $reply;
66
67
68         /* ------------------------------------ Question ------------------------------------ */
69         /**
70          * @ORM\Column(type="text")
71          */
72         protected $question = '';
73
74
75         /* ------------------------------------ Tracking ------------------------------------ */
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                 $this->$property = $value;
113         }
114
115         /**
116          * @ORM\PrePersist
117          */
118         public function setCreateTime()
119         {
120                 is_null($this->company)
121                         && $this->company = \Utility\Registry::resolveCompanyContext($this->company);
122                 is_null($this->profile)
123                         && $this->profile = \Utility\Registry::resolveProfileContext($this->profile);
124                 $this->created = new \DateTime("now");
125         }
126
127         /**
128          * @ORM\PreUpdate
129          */
130         public function setUpdateTime()
131         {
132                 $this->updated = new \DateTime("now");
133         }
134
135         /**
136          * Convert the object to an array.
137          * @param array $expand
138          * @param array $intersect
139          * @param boolean $showIdentifiers
140          * @param integer $expandAll
141          * @return array
142          */
143         public function toArray(
144                         array $expand = array(), array $intersect = array(),
145                         $showIdentifiers = false, $expandAll = 0
146                         )
147         {
148                 $intersect = array_flip($intersect);
149                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
150                 $includeAll = empty($intersect);
151                 $data = array();
152                 ($includeAll || isset($intersect['id']))
153                         && $data['id'] = $this->id;
154                 ($includeAll || isset($intersect['auction']))
155                         && $data['auction'] = (in_array('auction', $expand) || $expandAll || $showIdentifiers)
156                                                                         && !is_null($this->auction)
157                                 ? (!$showIdentifiers ? $this->auction->toArray(
158                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
159                                                 ) : $this->auction->id)
160                                 : null;
161                 ($includeAll || isset($intersect['company']))
162                         && $data['company'] = (in_array('company', $expand) || $expandAll || $showIdentifiers)
163                                                                         && !is_null($this->company)
164                                 ? (!$showIdentifiers ? $this->company->toArray(
165                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
166                                                 ) : $this->company->id)
167                                 : null;
168                 ($includeAll || isset($intersect['profile']))
169                         && $data['profile'] = (in_array('profile', $expand) || $expandAll || $showIdentifiers)
170                                                                         && !is_null($this->profile)
171                                 ? (!$showIdentifiers ? $this->profile->toArray(
172                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
173                                                 ) : $this->profile->id)
174                                 : null;
175                 ($includeAll || isset($intersect['reply']))
176                         && $data['reply'] = (in_array('reply', $expand) || $expandAll || $showIdentifiers)
177                                                                         && !is_null($this->reply)
178                                 ? (!$showIdentifiers ? $this->reply->toArray(
179                                                 array(), array(), true, false
180                                                 /* $expand, $intersect, $showIdentifiers, ($expandAll - 1) */
181                                                 ) : $this->reply->id)
182                                 : null;
183                 ($includeAll || isset($intersect['question']))
184                         && $data['question'] = $this->question;
185                 ($includeAll || isset($intersect['created']))
186                         && $data['created'] = !is_null($this->created)
187                                 ? $this->created->format($dateTimeFormat)
188                                 : null;
189                 ($includeAll || isset($intersect['updated']))
190                         && $data['updated'] = !is_null($this->updated)
191                                 ? $this->updated->format($dateTimeFormat)
192                                 : null;
193                 return $data;
194         }
195
196         /**
197          * Populate from an array.
198          * @param array $data
199          */
200         public function fromArray($data = array())
201         {
202                 isset($data['id'])
203                         && $this->id = $data['id'];
204                 isset($data['auction'])
205                         && $this->auction = $data['auction'];
206                 isset($data['company'])
207                         && $this->company = $data['company'];
208                 isset($data['profile'])
209                         && $this->profile = $data['profile'];
210                 isset($data['reply'])
211                         && $this->reply = $data['reply'];
212                 isset($data['question'])
213                         && $this->question = $data['question'];
214         }
215
216
217
218 }
219