Merge branch 'MDL-68437-400' of https://github.com/mihailges/moodle into MOODLE_400_STABLE
This commit is contained in:
Vendored
+1
-1
@@ -5,6 +5,6 @@ define("core_course/repository",["exports","core/ajax"],(function(_exports,_ajax
|
||||
* @module core_course/repository
|
||||
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};var _default={getEnrolledCoursesByTimelineClassification:(classification,limit,offset,sort)=>{const args={classification:classification};void 0!==limit&&(args.limit=limit),void 0!==offset&&(args.offset=offset),void 0!==sort&&(args.sort=sort);const request={methodname:"core_course_get_enrolled_courses_by_timeline_classification",args:args};return _ajax.default.call([request])[0]},getLastAccessedCourses:(userid,limit,offset,sort)=>{const args={};void 0!==userid&&(args.userid=userid),void 0!==limit&&(args.limit=limit),void 0!==offset&&(args.offset=offset),void 0!==sort&&(args.sort=sort);const request={methodname:"core_course_get_recent_courses",args:args};return _ajax.default.call([request])[0]},getUsersFromCourseModuleID:(cmid,groupID)=>{var request={methodname:"core_course_get_enrolled_users_by_cmid",args:{cmid:cmid,groupid:groupID}};return _ajax.default.call([request])[0]},toggleManualCompletion:(cmid,completed)=>{const request={methodname:"core_completion_update_activity_completion_status_manually",args:{cmid:cmid,completed:completed}};return _ajax.default.call([request])[0]},getEnrolledCoursesWithEventsByTimelineClassification:function(classification){let limit=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,offset=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,sort=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,searchValue=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,eventsFrom=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,eventsTo=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null;const args={classification:classification,limit:limit,offset:offset,sort:sort,eventsfrom:eventsFrom,eventsto:eventsTo,searchvalue:searchValue},request={methodname:"core_course_get_enrolled_courses_with_action_events_by_timeline_classification",args:args};return _ajax.default.call([request])[0]}};return _exports.default=_default,_exports.default}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};var _default={getEnrolledCoursesByTimelineClassification:(classification,limit,offset,sort)=>{const args={classification:classification};void 0!==limit&&(args.limit=limit),void 0!==offset&&(args.offset=offset),void 0!==sort&&(args.sort=sort);const request={methodname:"core_course_get_enrolled_courses_by_timeline_classification",args:args};return _ajax.default.call([request])[0]},getLastAccessedCourses:(userid,limit,offset,sort)=>{const args={};void 0!==userid&&(args.userid=userid),void 0!==limit&&(args.limit=limit),void 0!==offset&&(args.offset=offset),void 0!==sort&&(args.sort=sort);const request={methodname:"core_course_get_recent_courses",args:args};return _ajax.default.call([request])[0]},getUsersFromCourseModuleID:function(cmid,groupID){let onlyActive=arguments.length>2&&void 0!==arguments[2]&&arguments[2];var request={methodname:"core_course_get_enrolled_users_by_cmid",args:{cmid:cmid,groupid:groupID,onlyactive:onlyActive}};return _ajax.default.call([request])[0]},toggleManualCompletion:(cmid,completed)=>{const request={methodname:"core_completion_update_activity_completion_status_manually",args:{cmid:cmid,completed:completed}};return _ajax.default.call([request])[0]},getEnrolledCoursesWithEventsByTimelineClassification:function(classification){let limit=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,offset=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,sort=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,searchValue=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,eventsFrom=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,eventsTo=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null;const args={classification:classification,limit:limit,offset:offset,sort:sort,eventsfrom:eventsFrom,eventsto:eventsTo,searchvalue:searchValue},request={methodname:"core_course_get_enrolled_courses_with_action_events_by_timeline_classification",args:args};return _ajax.default.call([request])[0]}};return _exports.default=_default,_exports.default}));
|
||||
|
||||
//# sourceMappingURL=repository.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -134,14 +134,16 @@ const getLastAccessedCourses = (userid, limit, offset, sort) => {
|
||||
*
|
||||
* @param {Number} cmid Course Module from which the users will be obtained
|
||||
* @param {Number} groupID Group ID from which the users will be obtained
|
||||
* @param {Boolean} onlyActive Whether to fetch only the active enrolled users or all enrolled users in the course.
|
||||
* @returns {Promise} Promise containing a list of users
|
||||
*/
|
||||
const getEnrolledUsersFromCourseModuleID = (cmid, groupID) => {
|
||||
const getEnrolledUsersFromCourseModuleID = (cmid, groupID, onlyActive = false) => {
|
||||
var request = {
|
||||
methodname: 'core_course_get_enrolled_users_by_cmid',
|
||||
args: {
|
||||
cmid: cmid,
|
||||
groupid: groupID,
|
||||
onlyactive: onlyActive,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -4151,6 +4151,8 @@ class core_course_external extends external_api {
|
||||
return new external_function_parameters([
|
||||
'cmid' => new external_value(PARAM_INT, 'id of the course module', VALUE_REQUIRED),
|
||||
'groupid' => new external_value(PARAM_INT, 'id of the group', VALUE_DEFAULT, 0),
|
||||
'onlyactive' => new external_value(PARAM_BOOL, 'whether to return only active users or all.',
|
||||
VALUE_DEFAULT, false),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -4159,26 +4161,25 @@ class core_course_external extends external_api {
|
||||
*
|
||||
* @param int $cmid Course Module id from which the users will be obtained
|
||||
* @param int $groupid Group id from which the users will be obtained
|
||||
* @param bool $onlyactive Whether to return only the active enrolled users or all enrolled users in the course.
|
||||
* @return array List of users
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function get_enrolled_users_by_cmid(int $cmid, int $groupid = 0) {
|
||||
public static function get_enrolled_users_by_cmid(int $cmid, int $groupid = 0, bool $onlyactive = false) {
|
||||
global $PAGE;
|
||||
$warnings = [];
|
||||
|
||||
[
|
||||
'cmid' => $cmid,
|
||||
'groupid' => $groupid,
|
||||
] = self::validate_parameters(self::get_enrolled_users_by_cmid_parameters(), [
|
||||
self::validate_parameters(self::get_enrolled_users_by_cmid_parameters(), [
|
||||
'cmid' => $cmid,
|
||||
'groupid' => $groupid,
|
||||
'onlyactive' => $onlyactive,
|
||||
]);
|
||||
|
||||
list($course, $cm) = get_course_and_cm_from_cmid($cmid);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
self::validate_context($coursecontext);
|
||||
|
||||
$enrolledusers = get_enrolled_users($coursecontext, '', $groupid);
|
||||
$enrolledusers = get_enrolled_users($coursecontext, '', $groupid, 'u.*', null, 0, 0, $onlyactive);
|
||||
|
||||
$users = array_map(function ($user) use ($PAGE) {
|
||||
$user->fullname = fullname($user);
|
||||
|
||||
@@ -3630,6 +3630,7 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
|
||||
$user1 = self::getDataGenerator()->create_user();
|
||||
$user2 = self::getDataGenerator()->create_user();
|
||||
$user3 = self::getDataGenerator()->create_user();
|
||||
|
||||
$user1picture = new user_picture($user1);
|
||||
$user1picture->size = 1;
|
||||
@@ -3639,6 +3640,10 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
$user2picture->size = 1;
|
||||
$user2->profileimage = $user2picture->get_url($PAGE)->out(false);
|
||||
|
||||
$user3picture = new user_picture($user3);
|
||||
$user3picture->size = 1;
|
||||
$user3->profileimage = $user3picture->get_url($PAGE)->out(false);
|
||||
|
||||
// Set the first created user to the test user.
|
||||
self::setUser($user1);
|
||||
|
||||
@@ -3653,6 +3658,8 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
// Following lines enrol and assign default role id to the users.
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course1->id);
|
||||
// Enrol a suspended user in the course.
|
||||
$this->getDataGenerator()->enrol_user($user3->id, $course1->id, null, 'manual', 0, 0, ENROL_USER_SUSPENDED);
|
||||
|
||||
// Create what we expect to be returned when querying the course module.
|
||||
$expectedusers = array(
|
||||
@@ -3674,11 +3681,42 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
'lastname' => $user2->lastname,
|
||||
'profileimage' => $user2->profileimage,
|
||||
];
|
||||
$expectedusers['users'][2] = [
|
||||
'id' => $user3->id,
|
||||
'fullname' => fullname($user3),
|
||||
'firstname' => $user3->firstname,
|
||||
'lastname' => $user3->lastname,
|
||||
'profileimage' => $user3->profileimage,
|
||||
];
|
||||
|
||||
// Test getting the users in a given context.
|
||||
$users = core_course_external::get_enrolled_users_by_cmid($forum1->cmid);
|
||||
$users = external_api::clean_returnvalue(core_course_external::get_enrolled_users_by_cmid_returns(), $users);
|
||||
|
||||
$this->assertEquals(3, count($users['users']));
|
||||
$this->assertEquals($expectedusers, $users);
|
||||
|
||||
// Test getting only the active users in a given context.
|
||||
$users = core_course_external::get_enrolled_users_by_cmid($forum1->cmid, 0, true);
|
||||
$users = external_api::clean_returnvalue(core_course_external::get_enrolled_users_by_cmid_returns(), $users);
|
||||
|
||||
$expectedusers['users'] = [
|
||||
[
|
||||
'id' => $user1->id,
|
||||
'fullname' => fullname($user1),
|
||||
'firstname' => $user1->firstname,
|
||||
'lastname' => $user1->lastname,
|
||||
'profileimage' => $user1->profileimage,
|
||||
],
|
||||
[
|
||||
'id' => $user2->id,
|
||||
'fullname' => fullname($user2),
|
||||
'firstname' => $user2->firstname,
|
||||
'lastname' => $user2->lastname,
|
||||
'profileimage' => $user2->profileimage,
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals(2, count($users['users']));
|
||||
$this->assertEquals($expectedusers, $users);
|
||||
}
|
||||
|
||||
+1
-1
@@ -679,7 +679,7 @@ $functions = array(
|
||||
'classname' => 'core_course_external',
|
||||
'methodname' => 'get_enrolled_users_by_cmid',
|
||||
'classpath' => 'course/externallib.php',
|
||||
'description' => 'List users by course module id & filter by group id.',
|
||||
'description' => 'List users by course module id, filter by group and active enrolment status.',
|
||||
'type' => 'read',
|
||||
'ajax' => true,
|
||||
),
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@ define("mod_forum/grades/grader",["exports","./grader/selectors","mod_forum/repo
|
||||
* @module mod_forum/grades/grader
|
||||
* @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.registerLaunchListeners=void 0,Selectors=_interopRequireWildcard(Selectors),_repository=_interopRequireDefault(_repository),_templates=_interopRequireDefault(_templates),Grader=_interopRequireWildcard(Grader),_notification=_interopRequireDefault(_notification),_repository2=_interopRequireDefault(_repository2);const templateNames_contentRegion="mod_forum/grades/grader/discussion/posts",getContentForUserIdFunction=(cmid,experimentalDisplayMode)=>userid=>_repository.default.getDiscussionByUserID(userid,cmid).then((context=>(context.discussions=context.discussions.map(discussionPostMapper),context.experimentaldisplaymode=!!experimentalDisplayMode,_templates.default.render(templateNames_contentRegion,context)))).catch(_notification.default.exception),getUsersForCmidFunction=(cmid,groupID)=>async()=>(await _repository2.default.getUsersFromCourseModuleID(cmid,groupID)).users,findGradableNode=node=>node.closest(Selectors.gradableItem),discussionPostMapper=discussion=>{const parentMap=new Map;discussion.posts.parentposts.forEach((post=>parentMap.set(post.id,post)));const userPosts=discussion.posts.userposts.map((post=>{post.readonly=!0,post.hasreplies=!1,post.replies=[];const parent=post.parentid?parentMap.get(post.parentid):null;return parent&&(parent.hasreplies=!1,parent.replies=[],parent.readonly=!0,post.parentauthorname=parent.author.fullname),{parent:parent,post:post}}));return{...discussion,posts:userPosts}};_exports.registerLaunchListeners=()=>{document.addEventListener("click",(async e=>{if(e.target.matches(Selectors.launch)){const rootNode=findGradableNode(e.target);if(!rootNode)throw Error("Unable to find a gradable item");if(!rootNode.matches(Selectors.gradableItems.wholeForum))throw Error("Unable to find a valid gradable item");e.preventDefault();try{await async function(rootNode){let{focusOnClose:focusOnClose=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const data=rootNode.dataset,gradingPanelFunctions=await Grader.getGradingPanelFunctions("mod_forum",data.contextid,data.gradingComponent,data.gradingComponentSubtype,data.gradableItemtype),groupID=data.group?data.group:0;await Grader.launch(getUsersForCmidFunction(data.cmid,groupID),getContentForUserIdFunction(data.cmid,"1"==data.experimentalDisplayMode),gradingPanelFunctions.getter,gradingPanelFunctions.setter,{groupid:data.groupid,initialUserId:data.initialuserid,moduleName:data.name,courseName:data.courseName,courseUrl:(0,_url.relativeUrl)("/course/view.php",{id:data.courseId}),sendStudentNotifications:data.sendStudentNotifications,focusOnClose:focusOnClose})}(rootNode,{focusOnClose:e.target})}catch(error){_notification.default.exception(error)}}if(e.target.matches(Selectors.viewGrade)){e.preventDefault();const rootNode=findGradableNode(e.target);if(!rootNode)throw Error("Unable to find a gradable item");if(!rootNode.matches(Selectors.gradableItems.wholeForum))throw Error("Unable to find a valid gradable item");e.preventDefault();try{await async function(rootNode){let{focusOnClose:focusOnClose=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const data=rootNode.dataset,gradingPanelFunctions=await Grader.getGradingPanelFunctions("mod_forum",data.contextid,data.gradingComponent,data.gradingComponentSubtype,data.gradableItemtype);await Grader.view(gradingPanelFunctions.getter,data.userid,data.name,{focusOnClose:focusOnClose})}(rootNode,{focusOnClose:e.target})}catch(error){_notification.default.exception(error)}}}))}}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.registerLaunchListeners=void 0,Selectors=_interopRequireWildcard(Selectors),_repository=_interopRequireDefault(_repository),_templates=_interopRequireDefault(_templates),Grader=_interopRequireWildcard(Grader),_notification=_interopRequireDefault(_notification),_repository2=_interopRequireDefault(_repository2);const templateNames_contentRegion="mod_forum/grades/grader/discussion/posts",getContentForUserIdFunction=(cmid,experimentalDisplayMode)=>userid=>_repository.default.getDiscussionByUserID(userid,cmid).then((context=>(context.discussions=context.discussions.map(discussionPostMapper),context.experimentaldisplaymode=!!experimentalDisplayMode,_templates.default.render(templateNames_contentRegion,context)))).catch(_notification.default.exception),getUsersForCmidFunction=(cmid,groupID,onlyActive)=>async()=>(await _repository2.default.getUsersFromCourseModuleID(cmid,groupID,onlyActive)).users,findGradableNode=node=>node.closest(Selectors.gradableItem),discussionPostMapper=discussion=>{const parentMap=new Map;discussion.posts.parentposts.forEach((post=>parentMap.set(post.id,post)));const userPosts=discussion.posts.userposts.map((post=>{post.readonly=!0,post.hasreplies=!1,post.replies=[];const parent=post.parentid?parentMap.get(post.parentid):null;return parent&&(parent.hasreplies=!1,parent.replies=[],parent.readonly=!0,post.parentauthorname=parent.author.fullname),{parent:parent,post:post}}));return{...discussion,posts:userPosts}};_exports.registerLaunchListeners=()=>{document.addEventListener("click",(async e=>{if(e.target.matches(Selectors.launch)){const rootNode=findGradableNode(e.target);if(!rootNode)throw Error("Unable to find a gradable item");if(!rootNode.matches(Selectors.gradableItems.wholeForum))throw Error("Unable to find a valid gradable item");e.preventDefault();try{await async function(rootNode){let{focusOnClose:focusOnClose=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const data=rootNode.dataset,gradingPanelFunctions=await Grader.getGradingPanelFunctions("mod_forum",data.contextid,data.gradingComponent,data.gradingComponentSubtype,data.gradableItemtype),groupID=data.group?data.group:0,onlyActive=data.gradeOnlyActiveUsers;await Grader.launch(getUsersForCmidFunction(data.cmid,groupID,onlyActive),getContentForUserIdFunction(data.cmid,"1"==data.experimentalDisplayMode),gradingPanelFunctions.getter,gradingPanelFunctions.setter,{groupid:data.groupid,initialUserId:data.initialuserid,moduleName:data.name,courseName:data.courseName,courseUrl:(0,_url.relativeUrl)("/course/view.php",{id:data.courseId}),sendStudentNotifications:data.sendStudentNotifications,focusOnClose:focusOnClose})}(rootNode,{focusOnClose:e.target})}catch(error){_notification.default.exception(error)}}if(e.target.matches(Selectors.viewGrade)){e.preventDefault();const rootNode=findGradableNode(e.target);if(!rootNode)throw Error("Unable to find a gradable item");if(!rootNode.matches(Selectors.gradableItems.wholeForum))throw Error("Unable to find a valid gradable item");e.preventDefault();try{await async function(rootNode){let{focusOnClose:focusOnClose=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const data=rootNode.dataset,gradingPanelFunctions=await Grader.getGradingPanelFunctions("mod_forum",data.contextid,data.gradingComponent,data.gradingComponentSubtype,data.gradableItemtype);await Grader.view(gradingPanelFunctions.getter,data.userid,data.name,{focusOnClose:focusOnClose})}(rootNode,{focusOnClose:e.target})}catch(error){_notification.default.exception(error)}}}))}}));
|
||||
|
||||
//# sourceMappingURL=grader.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -62,10 +62,11 @@ const getContentForUserIdFunction = (cmid, experimentalDisplayMode) => (userid)
|
||||
*
|
||||
* @param {Number} cmid
|
||||
* @param {Number} groupID
|
||||
* @param {Boolean} onlyActive Whether to fetch only the active enrolled users or all enrolled users in the course.
|
||||
* @return {Array} Array of users for a given context.
|
||||
*/
|
||||
const getUsersForCmidFunction = (cmid, groupID) => async() => {
|
||||
const context = await CourseRepository.getUsersFromCourseModuleID(cmid, groupID);
|
||||
const getUsersForCmidFunction = (cmid, groupID, onlyActive) => async() => {
|
||||
const context = await CourseRepository.getUsersFromCourseModuleID(cmid, groupID, onlyActive);
|
||||
|
||||
return context.users;
|
||||
};
|
||||
@@ -128,9 +129,10 @@ const launchWholeForumGrading = async(rootNode, {
|
||||
);
|
||||
|
||||
const groupID = data.group ? data.group : 0;
|
||||
const onlyActive = data.gradeOnlyActiveUsers;
|
||||
|
||||
await Grader.launch(
|
||||
getUsersForCmidFunction(data.cmid, groupID),
|
||||
getUsersForCmidFunction(data.cmid, groupID, onlyActive),
|
||||
getContentForUserIdFunction(data.cmid, data.experimentalDisplayMode == "1"),
|
||||
gradingPanelFunctions.getter,
|
||||
gradingPanelFunctions.setter,
|
||||
|
||||
@@ -236,6 +236,23 @@ class forum_gradeitem extends component_gradeitem {
|
||||
return (int) $this->forum->get_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines whether only active users in the course should be gradeable.
|
||||
*
|
||||
* @return bool Whether only active users in the course should be gradeable.
|
||||
*/
|
||||
public function should_grade_only_active_users(): bool {
|
||||
global $CFG;
|
||||
|
||||
$showonlyactiveenrolconfig = !empty($CFG->grade_report_showonlyactiveenrol);
|
||||
// Grade only active users enrolled in the course either when the 'grade_report_showonlyactiveenrol' user
|
||||
// preference is set to true or the current user does not have the capability to view suspended users in the
|
||||
// course. In cases where the 'grade_report_showonlyactiveenrol' user preference is not set we are falling back
|
||||
// to the set value for the 'grade_report_showonlyactiveenrol' config.
|
||||
return get_user_preferences('grade_report_showonlyactiveenrol', $showonlyactiveenrolconfig) ||
|
||||
!has_capability('moodle/course:viewsuspendedusers', \context_course::instance($this->forum->get_course_id()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update the grade.
|
||||
*
|
||||
|
||||
@@ -197,6 +197,7 @@ class discussion_list {
|
||||
'gradingcomponent' => $this->forumgradeitem->get_grading_component_name(),
|
||||
'gradingcomponentsubtype' => $this->forumgradeitem->get_grading_component_subtype(),
|
||||
'sendstudentnotifications' => $forum->should_notify_students_default_when_grade_for_forum(),
|
||||
'gradeonlyactiveusers' => $this->forumgradeitem->should_grade_only_active_users(),
|
||||
'hasanyactions' => $hasanyactions,
|
||||
'groupchangemenu' => groups_print_activity_menu(
|
||||
$cm,
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
data-grading-component="{{gradingcomponent}}"
|
||||
data-grading-component-subtype="{{gradingcomponentsubtype}}"
|
||||
data-gradable-itemtype="forum"
|
||||
data-grade-only-active-users="{{gradeonlyactiveusers}}"
|
||||
{{#sendstudentnotifications}}data-send-student-notifications="1" {{/sendstudentnotifications}}
|
||||
>
|
||||
{{#str}}gradeusers, forum{{/str}}
|
||||
|
||||
@@ -171,6 +171,91 @@ class forum_gradeitem_test extends \advanced_testcase {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the logic in the should_grade_only_active_users() method.
|
||||
*
|
||||
* @covers ::should_grade_only_active_users
|
||||
* @dataProvider should_grade_only_active_users_provider
|
||||
* @param bool $showonlyactiveenrolconfig Whether the 'grade_report_showonlyactiveenrol' is enabled or not.
|
||||
* @param bool $showonlyactiveenrolpreference Whether the 'grade_report_showonlyactiveenrol' preference is enabled or not.
|
||||
* @param bool $viewsuspendeduserscapability Whether the 'moodle/course:viewsuspendedusers' capability is allowed or not.
|
||||
* @param bool $expected The expected result.
|
||||
*/
|
||||
public function test_should_grade_only_active_users(bool $showonlyactiveenrolconfig, bool $showonlyactiveenrolpreference,
|
||||
bool $viewsuspendeduserscapability, bool $expected): void {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$forum = $this->get_forum_instance([
|
||||
'grade_forum' => 100,
|
||||
]);
|
||||
$course = $forum->get_course_record();
|
||||
$gradeitem = component_gradeitem::instance('mod_forum', $forum->get_context(), 'forum');
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id, 'editingteacher');
|
||||
$editingteacherroleid = $DB->get_field('role', 'id', ['shortname' => 'editingteacher']);
|
||||
|
||||
// Set the 'grade_report_showonlyactiveenrol' config setting.
|
||||
set_config('grade_report_showonlyactiveenrol', $showonlyactiveenrolconfig);
|
||||
|
||||
$this->setUser($user);
|
||||
// Set the 'grade_report_showonlyactiveenrol' user preference.
|
||||
set_user_preference('grade_report_showonlyactiveenrol', $showonlyactiveenrolpreference);
|
||||
|
||||
// Set the 'moodle/course:viewsuspendedusers' user capability.
|
||||
assign_capability('moodle/course:viewsuspendedusers', $viewsuspendeduserscapability ?
|
||||
CAP_ALLOW : CAP_PROHIBIT, $editingteacherroleid, \context_course::instance($course->id));
|
||||
|
||||
$this->assertEquals($expected, $gradeitem->should_grade_only_active_users());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_should_grade_only_active_users.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function should_grade_only_active_users_provider(): array {
|
||||
return [
|
||||
'Enabled showonlyactiveenrol setting; enabled showonlyactiveenrol preference; view suspended users capability' =>
|
||||
[
|
||||
'showonlyactiveenrolconfig' => true,
|
||||
'showonlyactiveenrolpreference' => true,
|
||||
'viewsuspendeduserscapability' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Disabled showonlyactiveenrol setting; enabled showonlyactiveenrol preference; view suspended users capability' =>
|
||||
[
|
||||
'showonlyactiveenrolconfig' => false,
|
||||
'showonlyactiveenrolpreference' => true,
|
||||
'viewsuspendeduserscapability' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Disabled showonlyactiveenrol setting; disabled showonlyactiveenrol preference; view suspended users capability' =>
|
||||
[
|
||||
'showonlyactiveenrolconfig' => false,
|
||||
'showonlyactiveenrolpreference' => false,
|
||||
'viewsuspendeduserscapability' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Disabled showonlyactiveenrol setting; disabled showonlyactiveenrol preference; no view suspended users capability' =>
|
||||
[
|
||||
'showonlyactiveenrolconfig' => false,
|
||||
'showonlyactiveenrolpreference' => false,
|
||||
'viewsuspendeduserscapability' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Enabled showonlyactiveenrol setting; enabled showonlyactiveenrol preference; no view suspended users capability' =>
|
||||
[
|
||||
'showonlyactiveenrolconfig' => true,
|
||||
'showonlyactiveenrolpreference' => true,
|
||||
'viewsuspendeduserscapability' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a forum instance.
|
||||
*
|
||||
|
||||
@@ -197,6 +197,7 @@ switch ($forum->get_type()) {
|
||||
'gradingcomponent' => $forumgradeitem->get_grading_component_name(),
|
||||
'gradingcomponentsubtype' => $forumgradeitem->get_grading_component_subtype(),
|
||||
'sendstudentnotifications' => $forum->should_notify_students_default_when_grade_for_forum(),
|
||||
'gradeonlyactiveusers' => $forumgradeitem->should_grade_only_active_users(),
|
||||
];
|
||||
echo $OUTPUT->render_from_template('mod_forum/grades/grade_button', $gradeobj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user