itsam / imc

Improve My City :: The new extension package for Joomla 3
Other
24 stars 29 forks source link

Add a Subcategories box in new issue #76

Open kaiser36 opened 5 years ago

kaiser36 commented 5 years ago

Hi How can I add the subcategories field when you are entering a new issue. I need to have categories and subcategories available in a box to choose from.

itsam commented 5 years ago

Subcategories are included by default normally... Probably you are creating your own form so you can embed smt like this

function createCategoriesOptions()
{
    $options = array();
    $db = JFactory::getDbo();
    $query = $db->getQuery(true)
            ->select('a.id AS value')
            ->select('a.title AS text')
            ->select('a.path AS path')
            ->select('COUNT(DISTINCT b.id) AS level')
            ->from('#__categories as a')
            ->where('a.extension = "com_imc"')
            ->where('a.published = 1')
            ->join('LEFT', '#__categories AS b ON a.lft > b.lft AND a.rgt < b.rgt')
            ->group('a.id, a.title, a.lft, a.rgt')
            ->order('a.lft ASC');
    $db->setQuery($query);
    $categories = $db->loadObjectList();
    return $categories;
}
$categoriesOptions = createCategoriesOptions();