initial commit
[namibia] / module / Company / src / Company / Entity / GroupDivision.php
1 <?php
2 namespace Company\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * Dealer Group Division.
10  * @ORM\Entity
11  * @ORM\HasLifecycleCallbacks
12  * @ORM\Table(name="company_group_division")
13  */
14 class GroupDivision
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\ManyToOne(targetEntity="Group", inversedBy="divisions")
47          * @ORM\JoinColumn(name="company_group_id", referencedColumnName="id")
48          * @ORM\OrderBy({"name" = "ASC"})
49          **/
50         protected $group;
51
52         /**
53          * @ORM\Column(type="string", length=100)
54          */
55         protected $name;
56
57         /**
58          * @ORM\OneToMany(targetEntity="Company", mappedBy="groupDivision", fetch="EXTRA_LAZY")
59          **/
60         private $companies;
61
62         /**
63          * @ORM\Column(type="datetime");
64          */
65         protected $created;
66
67         /**
68          * @ORM\Column(type="datetime", nullable=true);
69          */
70         protected $updated;
71
72         /**
73          * @ORM\Column(type="boolean");
74          */
75         protected $archived = false;
76
77
78         /**
79          * Initialize collections.
80          */
81         public function __construct()
82         {
83                 $this->companies = new \Doctrine\Common\Collections\ArrayCollection();
84         }
85
86
87         /**
88          * Magic getter to expose protected properties.
89          * @param string $property
90          * @return mixed
91          */
92         public function __get($property)
93         {
94                 return $this->$property;
95         }
96
97         /**
98          * Magic setter to save protected properties.
99          * @param string $property
100          * @param mixed $value
101          */
102         public function __set($property, $value)
103         {
104                 $this->$property = $value;
105         }
106
107         /**
108          * @ORM\PrePersist
109          */
110         public function setCreateTime()
111         {
112                 $this->created = new \DateTime("now");
113         }
114
115         /**
116          * @ORM\PreUpdate
117          */
118         public function setUpdateTime()
119         {
120                 $this->updated = new \DateTime("now");
121         }
122
123         /**
124          * Convert the object to an array.
125          * @param array $expand
126          * @param array $intersect
127          * @return array
128          */
129         public function toArray(array $expand = array(), array $intersect = array())
130         {
131                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
132                 $includeAll = empty($intersect);
133                 $data = array();
134                 ($includeAll || isset($intersect['id']))
135                         && $data['id'] = $this->id;
136                 ($includeAll || isset($intersect['group']))
137                         && in_array('group', $expand)
138                         && $data['group'] = $this->group->toArray($expand, $intersect);
139                 ($includeAll || isset($intersect['name']))
140                         && $data['name'] = $this->name;
141                 ($includeAll || isset($intersect['created']))
142                         && $data['created'] = !is_null($this->created)
143                                 ? $this->created->format($dateTimeFormat)
144                                 : null;
145                 ($includeAll || isset($intersect['updated']))
146                         && $data['updated'] = !is_null($this->updated)
147                                 ? $this->updated->format($dateTimeFormat)
148                                 : null;
149                 return $data;
150         }
151
152         /**
153          * Populate from an array.
154          * @param array $data
155          */
156         public function fromArray($data = array())
157         {
158                 isset($data['id'])
159                         && $this->id = $data['id'];
160                 isset($data['group'])
161                         && $this->group = $data['group'];
162                 isset($data['name'])
163                         && $this->name = $data['name'];
164         }
165
166 }