groups = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Magic getter to expose protected properties. * @param string $property * @return mixed */ public function __get($property) { return $this->$property; } /** * Magic setter to save protected properties. * @param string $property * @param mixed $value */ public function __set($property, $value) { $this->$property = $value; } /** * @ORM\PrePersist */ public function setCreateTime() { $this->created = new \DateTime("now"); } /** * @ORM\PreUpdate */ public function setUpdateTime() { $this->updated = new \DateTime("now"); } /** * Convert the object to an array. * @param array $expand * @param array $intersect * @return array */ public function toArray( array $expand = array('attachment'), array $intersect = array(), $showIdentifiers = false, $expandAll = 0 ) { $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat'); $dateFormat = \Utility\Registry::getConfigParam('DateFormat'); $includeAll = empty($intersect); $data = array(); ($includeAll || isset($intersect['id'])) && $data['id'] = $this->id; ($includeAll || isset($intersect['openDate'])) && $data['openDate'] = !is_null($this->openDate) ? $this->openDate->format($dateFormat) : null; ($includeAll || isset($intersect['groups'])) && $data['groups'] = (in_array('groups', $expand) || $expandAll || $showIdentifiers) && !is_null($this->groups) ? $this->groupsToArray($showIdentifiers) : null; ($includeAll || isset($intersect['created'])) && $data['created'] = !is_null($this->created) ? $this->created->format($dateTimeFormat) : null; ($includeAll || isset($intersect['updated'])) && $data['updated'] = !is_null($this->updated) ? $this->updated->format($dateTimeFormat) : null; return $data; } /** * Internal utility to change auction groups collection into array. * @param boolean $showIdentifiers * @return array */ protected function groupsToArray($showIdentifiers = false) { $data = array(); $iterator = $this->groups->getIterator(); foreach ($iterator as $group) { $data[] = array('id' => $group->companyGroup->id); } return $data; } /** * Populate from an array. * @param array $data */ public function fromArray($data = array()) { isset($data['id']) && $this->id = $data['id']; isset($data['openDate']) && $this->openDate = is_object($data['openDate']) ? $data['openDate'] : new \DateTime($data['openDate']); if (isset($data['groups'])) { $em = \Utility\Registry::getEntityManager(); $newGrps = array(); foreach ($data['groups'] as $grp) { $newGrps[$grp['id']] = $grp['id']; } $currentGrps = array(); $iterator = $this->groups->getIterator(); foreach ($iterator as $grp) { $currentGrps[$grp->companyGroup->id] = $grp->companyGroup->id; !isset($newGrps[$grp->companyGroup->id]) && $em->remove($grp); } foreach ($data['groups'] as $grp) { if (!isset($currentGrps[$grp['id']])) { $openDayGrp = new \Auction\Entity\OpenDayGroup(); $openDayGrp->companyGroup = $em->getReference('\Company\Entity\Group', $grp['id']); $openDayGrp->openDay = $this; $this->groups->add($openDayGrp); } } } } }