mirror of
https://github.com/moodle/moodle.git
synced 2025-03-18 06:31:22 +01:00
MDL-47389 forum: Return discussions count in get_forums_by_courses ws
This commit is contained in:
parent
6597413d41
commit
7ea6ada343
mod/forum
@ -82,6 +82,8 @@ class mod_forum_external extends external_api {
|
||||
if ($forums = $DB->get_records('forum', array('course' => $cid))) {
|
||||
// Get the modinfo for the course.
|
||||
$modinfo = get_fast_modinfo($cid);
|
||||
// Get the course object.
|
||||
$course = $modinfo->get_course();
|
||||
// Get the forum instances.
|
||||
$foruminstances = $modinfo->get_instances_of('forum');
|
||||
// Loop through the forums returned by modinfo.
|
||||
@ -101,6 +103,10 @@ class mod_forum_external extends external_api {
|
||||
$context->id, 'mod_forum', 'intro', 0);
|
||||
// Add the course module id to the object, this information is useful.
|
||||
$forum->cmid = $cm->id;
|
||||
|
||||
// Discussions count. This function does static request cache.
|
||||
$forum->numdiscussions = forum_count_discussions($forum, $cm, $course);
|
||||
|
||||
// Add the forum to the array to return.
|
||||
$arrforums[$forum->id] = (array) $forum;
|
||||
}
|
||||
@ -144,7 +150,8 @@ class mod_forum_external extends external_api {
|
||||
'completiondiscussions' => new external_value(PARAM_INT, 'Student must create discussions'),
|
||||
'completionreplies' => new external_value(PARAM_INT, 'Student must post replies'),
|
||||
'completionposts' => new external_value(PARAM_INT, 'Student must post discussions or replies'),
|
||||
'cmid' => new external_value(PARAM_INT, 'Course module id')
|
||||
'cmid' => new external_value(PARAM_INT, 'Course module id'),
|
||||
'numdiscussions' => new external_value(PARAM_INT, 'Number of discussions in the forum', VALUE_OPTIONAL)
|
||||
), 'forum'
|
||||
)
|
||||
);
|
||||
|
@ -81,6 +81,24 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
||||
$record->course = $course2->id;
|
||||
$forum2 = self::getDataGenerator()->create_module('forum', $record);
|
||||
|
||||
// Add discussions to the forums.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $user->id;
|
||||
$record->forum = $forum1->id;
|
||||
$discussion1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
// Expect one discussion.
|
||||
$forum1->numdiscussions = 1;
|
||||
|
||||
$record = new stdClass();
|
||||
$record->course = $course2->id;
|
||||
$record->userid = $user->id;
|
||||
$record->forum = $forum2->id;
|
||||
$discussion2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
$discussion3 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
// Expect two discussions.
|
||||
$forum2->numdiscussions = 2;
|
||||
|
||||
// Check the forum was correctly created.
|
||||
$this->assertEquals(2, $DB->count_records_select('forum', 'id = :forum1 OR id = :forum2',
|
||||
array('forum1' => $forum1->id, 'forum2' => $forum2->id)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user