text changes to registration mail content
[namibia] / module / Location / src / Location / Entity / Region.php
1 <?php
2 namespace Location\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * A region in a country. Well, if we can fit a country in a file...
10  * @ORM\Entity
11  * @ORM\Table(name="lib_region")
12  */
13 class Region
14 {
15
16         /**
17          * Can archive records.
18          */
19         const ARCHIVE = true;
20         /**
21          * Pull Synchronization Strategy for this table.
22          */
23         const PULL_SYNCH_STRATEGY = 'Build';
24         /**
25          * Push Synchronization Strategy for this table.
26          */
27         const PUSH_SYNCH_STRATEGY = 'Build';
28
29         /**
30          * @ORM\Id
31          * @ORM\Column(type="integer");
32          * @ORM\GeneratedValue(strategy="AUTO")
33          */
34         protected $id;
35
36         /**
37          * @ORM\ManyToOne(targetEntity="Country", inversedBy="regions")
38          * @ORM\JoinColumn(name="lib_country_id", referencedColumnName="id")
39          **/
40         protected $country;
41
42         /**
43          * @ORM\Column(type="string", length=75)
44          */
45         protected $name;
46
47         /**
48          * @ORM\Column(type="string", length=2, nullable=true, name="iso3166_2_code")
49          */
50         protected $isoCode;
51
52         /**
53          * @ORM\Column(type="string", length=2, nullable=true, name="fips10_4_code")
54          */
55         protected $fipsCode;
56
57         /**
58          * @ORM\Column(type="boolean");
59          */
60         protected $archived = false;
61
62         /**
63          * @ORM\OneToMany(targetEntity="Town", mappedBy="region", fetch="EXTRA_LAZY")
64          **/
65         private $towns;
66
67
68         /**
69          * Initialize collections.
70          */
71         public function __construct()
72         {
73                 $this->towns = new \Doctrine\Common\Collections\ArrayCollection();
74         }
75
76         /**
77          * Add a new Region to this Country.
78          * @param Town $town
79          * @return \Location\Entity\Region
80          */
81         public function addTown(Town $town)
82         {
83                 $this->towns[] = $town;
84                 return $this;
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          * Convert the object to an array.
109          * @param array $expand
110          * @param array $intersect
111          * @return array
112          */
113         public function toArray(array $expand = array(), array $intersect = array())
114         {
115                 $includeAll = empty($intersect);
116                 $data = array();
117                 ($includeAll || isset($intersect['id']))
118                         && $data['id'] = $this->id;
119                 ($includeAll || isset($intersect['country']))
120                         && in_array('country', $expand)
121                         && $data['country'] = $this->country->toArray($expand, $intersect);
122                 ($includeAll || isset($intersect['name']))
123                         && $data['name'] = $this->name;
124                 ($includeAll || isset($intersect['isoCode']))
125                         && $data['isoCode'] = $this->isoCode;
126                 ($includeAll || isset($intersect['fipsCode']))
127                         && $data['fipsCode'] = $this->fipsCode;
128                 return $data;
129         }
130
131         /**
132          * Convert the object to an array for synchronization.
133          * @return array
134          */
135         public function toSynchArray()
136         {
137                 return array(
138                                 'id'      => $this->id,
139                                 'country' => $this->country->id,
140                                 'name'    => $this->name
141                 );
142         }
143
144         /**
145          * Populate from an array.
146          * @param array $data
147          */
148         public function fromArray($data = array())
149         {
150                 isset($data['id'])
151                         && $this->id = $data['id'];
152                 isset($data['country'])
153                         && $this->country  = $data['country'];
154                 isset($data['name'])
155                         && $this->name  = $data['name'];
156                 isset($data['isoCode'])
157                         && $this->isoCode  = $data['isoCode'];
158                 isset($data['fipsCode'])
159                         && $this->fipsCode  = $data['fipsCode'];
160         }
161
162 }