|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @package Com_Api |
| 4 | + * @copyright Copyright (C) 2009-2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved. |
| 5 | + * @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html> |
| 6 | + * @link http://www.techjoomla.com |
| 7 | + */ |
| 8 | +defined('_JEXEC') or die( 'Restricted access' ); |
| 9 | +require_once JPATH_ADMINISTRATOR . '/components/com_categories/models/categories.php'; |
| 10 | +jimport('joomla.plugin.plugin'); |
| 11 | +jimport('joomla.html.html'); |
| 12 | +JLoader::register('JCategoryNode', JPATH_BASE . '/libraries/legacy/categories/categories.php'); |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +class CategoriesApiResourceCategories extends ApiResource |
| 17 | +{ |
| 18 | + public function get() |
| 19 | + { |
| 20 | + $this->plugin->setResponse($this->getCategoryList()); |
| 21 | + } |
| 22 | + |
| 23 | + public function delete() |
| 24 | + { |
| 25 | + $this->plugin->setResponse('in delete'); |
| 26 | + } |
| 27 | + public function post() |
| 28 | + { |
| 29 | + $this->plugin->setResponse($this->CreateUpdateCategory()); |
| 30 | + } |
| 31 | + |
| 32 | + public function getCategory() |
| 33 | + { |
| 34 | + self::getListQuery(); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Get the master query for retrieving a list of articles subject to the model state. |
| 39 | + * |
| 40 | + * @return JDatabaseQuery |
| 41 | + * |
| 42 | + * @since 1.6 |
| 43 | + */ |
| 44 | + public function getCategoryList() |
| 45 | + { |
| 46 | + /*$model_categories = JCategories::getInstance('Content'); |
| 47 | + $root = $model_categories->get('root'); |
| 48 | + $categories = $root->getChildren();*/ |
| 49 | + |
| 50 | + $model_categories = JCategories::getInstance('Content'); |
| 51 | + $root = $model_categories->get('root'); |
| 52 | + $categories = $root->getChildren(true); |
| 53 | + |
| 54 | + return $categories; |
| 55 | + |
| 56 | + } |
| 57 | + /** |
| 58 | + * CreateUpdateArticle is to create / upadte article |
| 59 | + * |
| 60 | + * @return Bolean |
| 61 | + * |
| 62 | + * @since 3.5 |
| 63 | + */ |
| 64 | + public function CreateUpdateCategory() |
| 65 | + { |
| 66 | + if (version_compare(JVERSION, '3.0', 'lt')) |
| 67 | + { |
| 68 | + JTable::addIncludePath(JPATH_PLATFORM . 'joomla/database/table'); |
| 69 | + } |
| 70 | + |
| 71 | + $obj = new stdclass; |
| 72 | + |
| 73 | + $app = JFactory::getApplication(); |
| 74 | + $cat_id = $app->input->get('id', 0, 'INT'); |
| 75 | + |
| 76 | + if (empty($app->input->get('title', '', 'STRING'))) |
| 77 | + { |
| 78 | + $obj->code = 'ER001'; |
| 79 | + $obj->message = 'Title Field is Missing'; |
| 80 | + |
| 81 | + return $obj; |
| 82 | + } |
| 83 | + if (empty($app->input->get('extension', '', 'STRING'))) |
| 84 | + { |
| 85 | + $obj->code = 'ER002'; |
| 86 | + $obj->message = 'Extension Field is Missing'; |
| 87 | + |
| 88 | + return $obj; |
| 89 | + } |
| 90 | + |
| 91 | + |
| 92 | + if ($cat_id) |
| 93 | + { |
| 94 | + $category = JTable::getInstance('Content', 'JTable', array()); |
| 95 | + $category->load($cat_id); |
| 96 | + $data = array( |
| 97 | + 'title' => $app->input->get('title', '', 'STRING'), |
| 98 | + ); |
| 99 | + |
| 100 | + // Bind data |
| 101 | + if (!$cat_id->bind($data)) |
| 102 | + { |
| 103 | + $this->setError($article->getError()); |
| 104 | + return false; |
| 105 | + } |
| 106 | + } |
| 107 | + else |
| 108 | + { |
| 109 | + $category = JTable::getInstance('content'); |
| 110 | + $category->title = $app->input->get('title', '', 'STRING'); |
| 111 | + $category->alias = $app->input->get('alias', '', 'STRING'); |
| 112 | + $category->description = $app->input->get('description', '', 'STRING'); |
| 113 | + $category->published = $app->input->get('published', '', 'STRING'); |
| 114 | + $category->parent_id = $app->input->get('parent_id', '', 'STRING'); |
| 115 | + $category->extension = $app->input->get('language', '', 'INT'); |
| 116 | + $category->access = $app->input->get('catid', '', 'INT'); |
| 117 | + } |
| 118 | + |
| 119 | + // Check the data. |
| 120 | + if (!$category->check()) |
| 121 | + { |
| 122 | + $this->setError($category->getError()); |
| 123 | + |
| 124 | + return false; |
| 125 | + } |
| 126 | + |
| 127 | + // Store the data. |
| 128 | + if (!$category->store()) |
| 129 | + { |
| 130 | + $this->setError($category->getError()); |
| 131 | + |
| 132 | + return false; |
| 133 | + } |
| 134 | + |
| 135 | + //return true; |
| 136 | + } |
| 137 | + |
| 138 | +} |
0 commit comments