mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Merge branch 'MDL-77788-master' of https://github.com/rmady/moodle
This commit is contained in:
commit
2f771f3175
@ -2658,6 +2658,7 @@ class mod_assign_external extends \mod_assign\external\external_api {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->dirroot . "/mod/assign/locallib.php");
|
||||
require_once($CFG->dirroot . "/user/lib.php");
|
||||
require_once($CFG->libdir . '/grouplib.php');
|
||||
|
||||
$params = self::validate_parameters(self::list_participants_parameters(),
|
||||
array(
|
||||
@ -2679,8 +2680,10 @@ class mod_assign_external extends \mod_assign\external\external_api {
|
||||
$assign->require_view_grades();
|
||||
|
||||
$participants = array();
|
||||
$coursegroups = [];
|
||||
if (groups_group_visible($params['groupid'], $course, $cm)) {
|
||||
$participants = $assign->list_participants_with_filter_status_and_group($params['groupid'], $params['tablesort']);
|
||||
$coursegroups = groups_get_all_groups($course->id);
|
||||
}
|
||||
|
||||
$userfields = user_get_default_fields();
|
||||
@ -2731,9 +2734,12 @@ class mod_assign_external extends \mod_assign\external\external_api {
|
||||
$userdetails['submissionstatus'] = $record->submissionstatus;
|
||||
if (!empty($record->groupid)) {
|
||||
$userdetails['groupid'] = $record->groupid;
|
||||
}
|
||||
if (!empty($record->groupname)) {
|
||||
$userdetails['groupname'] = $record->groupname;
|
||||
|
||||
if (!empty($coursegroups[$record->groupid])) {
|
||||
// Format properly the group name.
|
||||
$group = $coursegroups[$record->groupid];
|
||||
$userdetails['groupname'] = \core_external\util::format_string($group->name, $context);
|
||||
}
|
||||
}
|
||||
// Unique id is required for blind marking.
|
||||
$userdetails['recordid'] = -1;
|
||||
@ -2848,6 +2854,7 @@ class mod_assign_external extends \mod_assign\external\external_api {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->dirroot . "/mod/assign/locallib.php");
|
||||
require_once($CFG->dirroot . "/user/lib.php");
|
||||
require_once($CFG->libdir . '/grouplib.php');
|
||||
|
||||
$params = self::validate_parameters(self::get_participant_parameters(), array(
|
||||
'assignid' => $assignid,
|
||||
@ -2890,9 +2897,11 @@ class mod_assign_external extends \mod_assign\external\external_api {
|
||||
|
||||
if (!empty($participant->groupid)) {
|
||||
$return['groupid'] = $participant->groupid;
|
||||
}
|
||||
if (!empty($participant->groupname)) {
|
||||
$return['groupname'] = $participant->groupname;
|
||||
|
||||
if ($group = groups_get_group($participant->groupid)) {
|
||||
// Format properly the group name.
|
||||
$return['groupname'] = \core_external\util::format_string($group->name, $context);
|
||||
}
|
||||
}
|
||||
|
||||
// Skip the expensive lookup of user detail if we're blind marking or the caller
|
||||
|
@ -2869,6 +2869,54 @@ class externallib_test extends \mod_assign\externallib_advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for WS returning group.
|
||||
* @covers ::get_participant
|
||||
* @covers ::list_participants
|
||||
*/
|
||||
public function test_participants_info_with_groups() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest(true);
|
||||
$CFG->showuseridentity = 'idnumber,email,phone1,phone2,department,institution';
|
||||
|
||||
// Set up filtering.
|
||||
filter_set_global_state('multilang', TEXTFILTER_ON);
|
||||
filter_set_applies_to_strings('multilang', true);
|
||||
external_settings::get_instance()->set_filter(true);
|
||||
|
||||
$result = $this->create_assign_with_student_and_teacher([
|
||||
'assignsubmission_onlinetext_enabled' => 1,
|
||||
'teamsubmission' => 1
|
||||
]);
|
||||
$assignmodule = $result['assign'];
|
||||
$student = $result['student'];
|
||||
$teacher = $result['teacher'];
|
||||
$course = $result['course'];
|
||||
$context = \context_course::instance($course->id);
|
||||
|
||||
$gname = '<span class="multilang" lang="en">G (en)</span><span class="multilang" lang="es">G (es)</span>';
|
||||
$group = $this->getDataGenerator()->create_group(['courseid' => $course->id, 'name' => $gname]);
|
||||
groups_add_member($group, $student);
|
||||
|
||||
$cm = get_coursemodule_from_instance('assign', $assignmodule->id);
|
||||
new mod_assign_testable_assign($context, $cm, $course);
|
||||
|
||||
// Prepare submission.
|
||||
$this->setUser($teacher);
|
||||
|
||||
// Test mod_assign_external::list_participants.
|
||||
$participants = mod_assign_external::list_participants($assignmodule->id, $group->id, '', 0, 0, false, true, true);
|
||||
$participants = external_api::clean_returnvalue(mod_assign_external::list_participants_returns(), $participants);
|
||||
$this->assertEquals($group->id, $participants[0]['groupid']);
|
||||
$this->assertEquals(format_string($gname, true), $participants[0]['groupname']);
|
||||
|
||||
// Test mod_assign_external::get_participant.
|
||||
$participant = mod_assign_external::get_participant($assignmodule->id, $student->id, true);
|
||||
$participant = external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $participant);
|
||||
$this->assertEquals($group->id, $participant['groupid']);
|
||||
$this->assertEquals(format_string($gname, true), $participant['groupname']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test test_view_assign
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user