return $this->_modnames;
}
+ /**
+ * Returns an instance of component-specific module form for the first selected module
+ *
+ * @return moodleform_mod|null
+ */
+ protected function get_module_form() {
+ global $CFG, $PAGE;
+
+ if ($this->_moduleform) {
+ return $this->_moduleform;
+ }
+
+ $cm = reset($this->cms);
+ $course = $this->course;
+ $modname = $cm->modname;
+
+ $modmoodleform = "$CFG->dirroot/mod/$modname/mod_form.php";
+ if (file_exists($modmoodleform)) {
+ require_once($modmoodleform);
+ } else {
+ print_error('noformdesc');
+ }
+
+ list($cmrec, $context, $module, $data, $cw) = get_moduleinfo_data($cm, $course);
+ $data->return = 0;
+ $data->sr = 0;
+ $data->update = $modname;
+
+ // Initialise the form but discard all JS requirements it adds, our form has already added them.
+ $mformclassname = 'mod_'.$modname.'_mod_form';
+ if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) {
+ $PAGE->start_collecting_javascript_requirements();
+ }
+ $this->_moduleform = new $mformclassname($data, 0, $cmrec, $course);
+ if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) {
+ $PAGE->end_collecting_javascript_requirements();
+ }
+
+ return $this->_moduleform;
+ }
+
/**
* Form definition
*/
return $this->_modnames;
}
+ /**
+ * Returns an instance of component-specific module form for the first selected module
+ *
+ * @return moodleform_mod|null
+ */
+ protected function get_module_form() {
+ global $CFG, $PAGE;
+
+ if ($this->_moduleform) {
+ return $this->_moduleform;
+ }
+
+ $modnames = array_keys($this->get_module_names());
+ $modname = $modnames[0];
+ $course = $this->course;
+
+ $modmoodleform = "$CFG->dirroot/mod/$modname/mod_form.php";
+ if (file_exists($modmoodleform)) {
+ require_once($modmoodleform);
+ } else {
+ print_error('noformdesc');
+ }
+
+ list($module, $context, $cw, $cmrec, $data) = prepare_new_moduleinfo_data($course, $modname, 0);
+ $data->return = 0;
+ $data->sr = 0;
+ $data->add = $modname;
+
+ // Initialise the form but discard all JS requirements it adds, our form has already added them.
+ $mformclassname = 'mod_'.$modname.'_mod_form';
+ if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) {
+ $PAGE->start_collecting_javascript_requirements();
+ }
+ $this->_moduleform = new $mformclassname($data, 0, $cmrec, $course);
+ if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) {
+ $PAGE->end_collecting_javascript_requirements();
+ }
+
+ return $this->_moduleform;
+ }
+
/**
* Form definition,
*/
*
* @return moodleform_mod|null
*/
- protected function get_module_form() {
- global $CFG, $PAGE;
-
- if ($this->_moduleform) {
- return $this->_moduleform;
- }
-
- $modnames = array_keys($this->get_module_names());
- $modname = $modnames[0];
- $course = $this->course;
-
- $modmoodleform = "$CFG->dirroot/mod/$modname/mod_form.php";
- if (file_exists($modmoodleform)) {
- require_once($modmoodleform);
- } else {
- print_error('noformdesc');
- }
-
- list($module, $context, $cw, $cmrec, $data) = prepare_new_moduleinfo_data($course, $modname, 0);
- $data->return = 0;
- $data->sr = 0;
- $data->add = $modname;
-
- // Initialise the form but discard all JS requirements it adds, our form has already added them.
- $mformclassname = 'mod_'.$modname.'_mod_form';
- if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) {
- $PAGE->start_collecting_javascript_requirements();
- }
- $this->_moduleform = new $mformclassname($data, 0, $cmrec, $course);
- if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) {
- $PAGE->end_collecting_javascript_requirements();
- }
-
- return $this->_moduleform;
- }
+ abstract protected function get_module_form();
/**
* If all selected modules are of the same module type, adds custom completion rules from this module type
use stdClass;
use context_course;
use cm_info;
+use tabobject;
+use lang_string;
+use moodle_url;
/**
* Bulk activity completion manager class
return false;
}
+ /**
+ * @param stdClass|int $courseorid
+ * @return tabobject[]
+ */
+ public static function get_available_completion_tabs($courseorid) {
+ $tabs = [];
+
+ $courseid = is_object($courseorid) ? $courseorid->id : $courseorid;
+ $coursecontext = context_course::instance($courseid);
+
+ if (has_capability('moodle/course:update', $coursecontext)) {
+ $tabs[] = new tabobject(
+ 'completion',
+ new moodle_url('/course/completion.php', ['id' => $courseid]),
+ new lang_string('coursecompletion', 'completion')
+ );
+ }
+
+ if (has_capability('moodle/course:manageactivities', $coursecontext)) {
+ $tabs[] = new tabobject(
+ 'defaultcompletion',
+ new moodle_url('/course/defaultcompletion.php', ['id' => $courseid]),
+ new lang_string('defaultcompletion', 'completion')
+ );
+ }
+
+ if (self::can_edit_bulk_completion($courseorid)) {
+ $tabs[] = new tabobject(
+ 'bulkcompletion',
+ new moodle_url('/course/bulkcompletion.php', ['id' => $courseid]),
+ new lang_string('bulkactivitycompletion', 'completion')
+ );
+ }
+
+ return $tabs;
+ }
+
/**
* Applies completion from the bulk edit form to all selected modules
*
$PAGE->set_heading($course->fullname);
$PAGE->set_pagelayout('admin');
-// Get all that stuff I need for the renderer.
+// Check access.
if (!core_completion\manager::can_edit_bulk_completion($id)) {
- throw new required_capability_exception(context_course::instance($course->id),
- 'moodle/course:manageactivities', 'nopermission');
+ require_capability('moodle/course:manageactivities', context_course::instance($course->id));
}
+// Get all that stuff I need for the renderer.
$manager = new \core_completion\manager($id);
$bulkcompletiondata = $manager->get_activities_and_headings();
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('bulkactivitycompletion', 'completion'));
-echo $renderer->navigation($id, 'bulkcompletion');
+echo $renderer->navigation($course, 'bulkcompletion');
$PAGE->requires->yui_module('moodle-core-formchangechecker',
'M.core_formchangechecker.init',
*/
class core_course_bulk_activity_completion_renderer extends plugin_renderer_base {
- public function navigation($courseid, $page) {
- $tabs = [];
-
- if (has_capability('moodle/course:update', context_course::instance($courseid))) {
- $tabs[] = new tabobject(
- 'completion',
- new moodle_url('/course/completion.php', ['id' => $courseid]),
- get_string('coursecompletion', 'completion')
- );
-
- $tabs[] = new tabobject(
- 'defaultcompletion',
- new moodle_url('/course/defaultcompletion.php', ['id' => $courseid]),
- get_string('defaultcompletion', 'completion')
- );
- }
-
- if (core_completion\manager::can_edit_bulk_completion($courseid)) {
- $tabs[] = new tabobject(
- 'bulkcompletion',
- new moodle_url('/course/bulkcompletion.php', ['id' => $courseid]),
- get_string('bulkactivitycompletion', 'completion')
- );
- }
-
+ public function navigation($courseorid, $page) {
+ $tabs = core_completion\manager::get_available_completion_tabs($courseorid);
if (count($tabs) > 1) {
return $this->tabtree($tabs, $page);
} else {
require_login($course);
$context = context_course::instance($course->id);
if (!has_capability('moodle/course:update', $context)) {
- if (core_completion\manager::can_edit_bulk_completion($course)) {
- redirect(new moodle_url('/course/bulkcompletion.php', ['id' => $course->id]));
+ // User is not allowed to modify course completion.
+ // Check if they can see default completion or edit bulk completion and redirect there.
+ if ($tabs = core_completion\manager::get_available_completion_tabs($course)) {
+ redirect($tabs[0]->link);
} else {
require_capability('moodle/course:update', $context);
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('editcoursecompletionsettings', 'core_completion'));
-echo $renderer->navigation($id, 'completion');
+echo $renderer->navigation($course, 'completion');
$form->display();
print_error('invalidcourseid');
}
require_login($course);
- require_capability('moodle/course:update', context_course::instance($course->id));
+ require_capability('moodle/course:manageactivities', context_course::instance($course->id));
} else {
require_login();
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('defaultcompletion', 'completion'));
-echo $renderer->navigation($id, 'defaultcompletion');
+echo $renderer->navigation($course, 'defaultcompletion');
$PAGE->requires->yui_module('moodle-core-formchangechecker',
'M.core_formchangechecker.init',
$PAGE->set_pagelayout('admin');
if (!core_completion\manager::can_edit_bulk_completion($course)) {
- throw new required_capability_exception(context_course::instance($course->id),
- 'moodle/course:manageactivities', 'nopermission');
+ require_capability('moodle/course:manageactivities', context_course::instance($course->id));
}
// Prepare list of modules to be updated.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('bulkactivitycompletion', 'completion'));
-echo $renderer->navigation($course->id, 'bulkcompletion');
+echo $renderer->navigation($course, 'bulkcompletion');
echo $renderer->edit_bulk_completion($form, $manager->get_activities(array_keys($cms)));
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('defaultcompletion', 'completion'));
-echo $renderer->navigation($course->id, 'defaultcompletion');
+echo $renderer->navigation($course, 'defaultcompletion');
echo $renderer->edit_default_completion($form, $modules);
$options = new stdClass;
$options->update = has_capability('moodle/course:update', $context);
- $options->editcompletion = core_completion\manager::can_edit_bulk_completion($course);
+ $options->editcompletion = $CFG->enablecompletion && $course->enablecompletion &&
+ ($options->update || count(core_completion\manager::get_available_completion_tabs($course, $context)) > 0);
$options->filters = has_capability('moodle/filter:manage', $context) &&
count(filter_get_available_in_context($context)) > 0;
$options->reports = has_capability('moodle/site:viewreports', $context);
<div class="activity-completionstatus col-sm-6">
<div class="col-sm-1">
{{#completionstatus.icon}}
- <img src="{{completionstatus.icon}}" class="m-r-2">
+ <img src="{{completionstatus.icon}}" class="m-r-2" alt=" " role="presentation">
{{/completionstatus.icon}}
{{^completionstatus.icon}}
<span class="m-r-3"></span>
</div>
</div>
<div class="topics">
-
+
{{#sections}}
-
+
<div class="topic-section m-b-1">
<div class="row m-b-1">
<div class="col-sm-12">
</div>
{{> core_course/activityinstance}}
</div>
-
+
{{/sections}}
-
+
</div>
<input type="hidden" name="id" value="{{courseid}}" />
<input type="hidden" name="sesskey" value="{{sesskey}}" />
{{#canmanage}}
<div class="module-section m-b-1">
<div class="row m-b-1">
- <div class="col-sm-12">
- <input type="checkbox" class="m-r-1" name="modids[]" value="{{id}}" aria-label="{{#str}}checkactivity, completion, {{formatedname}}{{/str}}">
- <img src={{icon}} />
+ <div class="col-sm-6">
+ <label class="accesshide" for="modtype_{{id}}">Select {{formattedname}}</label>
+ <input id="modtype_{{id}}" type="checkbox" class="m-r-1" name="modids[]" value="{{id}}" aria-label="{{#str}}checkactivity, completion, {{formattedname}}{{/str}}">
+ <img src="{{icon}}" alt=" " role="presentation" />
<span>{{formattedname}}</span>
</div>
<div class="activity-completionstatus col-sm-6">
<div class="col-sm-1">
{{#completionstatus.icon}}
- <img src="{{completionstatus.icon}}" class="m-r-2">
+ <img src="{{completionstatus.icon}}" class="m-r-2" alt=" " role="presentation">
{{/completionstatus.icon}}
{{^completionstatus.icon}}
<span class="m-r-3"></span>
<div class="row m-b-1">
{{#modules}}
<div class="col-sm-2">
- <img src="{{icon}}" class="m-r-1 m-b-1" alt=" " />
+ <img src="{{icon}}" class="m-r-1 m-b-1" alt=" " role="presentation" />
<span>{{{formattedname}}}</span>
</div>
{{/modules}}
$coursenode->add($editstring, $editurl, self::TYPE_SETTING, null, 'turneditingonoff', new pix_icon('i/edit', ''));
}
- if ($adminoptions->update || $adminoptions->editcompletion) {
-
+ if ($adminoptions->editcompletion) {
// Add the course completion settings link
- if ($CFG->enablecompletion && $course->enablecompletion) {
- $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', ''));
- }
+ $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', ''));
}
if (!$adminoptions->update && $adminoptions->tags) {