Skip to content

Commit 5ec617b

Browse files
author
ttplsudhir
committed
Merge pull request #1 from ttplsudhir/ttplsudhir-patch-1
Categories Plugin
2 parents 1ff2a15 + 074400e commit 5ec617b

File tree

3 files changed

+185
-0
lines changed

3 files changed

+185
-0
lines changed

categories/categories.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* @package API plugins
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+
9+
defined('_JEXEC') or die( 'Restricted access' );
10+
11+
jimport('joomla.plugin.plugin');
12+
13+
class plgAPICategories extends ApiPlugin
14+
{
15+
public function __construct(&$subject, $config = array())
16+
{
17+
parent::__construct($subject, $config = array());
18+
19+
ApiResource::addIncludePath(dirname(__FILE__).'/categories');
20+
}
21+
}

categories/categories.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<extension version="2.5.0" type="plugin" group="api" method="upgrade">
3+
<name>Api - categories</name>
4+
<version>1.6</version>
5+
<creationDate>22 July 2015</creationDate>
6+
<author>Techjoomla</author>
7+
<authorEmail>extensions@techjoomla.com</authorEmail>
8+
<authorUrl>www.techjoomla.com</authorUrl>
9+
<copyright>Techjoomla. All rights reserved.</copyright>
10+
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
11+
<description>This plugin is for content Request</description>
12+
<files>
13+
<filename plugin="categories">categories.php</filename>
14+
<folder>categories</folder>
15+
</files>
16+
<languages>
17+
<language tag="en-GB">en-GB.plg_api_categories.ini</language>
18+
<language tag="en-GB">en-GB.plg_api_categories.sys.ini</language>
19+
</languages>
20+
<config>
21+
<fields name="params">
22+
<fieldset name="basic">
23+
</fieldset>
24+
</fields>
25+
</config>
26+
</extension>
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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

Comments
 (0)