initial commit
[namibia] / module / PriceGuide / src / PriceGuide / Entity / Offer.php
1 <?php
2 namespace PriceGuide\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * A price guide club member.
10  *
11  * @ORM\Entity
12  * @ORM\HasLifecycleCallbacks
13  * @ORM\Table(name="price_guide_offer")
14  */
15 class Offer
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="PriceGuide")
45          * @ORM\JoinColumn(nullable=false, name="price_guide_id")
46          **/
47         protected $priceGuideStock;
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         /* ------------------------------------ Offer ------------------------------------ */
63         /**
64          * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, options={"unsigned"=true});
65          */
66         protected $amount = 0.0;
67
68
69         /* ------------------------------------ Tracking ------------------------------------ */
70
71         /**
72          * @ORM\Column(type="string", length=25, nullable=true, name="previous_status");
73          */
74         protected $previousStatus = '';
75
76         /**
77          * @ORM\Column(type="string", length=25, nullable=true, name="status");
78          */
79         protected $status = 'Updateable Offer';
80
81         /**
82          * @ORM\Column(type="datetime");
83          */
84         protected $created;
85
86         /**
87          * @ORM\Column(type="datetime", nullable=true);
88          */
89         protected $updated;
90
91         /**
92          * @ORM\Column(type="boolean");
93          */
94         protected $archived = false;
95
96
97
98         /**
99          * Magic getter to expose protected properties.
100          *
101          * @param string $property
102          * @return mixed
103          */
104         public function __get($property)
105         {
106                 return $this->$property;
107         }
108
109         /**
110          * Magic setter to save protected properties.
111          *
112          * @param string $property
113          * @param mixed $value
114          */
115         public function __set($property, $value)
116         {
117                 $this->$property = $value;
118         }
119
120         /**
121          * @ORM\PrePersist
122          */
123         public function setCreateTime()
124         {
125                 if (is_null($this->company))
126                 {
127                         $this->company = \Utility\Registry::resolveCompanyContext($this->company);
128                 }
129                 if (is_null($this->profile))
130                 {
131                         $this->profile = \Utility\Registry::resolveProfileContext($this->profile);
132                 }
133                 $this->created = new \DateTime("now");
134         }
135
136         /**
137          * @ORM\PreUpdate
138          */
139         public function setUpdateTime()
140         {
141                 $this->updated = new \DateTime("now");
142         }
143
144         /**
145          * Convert the object to an array.
146          * @param array $expand
147          * @param array $intersect
148          * @param boolean $showIdentifiers
149          * @param integer $expandAll
150          * @return array
151          */
152         public function toArray(
153                         array $expand = array(), array $intersect = array(),
154                         $showIdentifiers = false, $expandAll = 0
155                         )
156         {
157                 $intersect = array_flip($intersect);
158                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
159                 $includeAll = empty($intersect);
160                 $data = array();
161                 ($includeAll || isset($intersect['id']))
162                         && $data['id'] = $this->id;
163                 ($includeAll || isset($intersect['priceGuideStock']))
164                         && $data['priceGuideStock'] = (in_array('priceGuideStock', $expand) || $expandAll || $showIdentifiers)
165                                                                         && !is_null($this->priceGuideStock)
166                                 ? (!$showIdentifiers ? $this->priceGuideStock->toArray(
167                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
168                                                 ) : $this->priceGuideStock->id)
169                                 : null;
170                 ($includeAll || isset($intersect['company']))
171                         && $data['company'] = (in_array('company', $expand) || $expandAll || $showIdentifiers)
172                                                                         && !is_null($this->company)
173                                 ? (!$showIdentifiers ? $this->company->toArray(
174                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
175                                                 ) : $this->company->id)
176                                 : null;
177                 ($includeAll || isset($intersect['profile']))
178                         && $data['profile'] = (in_array('profile', $expand) || $expandAll || $showIdentifiers)
179                                                                         && !is_null($this->profile)
180                                 ? (!$showIdentifiers ? $this->profile->toArray(
181                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
182                                                 ) : $this->profile->id)
183                                 : null;
184                 ($includeAll || isset($intersect['amount']))
185                         && $data['amount'] = $this->amount;
186                 ($includeAll || isset($intersect['status']))
187                         && $data['status'] = $this->status;
188                 ($includeAll || isset($intersect['created']))
189                         && $data['created'] = !is_null($this->created)
190                                 ? $this->created->format($dateTimeFormat)
191                                 : null;
192                 ($includeAll || isset($intersect['updated']))
193                         && $data['updated'] = !is_null($this->updated)
194                                 ? $this->updated->format($dateTimeFormat)
195                                 : null;
196                 return $data;
197         }
198
199         /**
200          * Populate from an array.
201          * @param array $data
202          */
203         public function fromArray($data = array())
204         {
205                 isset($data['id'])
206                         && $this->id = $data['id'];
207                 isset($data['priceGuideStock'])
208                         && $this->priceGuideStock = $data['priceGuideStock'];
209                 isset($data['company'])
210                         && $this->company = $data['company'];
211                 isset($data['profile'])
212                         && $this->profile = $data['profile'];
213                 isset($data['amount'])
214                         && $this->amount = $data['amount'];
215                 isset($data['status'])
216                         && $this->status = $data['status'];
217         }
218
219
220
221 }
222