Page 1 of 1

Category Filter in Admin Categories

Posted: 20 Jan 2015, 00:00
by sukhbirgs
Hello i would like to filter categories on admin Categories section, similar to what we have for Files section.

I have lot of categories and subcategories, so in this case if i select parent category it should list all the subcategories. Just for testing i edited file
administrator/components/com_phocadownload/models/phocadownloadcats.php.
Added category parent id to the sql, resulting sql shows me all the subcategories if i run it through phpmyadmin but the actual page does not list any sub category, the list is empty. Here is the query

Code: Select all

SELECT a.*,l.title AS language_title,uc.name AS editor,ag.title AS access_level,c.title AS parentcat_title, c.id AS parentcat_id,cc.countid AS countid
FROM `wpgx9_phocadownload_categories` AS a
LEFT JOIN `wpgx9_languages` AS l ON l.lang_code = a.language
LEFT JOIN wpgx9_users AS uc ON uc.id=a.checked_out
LEFT JOIN wpgx9_viewlevels AS ag ON ag.id = a.access
LEFT JOIN wpgx9_phocadownload_categories AS c ON c.id = a.parent_id
LEFT JOIN (SELECT cc.parent_id, count(*) AS countid FROM wpgx9_phocadownload_categories AS cc GROUP BY cc.parent_id ) AS cc ON a.parent_id = cc.parent_id
WHERE (a.published IN (0, 1))
AND a.parent_id = 13     =====> this is the parent id with few subcategories
GROUP BY a.id
ORDER BY parentcat_title asc
Same query on phpmyadmin lists about 10 categories. Can anyone please provide me with directions to achieve this. Thanks

Joomla 3 with latest build of phoca downloads.

Re: Category Filter in Admin Categories

Posted: 20 Jan 2015, 23:36
by sukhbirgs
Hello i guess no one is using/need of this filter, i have got this working and adding my code here if anyone requires it.

What it does.
You have Multiple level categories and want to display only sub categories of selected category to one level.

Total 3 Files to edit.
1) administrator/components/com_phocadownload/views/phocadownloadcats/tmpl/default.php
Arount Line 35 Find

Code: Select all

echo $r->selectFilterLanguage('JOPTION_SELECT_LANGUAGE', $this->state->get('filter.language'));
After this code add

Code: Select all

echo $r->selectFilterCategory(PhocaDownloadCategory::options($this->t['o']), 'JOPTION_SELECT_CATEGORY', 
         $this->state->get('filter.category_id'));
2) administrator/components/com_phocadownload/views/phocadownloadcats/view.html.php

Arount Line 39 Find

Code: Select all

$this->items = $this->processTree($this->items, $tree, 0, $text, -1, 0);
REPLACE WITH THIS CODE

Code: Select all

// Check if category filter was selected and set category id 
// else set 0 for listing all the categories
$current_id = ($this->state->get('filter.category_id') != '' ? $this->state->get('filter.category_id') : 0);
$this->items = $this->processTree($this->items, $tree, $current_id, $text, -1, 0);
3) administrator/components/com_phocadownload/models/phocadownloadcats.php

Arount Line 60 Find

Code: Select all

$this->setState('filter.language', $language);
Add after this code

Code: Select all

$category_id = $app->getUserStateFromRequest($this->context.'.filter.category_id', 'filter_category_id', null);
$this->setState('filter.category_id', $category_id);
Arount Line 209 Find

Code: Select all

// Filter by search in title	
$search = $this->getState('filter.search');

ADD BEFORE THIS CODE

Code: Select all

// Filter by category.
$category_id = $this->getState('filter.category_id');
if (is_numeric($category_id)) {
	$query->where('a.parent_id = ' . (int) $category_id);
}
Hoping it might be useful to someone.
Thanks

Re: Category Filter in Admin Categories

Posted: 23 Jan 2015, 00:21
by Jan
Hi, thank you very much for the guide.

Jan