[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/blocks/activity_results/ -> edit_form.php (source)

   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  
  56          if (empty($activities)) {
  57              $mform->addElement('static', 'noactivitieswarning', get_string('config_select_activity', 'block_activity_results'),
  58                      get_string('config_no_activities_in_course', 'block_activity_results'));
  59          } else {
  60              foreach ($activities as $id => $name) {
  61                  $activities[$id] = strip_tags(format_string($name));
  62              }
  63              $mform->addElement('select', 'config_activitygradeitemid',
  64                      get_string('config_select_activity', 'block_activity_results'), $activities);
  65              $mform->setDefault('config_activitygradeitemid', $this->block->get_owning_activity()->id);
  66          }
  67  
  68          $mform->addElement('text', 'config_showbest',
  69                  get_string('config_show_best', 'block_activity_results'), array('size' => 3));
  70          $mform->setDefault('config_showbest', $blockconfig->config_showbest);
  71          $mform->setType('config_showbest', PARAM_INT);
  72          if ($blockconfig->config_showbest_locked) {
  73              $mform->freeze('config_showbest');
  74          }
  75  
  76          $mform->addElement('text', 'config_showworst',
  77                  get_string('config_show_worst', 'block_activity_results'), array('size' => 3));
  78          $mform->setDefault('config_showworst', $blockconfig->config_showworst);
  79          $mform->setType('config_showworst', PARAM_INT);
  80          if ($blockconfig->config_showworst_locked) {
  81              $mform->freeze('config_showworst');
  82          }
  83  
  84          $mform->addElement('selectyesno', 'config_usegroups', get_string('config_use_groups', 'block_activity_results'));
  85          $mform->setDefault('config_usegroups', $blockconfig->config_usegroups);
  86          if ($blockconfig->config_usegroups_locked) {
  87              $mform->freeze('config_usegroups');
  88          }
  89  
  90          $nameoptions = array(
  91              B_ACTIVITYRESULTS_NAME_FORMAT_FULL => get_string('config_names_full', 'block_activity_results'),
  92              B_ACTIVITYRESULTS_NAME_FORMAT_ID => get_string('config_names_id', 'block_activity_results'),
  93              B_ACTIVITYRESULTS_NAME_FORMAT_ANON => get_string('config_names_anon', 'block_activity_results')
  94          );
  95          $mform->addElement('select', 'config_nameformat',
  96                  get_string('config_name_format', 'block_activity_results'), $nameoptions);
  97          $mform->setDefault('config_nameformat', $blockconfig->config_nameformat);
  98          if ($blockconfig->config_nameformat_locked) {
  99              $mform->freeze('config_nameformat');
 100          }
 101  
 102          $gradeeoptions = array(
 103              B_ACTIVITYRESULTS_GRADE_FORMAT_PCT => get_string('config_format_percentage', 'block_activity_results'),
 104              B_ACTIVITYRESULTS_GRADE_FORMAT_FRA => get_string('config_format_fraction', 'block_activity_results'),
 105              B_ACTIVITYRESULTS_GRADE_FORMAT_ABS => get_string('config_format_absolute', 'block_activity_results')
 106          );
 107          $mform->addElement('select', 'config_gradeformat',
 108                  get_string('config_grade_format', 'block_activity_results'), $gradeeoptions);
 109          $mform->setDefault('config_gradeformat', $blockconfig->config_gradeformat);
 110          if ($blockconfig->config_gradeformat_locked) {
 111              $mform->freeze('config_gradeformat');
 112          }
 113  
 114          $options = array();
 115          for ($i = 0; $i <= 5; $i++) {
 116              $options[$i] = $i;
 117          }
 118          $mform->addElement('select', 'config_decimalpoints', get_string('config_decimalplaces', 'block_activity_results'),
 119                  $options);
 120          $mform->setDefault('config_decimalpoints', $blockconfig->config_decimalpoints);
 121          $mform->setType('config_decimalpoints', PARAM_INT);
 122          if ($blockconfig->config_decimalpoints_locked) {
 123              $mform->freeze('config_decimalpoints');
 124          }
 125      }
 126  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1