Back to PhocaGalleryCategory class

Method getCategoryById

public static
getCategoryById
(mixed $id)

Method getCategoryById - Source code

/*
	public static function CategoryTreeOption($data, $tree, $id=0, $text='', $currentId = 0) {

		foreach ($data as $key) {
			$show_text =  $text . $key->text;

			if ($key->parentid == $id && $currentId != $id && $currentId != $key->value) {
				$tree[$key->value] 			= new CMSObject();
				$tree[$key->value]->text 	= $show_text;
				$tree[$key->value]->value 	= $key->value;
				$tree = self::CategoryTreeOption($data, $tree, $key->value, $show_text . " - ", $currentId );
			}
		}
		return($tree);
	}

	public static function filterCategory($query, $active = NULL, $frontend = NULL, $onChange = TRUE, $fullTree = NULL ) {

		$db	= Factory::getDBO();

		$form = 'adminForm';
		if ($frontend == 1) {
			$form = 'phocacartproductsform';
		}

		if ($onChange) {
			$onChO = 'class="form-control" size="1" onchange="document.'.$form.'.submit( );"';
		} else {
			$onChO = 'class="form-control" size="1"';
		}

		$categories[] = HTMLHelper::_('select.option', '0', '- '.Text::_('COM_phocagallery_SELECT_CATEGORY').' -');
		$db->setQuery($query);
		$catData = $db->loadObjectList();



		if ($fullTree) {

			// Start - remove in case there is a memory problem
			$tree = array();
			$text = '';

			$queryAll = ' SELECT cc.id AS value, cc.title AS text, cc.parent_id as parentid'
					.' FROM #__phocagallery_categories AS cc'
					.' ORDER BY cc.ordering';
			$db->setQuery($queryAll);
			$catDataAll 		= $db->loadObjectList();

			$catDataTree	= PhocacartCategory::CategoryTreeOption($catDataAll, $tree, 0, $text, -1);

			$catDataTreeRights = array();
			//-
			/*foreach ($catData as $k => $v) {
				foreach ($catDataTree as $k2 => $v2) {
					if ($v->value == $v2->value) {
						$catDataTreeRights[$k]->text 	= $v2->text;
						$catDataTreeRights[$k]->value = $v2->value;
					}
				}
			} */
//-
/*

			foreach ($catDataTree as $k => $v) {
                foreach ($catData as $k2 => $v2) {
                   if ($v->value == $v2->value) {
						$catDataTreeRights[$k] = new StdClass();
						$catDataTreeRights[$k]->text  = $v->text;
						$catDataTreeRights[$k]->value = $v->value;
                   }
                }
             }



			$catDataTree = array();
			$catDataTree = $catDataTreeRights;
			// End - remove in case there is a memory problem

			// Uncomment in case there is a memory problem
			//$catDataTree	= $catData;
		} else {
			$catDataTree	= $catData;
		}

		$categories = array_merge($categories, $catDataTree );

		$category = HTMLHelper::_('select.genericlist',  $categories, 'catid', $onChO, 'value', 'text', $active);

		return $category;
	}

	public static function options($type = 0)
	{


		$db = Factory::getDBO();

       //build the list of categories
		$query = 'SELECT a.title AS text, a.id AS value, a.parent_id as parentid'
		. ' FROM #__phocagallery_categories AS a'
		. ' WHERE a.published = 1'
		. ' ORDER BY a.ordering';
		$db->setQuery( $query );
		$items = $db->loadObjectList();

		$catId	= -1;

		$javascript 	= 'class="form-control" size="1" onchange="submitform( );"';

		$tree = array();
		$text = '';
		$tree = PhocacartCategory::CategoryTreeOption($items, $tree, 0, $text, $catId);

		return $tree;

	}*/
public static function getCategoryById($id)
{
    $id = (int) $id;
    if (empty(self::$categoryI[$id])) {
        $db = Factory::getDBO();
        $query = 'SELECT a.title, a.alias, a.id, a.parent_id' . ' FROM #__phocagallery_categories AS a' . ' WHERE a.id = ' . (int) $id . ' ORDER BY a.ordering' . ' LIMIT 1';
        $db->setQuery($query);
        $category = $db->loadObject();
        if (!empty($category) && isset($category->id) && (int) $category->id > 0) {
            $query = 'SELECT a.title, a.alias, a.id, a.parent_id' . ' FROM #__phocagallery_categories AS a' . ' WHERE a.parent_id = ' . (int) $id . ' ORDER BY a.ordering';
            //. ' LIMIT 1'; We need all subcategories
            $db->setQuery($query);
            $subcategories = $db->loadObjectList();
            if (!empty($subcategories)) {
                $category->subcategories = $subcategories;
            }
        }
        self::$categoryI[$id] = $category;
    }
    return self::$categoryI[$id];
}