summaryrefslogtreecommitdiffstats
path: root/controller/entityapiserializer.php
diff options
context:
space:
mode:
Diffstat (limited to 'controller/entityapiserializer.php')
-rw-r--r--controller/entityapiserializer.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/controller/entityapiserializer.php b/controller/entityapiserializer.php
new file mode 100644
index 000000000..ef5e20fbe
--- /dev/null
+++ b/controller/entityapiserializer.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Alessandro Cosentino 2012
+ * @copyright Bernhard Posselt 2012, 2014
+ */
+
+namespace OCA\News\Controller;
+
+use \OCP\AppFramework\Http\IResponseSerializer;
+
+class EntityApiSeralizer implements IResponseSerializer {
+
+
+ public function __construct($level) {
+ $this->level = $level;
+ }
+
+
+ /**
+ * Wrap a list of entities in an array with $level as index and serialize
+ * them using the toAPI method
+ */
+ public function serialize($data) {
+ if(!is_array($data)) {
+ $data = array($data);
+ }
+
+ $response = array(
+ $this->level => array();
+ );
+
+ foreach($data as $entity) {
+ $response[$this->level][] = $entity->toAPI()
+ }
+ }
+
+} \ No newline at end of file