mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-58140 completion: Added bulk activity completion page.
Part of MDL-58138 epic
- Loading branch information
Showing
11 changed files
with
527 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Bulk activity completion manager class | ||
* | ||
* @package core_completion | ||
* @category completion | ||
* @copyright 2017 Adrian Greeve | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core_completion; | ||
|
||
use stdClass; | ||
|
||
/** | ||
* Bulk activity completion manager class | ||
* | ||
* @package core_completion | ||
* @category completion | ||
* @copyright 2017 Adrian Greeve | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class manager { | ||
|
||
protected $courseid; | ||
|
||
public function __construct($courseid) { | ||
$this->courseid = $courseid; | ||
} | ||
|
||
/** | ||
* Gets the data (context) to be used with the bulkactivitycompletion template. | ||
* | ||
* @return stdClass data for use with the bulkactivitycompletion template. | ||
*/ | ||
public function get_activities_and_headings() { | ||
global $OUTPUT; | ||
$moduleinfo = get_fast_modinfo($this->courseid); | ||
$sections = $moduleinfo->get_sections(); | ||
$data = new stdClass; | ||
$data->courseid = $this->courseid; | ||
$data->sesskey = sesskey(); | ||
$data->helpicon = $OUTPUT->help_icon('temphelp', 'moodle'); | ||
$data->sections = []; | ||
foreach ($sections as $sectionnumber => $section) { | ||
$sectioninfo = $moduleinfo->get_section_info($sectionnumber); | ||
|
||
$sectionobject = new stdClass(); | ||
$sectionobject->sectionnumber = $sectionnumber; | ||
$sectionobject->name = get_section_name($this->courseid, $sectioninfo); | ||
$sectionobject->activities = []; | ||
|
||
foreach ($section as $cmid) { | ||
$mod = $moduleinfo->get_cm($cmid); | ||
$moduleobject = new stdClass(); | ||
$moduleobject->cmid = $cmid; | ||
$moduleobject->modname = $mod->get_formatted_name(); | ||
$moduleobject->icon = $mod->get_icon_url()->out(); | ||
$moduleobject->url = $mod->url; | ||
|
||
// Get activity completion information. | ||
$moduleobject->completionstatus = $this->get_completion_detail($mod); | ||
|
||
$sectionobject->activities[] = $moduleobject; | ||
} | ||
$data->sections[] = $sectionobject; | ||
} | ||
return $data; | ||
} | ||
|
||
private function get_completion_detail(\cm_info $mod) { | ||
global $OUTPUT; | ||
$strings = []; | ||
switch ($mod->completion) { | ||
case 0: | ||
$strings['string'] = get_string('none'); | ||
break; | ||
|
||
case 1: | ||
$strings['string'] = get_string('manual'); | ||
$strings['icon'] = $OUTPUT->pix_url('i/completion-manual-enabled')->out(); | ||
break; | ||
|
||
case 2: | ||
$strings['string'] = get_string('withconditions'); | ||
|
||
// Get the descriptions for all the active completion rules for the module. | ||
if ($ruledescriptions = $mod->get_completion_active_rule_descriptions()) { | ||
foreach ($ruledescriptions as $ruledescription) { | ||
$strings['string'] .= \html_writer::empty_tag('br') . $ruledescription; | ||
} | ||
} | ||
|
||
$strings['icon'] = $OUTPUT->pix_url('i/completion-auto-enabled')->out(); | ||
break; | ||
|
||
default: | ||
$strings['string'] = get_string('none'); | ||
break; | ||
} | ||
return $strings; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Bulk activity completion selection | ||
* | ||
* @package core_completion | ||
* @category completion | ||
* @copyright 2017 Adrian Greeve | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
require_once(__DIR__.'/../config.php'); | ||
require_once($CFG->dirroot.'/course/lib.php'); | ||
require_once($CFG->libdir.'/completionlib.php'); | ||
|
||
$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){ | ||
// Don't allow editing of 'site course' using this form. | ||
print_error('cannoteditsiteform'); | ||
} | ||
|
||
if (!$course = $DB->get_record('course', array('id' => $id))) { | ||
print_error('invalidcourseid'); | ||
} | ||
require_login($course); | ||
require_capability('moodle/course:update', context_course::instance($course->id)); | ||
|
||
} else { | ||
require_login(); | ||
print_error('needcourseid'); | ||
} | ||
|
||
// Set up the page. | ||
$PAGE->set_course($course); | ||
$PAGE->set_url('/course/bulkcompletion.php', array('id' => $course->id)); | ||
$PAGE->set_title($course->shortname); | ||
$PAGE->set_heading($course->fullname); | ||
$PAGE->set_pagelayout('admin'); | ||
|
||
// Get all that stuff I need for the renderer. | ||
$manager = new \core_completion\manager($id); | ||
$bulkcompletiondata = $manager->get_activities_and_headings(); | ||
|
||
$renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion'); | ||
|
||
// Print the form. | ||
echo $OUTPUT->header(); | ||
echo $OUTPUT->heading(get_string('editcoursecompletionsettings', 'core_completion')); | ||
|
||
echo $renderer->navigation($id, 'bulkcompletion'); | ||
|
||
echo $renderer->bulkcompletion($bulkcompletiondata); | ||
|
||
echo $OUTPUT->footer(); |
61 changes: 61 additions & 0 deletions
61
course/classes/output/bulk_activity_completion_renderer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Contains renderers for the bulk activity completion stuff. | ||
* | ||
* @package core_course | ||
* @copyright 2017 Adrian Greeve | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die; | ||
|
||
require_once($CFG->dirroot.'/course/renderer.php'); | ||
|
||
/** | ||
* Main renderer for the bulk activity completion stuff. | ||
* | ||
* @package core_course | ||
* @copyright 2017 Adrian Greeve | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class core_course_bulk_activity_completion_renderer extends plugin_renderer_base { | ||
|
||
public function navigation($courseid, $page) { | ||
$tabs = []; | ||
|
||
$tabs[] = new tabobject( | ||
'completion', | ||
new moodle_url('/course/completion.php', ['id' => $courseid]), | ||
get_string('coursecompletion', 'completion') | ||
); | ||
|
||
$tabs[] = new tabobject( | ||
'bulkcompletion', | ||
new moodle_url('/course/bulkcompletion.php', ['id' => $courseid]), | ||
get_string('bulkactivitycompletion', 'completion'); | ||
); | ||
|
||
return $this->tabtree($tabs, $page); | ||
} | ||
|
||
|
||
public function bulkcompletion($data) { | ||
return parent::render_from_template('core_course/bulkactivitycompletion', $data); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{{! | ||
This file is part of Moodle - http://moodle.org/ | ||
Moodle is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Moodle is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
}} | ||
{{! | ||
@template core_course/activityinstance | ||
Activity completion selector. | ||
Example context (json): | ||
{ | ||
"activities": [{ | ||
"cmid": "4", | ||
"modname": "Test activity", | ||
"icon": { | ||
"attributes": [ | ||
{"name": "src", "value": "https://raw.githubusercontent.com/moodle/moodle/master/pix/t/check.png"}, | ||
{"name": "alt", "value": "Activity icon"} | ||
] | ||
}, | ||
"completionstatus": { | ||
"string": "Manual", | ||
"icon": { | ||
"attributes": [ | ||
{"name": "src", "value": "https://raw.githubusercontent.com/moodle/moodle/master/pix/t/check.png"}, | ||
{"name": "alt", "value": "Completion icon"} | ||
] | ||
} | ||
} | ||
}] | ||
} | ||
}} | ||
{{#activities}} | ||
<div class="row m-b-1"> | ||
<div class="activityinstance col-sm-6 span6"> | ||
<div class="mod-indent-outer"></div> | ||
<div> | ||
<input type="checkbox" class="m-r-1" name="cmid[]" data-section="{{sectionnumber}}" value="{{cmid}}" aria-label="{{#str}}checkactivity, completion, {{modname}}{{/str}}"> | ||
<a href={{url}}> | ||
<img src="{{icon}}" class="iconlarge activityicon" alt=" " role="presentation" /> | ||
<span class="instancename">{{modname}}</span> | ||
</a> | ||
</div> | ||
</div> | ||
<div class="activity-completionstatus col-sm-6"> | ||
<div class="col-sm-1"> | ||
{{#completionstatus.icon}} | ||
<img src="{{completionstatus.icon}}" class="m-r-2"> | ||
{{/completionstatus.icon}} | ||
{{^completionstatus.icon}} | ||
<span class="m-r-3"></span> | ||
{{/completionstatus.icon}} | ||
</div> | ||
<div class="col-sm-11"> | ||
<span class="text-muted muted">{{{completionstatus.string}}}</span> | ||
</div> | ||
</div> | ||
</div> | ||
{{/activities}} |
Oops, something went wrong.