[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ocs-webserver/dev] application/modules/default/controllers: Add _buildCategoriesList()
From:       Akira Ohgaki <null () kde ! org>
Date:       2017-04-01 0:12:33
Message-ID: E1cu6ef-0008Fc-BN () code ! kde ! org
[Download RAW message or body]

Git commit 23696776e9792f380eee86ebac51ca44bced6344 by Akira Ohgaki.
Committed on 01/04/2017 at 00:08.
Pushed by akiraohgaki into branch 'dev'.

Add _buildCategoriesList()

M  +67   -0    application/modules/default/controllers/Ocsv1Controller.php

https://commits.kde.org/ocs-webserver/23696776e9792f380eee86ebac51ca44bced6344

diff --git a/application/modules/default/controllers/Ocsv1Controller.php \
b/application/modules/default/controllers/Ocsv1Controller.php index 2a7f430..aaecd5f 100644
--- a/application/modules/default/controllers/Ocsv1Controller.php
+++ b/application/modules/default/controllers/Ocsv1Controller.php
@@ -810,6 +810,73 @@ class Ocsv1Controller extends Zend_Controller_Action
         $this->_sendResponse($response, $this->_format);
     }
 
+    protected function _buildCategoriesList($tableCategories = null, $parentCategoryId = null, \
$categoriesList = array()) +    {
+        $categories = null;
+
+        // Top-level categories
+        if (!$tableCategories) {
+            $tableCategories = new Default_Model_DbTable_ProjectCategory();
+            if (Zend_Registry::isRegistered('store_category_list')) {
+                $categories = $tableCategories->fetchActive(Zend_Registry::get('store_category_list'));
+            }
+            else {
+                $categories = $tableCategories->fetchAllActive();
+            }
+        }
+        // Sub-categories
+        else if ($parentCategoryId) {
+            $categories = $tableCategories->fetchImmediateChildren($parentCategoryId);
+        }
+
+        // Build categories list
+        if (!empty($categories)) {
+            foreach ($categories as $category) {
+                if (is_array($category)) {
+                    $category = (object)$category;
+                }
+
+                $categoryName = $category->title;
+                $categoryDisplayName = $category->title;
+                if (!empty($category->name_legacy)) {
+                    $categoryName = $category->name_legacy;
+                }
+                $categoryParentId = '';
+                if (!empty($parentCategoryId)) {
+                    $categoryParentId = $parentCategoryId;
+                }
+                $categoryXdgType = '';
+                if (!empty($category->xdg_type)) {
+                    $categoryXdgType = $category->xdg_type;
+                }
+
+                if ($this->_format == 'json') {
+                    $categoriesList[] = array(
+                        'id' => $category->project_category_id,
+                        'name' => $categoryName,
+                        'display_name' => $categoryDisplayName,
+                        'parent_id' => $categoryParentId,
+                        'xdg_type' => $categoryXdgType
+                    );
+                }
+                else {
+                    $categoriesList[] = array(
+                        'id' => array('@text' => $category->project_category_id),
+                        'name' => array('@text' => $categoryName),
+                        'display_name' => array('@text' => $categoryDisplayName),
+                        'parent_id' => array('@text' => $categoryParentId),
+                        'xdg_type' => array('@text' => $categoryXdgType)
+                    );
+                }
+
+                // Update the list recursive
+                $categoriesList = $this->_buildCategoriesList($tableCategories, \
$category->project_category_id, $categoriesList); +            }
+        }
+
+        return $categoriesList;
+    }
+
     public function contentdataAction()
     {
         Zend_Registry::get('logger')->debug(__METHOD__ . ' - ' . print_r(func_get_args(), true));


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic