mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-81089 block_recentlyaccesseditems: Return module branded
This commit is contained in:
parent
b2fa19f45d
commit
1e87c997df
@ -53,6 +53,9 @@ class recentlyaccesseditems_item_exporter extends \core\external\exporter {
|
||||
require_once($CFG->libdir.'/modinfolib.php');
|
||||
$iconurl = get_fast_modinfo($this->data->courseid)->cms[$this->data->cmid]->get_icon_url();
|
||||
$iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter';
|
||||
|
||||
$isbranded = component_callback('mod_' . $this->data->modname, 'is_branded') !== null ? : false;
|
||||
|
||||
return array(
|
||||
'viewurl' => (new moodle_url('/mod/'.$this->data->modname.'/view.php',
|
||||
array('id' => $this->data->cmid)))->out(false),
|
||||
@ -63,6 +66,7 @@ class recentlyaccesseditems_item_exporter extends \core\external\exporter {
|
||||
['title' => get_string('pluginname', $this->data->modname), 'class' => "icon $iconclass"]
|
||||
),
|
||||
'purpose' => plugin_supports('mod', $this->data->modname, FEATURE_MOD_PURPOSE, MOD_PURPOSE_OTHER),
|
||||
'branded' => $isbranded,
|
||||
);
|
||||
}
|
||||
|
||||
@ -118,7 +122,11 @@ class recentlyaccesseditems_item_exporter extends \core\external\exporter {
|
||||
),
|
||||
'purpose' => array(
|
||||
'type' => PARAM_ALPHA,
|
||||
)
|
||||
),
|
||||
'branded' => [
|
||||
'type' => PARAM_BOOL,
|
||||
'optional' => true,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
|
||||
$this->resetAfterTest();
|
||||
$generator = $this->getDataGenerator();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Add courses.
|
||||
$courses = array();
|
||||
@ -59,6 +60,7 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
$forum[] = $this->getDataGenerator()->create_module('forum', array('course' => $course));
|
||||
$glossary[] = $this->getDataGenerator()->create_module('glossary', array('course' => $course));
|
||||
$assign[] = $this->getDataGenerator()->create_module('assign', ['course' => $course]);
|
||||
$h5pactivity[] = $this->getDataGenerator()->create_module('h5pactivity', ['course' => $course]);
|
||||
}
|
||||
$generator->enrol_user($teacher->id, $courses[0]->id, 'teacher');
|
||||
|
||||
@ -88,24 +90,39 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
$this->waitForSecond();
|
||||
}
|
||||
|
||||
// Student access all h5p.
|
||||
foreach ($h5pactivity as $module) {
|
||||
$event = \mod_h5pactivity\event\course_module_viewed::create(
|
||||
['context' => \context_module::instance($module->cmid), 'objectid' => $module->id]
|
||||
);
|
||||
$event->trigger();
|
||||
$this->waitForSecond();
|
||||
}
|
||||
|
||||
// Test that results are sorted by timeaccess DESC (default).
|
||||
$result = \block_recentlyaccesseditems\external::get_recent_items();
|
||||
$this->assertCount((count($forum) + count($assign)), $result);
|
||||
$this->assertCount((count($forum) + count($assign) + count($h5pactivity)), $result);
|
||||
foreach ($result as $key => $record) {
|
||||
if ($key == 0) {
|
||||
continue;
|
||||
}
|
||||
$this->assertTrue($record->timeaccess < $result[$key - 1]->timeaccess);
|
||||
// Check that the branded property is set correctly.
|
||||
if ($record->modname == 'h5pactivity') {
|
||||
$this->assertTrue($record->branded);
|
||||
} else {
|
||||
$this->assertFalse($record->branded);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete a course and confirm it's activities don't get returned.
|
||||
delete_course($courses[0], false);
|
||||
$result = \block_recentlyaccesseditems\external::get_recent_items();
|
||||
$this->assertCount((count($forum) + count($assign)) - 2, $result);
|
||||
$this->assertCount((count($forum) + count($assign) + count($h5pactivity)) - 3, $result);
|
||||
|
||||
// Delete a single course module should still return.
|
||||
course_delete_module($forum[1]->cmid);
|
||||
$result = \block_recentlyaccesseditems\external::get_recent_items();
|
||||
$this->assertCount((count($forum) + count($assign)) - 3, $result);
|
||||
$this->assertCount((count($forum) + count($assign) + count($h5pactivity)) - 4, $result);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
This file describes API changes in the recentlyaccesseditems block code.
|
||||
|
||||
=== 4.4 ===
|
||||
* The external function \block_recentlyaccesseditems\external\get_recent_items() now returns
|
||||
a field called "branded" indicating whether the module is branded or not.
|
||||
|
||||
=== 3.7 ===
|
||||
|
||||
* The 'block/recentlyaccesseditems:addinstance' capability has been removed. It has never been used in code.
|
Loading…
x
Reference in New Issue
Block a user