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;
}