From 580f2fbc07a299b7133b853b027e479735585b09 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 25 Apr 2003 05:24:29 +0000 Subject: [PATCH] New function to detect visibility of a single module, and use of this function when displaying list of forums --- lib/datalib.php | 25 ++++++++++++++++++++++++ mod/forum/index.php | 47 +++++++++++++++------------------------------ 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/lib/datalib.php b/lib/datalib.php index ed94653ede..a3a054cc16 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -1024,6 +1024,31 @@ function get_all_instances_in_course($modulename, $courseid, $sort="cw.section") } +function instance_is_visible($moduletype, $module) { +/// Given a valid module object with info about the id and course, +/// and the module's type (eg "forum") returns whether the object +/// is visible or not + + global $CFG; + + if ($records = get_records_sql("SELECT f.id, cm.visible + FROM {$CFG->prefix}course_modules cm, + {$CFG->prefix}forum f, + {$CFG->prefix}modules m + WHERE cm.course = '$module->course' AND + cm.module = m.id AND + m.name = '$moduletype' AND + cm.instance = f.id AND + f.id = '$module->id'")) { + + foreach ($records as $record) { // there should only be one - use the first one + return $record->visible; + } + } + + return true; // visible by default! +} + diff --git a/mod/forum/index.php b/mod/forum/index.php index eb150e0551..d610abb2e4 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -51,22 +51,13 @@ $table->align[] = "CENTER"; } - //Obtains all the forum data and visible field - if ($forums = get_records_sql("SELECT f.*,cm.visible as visible - FROM {$CFG->prefix}course_modules cm, - {$CFG->prefix}forum f, - {$CFG->prefix}modules md - WHERE cm.course = '$id' AND - f.course = '$id' AND - md.name = 'forum' AND - md.id = cm.module AND - f.id = cm.instance - ORDER BY f.name")) - { + if ($forums = get_records("forum", "course", $id, "name ASC")) { foreach ($forums as $forum) { + $forum->visible = true; switch ($forum->type) { case "news": case "social": + $forum->visible = instance_is_visible("forum", $forum); $generalforums[] = $forum; break; case "teacher": @@ -87,13 +78,10 @@ foreach ($generalforums as $forum) { $count = count_records("forum_discussions", "forum", "$forum->id"); - //Calculate the href - if (!$forum->visible) { - //Show dimmed if the mod is hidden - $tt_href = "id\">$forum->name"; + if ($forum->visible) { + $forumlink = "id\">$forum->name"; } else { - //Show normal if the mod is visible - $tt_href = "id\">$forum->name"; + $forumlink = "id\">$forum->name"; } if ($can_subscribe) { @@ -107,11 +95,11 @@ $subscribed = get_string("no"); $subtitle = get_string("subscribe", "forum"); } - $sublink = "id\">$subscribed"; + $sublink = "id\">$subscribed"; } - $table->data[] = array ($tt_href, "$forum->intro", "$count", "$sublink"); + $table->data[] = array ($forumlink, "$forum->intro", "$count", $sublink); } else { - $table->data[] = array ($tt_href, "$forum->intro", "$count"); + $table->data[] = array ($forumlink, "$forum->intro", "$count"); } } print_heading(get_string("generalforums", "forum")); @@ -141,15 +129,12 @@ $forum->section = ""; } - //Calculate the href - if (!$forum->visible) { - //Show dimmed if the mod is hidden - $tt_href = "id\">$forum->name"; + if ($forum->visible) { + $forumlink = "id\">$forum->name"; } else { - //Show normal if the mod is visible - $tt_href = "id\">$forum->name"; + $forumlink = "id\">$forum->name"; } - + if ($can_subscribe) { if (forum_is_forcesubscribed($forum->id)) { $sublink = get_string("yes"); @@ -161,11 +146,11 @@ $subscribed = get_string("no"); $subtitle = get_string("subscribe", "forum"); } - $sublink = "id\">$subscribed"; + $sublink = "id\">$subscribed"; } - $table->data[] = array ("$forum->section", $tt_href, "$forum->intro", "$count", "$sublink"); + $table->data[] = array ("$forum->section", $forumlink, "$forum->intro", "$count", "$sublink"); } else { - $table->data[] = array ("$forum->section", $tt_href, "$forum->intro", "$count"); + $table->data[] = array ("$forum->section", $forumlink, "$forum->intro", "$count"); } } print_heading(get_string("learningforums", "forum")); -- 2.39.5