Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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  /**
  19   * Course competency rule element.
  20   *
  21   * @package   tool_lp
  22   * @copyright 2016 Damyon Wiese
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  global $CFG;
  29  
  30  use core_competency\api;
  31  use core_competency\external\competency_exporter;
  32  use core_competency\course_module_competency;
  33  
  34  require_once($CFG->libdir . '/form/select.php');
  35  
  36  /**
  37   * Course competency rule element.
  38   *
  39   * @package   tool_lp
  40   * @copyright 2016 Damyon Wiese
  41   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class tool_lp_course_competency_rule_form_element extends MoodleQuickForm_select {
  44  
  45      /**
  46       * Constructor
  47       *
  48       * @param string $elementName Element name
  49       * @param mixed $elementLabel Label(s) for an element
  50       * @param array $options Options to control the element's display
  51       * @param mixed $attributes Either a typical HTML attribute string or an associative array.
  52       */
  53      public function __construct($elementName=null, $elementLabel=null, $options=array(), $attributes=null) {
  54          if ($elementName == null) {
  55              // This is broken quickforms messing with the constructors.
  56              return;
  57          }
  58  
  59          if (!empty($options['cmid'])) {
  60              $cmid = $options['cmid'];
  61  
  62              $current = \core_competency\api::list_course_module_competencies_in_course_module($cmid);
  63  
  64              // Note: We just pick the outcome set on the first course_module_competency - because in our UI are are
  65              // forcing them to be all the same for each activity.
  66              if (!empty($current)) {
  67                  $one = array_pop($current);
  68                  $this->setValue($one->get('ruleoutcome'));
  69              }
  70          }
  71          $validoptions = course_module_competency::get_ruleoutcome_list();
  72          parent::__construct($elementName, $elementLabel, $validoptions, $attributes);
  73      }
  74  }