MDL-58138 completion: Assorted linting fixes.

Part of MDL-58138 epic
This commit is contained in:
Jake Dallimore 2017-03-21 15:09:56 +08:00
parent 8db355c58f
commit b17ee68202
8 changed files with 68 additions and 39 deletions

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -32,6 +31,7 @@ use cm_info;
use tabobject; use tabobject;
use lang_string; use lang_string;
use moodle_url; use moodle_url;
defined('MOODLE_INTERNAL') || die;
/** /**
* Bulk activity completion manager class * Bulk activity completion manager class
@ -43,8 +43,15 @@ use moodle_url;
*/ */
class manager { class manager {
/**
* @var int $courseid the course id.
*/
protected $courseid; protected $courseid;
/**
* manager constructor.
* @param int $courseid the course id.
*/
public function __construct($courseid) { public function __construct($courseid) {
$this->courseid = $courseid; $this->courseid = $courseid;
} }
@ -185,6 +192,11 @@ class manager {
return $activeruledescriptions; return $activeruledescriptions;
} }
/**
* Gets the course modules for the current course.
*
* @return stdClass $data containing the modules
*/
public function get_activities_and_resources() { public function get_activities_and_resources() {
global $DB, $OUTPUT, $CFG; global $DB, $OUTPUT, $CFG;
require_once($CFG->dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/course/lib.php');
@ -238,7 +250,9 @@ class manager {
} }
/** /**
* @param stdClass|int $courseorid * Gets the available completion tabs for the current course and user.
*
* @param stdClass|int $courseorid the course object or id.
* @return tabobject[] * @return tabobject[]
*/ */
public static function get_available_completion_tabs($courseorid) { public static function get_available_completion_tabs($courseorid) {

View file

@ -173,37 +173,42 @@ class core_completion_bulk_update_testcase extends advanced_testcase {
*/ */
public function bulk_form_submit_multiple_provider() { public function bulk_form_submit_multiple_provider() {
return [ return [
'Several modules with the same module type (choice)' => 'Several modules with the same module type (choice)' => [
[['modulenames' => ['choice', 'choice', 'choice'], [
'submitdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionsubmit' => 1], 'modulenames' => ['choice', 'choice', 'choice'],
'validatedata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionsubmit' => 1], 'submitdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionsubmit' => 1],
'cmdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC], 'validatedata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionsubmit' => 1],
'instancedata' => [ 'cmdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC],
['completionsubmit' => 1], 'instancedata' => [['completionsubmit' => 1], ['completionsubmit' => 1], ['completionsubmit' => 1]]
['completionsubmit' => 1], ]
['completionsubmit' => 1], ],
]]], 'Several modules with different module type' => [
'Several modules with different module type' => [
[['modulenames' => ['choice', 'forum'], 'modulenames' => ['choice', 'forum'],
'submitdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1], 'submitdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1],
'validatedata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1], 'validatedata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1],
'cmdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC], 'cmdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC],
'instancedata' => null]], 'instancedata' => null
'Setting manual completion (completionview shoud be ignored)' => ]
[['modulenames' => ['scorm', 'forum', 'label', 'assign'], ],
'Setting manual completion (completionview shoud be ignored)' => [
[
'modulenames' => ['scorm', 'forum', 'label', 'assign'],
'submitdata' => ['completion' => COMPLETION_TRACKING_MANUAL, 'completionview' => 1], 'submitdata' => ['completion' => COMPLETION_TRACKING_MANUAL, 'completionview' => 1],
'validatedata' => [], 'validatedata' => [],
'cmdata' => ['completion' => COMPLETION_TRACKING_MANUAL, 'completionview' => 0], 'cmdata' => ['completion' => COMPLETION_TRACKING_MANUAL, 'completionview' => 0],
'instancedata' => null]], 'instancedata' => null
'If at least one module does not support completionsubmit it can\'t be set' => ]
[['modulenames' => ['survey', 'wiki'], ],
'If at least one module does not support completionsubmit it can\'t be set' => [
[
'modulenames' => ['survey', 'wiki'],
'submitdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1, 'completionsubmit' => 1], 'submitdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1, 'completionsubmit' => 1],
'validatedata' => [], 'validatedata' => [],
'cmdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1], 'cmdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1],
'instancedata' => [ 'instancedata' => [['completionsubmit' => 0], []]
['completionsubmit' => 0], ]
[] ]
]]],
]; ];
} }

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -28,13 +27,13 @@ require_once(__DIR__.'/../config.php');
require_once($CFG->dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->libdir.'/completionlib.php'); require_once($CFG->libdir.'/completionlib.php');
$id = required_param('id', PARAM_INT); // course id $id = required_param('id', PARAM_INT); // Course id.
$cmids = optional_param_array('cmid', [], PARAM_INT); $cmids = optional_param_array('cmid', [], PARAM_INT);
// Perform some basic access control checks. // Perform some basic access control checks.
if ($id) { if ($id) {
if($id == SITEID){ if ($id == SITEID) {
// Don't allow editing of 'site course' using this form. // Don't allow editing of 'site course' using this form.
print_error('cannoteditsiteform'); print_error('cannoteditsiteform');
} }

View file

@ -35,6 +35,13 @@ require_once($CFG->dirroot.'/course/renderer.php');
*/ */
class core_course_bulk_activity_completion_renderer extends plugin_renderer_base { class core_course_bulk_activity_completion_renderer extends plugin_renderer_base {
/**
* Render the navigation tabs for the completion page.
*
* @param int|stdClass $courseorid the course object or id.
* @param String $page the tab to focus.
* @return string html
*/
public function navigation($courseorid, $page) { public function navigation($courseorid, $page) {
$tabs = core_completion\manager::get_available_completion_tabs($courseorid); $tabs = core_completion\manager::get_available_completion_tabs($courseorid);
if (count($tabs) > 1) { if (count($tabs) > 1) {
@ -44,11 +51,22 @@ class core_course_bulk_activity_completion_renderer extends plugin_renderer_base
} }
} }
/**
* Render the bulk completion tab.
*
* @param Array|stdClass $data the context data to pass to the template.
* @return bool|string
*/
public function bulkcompletion($data) { public function bulkcompletion($data) {
return parent::render_from_template('core_course/bulkactivitycompletion', $data); return parent::render_from_template('core_course/bulkactivitycompletion', $data);
} }
/**
* Render the default completion tab.
*
* @param Array|stdClass $data the context data to pass to the template.
* @return bool|string
*/
public function defaultcompletion($data) { public function defaultcompletion($data) {
return parent::render_from_template('core_course/defaultactivitycompletion', $data); return parent::render_from_template('core_course/defaultactivitycompletion', $data);
} }

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -33,7 +32,7 @@ $id = required_param('id', PARAM_INT); // Course id.
// Perform some basic access control checks. // Perform some basic access control checks.
if ($id) { if ($id) {
if($id == SITEID){ if ($id == SITEID) {
// Don't allow editing of 'site course' using this form. // Don't allow editing of 'site course' using this form.
print_error('cannoteditsiteform'); print_error('cannoteditsiteform');
} }

View file

@ -560,8 +560,7 @@ class dndupload_ajax_processor {
protected function create_course_module() { protected function create_course_module() {
global $CFG; global $CFG;
require_once($CFG->dirroot.'/course/modlib.php'); require_once($CFG->dirroot.'/course/modlib.php');
list($module, $context, $cw, $cm, $data) = list($module, $context, $cw, $cm, $data) = prepare_new_moduleinfo_data($this->course, $this->module->name, $this->section);
prepare_new_moduleinfo_data($this->course, $this->module->name, $this->section);
$data->coursemodule = $data->id = add_course_module($data); $data->coursemodule = $data->id = add_course_module($data);
$this->cm = $data; $this->cm = $data;

View file

@ -60,9 +60,7 @@
</div> </div>
</div> </div>
<div class="topics"> <div class="topics">
{{#sections}} {{#sections}}
<div class="topic-section m-b-1"> <div class="topic-section m-b-1">
<div class="row m-b-1"> <div class="row m-b-1">
<div class="col-sm-12"> <div class="col-sm-12">
@ -72,9 +70,7 @@
</div> </div>
{{> core_course/activityinstance}} {{> core_course/activityinstance}}
</div> </div>
{{/sections}} {{/sections}}
</div> </div>
<input type="hidden" name="id" value="{{courseid}}" /> <input type="hidden" name="id" value="{{courseid}}" />
<input type="hidden" name="sesskey" value="{{sesskey}}" /> <input type="hidden" name="sesskey" value="{{sesskey}}" />
@ -105,7 +101,5 @@ require([
$(this).prop('checked', checked); $(this).prop('checked', checked);
}); });
}); });
}); });
{{/js}} {{/js}}

View file

@ -4210,7 +4210,8 @@ class settings_navigation extends navigation_node {
if ($adminoptions->editcompletion) { if ($adminoptions->editcompletion) {
// Add the course completion settings link // Add the course completion settings link
$url = new moodle_url('/course/completion.php', array('id' => $course->id)); $url = new moodle_url('/course/completion.php', array('id' => $course->id));
$coursenode->add(get_string('coursecompletion', 'completion'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/settings', '')); $coursenode->add(get_string('coursecompletion', 'completion'), $url, self::TYPE_SETTING, null, null,
new pix_icon('i/settings', ''));
} }
if (!$adminoptions->update && $adminoptions->tags) { if (!$adminoptions->update && $adminoptions->tags) {