Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [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 public function supports_preview(): bool { 36 return true; 37 } 38 39 public function get_data_content_preview(int $recordid): stdClass { 40 return (object)[ 41 'id' => 0, 42 'fieldid' => $this->field->id, 43 'recordid' => $recordid, 44 'content' => get_string('sample', 'datafield_text'), 45 'content1' => null, 46 'content2' => null, 47 'content3' => null, 48 'content4' => null, 49 ]; 50 } 51 52 function display_search_field($value = '') { 53 return '<label class="accesshide" for="f_' . $this->field->id . '">' . $this->field->name.'</label>' . 54 '<input type="text" class="form-control" size="16" id="f_' . $this->field->id . '" ' . 55 'name="f_' . $this->field->id . '" value="' . s($value) . '" />'; 56 } 57 58 public function parse_search_field($defaults = null) { 59 $param = 'f_'.$this->field->id; 60 if (empty($defaults[$param])) { 61 $defaults = array($param => ''); 62 } 63 return optional_param($param, $defaults[$param], PARAM_NOTAGS); 64 } 65 66 function generate_sql($tablealias, $value) { 67 global $DB; 68 69 static $i=0; 70 $i++; 71 $name = "df_text_$i"; 72 return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%")); 73 } 74 75 /** 76 * Check if a field from an add form is empty 77 * 78 * @param mixed $value 79 * @param mixed $name 80 * @return bool 81 */ 82 function notemptyfield($value, $name) { 83 return strval($value) !== ''; 84 } 85 86 /** 87 * Return the plugin configs for external functions. 88 * 89 * @return array the list of config parameters 90 * @since Moodle 3.3 91 */ 92 public function get_config_for_external() { 93 // Return all the config parameters. 94 $configs = []; 95 for ($i = 1; $i <= 10; $i++) { 96 $configs["param$i"] = $this->field->{"param$i"}; 97 } 98 return $configs; 99 } 100 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body