From 616ad119ad753e10db7f578d4bd1bd82540e2433 Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Wed, 21 Feb 2007 11:42:48 +0000 Subject: [PATCH] MDL-8087 Modules and Blocks lists now link to course search page for actual instances. --- admin/blocks.php | 11 +++++- admin/modules.php | 10 ++++- course/search.php | 81 +++++++++++++++++++++++++++++++++++------ lang/en_utf8/moodle.php | 2 + 4 files changed, 90 insertions(+), 14 deletions(-) diff --git a/admin/blocks.php b/admin/blocks.php index ccc7ccb45f..2a83952674 100644 --- a/admin/blocks.php +++ b/admin/blocks.php @@ -17,7 +17,6 @@ $delete = optional_param('delete', 0, PARAM_INT); $multiple = optional_param('multiple', 0, PARAM_INT); - /// Print headings $strmanageblocks = get_string('manageblocks'); @@ -29,6 +28,7 @@ $strcourses = get_string('blockinstances', 'admin'); $strname = get_string('name'); $strmultiple = get_string('blockmultiple', 'admin'); + $strshowblockcourse = get_string('showblockcourse'); admin_externalpage_print_header($adminroot); @@ -184,6 +184,13 @@ } $count = count_records('block_instance', 'blockid', $blockid); + if ($count>0) { + $blocklist = "wwwroot}/course/search.php?blocklist=$blockid&sesskey={$USER->sesskey}\" "; + $blocklist .= "title=\"$strshowblockcourse\" >$count"; + } + else { + $blocklist = "$count"; + } $class = ''; // Nothing fancy, by default if ($blocks[$blockid]->visible) { @@ -208,7 +215,7 @@ $table->add_data(array( ''.$blockobject->get_title().'', - $count, + $blocklist, $blockobject->get_version(), $visible, $multiple, diff --git a/admin/modules.php b/admin/modules.php index a86eedc50d..f95327a191 100644 --- a/admin/modules.php +++ b/admin/modules.php @@ -23,6 +23,7 @@ $strsettings = get_string("settings"); $stractivities = get_string("activities"); $stractivitymodule = get_string("activitymodule"); + $strshowmodulecourse = get_string('showmodulecourse'); admin_externalpage_print_header($adminroot); @@ -170,6 +171,13 @@ } $count = count_records("$module->name"); + if ($count>0) { + $countlink = "wwwroot}/course/search.php?modulelist=$module->name" . + "&sesskey={$USER->sesskey}\" title=\"$strshowmodulecourse\">$count"; + } + else { + $countlink = "$count"; + } if ($module->visible) { $visible = "name&sesskey=$USER->sesskey\" title=\"$strhide\">". @@ -185,7 +193,7 @@ $visible = ""; $class = ""; } - $table->data[] = array ("$icon $modulename", $count, $module->version, $visible, $delete, $settings); + $table->data[] = array ("$icon $modulename", $countlink, $module->version, $visible, $delete, $settings); } print_table($table); diff --git a/course/search.php b/course/search.php index 747033c03a..4283d76f4c 100644 --- a/course/search.php +++ b/course/search.php @@ -5,13 +5,15 @@ require_once("../config.php"); require_once("lib.php"); - $search = optional_param('search', '', PARAM_RAW); // search words - $page = optional_param('page', 0, PARAM_INT); // which page to show - $perpage = optional_param('perpage', 10, PARAM_INT); // how many per page - $moveto = optional_param('moveto', 0, PARAM_INT); // move to category - $edit = optional_param('edit', -1, PARAM_BOOL); - $hide = optional_param('hide', 0, PARAM_INT); - $show = optional_param('show', 0, PARAM_INT); + $search = optional_param('search', '', PARAM_RAW); // search words + $page = optional_param('page', 0, PARAM_INT); // which page to show + $perpage = optional_param('perpage', 10, PARAM_INT); // how many per page + $moveto = optional_param('moveto', 0, PARAM_INT); // move to category + $edit = optional_param('edit', -1, PARAM_BOOL); + $hide = optional_param('hide', 0, PARAM_INT); + $show = optional_param('show', 0, PARAM_INT); + $blocklist = optional_param('blocklist', 0, PARAM_INT); + $modulelist= optional_param('modulelist', '', PARAM_ALPHAEXT); $search = trim(strip_tags($search)); // trim & clean raw searched string @@ -80,8 +82,9 @@ $strselectall = get_string("selectall"); $strdeselectall = get_string("deselectall"); $stredit = get_string("edit"); + $strfrontpage = get_string('frontpage', 'admin'); - if (!$search) { + if (empty($search) and empty($blocklist) and empty($modulelist)) { print_header("$site->fullname : $strsearch", $site->fullname, "$strcourses -> $strsearch", "", ""); print_simple_box_start("center"); @@ -112,8 +115,50 @@ move_courses($courses, $data->moveto); } - $courses = get_courses_search($searchterms, "fullname ASC", - $page*$perpage, $perpage, $totalcount); + // get list of courses containing blocks if required + if (!empty($blocklist) and confirm_sesskey()) { + $blockid = $blocklist; + if (!$blocks = get_records('block_instance', 'blockid', $blockid)) { + error( "Could not read data for blockid=$blockid" ); + } + + // run through blocks and get (unique) courses + $courses = array(); + foreach ($blocks as $block) { + $courseid = $block->pageid; + if ($courseid==0) { + continue; + } + if (!$course = get_record('course', 'id', $courseid)) { + error( "Could not read data for courseid=$courseid" ); + } + $courses[$courseid] = $course; + } + } + // get list of courses containing modules if required + elseif (!empty($modulelist) and confirm_sesskey()) { + $modulename = $modulelist; + if (!$modules = get_records($modulename)) { + error( "Could not read data for module=$modulename" ); + } + + // run through modules and get (unique) courses + $courses = array(); + foreach ($modules as $module) { + $courseid = $module->course; + if ($courseid==0) { + continue; + } + if (!$course = get_record('course', 'id', $courseid)) { + error( "Could not read data for courseid=$courseid" ); + } + $courses[$courseid] = $course; + } + } + else { + $courses = get_courses_search($searchterms, "fullname ASC", + $page*$perpage, $perpage, $totalcount); + } $searchform = print_course_search($search, true, "navbar"); @@ -166,9 +211,23 @@ foreach ($courses as $course) { $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); - + $course->fullname = highlight("$search", $course->fullname); $linkcss = $course->visible ? "" : " class=\"dimmed\" "; + + // are we displaying the front page (courseid=1)? + if ($course->id == 1) { + echo ""; + echo "wwwroot\">$strfrontpage"; + + // can't do anything else with the front page + echo "  "; // category place + echo "  "; // select place + echo "  "; // edit place + echo ""; + continue; + } + echo ""; echo "id\">$course->fullname"; echo "".$displaylist[$course->category].""; diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index e1ab129bbd..d1ea99b62d 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -1227,8 +1227,10 @@ $string['showallcourses'] = 'Show all courses'; $string['showalltopics'] = 'Show all topics'; $string['showallusers'] = 'Show all users'; $string['showallweeks'] = 'Show all weeks'; +$string['showblockcourse'] = 'Show list of courses containing block'; $string['showgrades'] = 'Show grades'; $string['showlistofcourses'] = 'Show list of courses'; +$string['showmodulecourse'] = 'Show list of courses containing activity'; $string['showonly'] = 'Show only'; $string['showonlytopic'] = 'Show only topic $a'; $string['showonlyweek'] = 'Show only week $a'; -- 2.39.5