Skip to content

Commit

Permalink
MDL-57791 analytics: Replace settings by get_archetype_roles
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Jul 24, 2017
1 parent f39cebb commit 3a217fc
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 59 deletions.
24 changes: 0 additions & 24 deletions admin/settings/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,5 @@
$defaultmodeloutputdir = rtrim($CFG->dataroot, '/') . DIRECTORY_SEPARATOR . 'models';
$settings->add(new admin_setting_configdirectory('analytics/modeloutputdir', new lang_string('modeloutputdir', 'analytics'),
new lang_string('modeloutputdirinfo', 'analytics'), $defaultmodeloutputdir));
$studentdefaultroles = [];
$teacherdefaultroles = [];

// Student and teacher roles.
$allroles = role_fix_names(get_all_roles());
$rolechoices = [];
foreach ($allroles as $role) {
$rolechoices[$role->id] = $role->localname;

if ($role->shortname == 'student') {
$studentdefaultroles[] = $role->id;
} else if ($role->shortname == 'teacher') {
$teacherdefaultroles[] = $role->id;
} else if ($role->shortname == 'editingteacher') {
$teacherdefaultroles[] = $role->id;
}
}

$settings->add(new admin_setting_configmultiselect('analytics/teacherroles', new lang_string('teacherroles', 'analytics'),
'', $teacherdefaultroles, $rolechoices));

$settings->add(new admin_setting_configmultiselect('analytics/studentroles', new lang_string('studentroles', 'analytics'),
'', $studentdefaultroles, $rolechoices));

}
}
32 changes: 12 additions & 20 deletions analytics/classes/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class course implements \core_analytics\analysable {

protected static $instances = array();

protected $studentroles = [];
protected $teacherroles = [];
protected static $studentroles = [];
protected static $teacherroles = [];

protected $course = null;
protected $coursecontext = null;
Expand All @@ -61,15 +61,11 @@ class course implements \core_analytics\analysable {
* Course manager constructor.
*
* Use self::instance() instead to get cached copies of the course. Instances obtained
* through this constructor will not be cached either.
* through this constructor will not be cached.
*
* Loads course students and teachers.
*
* Let's try to keep this computationally inexpensive.
*
* @param int|stdClass $course Course id
* @param array $studentroles
* @param array $teacherroles
* @return void
*/
public function __construct($course) {
Expand All @@ -82,29 +78,25 @@ public function __construct($course) {

$this->coursecontext = \context_course::instance($this->course->id);

$studentroles = get_config('analytics', 'studentroles');
$teacherroles = get_config('analytics', 'teacherroles');

if (empty($studentroles) || empty($teacherroles)) {
// Unexpected, site settings should be set with default values.
throw new \moodle_exception('errornoroles', 'analytics');
if (empty(self::$studentroles)) {
self::$studentroles = array_keys(get_archetype_roles('student'));
}
if (empty(self::$teacherroles)) {
self::$teacherroles = array_keys(get_archetype_roles('editingteacher') + get_archetype_roles('teacher'));
}

$this->studentroles = explode(',', $studentroles);
$this->teacherroles = explode(',', $teacherroles);

$this->now = time();

// Get the course users, including users assigned to student and teacher roles at an higher context.
$this->studentids = $this->get_user_ids($this->studentroles);
$this->teacherids = $this->get_user_ids($this->teacherroles);
$this->studentids = $this->get_user_ids(self::$studentroles);
$this->teacherids = $this->get_user_ids(self::$teacherroles);
}

/**
* instance
* Returns an analytics course instance.
*
* @param int|stdClass $course Course id
* @return void
* @return \core_analytics\course
*/
public static function instance($course) {

Expand Down
8 changes: 4 additions & 4 deletions analytics/classes/local/analyser/by_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public function get_courses() {

// Default to all system courses.
if (!empty($this->options['filter'])) {
$courseids = $this->options['filter'];
$it = $this->options['filter'];
} else {
// Iterate through all potentially valid courses.
$courseids = $DB->get_fieldset_select('course', 'id', 'id != :frontpage', array('frontpage' => SITEID), 'sortorder ASC');
$it = $DB->get_recordset_select('course', 'id != :frontpage', array('frontpage' => SITEID), 'sortorder ASC');
}

$analysables = array();
foreach ($courseids as $courseid) {
$analysable = new \core_analytics\course($courseid);
foreach ($it as $course) {
$analysable = \core_analytics\course::instance($course);
$analysables[$analysable->get_id()] = $analysable;
}

Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/local/analyser/courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function get_samples_origin() {
* @return \core_analytics\analysable
*/
public function get_sample_analysable($sampleid) {
return new \core_analytics\course($sampleid);
return \core_analytics\course::instance($sampleid);
}

protected function provided_sample_data() {
Expand Down
2 changes: 0 additions & 2 deletions analytics/classes/local/analyser/sitewide.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function get_analysable_data($includetarget) {
$files = $this->process_analysable($analysable, $includetarget);

// Copy to range files as there is just one analysable.
// TODO Not abstracted as we should ideally directly store it as range-scope file.
foreach ($files as $timesplittingid => $file) {

if ($this->options['evaluation'] === true) {
Expand All @@ -56,7 +55,6 @@ public function get_analysable_data($includetarget) {
}

// We use merge but it is just a copy
// TODO use copy or move if there are performance issues.
$files[$timesplittingid] = \core_analytics\dataset_manager::merge_datasets(array($file), $this->modelid,
$timesplittingid, $this->options['evaluation'], $includetarget);
}
Expand Down
4 changes: 2 additions & 2 deletions analytics/classes/local/analyser/student_enrolments.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function sample_access_context($sampleid) {
}

public function get_sample_analysable($sampleid) {
$course = enrol_get_course_by_user_enrolment_id($ueid);
return \core_analytics\course($course);
$course = enrol_get_course_by_user_enrolment_id($sampleid);
return \core_analytics\course::instance($course);
}

protected function provided_sample_data() {
Expand Down
4 changes: 0 additions & 4 deletions analytics/tests/course_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public function setUp() {
$this->getDataGenerator()->enrol_user($this->both->id, $this->course->id, $this->editingteacherroleid);
$this->getDataGenerator()->enrol_user($this->editingteacher->id, $this->course->id, $this->editingteacherroleid);
$this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, $this->teacherroleid);


set_config('studentroles', $this->studentroleid, 'analytics');
set_config('teacherroles', $this->editingteacherroleid . ',' . $this->teacherroleid, 'analytics');
}

/**
Expand Down
2 changes: 0 additions & 2 deletions lang/en/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@
$string['predictionsprocessor_help'] = 'Prediction processors are the machine learning backends that process the datasets generated by calculating models\' indicators and targets.';
$string['processingsitecontents'] = 'Processing site contents';
$string['processingsitecontents'] = 'Processing site contents';
$string['studentroles'] = 'Student roles';
$string['successfullyanalysed'] = 'Successfully analysed';
$string['teacherroles'] = 'Teacher roles';
$string['timesplitting:deciles'] = 'Deciles';
$string['timesplitting:decilesaccum'] = 'Deciles accumulative';
$string['timesplitting:nosplitting'] = 'No time splitting';
Expand Down

0 comments on commit 3a217fc

Please sign in to comment.