Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task #121870 chore: Get categories by providing extension #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions categories/categories/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,77 @@
jimport('joomla.html.html');
JLoader::register('JCategoryNode', JPATH_BASE . '/libraries/legacy/categories/categories.php');



/**
* Categories Api
*
* @since 1.0
*/
class CategoriesApiResourceCategories extends ApiResource
{
/**
* Get categories
*
* @return void
*
* @since 1.0
*/
public function get()
{
$this->plugin->setResponse($this->getCategoryList());
$app = JFactory::getApplication();
$extension = $app->input->get('extension', 'content');
$this->plugin->setResponse($this->getCategoryList($extension));
}

/**
* Delete category
*
* @return void
*
* @since 1.0
*/
public function delete()
{
$this->plugin->setResponse('in delete');
}

/**
* Create category
*
* @return void
*
* @since 1.0
*/
public function post()
{
$this->plugin->setResponse($this->CreateUpdateCategory());
}

public function getCategory()
{
self::getListQuery();
}

/**
* Get the master query for retrieving a list of categories subject to the model state.
/**
* Get the master query for retrieving a list of categories subject to the mzodel state.
*
* @param string $extension extension name
*
* @return JDatabaseQuery
*
* @since 1.6
*/
public function getCategoryList()
private function getCategoryList($extension)
{
/*$model_categories = JCategories::getInstance('Content');
$root = $model_categories->get('root');
$categories = $root->getChildren();*/

$model_categories = JCategories::getInstance('Content');
$model_categories = JCategories::getInstance($extension);
$root = $model_categories->get('root');
$categories = $root->getChildren(true);

return $categories;

}

/**
* CreateUpdateCategory is to create / upadte Category
*
* @return Bolean
*
* @since 3.5
*/
public function CreateUpdateCategory()
private function CreateUpdateCategory()
{
if (version_compare(JVERSION, '3.0', 'lt'))
{
Expand All @@ -80,6 +100,7 @@ public function CreateUpdateCategory()

return $obj;
}

if (empty($app->input->get('extension', '', 'STRING')))
{
$obj->code = 'ER002';
Expand All @@ -88,7 +109,6 @@ public function CreateUpdateCategory()
return $obj;
}


if ($cat_id)
{
$category = JTable::getInstance('Content', 'JTable', array());
Expand All @@ -101,6 +121,7 @@ public function CreateUpdateCategory()
if (!$cat_id->bind($data))
{
$this->setError($article->getError());

return false;
}
}
Expand Down Expand Up @@ -131,8 +152,5 @@ public function CreateUpdateCategory()

return false;
}

//return true;
}

}