Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

   1  <?php
   2  ///////////////////////////////////////////////////////////////////////////
   3  //                                                                       //
   4  // NOTICE OF COPYRIGHT                                                   //
   5  //                                                                       //
   6  // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
   7  //          http://moodle.org                                            //
   8  //                                                                       //
   9  // Copyright (C) 1999-onwards Moodle Pty Ltd  http://moodle.com          //
  10  //                                                                       //
  11  // This program is free software; you can redistribute it and/or modify  //
  12  // it under the terms of the GNU General Public License as published by  //
  13  // the Free Software Foundation; either version 2 of the License, or     //
  14  // (at your option) any later version.                                   //
  15  //                                                                       //
  16  // This program is distributed in the hope that it will be useful,       //
  17  // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  18  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  19  // GNU General Public License for more details:                          //
  20  //                                                                       //
  21  //          http://www.gnu.org/copyleft/gpl.html                         //
  22  //                                                                       //
  23  ///////////////////////////////////////////////////////////////////////////
  24  
  25  class data_field_text extends data_field_base {
  26  
  27      var $type = 'text';
  28      /**
  29       * priority for globalsearch indexing
  30       *
  31       * @var int
  32       */
  33      protected static $priority = self::MAX_PRIORITY;
  34  
  35      function display_search_field($value = '') {
  36          return '<label class="accesshide" for="f_' . $this->field->id . '">' . $this->field->name.'</label>' .
  37                 '<input type="text" class="form-control" size="16" id="f_' . $this->field->id . '" ' .
  38                 'name="f_' . $this->field->id . '" value="' . s($value) . '" />';
  39      }
  40  
  41      public function parse_search_field($defaults = null) {
  42          $param = 'f_'.$this->field->id;
  43          if (empty($defaults[$param])) {
  44              $defaults = array($param => '');
  45          }
  46          return optional_param($param, $defaults[$param], PARAM_NOTAGS);
  47      }
  48  
  49      function generate_sql($tablealias, $value) {
  50          global $DB;
  51  
  52          static $i=0;
  53          $i++;
  54          $name = "df_text_$i";
  55          return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%"));
  56      }
  57  
  58      /**
  59       * Check if a field from an add form is empty
  60       *
  61       * @param mixed $value
  62       * @param mixed $name
  63       * @return bool
  64       */
  65      function notemptyfield($value, $name) {
  66          return strval($value) !== '';
  67      }
  68  
  69      /**
  70       * Return the plugin configs for external functions.
  71       *
  72       * @return array the list of config parameters
  73       * @since Moodle 3.3
  74       */
  75      public function get_config_for_external() {
  76          // Return all the config parameters.
  77          $configs = [];
  78          for ($i = 1; $i <= 10; $i++) {
  79              $configs["param$i"] = $this->field->{"param$i"};
  80          }
  81          return $configs;
  82      }
  83  }
  84  
  85