Skip to content

Commit

Permalink
MDL-58138 completion: Assorted linting fixes.
Browse files Browse the repository at this point in the history
Part of MDL-58138 epic
  • Loading branch information
snake committed Apr 19, 2017
1 parent 8db355c commit b17ee68
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 39 deletions.
18 changes: 16 additions & 2 deletions completion/classes/manager.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -32,6 +31,7 @@
use tabobject;
use lang_string;
use moodle_url;
defined('MOODLE_INTERNAL') || die;

/**
* Bulk activity completion manager class
Expand All @@ -43,8 +43,15 @@
*/
class manager {

/**
* @var int $courseid the course id.
*/
protected $courseid;

/**
* manager constructor.
* @param int $courseid the course id.
*/
public function __construct($courseid) {
$this->courseid = $courseid;
}
Expand Down Expand Up @@ -185,6 +192,11 @@ protected function get_completion_active_rule_descriptions($moduledata) {
return $activeruledescriptions;
}

/**
* Gets the course modules for the current course.
*
* @return stdClass $data containing the modules
*/
public function get_activities_and_resources() {
global $DB, $OUTPUT, $CFG;
require_once($CFG->dirroot.'/course/lib.php');
Expand Down Expand Up @@ -238,7 +250,9 @@ public static function can_edit_bulk_completion($courseorid, $cm = null) {
}

/**
* @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[]
*/
public static function get_available_completion_tabs($courseorid) {
Expand Down
49 changes: 27 additions & 22 deletions completion/tests/bulk_update_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,37 +173,42 @@ protected function create_course_and_modules($modulenames) {
*/
public function bulk_form_submit_multiple_provider() {
return [
'Several modules with the same module type (choice)' =>
[['modulenames' => ['choice', 'choice', 'choice'],
'submitdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionsubmit' => 1],
'validatedata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionsubmit' => 1],
'cmdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC],
'instancedata' => [
['completionsubmit' => 1],
['completionsubmit' => 1],
['completionsubmit' => 1],
]]],
'Several modules with different module type' =>
[['modulenames' => ['choice', 'forum'],
'Several modules with the same module type (choice)' => [
[
'modulenames' => ['choice', 'choice', 'choice'],
'submitdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionsubmit' => 1],
'validatedata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionsubmit' => 1],
'cmdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC],
'instancedata' => [['completionsubmit' => 1], ['completionsubmit' => 1], ['completionsubmit' => 1]]
]
],
'Several modules with different module type' => [
[
'modulenames' => ['choice', 'forum'],
'submitdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1],
'validatedata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1],
'cmdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC],
'instancedata' => null]],
'Setting manual completion (completionview shoud be ignored)' =>
[['modulenames' => ['scorm', 'forum', 'label', 'assign'],
'instancedata' => null
]
],
'Setting manual completion (completionview shoud be ignored)' => [
[
'modulenames' => ['scorm', 'forum', 'label', 'assign'],
'submitdata' => ['completion' => COMPLETION_TRACKING_MANUAL, 'completionview' => 1],
'validatedata' => [],
'cmdata' => ['completion' => COMPLETION_TRACKING_MANUAL, 'completionview' => 0],
'instancedata' => null]],
'If at least one module does not support completionsubmit it can\'t be set' =>
[['modulenames' => ['survey', 'wiki'],
'instancedata' => null
]
],
'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],
'validatedata' => [],
'cmdata' => ['completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1],
'instancedata' => [
['completionsubmit' => 0],
[]
]]],
'instancedata' => [['completionsubmit' => 0], []]
]
]
];
}

Expand Down
5 changes: 2 additions & 3 deletions course/bulkcompletion.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -28,13 +27,13 @@
require_once($CFG->dirroot.'/course/lib.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);

// Perform some basic access control checks.
if ($id) {

if($id == SITEID){
if ($id == SITEID) {
// Don't allow editing of 'site course' using this form.
print_error('cannoteditsiteform');
}
Expand Down
20 changes: 19 additions & 1 deletion course/classes/output/bulk_activity_completion_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
*/
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) {
$tabs = core_completion\manager::get_available_completion_tabs($courseorid);
if (count($tabs) > 1) {
Expand All @@ -44,11 +51,22 @@ public function navigation($courseorid, $page) {
}
}


/**
* Render the bulk completion tab.
*
* @param Array|stdClass $data the context data to pass to the template.
* @return bool|string
*/
public function bulkcompletion($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) {
return parent::render_from_template('core_course/defaultactivitycompletion', $data);
}
Expand Down
3 changes: 1 addition & 2 deletions course/defaultcompletion.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -33,7 +32,7 @@
// Perform some basic access control checks.
if ($id) {

if($id == SITEID){
if ($id == SITEID) {
// Don't allow editing of 'site course' using this form.
print_error('cannoteditsiteform');
}
Expand Down
3 changes: 1 addition & 2 deletions course/dnduploadlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,7 @@ protected function display_name_from_file($filename) {
protected function create_course_module() {
global $CFG;
require_once($CFG->dirroot.'/course/modlib.php');
list($module, $context, $cw, $cm, $data) =
prepare_new_moduleinfo_data($this->course, $this->module->name, $this->section);
list($module, $context, $cw, $cm, $data) = prepare_new_moduleinfo_data($this->course, $this->module->name, $this->section);

$data->coursemodule = $data->id = add_course_module($data);
$this->cm = $data;
Expand Down
6 changes: 0 additions & 6 deletions course/templates/bulkactivitycompletion.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@
</div>
</div>
<div class="topics">

{{#sections}}

<div class="topic-section m-b-1">
<div class="row m-b-1">
<div class="col-sm-12">
Expand All @@ -72,9 +70,7 @@
</div>
{{> core_course/activityinstance}}
</div>

{{/sections}}

</div>
<input type="hidden" name="id" value="{{courseid}}" />
<input type="hidden" name="sesskey" value="{{sesskey}}" />
Expand Down Expand Up @@ -105,7 +101,5 @@ require([
$(this).prop('checked', checked);
});
});


});
{{/js}}
3 changes: 2 additions & 1 deletion lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4210,7 +4210,8 @@ protected function load_course_settings($forceopen = false) {
if ($adminoptions->editcompletion) {
// Add the course completion settings link
$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) {
Expand Down

0 comments on commit b17ee68

Please sign in to comment.