2 namespace Location\Entity;
4 use Doctrine\ORM\Mapping as ORM;
11 * @ORM\HasLifecycleCallbacks
12 * @ORM\Table(name="lib_city")
18 * Can archive records.
22 * Pull Synchronization Strategy for this table.
24 const PULL_SYNCH_STRATEGY = 'Update';
26 * Push Synchronization Strategy for this table.
28 const PUSH_SYNCH_STRATEGY = 'Update';
32 * @ORM\Column(type="integer");
33 * @ORM\GeneratedValue(strategy="AUTO")
38 * @ORM\ManyToOne(targetEntity="Region", inversedBy="towns")
39 * @ORM\JoinColumn(name="lib_region_id", referencedColumnName="id")
44 * @ORM\Column(type="string", length=150)
49 * @ORM\Column(type="datetime");
54 * @ORM\Column(type="datetime", nullable=true);
59 * @ORM\Column(type="boolean");
61 protected $archived = false;
65 * Magic getter to expose protected properties.
67 * @param string $property
70 public function __get($property)
72 return $this->$property;
76 * Magic setter to save protected properties.
78 * @param string $property
81 public function __set($property, $value)
83 $this->$property = $value;
89 public function setCreateTime()
91 $this->created = new \DateTime("now");
97 public function setUpdateTime()
99 $this->updated = new \DateTime("now");
103 * Convert the object to an array.
104 * @param array $expand
105 * @param array $intersect
108 public function toArray(array $expand = array(), array $intersect = array())
110 $includeAll = empty($intersect);
112 ($includeAll || isset($intersect['id']))
113 && $data['id'] = $this->id;
114 ($includeAll || isset($intersect['region']))
115 && in_array('region', $expand)
116 && $data['region'] = $this->region->toArray($expand, $intersect);
117 ($includeAll || isset($intersect['name']))
118 && $data['name'] = $this->name;
119 ($includeAll || isset($intersect['created']))
120 && $data['created'] = !is_null($this->created)
121 ? $this->created->format(\Utility\Registry::getConfigParam('DateTimeFormat'))
123 ($includeAll || isset($intersect['updated']))
124 && $data['updated'] = !is_null($this->updated)
125 ? $this->updated->format(\Utility\Registry::getConfigParam('DateTimeFormat'))
131 * Convert the object to an array for synchronization.
134 public function toSynchArray()
138 'region' => $this->region->id,
139 'name' => $this->name
144 * Populate from an array.
147 public function fromArray($data = array())
150 && $this->id = $data['id'];
151 isset($data['region'])
152 && $this->region = $data['region'];
154 && $this->name = $data['name'];