Commit daf7c8c9 authored by speedprogs_de's avatar speedprogs_de

added json views, added array utility, added toArray method to all entities and value objects

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51645 735d13b6-9817-0410-8766-e36946ffe9aa
parent a2b79ee5
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Abstract entity
*/
class Tx_TerFe2_Domain_Model_AbstractEntity extends Tx_Extbase_DomainObject_AbstractEntity {
/**
* Build an array from all attributes
*
* @return array
*/
public function toArray() {
return Tx_TerFe2_Utility_Array::objectToArray($this);
}
}
?>
\ No newline at end of file
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Abstract value object
*/
class Tx_TerFe2_Domain_Model_AbstractValueObject extends Tx_Extbase_DomainObject_AbstractValueObject {
/**
* Build an array from all attributes
*
* @return array
*/
public function toArray() {
return Tx_TerFe2_Utility_Array::objectToArray($this);
}
}
?>
\ No newline at end of file
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/** /**
* Author of an extension * Author of an extension
*/ */
class Tx_TerFe2_Domain_Model_Author extends Tx_Extbase_DomainObject_AbstractEntity { class Tx_TerFe2_Domain_Model_Author extends Tx_TerFe2_Domain_Model_AbstractEntity {
/** /**
* Name of the author * Name of the author
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/** /**
* Frontend category of the extension * Frontend category of the extension
*/ */
class Tx_TerFe2_Domain_Model_Category extends Tx_Extbase_DomainObject_AbstractValueObject { class Tx_TerFe2_Domain_Model_Category extends Tx_TerFe2_Domain_Model_AbstractValueObject {
/** /**
* Title of the category * Title of the category
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/** /**
* User experience with an extension * User experience with an extension
*/ */
class Tx_TerFe2_Domain_Model_Experience extends Tx_Extbase_DomainObject_AbstractValueObject { class Tx_TerFe2_Domain_Model_Experience extends Tx_TerFe2_Domain_Model_AbstractValueObject {
/** /**
* Timestamp of the experience * Timestamp of the experience
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/** /**
* Extension container * Extension container
*/ */
class Tx_TerFe2_Domain_Model_Extension extends Tx_Extbase_DomainObject_AbstractEntity { class Tx_TerFe2_Domain_Model_Extension extends Tx_TerFe2_Domain_Model_AbstractEntity {
/** /**
* Extension key * Extension key
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/** /**
* Any type of media associated to an extension * Any type of media associated to an extension
*/ */
class Tx_TerFe2_Domain_Model_Media extends Tx_Extbase_DomainObject_AbstractEntity { class Tx_TerFe2_Domain_Model_Media extends Tx_TerFe2_Domain_Model_AbstractEntity {
/** /**
* Title of the media * Title of the media
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/** /**
* Any type of relation of an extension * Any type of relation of an extension
*/ */
class Tx_TerFe2_Domain_Model_Relation extends Tx_Extbase_DomainObject_AbstractValueObject { class Tx_TerFe2_Domain_Model_Relation extends Tx_TerFe2_Domain_Model_AbstractValueObject {
/** /**
* Dependancy, conflict or suggest * Dependancy, conflict or suggest
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/** /**
* Tag for the extension * Tag for the extension
*/ */
class Tx_TerFe2_Domain_Model_Tag extends Tx_Extbase_DomainObject_AbstractValueObject { class Tx_TerFe2_Domain_Model_Tag extends Tx_TerFe2_Domain_Model_AbstractValueObject {
/** /**
* Title of the tag * Title of the tag
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/** /**
* Single version of an extension * Single version of an extension
*/ */
class Tx_TerFe2_Domain_Model_Version extends Tx_Extbase_DomainObject_AbstractEntity { class Tx_TerFe2_Domain_Model_Version extends Tx_TerFe2_Domain_Model_AbstractEntity {
/** /**
* Title of the extension * Title of the extension
......
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Utilities to manage arrays
*/
class Tx_TerFe2_Utility_Array {
/**
* Build an array from an object
*
* @param object $object The object
* @return array Array of all attributes
*/
public static function objectToArray($object) {
if (empty($object)) {
return array();
}
$attributesArray = array();
$className = get_class($object);
$classVars = get_class_vars($className);
$classMethods = get_class_methods($className);
foreach($classVars as $attributeName => $attributeValue) {
if (strpos($attributeName, '_') === 0) {
continue;
}
$method = 'get' . ucfirst($attributeName);
if (!in_array($method, $classMethods)) {
continue;
}
$value = $object->$method();
if ($value instanceof Tx_Extbase_Persistence_ObjectStorage) {
$valueArray = array();
foreach($value as $model) {
$valueArray[] = $model->toArray();
}
$value = $valueArray;
}
if ($value instanceof Tx_TerFe2_Domain_Model_AbstractEntity) {
$value = $value->toArray();
}
if ($value instanceof Tx_TerFe2_Domain_Model_AbstractValueObject) {
$value = $value->toArray();
}
$attributesArray[$attributeName] = $value;
}
return $attributesArray;
}
}
?>
\ No newline at end of file
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Json output view for the list action of extension controller
*/
class Tx_TerFe2_View_Extension_ListJson extends Tx_Extbase_MVC_View_AbstractView {
/**
* Render method, returns latest Extensions
*
* @return string JSON content
*/
public function render() {
$jsonArray = array();
$extensions = array();
// Get extensions from view data
if (!empty($this->variables['extensions']) && $this->variables['extensions'] instanceof Tx_Extbase_Persistence_QueryResult) {
$extensions = $this->variables['extensions']->toArray();
}
if (!empty($extensions)) {
foreach ($this->variables['extensions'] as $extension) {
$jsonArray[] = $extension->toArray();
}
}
return json_encode($jsonArray);
}
}
?>
\ No newline at end of file
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Json output view for the list latest action of extension controller
*/
class Tx_TerFe2_View_Extension_ListLatestJson extends Tx_TerFe2_View_Extension_ListJson {
// No own functionallity here, uses render method from list
}
?>
\ No newline at end of file
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
$extensionClassesPath = t3lib_extMgm::extPath('ter_fe2', 'Classes/'); $extensionClassesPath = t3lib_extMgm::extPath('ter_fe2', 'Classes/');
return array( return array(
'tx_terfe2_domain_model_abstractentity' => $extensionClassesPath . 'Domain/Model/AbstractEntity.php',
'tx_terfe2_domain_model_abstractvalueobject' => $extensionClassesPath . 'Domain/Model/AbstractValueObject.php',
'tx_terfe2_domain_model_author' => $extensionClassesPath . 'Domain/Model/Author.php', 'tx_terfe2_domain_model_author' => $extensionClassesPath . 'Domain/Model/Author.php',
'tx_terfe2_domain_model_category' => $extensionClassesPath . 'Domain/Model/Category.php', 'tx_terfe2_domain_model_category' => $extensionClassesPath . 'Domain/Model/Category.php',
'tx_terfe2_domain_model_experience' => $extensionClassesPath . 'Domain/Model/Experience.php', 'tx_terfe2_domain_model_experience' => $extensionClassesPath . 'Domain/Model/Experience.php',
...@@ -34,6 +36,7 @@ ...@@ -34,6 +36,7 @@
'tx_terfe2_task_updateextensionlisttask' => $extensionClassesPath . 'Task/UpdateExtensionListTask.php', 'tx_terfe2_task_updateextensionlisttask' => $extensionClassesPath . 'Task/UpdateExtensionListTask.php',
'tx_terfe2_task_updateextensionlisttaskadditionalfieldprovider' => $extensionClassesPath . 'Task/UpdateExtensionListTaskAdditionalFieldProvider.php', 'tx_terfe2_task_updateextensionlisttaskadditionalfieldprovider' => $extensionClassesPath . 'Task/UpdateExtensionListTaskAdditionalFieldProvider.php',
'tx_terfe2_utility_archive' => $extensionClassesPath . 'Utility/Archive.php', 'tx_terfe2_utility_archive' => $extensionClassesPath . 'Utility/Archive.php',
'tx_terfe2_utility_array' => $extensionClassesPath . 'Utility/Array.php',
'tx_terfe2_utility_file' => $extensionClassesPath . 'Utility/File.php', 'tx_terfe2_utility_file' => $extensionClassesPath . 'Utility/File.php',
'tx_terfe2_utility_typoscript' => $extensionClassesPath . 'Utility/TypoScript.php', 'tx_terfe2_utility_typoscript' => $extensionClassesPath . 'Utility/TypoScript.php',
'tx_terfe2_viewhelpers_cdataviewhelper' => $extensionClassesPath . 'ViewHelpers/CdataViewHelper.php', 'tx_terfe2_viewhelpers_cdataviewhelper' => $extensionClassesPath . 'ViewHelpers/CdataViewHelper.php',
......
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