2 namespace Location\Entity;
4 use Doctrine\ORM\Mapping as ORM;
9 * A region in a country. Well, if we can fit a country in a file...
11 * @ORM\Table(name="lib_region")
17 * Can archive records.
21 * Pull Synchronization Strategy for this table.
23 const PULL_SYNCH_STRATEGY = 'Build';
25 * Push Synchronization Strategy for this table.
27 const PUSH_SYNCH_STRATEGY = 'Build';
31 * @ORM\Column(type="integer");
32 * @ORM\GeneratedValue(strategy="AUTO")
37 * @ORM\ManyToOne(targetEntity="Country", inversedBy="regions")
38 * @ORM\JoinColumn(name="lib_country_id", referencedColumnName="id")
43 * @ORM\Column(type="string", length=75)
48 * @ORM\Column(type="string", length=2, nullable=true, name="iso3166_2_code")
53 * @ORM\Column(type="string", length=2, nullable=true, name="fips10_4_code")
58 * @ORM\Column(type="boolean");
60 protected $archived = false;
63 * @ORM\OneToMany(targetEntity="Town", mappedBy="region", fetch="EXTRA_LAZY")
69 * Initialize collections.
71 public function __construct()
73 $this->towns = new \Doctrine\Common\Collections\ArrayCollection();
77 * Add a new Region to this Country.
79 * @return \Location\Entity\Region
81 public function addTown(Town $town)
83 $this->towns[] = $town;
88 * Magic getter to expose protected properties.
89 * @param string $property
92 public function __get($property)
94 return $this->$property;
98 * Magic setter to save protected properties.
99 * @param string $property
100 * @param mixed $value
102 public function __set($property, $value)
104 $this->$property = $value;
108 * Convert the object to an array.
109 * @param array $expand
110 * @param array $intersect
113 public function toArray(array $expand = array(), array $intersect = array())
115 $includeAll = empty($intersect);
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;
132 * Convert the object to an array for synchronization.
135 public function toSynchArray()
139 'country' => $this->country->id,
140 'name' => $this->name
145 * Populate from an array.
148 public function fromArray($data = array())
151 && $this->id = $data['id'];
152 isset($data['country'])
153 && $this->country = $data['country'];
155 && $this->name = $data['name'];
156 isset($data['isoCode'])
157 && $this->isoCode = $data['isoCode'];
158 isset($data['fipsCode'])
159 && $this->fipsCode = $data['fipsCode'];