MDL-83890 mod_choice: Migrate index to course overview
* Index page for mod_choice should be consistent with the overview page
This commit is contained in:
@@ -97,7 +97,7 @@ final class overviewfactory_test extends \advanced_testcase {
|
||||
],
|
||||
'choice' => [
|
||||
'resourcetype' => 'choice',
|
||||
'expected' => resourceoverview::class,
|
||||
'expected' => \mod_choice\courseformat\overview::class,
|
||||
],
|
||||
'data' => [
|
||||
'resourcetype' => 'data',
|
||||
|
||||
@@ -66,7 +66,7 @@ final class missingoverviewnotice_test extends \advanced_testcase {
|
||||
'assign' => ['modname' => 'assign', 'expectempty' => true],
|
||||
'bigbluebuttonbn' => ['modname' => 'bigbluebuttonbn', 'expectempty' => false],
|
||||
'book' => ['modname' => 'book', 'expectempty' => false],
|
||||
'choice' => ['modname' => 'choice', 'expectempty' => false],
|
||||
'choice' => ['modname' => 'choice', 'expectempty' => true],
|
||||
'data' => ['modname' => 'data', 'expectempty' => true],
|
||||
'feedback' => ['modname' => 'feedback', 'expectempty' => true],
|
||||
'folder' => ['modname' => 'folder', 'expectempty' => false],
|
||||
|
||||
+25
-100
@@ -1,105 +1,30 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
// For this type of page this is the course id.
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
/**
|
||||
* Prints the list of all choices in the course
|
||||
*
|
||||
* @package mod_choice
|
||||
* @copyright 2023 Laurent David <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$id = required_param('id',PARAM_INT); // course
|
||||
require_once("../../config.php");
|
||||
|
||||
$PAGE->set_url('/mod/choice/index.php', array('id'=>$id));
|
||||
$courseid = required_param('id', PARAM_INT);
|
||||
|
||||
if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
||||
throw new \moodle_exception('invalidcourseid');
|
||||
}
|
||||
|
||||
require_course_login($course);
|
||||
$PAGE->set_pagelayout('incourse');
|
||||
|
||||
$eventdata = array('context' => context_course::instance($id));
|
||||
$event = \mod_choice\event\course_module_instance_list_viewed::create($eventdata);
|
||||
$event->add_record_snapshot('course', $course);
|
||||
$event->trigger();
|
||||
|
||||
$strchoice = get_string("modulename", "choice");
|
||||
$strchoices = get_string("modulenameplural", "choice");
|
||||
$PAGE->set_title($strchoices);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
$PAGE->navbar->add($strchoices);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if (! $choices = get_all_instances_in_course("choice", $course)) {
|
||||
notice(get_string('thereareno', 'moodle', $strchoices), "../../course/view.php?id=$course->id");
|
||||
}
|
||||
|
||||
$usesections = course_format_uses_sections($course->format);
|
||||
|
||||
$sql = "SELECT cha.*
|
||||
FROM {choice} ch, {choice_answers} cha
|
||||
WHERE cha.choiceid = ch.id AND
|
||||
ch.course = ? AND cha.userid = ?";
|
||||
|
||||
$answers = array () ;
|
||||
if (isloggedin() and !isguestuser() and $allanswers = $DB->get_records_sql($sql, array($course->id, $USER->id))) {
|
||||
foreach ($allanswers as $aa) {
|
||||
$answers[$aa->choiceid] = $aa;
|
||||
}
|
||||
unset($allanswers);
|
||||
}
|
||||
|
||||
|
||||
$timenow = time();
|
||||
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = course_get_format($course)->get_generic_section_name();
|
||||
$table->head = array ($strsectionname, get_string("question"), get_string("answer"));
|
||||
$table->align = array ("center", "left", "left");
|
||||
} else {
|
||||
$table->head = array (get_string("question"), get_string("answer"));
|
||||
$table->align = array ("left", "left");
|
||||
}
|
||||
|
||||
$currentsection = "";
|
||||
|
||||
foreach ($choices as $choice) {
|
||||
if (!empty($answers[$choice->id])) {
|
||||
$answer = $answers[$choice->id];
|
||||
} else {
|
||||
$answer = "";
|
||||
}
|
||||
if (!empty($answer->optionid)) {
|
||||
$aa = format_string(choice_get_option_text($choice, $answer->optionid));
|
||||
} else {
|
||||
$aa = "";
|
||||
}
|
||||
if ($usesections) {
|
||||
$printsection = "";
|
||||
if ($choice->section !== $currentsection) {
|
||||
if ($choice->section) {
|
||||
$printsection = get_section_name($course, $choice->section);
|
||||
}
|
||||
if ($currentsection !== "") {
|
||||
$table->data[] = 'hr';
|
||||
}
|
||||
$currentsection = $choice->section;
|
||||
}
|
||||
}
|
||||
|
||||
//Calculate the href
|
||||
if (!$choice->visible) {
|
||||
//Show dimmed if the mod is hidden
|
||||
$tt_href = "<a class=\"dimmed\" href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name,true)."</a>";
|
||||
} else {
|
||||
//Show normal if the mod is visible
|
||||
$tt_href = "<a href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name,true)."</a>";
|
||||
}
|
||||
if ($usesections) {
|
||||
$table->data[] = array ($printsection, $tt_href, $aa);
|
||||
} else {
|
||||
$table->data[] = array ($tt_href, $aa);
|
||||
}
|
||||
}
|
||||
echo "<br />";
|
||||
echo html_writer::table($table);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
\core_courseformat\activityoverviewbase::redirect_to_overview_page($courseid, 'choice');
|
||||
|
||||
Reference in New Issue
Block a user