Agora_Driver_Sql::_getForums PHP Метод

_getForums() защищенный Метод

Fetches a list of forums.
protected _getForums ( integer $root_forum, boolean $formatted = true, string $sort_by = 'forum_name', integer $sort_dir, boolean $add_scope = false, string $from, string $count ) : array
$root_forum integer The first level forum.
$formatted boolean Whether to return the list formatted or raw.
$sort_by string The column to sort by.
$sort_dir integer Sort direction, 0 = ascending, 1 = descending.
$add_scope boolean Add parent forum if forum for another scopelication.
$from string The forum to start listing at.
$count string The number of forums to return.
Результат array An array of forums.
    protected function _getForums($root_forum = 0, $formatted = true, $sort_by = 'forum_name', $sort_dir = 0, $add_scope = false, $from = 0, $count = 0)
    {
        $key = $this->_scope . ':' . $root_forum . ':' . $formatted . ':' . $sort_by . ':' . $sort_dir . ':' . $add_scope . ':' . $from . ':' . $count;
        $forums = $this->_getCache($key);
        if ($forums) {
            return unserialize($forums);
        }
        $sql = 'SELECT forum_id, forum_name';
        if ($formatted) {
            $sql .= ', scope, active, forum_description, forum_parent_id, ' . 'forum_moderated, forum_attachments, message_count, thread_count, ' . 'last_message_id, last_message_author, last_message_timestamp';
        }
        $sql .= ' FROM ' . $this->_forums_table . ' WHERE active = ? ';
        $params = array(1);
        if ($root_forum != 0) {
            $sql .= ' AND forum_parent_id = ? ';
            $params[] = $root_forum;
        }
        if ($add_scope) {
            $sql .= ' AND scope = ? ';
            $params[] = $this->_scope;
        }
        /* Sort by result colomn if possible */
        $sql .= ' ORDER BY ';
        if ($sort_by == 'forum_name' || $sort_by == 'message_count') {
            $sql .= $sort_by;
        } else {
            $sql .= 'forum_id';
        }
        $sql .= ' ' . ($sort_dir ? 'DESC' : 'ASC');
        /* Slice direcly in DB. */
        if ($count) {
            $sql = $this->_db->addLimitOffset($sql, array('limit' => $count, 'offset' => $from));
        }
        try {
            $forums = $this->_db->selectAll($sql, $params);
        } catch (Horde_Db_Exception $e) {
            throw new Agora_Exception($e->getMessage());
        }
        if (empty($forums)) {
            throw new Horde_Exception_NotFound(_("There are no forums."));
        }
        if ($formatted) {
            $forums = $this->_formatForums($forums);
        }
        $this->_setCache($key, serialize($forums));
        return $forums;
    }