initial commit
[namibia] / module / Company / src / Company / Entity / Group.php
1 <?php
2 namespace Company\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * Dealer Group.
10  * @ORM\Entity
11  * @ORM\HasLifecycleCallbacks
12  * @ORM\Table(name="company_group")
13  */
14 class Group
15 {
16
17         /**
18          * Can archive records.
19          */
20         const ARCHIVE = true;
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         /**
32          * Valid pricing types.
33          */
34         const PRICINGTYPE_INCREMENTAL = 'Incremental';
35         const PRICINGTYPE_FIXED       = 'Fixed';
36
37
38         /**
39          * @ORM\Id
40          * @ORM\Column(type="integer");
41          * @ORM\GeneratedValue(strategy="AUTO")
42          */
43         protected $id;
44
45         /**
46          * @ORM\Column(type="string", length=100)
47          */
48         protected $name;
49
50         /**
51          * @ORM\OneToOne(targetEntity="\Utility\Entity\Image")
52          * @ORM\JoinColumn(nullable=true, name="logo_lib_photo_id")
53          **/
54         protected $logo;
55
56         /**
57          * @ORM\OneToOne(targetEntity="\Utility\Entity\Image")
58          * @ORM\JoinColumn(nullable=true, name="watermark_lib_photo_id")
59          **/
60         protected $watermark;
61
62         /**
63          * @ORM\Column(type="smallint", name="number_of_dealers");
64          */
65         protected $numberOfDealers = 0;
66
67         /**
68          * @ORM\Column(type="string", length=25, nullable=true, name="pricing_type")
69          */
70         protected $pricingType = 'Incremental';
71
72         /**
73          * @ORM\Column(type="integer", nullable=true, name="fixed_pricing")
74          */
75         protected $fixedPricing = 0;
76
77         /**
78          * @ORM\Column(type="boolean", name="price_guide");
79          */
80         protected $priceGuide = false;
81
82         /**
83          * @ORM\Column(type="datetime");
84          */
85         protected $created;
86
87         /**
88          * @ORM\Column(type="datetime", nullable=true);
89          */
90         protected $updated;
91
92         /**
93          * @ORM\Column(type="boolean");
94          */
95         protected $archived = false;
96
97         /**
98          * @ORM\OneToMany(targetEntity="Config\Entity\RegionalManager", mappedBy="group", fetch="EXTRA_LAZY")
99          **/
100         private $regionalManagers;
101
102         /**
103          * @ORM\OneToMany(targetEntity="GroupDivision", mappedBy="group", fetch="EXTRA_LAZY")
104          **/
105         private $divisions;
106
107         /**
108          * @ORM\OneToMany(targetEntity="Company", mappedBy="group", fetch="EXTRA_LAZY")
109          **/
110         private $companies;
111
112         /**
113          * @ORM\Column(type="string", name="landing_page");
114          */
115         protected $landingPage = '';
116
117
118         /**
119          * Initialize collections.
120          */
121         public function __construct()
122         {
123                 $this->regionalManagers = new \Doctrine\Common\Collections\ArrayCollection();
124                 $this->divisions = new \Doctrine\Common\Collections\ArrayCollection();
125                 $this->companies = new \Doctrine\Common\Collections\ArrayCollection();
126         }
127
128         /**
129          * Add a new division to this group.
130          * @param Town $town
131          * @return \Location\Entity\Region
132          */
133         public function addDivision(GroupDivision $division)
134         {
135                 $this->divisions[] = $division;
136                 return $this;
137         }
138
139         /**
140          * Magic getter to expose protected properties.
141          * @param string $property
142          * @return mixed
143          */
144         public function __get($property)
145         {
146                 return $this->$property;
147         }
148
149         /**
150          * Magic setter to save protected properties.
151          * @param string $property
152          * @param mixed $value
153          */
154         public function __set($property, $value)
155         {
156                 $this->$property = $value;
157         }
158
159         /**
160          * @ORM\PrePersist
161          */
162         public function setCreateTime()
163         {
164                 $this->created = new \DateTime("now");
165         }
166
167         /**
168          * @ORM\PreUpdate
169          */
170         public function setUpdateTime()
171         {
172                 $this->updated = new \DateTime("now");
173         }
174
175         /**
176          * Convert the object to an array.
177          * @param array $expand
178          * @param array $intersect
179          * @return array
180          */
181         public function toArray(array $expand = array(), array $intersect = array())
182         {
183                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
184                 $includeAll = empty($intersect);
185                 $data = array();
186                 ($includeAll || isset($intersect['id']))
187                         && $data['id'] = $this->id;
188                 ($includeAll || isset($intersect['name']))
189                         && $data['name'] = $this->name;
190                 ($includeAll || isset($intersect['logo']))
191                         && $data['logo'] = in_array('logo', $expand)
192                                                                         && !is_null($this->logo)
193                                 ? $this->logo->toArray($expand, $intersect)
194                                 : null;
195                 ($includeAll || isset($intersect['watermark']))
196                         && $data['watermark'] = in_array('watermark', $expand)
197                                                                         && !is_null($this->watermark)
198                                 ? $this->watermark->toArray($expand, $intersect)
199                                 : null;
200                 ($includeAll || isset($intersect['numberOfDealers']))
201                         && $data['numberOfDealers'] = $this->numberOfDealers;
202                 ($includeAll || isset($intersect['pricingType']))
203                         && $data['pricingType'] = $this->pricingType;
204                 ($includeAll || isset($intersect['landingPage']))
205                         && $data['landingPage'] = $this->landingPage;
206                 ($includeAll || isset($intersect['fixedPricing']))
207                         && $data['fixedPricing'] = $this->fixedPricing;
208                 ($includeAll || isset($intersect['priceGuide']))
209                         && $data['priceGuide'] = $this->priceGuide;
210                 ($includeAll || isset($intersect['created']))
211                         && $data['created'] = !is_null($this->created)
212                                 ? $this->created->format($dateTimeFormat)
213                                 : null;
214                 ($includeAll || isset($intersect['updated']))
215                         && $data['updated'] = !is_null($this->updated)
216                                 ? $this->updated->format($dateTimeFormat)
217                                 : null;
218                 return $data;
219         }
220
221         /**
222          * Populate from an array.
223          * @param array $data
224          */
225         public function fromArray($data = array())
226         {
227                 isset($data['id'])
228                         && $this->id = $data['id'];
229                 isset($data['name'])
230                         && $this->name = $data['name'];
231                 isset($data['logo'])
232                         && $this->logo = $data['logo'];
233                 isset($data['watermark'])
234                         && $this->watermark = $data['watermark'];
235                 isset($data['numberOfDealers'])
236                         && $this->numberOfDealers = $data['numberOfDealers'];
237                 isset($data['pricingType'])
238                         && $this->pricingType = $data['pricingType'];
239                 isset($data['fixedPricing'])
240                         && $this->fixedPricing = $data['fixedPricing'];
241                 isset($data['priceGuide'])
242                         && $this->priceGuide = $data['priceGuide'];
243                 isset($data['landingPage'])
244                         && $this->landingPage = $data['landingPage'];
245         }
246
247 }