initial commit
[namibia] / module / Auction / src / Auction / Entity / Bid.php
1 <?php
2 namespace Auction\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="auction_bid")
14  */
15 class Bid
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", cascade={"all"})
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="AutoBid")
63          * @ORM\JoinColumn(nullable=true, name="auction_autobid_id")
64          **/
65         protected $autoBid;
66
67
68         /* ------------------------------------ Bid ------------------------------------ */
69         /**
70          * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, options={"unsigned"=true});
71          */
72         protected $amount = 0.0;
73
74
75         /* ------------------------------------ Tracking ------------------------------------ */
76         /**
77          * @ORM\Column(type="string", length=25, nullable=true, name="status");
78          */
79         protected $status = 'Active';
80
81         /**
82          * @ORM\Column(type="datetime");
83          */
84         protected $created;
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          * Convert the object to an array.
129          * @param array $expand
130          * @param array $intersect
131          * @param boolean $showIdentifiers
132          * @param integer $expandAll
133          * @return array
134          */
135         public function toArray(
136                         array $expand = array(), array $intersect = array(),
137                         $showIdentifiers = false, $expandAll = 0
138                         )
139         {
140                 $intersect = array_flip($intersect);
141                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
142                 $includeAll = empty($intersect);
143                 $data = array();
144                 ($includeAll || isset($intersect['id']))
145                         && $data['id'] = $this->id;
146                 ($includeAll || isset($intersect['auction']))
147                         && $data['auction'] = (in_array('auction', $expand) || $expandAll || $showIdentifiers)
148                                                                         && !is_null($this->auction)
149                                 ? (!$showIdentifiers ? $this->auction->toArray(
150                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
151                                                 ) : $this->auction->id)
152                                 : null;
153                 ($includeAll || isset($intersect['company']))
154                         && $data['company'] = (in_array('company', $expand) || $expandAll || $showIdentifiers)
155                                                                         && !is_null($this->company)
156                                 ? (!$showIdentifiers ? $this->company->toArray(
157                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
158                                                 ) : $this->company->id)
159                                 : null;
160                 ($includeAll || isset($intersect['profile']))
161                         && $data['profile'] = (in_array('profile', $expand) || $expandAll || $showIdentifiers)
162                                                                         && !is_null($this->profile)
163                                 ? (!$showIdentifiers ? $this->profile->toArray(
164                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
165                                                 ) : $this->profile->id)
166                                 : null;
167                 ($includeAll || isset($intersect['autoBid']))
168                         && $data['autoBid'] = (in_array('autoBid', $expand) || $expandAll || $showIdentifiers)
169                                                                         && !is_null($this->autoBid)
170                                 ? (!$showIdentifiers ? $this->autoBid->toArray(
171                                                 array(), array(), true, false
172                                                 /* $expand, $intersect, $showIdentifiers, ($expandAll - 1) */
173                                                 ) : $this->autoBid->id)
174                                 : null;
175                 ($includeAll || isset($intersect['amount']))
176                         && $data['amount'] = $this->amount;
177                 ($includeAll || isset($intersect['status']))
178                         && $data['status'] = $this->status;
179                 ($includeAll || isset($intersect['created']))
180                         && $data['created'] = !is_null($this->created)
181                                 ? $this->created->format($dateTimeFormat)
182                                 : null;
183                 return $data;
184         }
185
186         /**
187          * Populate from an array.
188          * @param array $data
189          */
190         public function fromArray($data = array())
191         {
192                 isset($data['id'])
193                         && $this->id = $data['id'];
194                 isset($data['auction'])
195                         && $this->auction = $data['auction'];
196                 isset($data['company'])
197                         && $this->company = $data['company'];
198                 isset($data['profile'])
199                         && $this->profile = $data['profile'];
200                 isset($data['autoBid'])
201                         && $this->autoBid = $data['autoBid'];
202                 isset($data['amount'])
203                         && $this->amount = $data['amount'];
204                 isset($data['status'])
205                         && $this->status = $data['status'];
206         }
207
208
209
210 }
211