public function map($object) { $keys = get_object_vars($this); foreach ($keys as $key => $value) { $method = "get" . $key; if (method_exists($object, $method)) { if ($object->{$method}()) { $this->{$key} = $object->{$method}(); // check for a pimcore data type if ($this->{$key} instanceof Element_Interface) { $this->{$key} = $this->{$key}->getId(); } // if the value is an object or array call the mapper again for the value if (is_object($this->{$key}) || is_array($this->{$key})) { $type = "out"; if (strpos(get_class($this), "_In") !== FALSE) { $type = "in"; } $className = Webservice_Data_Mapper::findWebserviceClass($this->{$key}, "out"); $this->{$key} = Webservice_Data_Mapper::map($this->{$key}, $className, $type); } } } } }
/** * @param int $id * @return Webservice_Data_Asset_Folder_Out */ public function getAssetFolderById($id) { try { $asset = Asset::getById($id); if ($asset instanceof Asset_Folder) { $className = Webservice_Data_Mapper::findWebserviceClass($asset, "out"); $apiAsset = Webservice_Data_Mapper::map($asset, $className, "out"); return $apiAsset; } throw new Exception("Asset Folder with given ID (" . $id . ") does not exist."); } catch (Exception $e) { Logger::error($e); throw $e; } }
/** * Returns the current tag's data for web service export * * @abstract * @return array */ public function getForWebserviceExport() { $keys = get_object_vars($this); $el = array(); foreach ($keys as $key => $value) { if ($value instanceof Element_Interface) { $value = $value->getId(); } $className = Webservice_Data_Mapper::findWebserviceClass($value, "out"); $el[$key] = Webservice_Data_Mapper::map($value, $className, "out"); } unset($el["resource"]); unset($el["documentId"]); unset($el["controller"]); unset($el["view"]); unset($el["editmode"]); $el = Webservice_Data_Mapper::toObject($el); return $el; }