MDL-52916 cbe: Fix group handling for user_competency_in_course page, and competency breakdown report

This commit is contained in:
Damyon Wiese 2016-02-09 14:59:23 +08:00 committed by Frederic Massart
parent 21e0dd61e5
commit a800711909
12 changed files with 98 additions and 111 deletions

View File

@ -82,11 +82,15 @@ class user_competency_course_navigation implements renderable, templatable {
$data->competencyid = $this->competencyid;
$data->courseid = $this->courseid;
$data->baseurl = $this->baseurl;
$data->groupselector = '';
if (has_capability('tool/lp:coursecompetencymanage', $context)) {
$course = $DB->get_record('course', array('id' => $this->courseid));
$currentgroup = optional_param('group', null, PARAM_INT);
$select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup);
$currentgroup = groups_get_course_group($course, true);
if ($currentgroup !== false) {
$select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup);
$data->groupselector = $select;
}
// Fetch showactive.
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
@ -94,7 +98,6 @@ class user_competency_course_navigation implements renderable, templatable {
// Fetch current active group.
$groupmode = groups_get_course_groupmode($course);
$currentgroup = $SESSION->activegroup[$course->id][$groupmode][$course->defaultgroupingid];
$users = get_enrolled_users($context, 'tool/lp:coursecompetencygradable', $currentgroup,
'u.*', null, 0, 0, $showonlyactiveenrol);

View File

@ -202,6 +202,7 @@ $string['nocompetencyselected'] = 'No competency selected';
$string['nofiles'] = 'No files';
$string['noevidence'] = 'No evidence';
$string['nolinkedcourses'] = 'No courses are linked to this competency';
$string['noparticipants'] = 'No participants found.';
$string['noplanswerecreated'] = 'No plans were created.';
$string['norelatedcompetencies'] = 'No other competencies have been related to this competency.';
$string['notemplates'] = 'No learning plan templates have been created yet.';

View File

@ -202,8 +202,4 @@ input[type="checkbox"].tool_lp_scale_proficient {
}
.user-competency-course-navigation {
width: 240px;
height: 80px;
}
.user-competency-course-navigation .form-autocomplete-selection {
display: none;
}

View File

@ -1,4 +1,6 @@
<form class="pull-right well user-competency-course-navigation">
<div class="pull-right well">
<p>{{{groupselector}}}</p>
<form class="user-competency-course-navigation">
{{#hasusers}}
<span>
<label for="user-nav-{{uniqid}}" class="accesshide">{{#str}}jumptouser, tool_lp{{/str}}</label>
@ -21,6 +23,7 @@
</span>
{{/hascompetencies}}
</form>
</div>
{{#js}}
require(['core/form-autocomplete', 'tool_lp/user_competency_course_navigation'], function(autocomplete, nav) {
{{#hasusers}}

View File

@ -33,43 +33,65 @@ if (isguestuser()) {
throw new require_login_exception('Guests are not allowed here.');
}
$course = $DB->get_record('course', array('id' => $courseid));
$context = context_course::instance($courseid);
$currentgroup = groups_get_course_group($course, true);
if (empty($userid)) {
$context = context_course::instance($courseid);
$gradable = get_enrolled_users($context, 'tool/lp:coursecompetencygradable', 0, 'u.id', null, 0, 1);
$gradable = get_enrolled_users($context, 'tool/lp:coursecompetencygradable', $currentgroup, 'u.id', null, 0, 1);
if (empty($gradable)) {
print_error('noparticipants');
$userid = 0;
} else {
$userid = array_pop($gradable)->id;
}
} else {
$gradable = get_enrolled_users($context, 'tool/lp:coursecompetencygradable', $currentgroup, 'u.id');
if (count($gradable) == 0) {
$userid = 0;
} else if (!in_array($userid, array_keys($gradable))) {
$userid = array_shift($gradable)->id;
}
$userid = array_pop($gradable)->id;
}
$params = array('userid' => $userid, 'competencyid' => $competencyid, 'courseid' => $courseid);
$course = $DB->get_record('course', array('id' => $courseid));
$url = new moodle_url('/admin/tool/lp/user_competency_in_course.php', $params);
$usercontext = context_user::instance($userid);
$user = $DB->get_record('user', array('id' => $userid));
if ($userid > 0) {
$usercontext = context_user::instance($userid);
$user = $DB->get_record('user', array('id' => $userid));
}
$competency = new \tool_lp\competency($competencyid);
// Does a permissions check for us.
$usercompetencies = \tool_lp\api::list_user_competencies_in_course($courseid, $userid);
if ($userid > 0) {
$usercompetencies = \tool_lp\api::list_user_competencies_in_course($courseid, $userid);
}
$subtitle = $competency->get_shortname() . ' <em>' . $competency->get_idnumber() . '</em>';
list($title, $subtitle) = \tool_lp\page_helper::setup_for_course($url, $course, $subtitle);
$output = $PAGE->get_renderer('tool_lp');
$userheading = array(
'heading' => fullname($user),
'user' => $user,
'usercontext' => $usercontext
);
if ($userid > 0) {
$userheading = array(
'heading' => fullname($user),
'user' => $user,
'usercontext' => $usercontext
);
}
echo $output->header();
echo $OUTPUT->context_header($userheading, 3);
if ($userid > 0) {
echo $OUTPUT->context_header($userheading, 3);
}
//echo $output->heading($title, 3);
$baseurl = new moodle_url('/admin/tool/lp/user_competency_in_course.php');
$nav = new \tool_lp\output\user_competency_course_navigation($userid, $competencyid, $courseid, $baseurl);
echo $output->render($nav);
$page = new \tool_lp\output\user_competency_summary_in_course($userid, $competencyid, $courseid);
echo $output->render($page);
if ($userid > 0) {
$page = new \tool_lp\output\user_competency_summary_in_course($userid, $competencyid, $courseid);
echo $output->render($page);
} else {
echo $output->container('', 'clearfix');
echo $output->notify_problem(get_string('noparticipants', 'tool_lp'));
}
echo $output->footer();

View File

@ -82,13 +82,11 @@ define(['jquery', 'core/notification', 'core/str', 'core/ajax', 'core/log', 'cor
GradingPopup.prototype._refresh = function() {
var region = $(this._regionSelector);
var courseId = region.data('courseid');
var groupId = region.data('groupid');
var userId = region.data('userid');
var onlyActive = region.data('onlyactive');
ajax.call([{
methodname : 'report_competency_data_for_report',
args: { courseid: courseId, groupid: groupId, userid: userId, onlyactive: onlyActive },
args: { courseid: courseId, userid: userId },
done: this._pageContextLoaded.bind(this),
fail: notification.exception
}]);

View File

@ -62,21 +62,9 @@ class external extends external_api {
'The user id',
VALUE_REQUIRED
);
$groupid = new external_value(
PARAM_INT,
'The group id',
VALUE_REQUIRED
);
$onlyactive = new external_value(
PARAM_BOOL,
'Only active users',
VALUE_REQUIRED
);
$params = array(
'courseid' => $courseid,
'userid' => $userid,
'groupid' => $groupid,
'onlyactive' => $onlyactive,
'userid' => $userid
);
return new external_function_parameters($params);
}
@ -85,20 +73,16 @@ class external extends external_api {
* Loads the data required to render the report.
*
* @param int $courseid The course id
* @param int $groupid The group id
* @param boolean $onlyactive Only show active enrolments
* @return \stdClass
*/
public static function data_for_report($courseid, $userid, $groupid, $onlyactive) {
public static function data_for_report($courseid, $userid) {
global $PAGE;
$params = self::validate_parameters(
self::data_for_report_parameters(),
array(
'courseid' => $courseid,
'userid' => $userid,
'groupid' => $groupid,
'onlyactive' => $onlyactive
'userid' => $userid
)
);
$context = context_course::instance($params['courseid']);
@ -107,7 +91,7 @@ class external extends external_api {
throw new coding_exception('invaliduser');
}
$renderable = new output\report($params['courseid'], $params['userid'], $params['groupid'], $params['onlyactive']);
$renderable = new output\report($params['courseid'], $params['userid']);
$renderer = $PAGE->get_renderer('report_competency');
$data = $renderable->export_for_template($renderer);
@ -123,8 +107,6 @@ class external extends external_api {
public static function data_for_report_returns() {
return new external_single_structure(array (
'courseid' => new external_value(PARAM_INT, 'Course id'),
'groupid' => new external_value(PARAM_INT, 'Group id'),
'onlyactive' => new external_value(PARAM_BOOL, 'Only include active enrolments'),
'user' => user_summary_exporter::get_read_structure(),
'course' => course_summary_exporter::get_read_structure(),
'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'),

View File

@ -49,28 +49,18 @@ class report implements renderable, templatable {
protected $context;
/** @var int $courseid */
protected $courseid;
/** @var int $groupid */
protected $groupid;
/** @var boolean $onlyactive */
protected $onlyactive;
/** @var array $competencies */
protected $competencies;
/** @var array $users */
protected $users;
/**
* Construct this renderable.
*
* @param int $courseid The course id
* @param int $userid The user id
* @param int $groupid The group id
* @param bool $onlyactive Only show active (not suspended) students.
*/
public function __construct($courseid, $userid, $groupid, $onlyactive) {
public function __construct($courseid, $userid) {
$this->courseid = $courseid;
$this->groupid = $groupid;
$this->userid = $userid;
$this->onlyactive = $onlyactive;
$this->context = context_course::instance($courseid);
}
@ -85,8 +75,6 @@ class report implements renderable, templatable {
$data = new stdClass();
$data->courseid = $this->courseid;
$data->groupid = $this->groupid;
$data->onlyactive = $this->onlyactive;
$course = $DB->get_record('course', array('id' => $this->courseid));
$coursecontext = context_course::instance($course->id);

View File

@ -76,11 +76,15 @@ class user_course_navigation implements renderable, templatable {
$data->userid = $this->userid;
$data->courseid = $this->courseid;
$data->baseurl = $this->baseurl;
$data->groupselector = '';
if (has_capability('tool/lp:coursecompetencymanage', $context)) {
$course = $DB->get_record('course', array('id' => $this->courseid));
$currentgroup = optional_param('group', null, PARAM_INT);
$select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup);
$currentgroup = groups_get_course_group($course, true);
if ($currentgroup !== false) {
$select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup);
$data->groupselector = $select;
}
// Fetch showactive.
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
@ -88,7 +92,6 @@ class user_course_navigation implements renderable, templatable {
// Fetch current active group.
$groupmode = groups_get_course_groupmode($course);
$currentgroup = $SESSION->activegroup[$course->id][$groupmode][$course->defaultgroupingid];
$users = get_enrolled_users($context, 'tool/lp:coursecompetencygradable', $currentgroup,
'u.*', null, 0, 0, $showonlyactiveenrol);

View File

@ -30,35 +30,28 @@ $params = array('id' => $id);
$course = $DB->get_record('course', $params, '*', MUST_EXIST);
require_login($course);
$context = context_course::instance($course->id);
$currentgroup = optional_param('group', null, PARAM_INT);
$currentuser = optional_param('user', null, PARAM_INT);
// Fetch current active group.
$groupmode = groups_get_course_groupmode($course);
$currentgroup = $SESSION->activegroup[$course->id][$groupmode][$course->defaultgroupingid];
// Will exclude suspended users if required.
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
if (!$currentuser) {
$users = get_enrolled_users($context, 'tool/lp:coursecompetencygradable', $currentgroup,
'u.id', null, 0, 1, $showonlyactiveenrol);
if (empty($users)) {
print_error('noparticipants');
$currentgroup = groups_get_course_group($course, true);
if (empty($currentuser)) {
$gradable = get_enrolled_users($context, 'tool/lp:coursecompetencygradable', $currentgroup, 'u.id', null, 0, 1);
if (empty($gradable)) {
$currentuser = 0;
} else {
$currentuser = array_pop($gradable)->id;
}
$first = array_pop($users);
$currentuser = $first->id;
} else {
if (!is_enrolled($context, $currentuser, 'tool/lp:coursecompetencygradable')) {
print_error('invaliduser');
$gradable = get_enrolled_users($context, 'tool/lp:coursecompetencygradable', $currentgroup, 'u.id');
if (count($gradable) == 0) {
$currentuser = 0;
} else if (!in_array($currentuser, array_keys($gradable))) {
$currentuser = array_shift($gradable)->id;
}
}
$urlparams = array('id' => $id, 'group' => $currentgroup, 'user' => $currentuser);
$urlparams = array('id' => $id, 'user' => $currentuser);
$url = new moodle_url('/report/competency/index.php', $urlparams);
$title = get_string('pluginname', 'report_competency');
@ -70,32 +63,27 @@ $PAGE->set_pagelayout('incourse');
$output = $PAGE->get_renderer('report_competency');
$user = core_user::get_user($currentuser);
$usercontext = context_user::instance($currentuser);
$userheading = array(
'heading' => fullname($user),
'user' => $user,
'usercontext' => $usercontext
);
echo $output->header();
echo $output->context_header($userheading, 3);
echo $output->heading($title, 3);
$select = groups_allgroups_course_menu($course, $url, true, $currentgroup);
// User cannot see any group.
if (empty($select)) {
echo $OUTPUT->heading(get_string("notingroup"));
echo $OUTPUT->footer();
exit;
} else {
echo '<p>' . $select . '</p>';
if ($currentuser > 0) {
$user = core_user::get_user($currentuser);
$usercontext = context_user::instance($currentuser);
$userheading = array(
'heading' => fullname($user),
'user' => $user,
'usercontext' => $usercontext
);
echo $output->context_header($userheading, 3);
}
echo $output->heading($title, 3);
$baseurl = new moodle_url('/report/competency/index.php');
$nav = new \report_competency\output\user_course_navigation($currentuser, $course->id, $baseurl);
echo $output->render($nav);
$page = new \report_competency\output\report($course->id, $currentuser, $currentgroup, $showonlyactiveenrol);
echo $output->render($page);
if ($currentuser > 0) {
$page = new \report_competency\output\report($course->id, $currentuser);
echo $output->render($page);
} else {
echo $output->container('', 'clearfix');
echo $output->notify_problem(get_string('noparticipants', 'tool_lp'));
}
echo $output->footer();

View File

@ -1,8 +1,8 @@
<div data-region="competency-breakdown-report" data-courseid="{{course.id}}" data-groupid="{{groupid}}" data-userid="{{user.id}}" data-onlyactive="{{onlyactive}}">
<div data-region="competency-breakdown-report" data-courseid="{{course.id}}" data-userid="{{user.id}}">
<div class="row-fluid">
<span class="span6">
<table class="table table-bordered">
<summary><p>{{#str}}coursecompetencybreakdownsummary, report_competency{{/str}}</p></summary>
<summary class="accesshide"><p>{{#str}}coursecompetencybreakdownsummary, report_competency{{/str}}</p></summary>
<tr>
<th scope="col">{{#str}}competency, report_competency{{/str}}</span></th>
<th scope="col">{{#str}}rating, report_competency{{/str}}</span></th>
@ -10,7 +10,7 @@
{{#usercompetencies}}
<tr>
{{#competency}}
<td><a href="#" data-action="competency-dialogue" data-id="{{competency.id}}">{{competency.shortname}} - {{competency.idnumber}}</a></td>
<td><a href="#" data-action="competency-dialogue" data-id="{{competency.id}}">{{competency.shortname}} <em>{{competency.idnumber}}</em></a></td>
{{/competency}}
{{#usercompetency}}
<td class="alert {{#proficiency}}alert-success{{/proficiency}}"

View File

@ -1,4 +1,6 @@
<form class="pull-right well user-competency-course-navigation">
<div class="pull-right well">
<p>{{{groupselector}}}</p>
<form class="user-competency-course-navigation">
{{#hasusers}}
<span>
<label for="user-nav-{{uniqid}}" class="accesshide">{{#str}}jumptouser, tool_lp{{/str}}</label>
@ -10,6 +12,7 @@
</span>
{{/hasusers}}
</form>
</div>
{{#js}}
require(['core/form-autocomplete', 'report_competency/user_course_navigation'], function(autocomplete, nav) {
{{#hasusers}}