/** * Implements Base\BaseObject::__toString(). * * @return string */ public function __toString() { $obj = array(); $obj['organization'] = array('id' => $this->organization->getId()); $obj['applicationCategory'] = array('id' => $this->applicationCategory->getId()); $obj['product'] = array(); foreach ($this->products as $product) { $obj['product'][] = array('id' => $product->getId()); } $properties = array_keys(get_object_vars($this)); $excluded_properties = array_keys(get_class_vars(get_parent_class($this))); foreach ($properties as $property) { if ($property == 'product' || $property == 'organization' || in_array($property, $excluded_properties)) { continue; } if (isset($this->{$property})) { $obj[$property] = $this->{$property}; } } return json_encode($obj); }
/** * Implements Base\BaseObject::loadFromRawData(). * * @param array $data * @param bool $reset */ public function loadFromRawData($data, $reset = false) { if ($reset) { $this->initValues(); } $excluded_properties = array('organization', 'product', 'applicationCategory'); foreach (array_keys($data) as $property) { if (in_array($property, $excluded_properties)) { continue; } // form the setter method name to invoke setXxxx $setter_method = 'set' . ucfirst($property); if (method_exists($this, $setter_method)) { $this->{$setter_method}($data[$property]); } else { self::$logger->notice('No setter method was found for property "' . $property . '"'); } } if (isset($data['product']) && is_array($data['product']) && count($data['product']) > 0) { foreach ($data['product'] as $product_item) { $product = new Product($this->config); $product->loadFromRawData($product_item); $this->products[] = $product; } } if (isset($data['organization'])) { $organization = new Organization($this->config); $organization->loadFromRawData($data['organization']); $this->organization = $organization; } if (isset($data['applicationCategory'])) { $appCat = new ApplicationCategory($this->config); $appCat->loadFromRawData($data['applicationCategory']); $this->applicationCategory = $appCat; } }