Agora_Driver::getForum PHP Method

getForum() public method

Fetches a forum data.
public getForum ( integer $forum_id ) : array
$forum_id integer The ID of the forum to fetch.
return array The forum hash or a PEAR_Error on failure.
    public function getForum($forum_id = 0)
    {
        if (!$forum_id) {
            $forum_id = $this->_forum_id;
        } elseif ($forum_id instanceof PEAR_Error) {
            return $forum_id;
        }
        // Make the requested forum the current forum
        $this->_forum_id = $forum_id;
        /* Check if we can read messages in this forum */
        if (!$this->hasPermission(Horde_Perms::SHOW, $forum_id)) {
            return PEAR::raiseError(sprintf(_("You don't have permission to access messages in forum %s."), $forum_id));
        }
        $forum = $this->_cache->get('agora_forum_' . $forum_id, $GLOBALS['conf']['cache']['default_lifetime']);
        if ($forum) {
            return unserialize($forum);
        }
        $sql = 'SELECT forum_id, forum_name, scope, active, forum_description, ' . 'forum_parent_id, forum_moderated, forum_attachments, ' . 'forum_distribution_address, author, message_count, thread_count ' . 'FROM ' . $this->_forums_table . ' WHERE forum_id = ?';
        try {
            $forum = $this->_db->selectOne($sql, array($forum_id));
        } catch (Horde_Db_Exception $e) {
            throw new Agora_Exception($e->getMessage());
        }
        if (empty($forum)) {
            throw new Horde_Exception_NotFound(sprintf(_("Forum %s does not exist."), $forum_id));
        }
        $forum['forum_name'] = $this->convertFromDriver($forum['forum_name']);
        $forum['forum_description'] = $this->convertFromDriver($forum['forum_description']);
        $forum['forum_distribution_address'] = $this->convertFromDriver($forum['forum_distribution_address']);
        /* Get moderators */
        $sql = 'SELECT horde_uid FROM agora_moderators WHERE forum_id = ?';
        try {
            $moderators = $this->_db->selectValues($sql, array($forum_id));
        } catch (Horde_Db_Exception $e) {
            throw new Agora_Exception($e->getMessage());
        }
        if (!empty($moderators)) {
            $forum['moderators'] = $moderators;
        }
        $this->_cache->set('agora_forum_' . $forum_id, serialize($forum));
        return $forum;
    }