Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Bulk activity completion selection
  19   *
  20   * @package     core_completion
  21   * @copyright   2017 Marina Glancy
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once (__DIR__ . "/../config.php");
  26  require_once($CFG->libdir . '/completionlib.php');
  27  
  28  $courseid = required_param('id', PARAM_INT);
  29  $modids = optional_param_array('modids', [], PARAM_INT);
  30  $course = get_course($courseid);
  31  require_login($course);
  32  
  33  navigation_node::override_active_url(new moodle_url('/course/completion.php', array('id' => $course->id)));
  34  $PAGE->set_url(new moodle_url('/course/editdefaultcompletion.php', ['id' => $courseid]));
  35  $PAGE->set_title($course->shortname);
  36  $PAGE->set_heading($course->fullname);
  37  $PAGE->set_pagelayout('admin');
  38  
  39  require_capability('moodle/course:manageactivities', context_course::instance($course->id));
  40  
  41  // Prepare list of selected modules.
  42  $manager = new \core_completion\manager($course->id);
  43  $allmodules = $manager->get_activities_and_resources();
  44  $modules = [];
  45  foreach ($allmodules->modules as $module) {
  46      if ($module->canmanage && in_array($module->id, $modids)) {
  47          $modules[$module->id] = $module;
  48      }
  49  }
  50  
  51  $returnurl = new moodle_url('/course/defaultcompletion.php', ['id' => $course->id]);
  52  if (empty($modules)) {
  53      redirect($returnurl);
  54  }
  55  
  56  $form = new core_completion_defaultedit_form(null, ['course' => $course, 'modules' => $modules]);
  57  
  58  if ($form->is_cancelled()) {
  59      redirect($returnurl);
  60  } else if ($data = $form->get_data()) {
  61      $manager->apply_default_completion($data, $form->has_custom_completion_rules());
  62      redirect($returnurl);
  63  }
  64  
  65  $renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
  66  
  67  echo $OUTPUT->header();
  68  
  69  echo $OUTPUT->heading(get_string('defaultcompletion', 'completion'));
  70  
  71  echo $renderer->edit_default_completion($form, $modules);
  72  
  73  echo $OUTPUT->footer();
  74