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.

Differences Between: [Versions 310 and 402] [Versions 310 and 403]

   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   * Defines the form for editing Quiz results block instances.
  19   *
  20   * @package    block_activity_results
  21   * @copyright  2009 Tim Hunt
  22   * @copyright  2015 Stephen Bourget
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  require_once($CFG->dirroot . '/lib/grade/constants.php');
  28  
  29  /**
  30   * Form for editing activity results block instances.
  31   *
  32   * @copyright 2009 Tim Hunt
  33   * @copyright 2015 Stephen Bourget
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class block_activity_results_edit_form extends block_edit_form {
  37      /**
  38       * The definition of the fields to use.
  39       *
  40       * @param MoodleQuickForm $mform
  41       */
  42      protected function specific_definition($mform) {
  43          global $DB;
  44  
  45          // Load defaults.
  46          $blockconfig = get_config('block_activity_results');
  47  
  48          // Fields for editing activity_results block title and contents.
  49          $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
  50  
  51          // Get supported modules (Only modules using grades or scales will be listed).
  52          $sql = 'SELECT id, itemname FROM {grade_items} WHERE courseid = ? and itemtype = ? and (gradetype = ? or gradetype = ?)';
  53          $params = array($this->page->course->id, 'mod', GRADE_TYPE_VALUE, GRADE_TYPE_SCALE);
  54          $activities = $DB->get_records_sql_menu($sql, $params);
  55          core_collator::asort($activities);
  56  
  57          if (empty($activities)) {
  58              $mform->addElement('static', 'noactivitieswarning', get_string('config_select_activity', 'block_activity_results'),
  59                      get_string('config_no_activities_in_course', 'block_activity_results'));
  60          } else {
  61              foreach ($activities as $id => $name) {
  62                  $activities[$id] = strip_tags(format_string($name));
  63              }
  64              $mform->addElement('select', 'config_activitygradeitemid',
  65                      get_string('config_select_activity', 'block_activity_results'), $activities);
  66              $mform->setDefault('config_activitygradeitemid', $this->block->get_owning_activity()->id);
  67          }
  68  
  69          $mform->addElement('text', 'config_showbest',
  70                  get_string('config_show_best', 'block_activity_results'), array('size' => 3));
  71          $mform->setDefault('config_showbest', $blockconfig->config_showbest);
  72          $mform->setType('config_showbest', PARAM_INT);
  73          if ($blockconfig->config_showbest_locked) {
  74              $mform->freeze('config_showbest');
  75          }
  76  
  77          $mform->addElement('text', 'config_showworst',
  78                  get_string('config_show_worst', 'block_activity_results'), array('size' => 3));
  79          $mform->setDefault('config_showworst', $blockconfig->config_showworst);
  80          $mform->setType('config_showworst', PARAM_INT);
  81          if ($blockconfig->config_showworst_locked) {
  82              $mform->freeze('config_showworst');
  83          }
  84  
  85          $mform->addElement('selectyesno', 'config_usegroups', get_string('config_use_groups', 'block_activity_results'));
  86          $mform->setDefault('config_usegroups', $blockconfig->config_usegroups);
  87          if ($blockconfig->config_usegroups_locked) {
  88              $mform->freeze('config_usegroups');
  89          }
  90  
  91          $nameoptions = array(
  92              B_ACTIVITYRESULTS_NAME_FORMAT_FULL => get_string('config_names_full', 'block_activity_results'),
  93              B_ACTIVITYRESULTS_NAME_FORMAT_ID => get_string('config_names_id', 'block_activity_results'),
  94              B_ACTIVITYRESULTS_NAME_FORMAT_ANON => get_string('config_names_anon', 'block_activity_results')
  95          );
  96          $mform->addElement('select', 'config_nameformat',
  97                  get_string('config_name_format', 'block_activity_results'), $nameoptions);
  98          $mform->setDefault('config_nameformat', $blockconfig->config_nameformat);
  99          if ($blockconfig->config_nameformat_locked) {
 100              $mform->freeze('config_nameformat');
 101          }
 102  
 103          $gradeeoptions = array(
 104              B_ACTIVITYRESULTS_GRADE_FORMAT_PCT => get_string('config_format_percentage', 'block_activity_results'),
 105              B_ACTIVITYRESULTS_GRADE_FORMAT_FRA => get_string('config_format_fraction', 'block_activity_results'),
 106              B_ACTIVITYRESULTS_GRADE_FORMAT_ABS => get_string('config_format_absolute', 'block_activity_results')
 107          );
 108          $mform->addElement('select', 'config_gradeformat',
 109                  get_string('config_grade_format', 'block_activity_results'), $gradeeoptions);
 110          $mform->setDefault('config_gradeformat', $blockconfig->config_gradeformat);
 111          if ($blockconfig->config_gradeformat_locked) {
 112              $mform->freeze('config_gradeformat');
 113          }
 114  
 115          $options = array();
 116          for ($i = 0; $i <= 5; $i++) {
 117              $options[$i] = $i;
 118          }
 119          $mform->addElement('select', 'config_decimalpoints', get_string('config_decimalplaces', 'block_activity_results'),
 120                  $options);
 121          $mform->setDefault('config_decimalpoints', $blockconfig->config_decimalpoints);
 122          $mform->setType('config_decimalpoints', PARAM_INT);
 123          if ($blockconfig->config_decimalpoints_locked) {
 124              $mform->freeze('config_decimalpoints');
 125          }
 126      }
 127  }