initial commit
[namibia] / module / Auction / src / Auction / Entity / AutoBid.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_autobid")
14  */
15 class AutoBid
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         /* ------------------------------------ Bid ------------------------------------ */
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          * @ORM\Column(type="string", length=25, nullable=true, name="status");
72          */
73         protected $status = 'Active';
74
75         /**
76          * @ORM\Column(type="datetime");
77          */
78         protected $created;
79
80         /**
81          * @ORM\Column(type="boolean");
82          */
83         protected $archived = false;
84
85
86
87         /**
88          * Magic getter to expose protected properties.
89          *
90          * @param string $property
91          * @return mixed
92          */
93         public function __get($property)
94         {
95                 return $this->$property;
96         }
97
98         /**
99          * Magic setter to save protected properties.
100          *
101          * @param string $property
102          * @param mixed $value
103          */
104         public function __set($property, $value)
105         {
106                 $this->$property = $value;
107         }
108
109         /**
110          * @ORM\PrePersist
111          */
112         public function setCreateTime()
113         {
114                 $this->company = \Utility\Registry::resolveCompanyContext($this->company);
115                 $this->profile = \Utility\Registry::resolveProfileContext($this->profile);
116                 $this->created = new \DateTime("now");
117         }
118
119         /**
120          * Convert the object to an array.
121          * @param array $expand
122          * @param array $intersect
123          * @param boolean $showIdentifiers
124          * @param integer $expandAll
125          * @return array
126          */
127         public function toArray(
128                         array $expand = array(), array $intersect = array(),
129                         $showIdentifiers = false, $expandAll = 0
130                         )
131         {
132                 $intersect = array_flip($intersect);
133                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
134                 $includeAll = empty($intersect);
135                 $data = array();
136                 ($includeAll || isset($intersect['id']))
137                         && $data['id'] = $this->id;
138                 ($includeAll || isset($intersect['auction']))
139                         && $data['auction'] = (in_array('auction', $expand) || $expandAll || $showIdentifiers)
140                                                                         && !is_null($this->auction)
141                                 ? (!$showIdentifiers ? $this->auction->toArray(
142                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
143                                                 ) : $this->auction->id)
144                                 : null;
145                 ($includeAll || isset($intersect['company']))
146                         && $data['company'] = (in_array('company', $expand) || $expandAll || $showIdentifiers)
147                                                                         && !is_null($this->company)
148                                 ? (!$showIdentifiers ? $this->company->toArray(
149                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
150                                                 ) : $this->company->id)
151                                 : null;
152                 ($includeAll || isset($intersect['profile']))
153                         && $data['profile'] = (in_array('profile', $expand) || $expandAll || $showIdentifiers)
154                                                                         && !is_null($this->profile)
155                                 ? (!$showIdentifiers ? $this->profile->toArray(
156                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
157                                                 ) : $this->profile->id)
158                                 : null;
159                 ($includeAll || isset($intersect['amount']))
160                         && $data['amount'] = $this->amount;
161                 ($includeAll || isset($intersect['status']))
162                         && $data['status'] = $this->status;
163                 ($includeAll || isset($intersect['created']))
164                         && $data['created'] = !is_null($this->created)
165                                 ? $this->created->format($dateTimeFormat)
166                                 : null;
167                 return $data;
168         }
169
170         /**
171          * Populate from an array.
172          * @param array $data
173          */
174         public function fromArray($data = array())
175         {
176                 isset($data['id'])
177                         && $this->id = $data['id'];
178                 isset($data['auction'])
179                         && $this->auction = $data['auction'];
180                 isset($data['company'])
181                         && $this->company = $data['company'];
182                 isset($data['profile'])
183                         && $this->profile = $data['profile'];
184                 isset($data['amount'])
185                         && $this->amount = $data['amount'];
186                 isset($data['status'])
187                         && $this->status = $data['status'];
188         }
189
190
191
192 }
193