MDL-83891 mod_data: Redirect index.php to activities overview page

This commit is contained in:
Amaia Anabitarte
2025-06-26 14:10:56 +02:00
parent 9d0c655576
commit 5d44690c27
3 changed files with 12 additions and 166 deletions
+2 -124
View File
@@ -24,128 +24,6 @@
*/
require_once("../../config.php");
require_once("lib.php");
$id = required_param('id', PARAM_INT); // course
$PAGE->set_url('/mod/data/index.php', array('id'=>$id));
if (!$course = $DB->get_record('course', array('id'=>$id))) {
throw new \moodle_exception('invalidcourseid');
}
require_course_login($course);
$PAGE->set_pagelayout('incourse');
$context = context_course::instance($course->id);
$params = array(
'context' => context_course::instance($course->id)
);
$event = \mod_data\event\course_module_instance_list_viewed::create($params);
$event->add_record_snapshot('course', $course);
$event->trigger();
$strname = get_string('name');
$strdata = get_string('modulename','data');
$strdataplural = get_string('modulenameplural','data');
$PAGE->navbar->add($strdata, new moodle_url('/mod/data/index.php', array('id'=>$course->id)));
$titleparts = [
$strdataplural,
format_string($course->fullname),
];
$PAGE->set_title(implode(moodle_page::TITLE_SEPARATOR, $titleparts));
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($strdataplural, 2);
if (! $datas = get_all_instances_in_course("data", $course)) {
notice(get_string('thereareno', 'moodle',$strdataplural) , "$CFG->wwwroot/course/view.php?id=$course->id");
}
$usesections = course_format_uses_sections($course->format);
$timenow = time();
$strname = get_string('name');
$strdescription = get_string("description");
$strentries = get_string('entries', 'data');
$strnumnotapproved = get_string('numnotapproved', 'data');
$table = new html_table();
if ($usesections) {
$strsectionname = course_get_format($course)->get_generic_section_name();
$table->head = array ($strsectionname, $strname, $strdescription, $strentries, $strnumnotapproved);
$table->align = array ('center', 'center', 'center', 'center', 'center');
} else {
$table->head = array ($strname, $strdescription, $strentries, $strnumnotapproved);
$table->align = array ('center', 'center', 'center', 'center');
}
$rss = (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds));
if ($rss) {
require_once($CFG->libdir."/rsslib.php");
array_push($table->head, 'RSS');
array_push($table->align, 'center');
}
$currentsection = "";
foreach ($datas as $data) {
$printsection = "";
//Calculate the href
if (!$data->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
}
// TODO: add group restricted counts here, and limit unapproved to ppl with approve cap only + link to approval page
$numrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =?', array($data->id));
if ($data->approval == 1) {
$numunapprovedrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =? AND r.approved <> 1', array($data->id));
} else {
$numunapprovedrecords = '-';
}
$rsslink = '';
if ($rss && $data->rssarticles > 0) {
$rsslink = rss_get_link($context->id, $USER->id, 'mod_data', $data->id, 'RSS');
}
if ($usesections) {
if ($data->section !== $currentsection) {
if ($data->section) {
$printsection = get_section_name($course, $data->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $data->section;
}
$row = array($printsection, $link, format_module_intro('data', $data, $data->coursemodule),
$numrecords, $numunapprovedrecords);
} else {
$row = array($link, format_module_intro('data', $data, $data->coursemodule),
$numrecords, $numunapprovedrecords);
}
if ($rss) {
array_push($row, $rsslink);
}
$table->data[] = $row;
}
echo "<br />";
echo html_writer::tag('div', html_writer::table($table), ['class' => 'table-responsive']);
echo $OUTPUT->footer();
$courseid = required_param('id', PARAM_INT);
\core_courseformat\activityoverviewbase::redirect_to_overview_page($courseid, 'data');
@@ -1,42 +0,0 @@
@mod @mod_data
Feature: Users can view the list of data activities and their formatted descriptions
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Bob | 1 | student1@example.com |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| data | Test database 1 | This is an intro without an image | C1 | data1 |
| data | Test database 2 | This is an intro with an image: <img src="@@PLUGINFILE@@/some_image.jpg"> | C1 | data2 |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| activity_modules | Course | C1 | course-view-* | side-pre |
Scenario: Teachers can view the list of data activities and their formatted descriptions
Given I am on the "Course 1" course page logged in as teacher1
When I follow "Databases"
Then I should see "Test database 1"
And I should see "Test database 2"
And I should see "This is an intro without an image"
And I should see "This is an intro with an image: "
And "//img[contains(@src, 'some_image.jpg')]" "xpath_element" should exist
And "//img[contains(@src, '@@PLUGINFILE@@/some_image.jpg')]" "xpath_element" should not exist
Scenario: Students can view the list of data activities and their formatted descriptions
Given I am on the "Course 1" course page logged in as student1
When I follow "Databases"
Then I should see "Test database 1"
And I should see "Test database 2"
And I should see "This is an intro without an image"
And I should see "This is an intro with an image: "
And "//img[contains(@src, 'some_image.jpg')]" "xpath_element" should exist
And "//img[contains(@src, '@@PLUGINFILE@@/some_image.jpg')]" "xpath_element" should not exist
@@ -121,3 +121,13 @@ Feature: Testing overview integration in database activity
# Check the Approve link.
And I click on "Approve" "link" in the "data_overview_collapsible" "region"
And I should see "Pending approval"
Scenario: The database activity index redirect to the activities overview
When I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I add the "Activities" block
And I click on "Database" "link" in the "Activities" "block"
Then I should see "An overview of all activities in the course"
And I should see "Name" in the "data_overview_collapsible" "region"
And I should see "Due date" in the "data_overview_collapsible" "region"
And I should see "Actions" in the "data_overview_collapsible" "region"