[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/user/profile/field/checkbox/ -> field.class.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   * Strings for component 'profilefield_checkbox', language 'en', branch 'MOODLE_20_STABLE'
  19   *
  20   * @package   profilefield_checkbox
  21   * @copyright  2008 onwards Shane Elliot {@link http://pukunui.com}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  /**
  26   * Class profile_field_checkbox
  27   *
  28   * @copyright  2008 onwards Shane Elliot {@link http://pukunui.com}
  29   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class profile_field_checkbox extends profile_field_base {
  32  
  33      /**
  34       * Constructor method.
  35       * Pulls out the options for the checkbox from the database and sets the
  36       * the corresponding key for the data if it exists
  37       *
  38       * @param int $fieldid
  39       * @param int $userid
  40       */
  41      public function profile_field_checkbox($fieldid=0, $userid=0) {
  42          global $DB;
  43          // First call parent constructor.
  44          $this->profile_field_base($fieldid, $userid);
  45  
  46          if (!empty($this->field)) {
  47              $datafield = $DB->get_field('user_info_data', 'data', array('userid' => $this->userid, 'fieldid' => $this->fieldid));
  48              if ($datafield !== false) {
  49                  $this->data = $datafield;
  50              } else {
  51                  $this->data = $this->field->defaultdata;
  52              }
  53          }
  54      }
  55  
  56      /**
  57       * Add elements for editing the profile field value.
  58       * @param moodleform $mform
  59       */
  60      public function edit_field_add($mform) {
  61          // Create the form field.
  62          $checkbox = $mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name));
  63          if ($this->data == '1') {
  64              $checkbox->setChecked(true);
  65          }
  66          $mform->setType($this->inputname, PARAM_BOOL);
  67          if ($this->is_required() and !has_capability('moodle/user:update', context_system::instance())) {
  68              $mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client');
  69          }
  70      }
  71  
  72      /**
  73       * Display the data for this field
  74       *
  75       * @return string HTML.
  76       */
  77      public function display_data() {
  78          $options = new stdClass();
  79          $options->para = false;
  80          $checked = intval($this->data) === 1 ? 'checked="checked"' : '';
  81          return '<input disabled="disabled" type="checkbox" name="'.$this->inputname.'" '.$checked.' />';
  82      }
  83  
  84  }
  85  
  86  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1