Commit f02eba77 authored by speedprogs_de's avatar speedprogs_de

modified array utility, fixed json output

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51674 735d13b6-9817-0410-8766-e36946ffe9aa
parent c0fb39a7
......@@ -32,29 +32,32 @@
* Build an array from an object
*
* @param object $object The object
* @param boolean $excludeEmpty Return only non-empty values
* @return array Array of all attributes
*/
public static function objectToArray($object) {
public static function objectToArray($object, $excludeEmpty = TRUE) {
if (empty($object)) {
return array();
}
$attributesArray = array();
$className = get_class($object);
$classVars = get_class_vars($className);
$classMethods = get_class_methods($className);
$classMethods = get_class_methods(get_class($object));
foreach($classVars as $attributeName => $attributeValue) {
if (strpos($attributeName, '_') === 0) {
foreach($classMethods as $method) {
if (strpos($method, '_') === 0 || strpos($method, 'get') !== 0) {
continue;
}
$method = 'get' . ucfirst($attributeName);
if (!in_array($method, $classMethods)) {
$value = $object->$method();
if ($excludeEmpty && empty($value)) {
continue;
}
$value = $object->$method();
if ($value instanceof Tx_Extbase_Persistence_LazyLoadingProxy) {
// TODO: Implement a clean way to get attributes from concrete object
$value = '__lazy__';
}
if ($value instanceof Tx_Extbase_Persistence_ObjectStorage) {
$valueArray = array();
foreach($value as $model) {
......@@ -71,6 +74,12 @@
$value = $value->toArray();
}
if (is_object($value)) {
$value = (string) $value;
}
$attributeName = substr($method, 3);
$attributeName[0] = strtolower($attributeName[0]);
$attributesArray[$attributeName] = $value;
}
......
......@@ -42,7 +42,7 @@
$extensions = $this->variables['extensions']->toArray();
}
if (!empty($extensions)) {
foreach ($this->variables['extensions'] as $extension) {
foreach ($extensions as $extension) {
$jsonArray[] = $extension->toArray();
}
}
......
......@@ -3,8 +3,8 @@
<f:for each="{extensions}" as="extension">
<item>
<title>{extension.lastVersion.title}</title>
<link><terfe2:cdata><terfe2:url action="show" arguments="{extension : extension}" absolute="1"></terfe2:url></terfe2:cdata></link>
<guid><terfe2:cdata><terfe2:url action="download" arguments="{extension : extension, version : extension.lastVersion}" absolute="1"></terfe2:url></terfe2:cdata></guid>
<link><terfe2:cdata><f:uri.action action="show" arguments="{extension : extension}" absolute="1"></f:uri.action></terfe2:cdata></link>
<guid><terfe2:cdata><f:uri.action action="download" arguments="{extension : extension, version : extension.lastVersion}" absolute="1"></f:uri.action></terfe2:cdata></guid>
<description><terfe2:cdata>{extension.lastVersion.description}</terfe2:cdata></description>
<content:encoded><terfe2:cdata></terfe2:cdata></content:encoded>
<pubDate><terfe2:dateTime format="{settings.rssOutput.dateFormat}">{extension.lastVersion.uploadDate}</terfe2:dateTime></pubDate>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment