/** * Get a list of categories that are reachable by a list view page * * @return array */ protected function _getCategories() { if (self::$_categories === null) { $table = $this->getObject('com://admin/docman.database.table.categories'); $query = $this->getObject('lib:database.query.select'); // Gather the category slugs of active pages $category_slugs = array(); $pages = $this->_getPages(); foreach ($pages as $page) { if (isset($page->query['view']) && $page->query['view'] === 'list' && isset($page->query['slug'])) { $category_slugs[] = $page->query['slug']; } } // Get a list of categories and their children if ($category_slugs) { $query->columns('tbl.slug, r.ancestor_id, r.descendant_id')->table(array('r' => $table->getBehavior('nestable')->getRelationTable()))->join(array('tbl' => $table->getName()), 'tbl.docman_category_id = r.ancestor_id')->where('tbl.slug IN :slug')->bind(array('slug' => (array) $category_slugs)); self::$_categories = $table->getAdapter()->select($query, KDatabase::FETCH_OBJECT_LIST); } else { self::$_categories = array(); } } return self::$_categories; }
/** * Get a list of categories that are reachable by a list view page * * @return array */ protected function _getCategories() { if (self::$_categories === null) { $table = clone $this->getService('com://admin/docman.database.table.categories'); $query = $table->getDatabase()->getQuery(); // Gather the category slugs of active pages $category_slugs = array(); $pages = $this->_getPages(); foreach ($pages as $page) { if ($page->query['view'] === 'list') { $category_slugs[] = $page->query['slug']; } } // Get a list of categories and their children if ($category_slugs) { $query->select('tbl.slug, r.ancestor_id, r.descendant_id') ->from($table->getRelationTable().' AS r') ->join('left', $table->getName().' AS tbl', 'tbl.docman_category_id = r.ancestor_id') ->where('tbl.slug', 'IN', $category_slugs); self::$_categories = $table->getDatabase()->select($query, KDatabase::FETCH_OBJECT_LIST); } else self::$_categories = array(); } return self::$_categories; }