[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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_menu extends data_field_base { 26 27 var $type = 'menu'; 28 29 function display_add_field($recordid = 0, $formdata = null) { 30 global $DB, $OUTPUT; 31 32 if ($formdata) { 33 $fieldname = 'field_' . $this->field->id; 34 $content = $formdata->$fieldname; 35 } else if ($recordid) { 36 $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); 37 $content = trim($content); 38 } else { 39 $content = ''; 40 } 41 $str = '<div title="' . s($this->field->description) . '">'; 42 43 $options = array(); 44 $rawoptions = explode("\n",$this->field->param1); 45 foreach ($rawoptions as $option) { 46 $option = trim($option); 47 if ($option) { 48 $options[$option] = $option; 49 } 50 } 51 52 $str .= '<label for="' . 'field_' . $this->field->id . '">'; 53 $str .= html_writer::span($this->field->name, 'accesshide'); 54 if ($this->field->required) { 55 $image = html_writer::img($OUTPUT->pix_url('req'), get_string('requiredelement', 'form'), 56 array('class' => 'req', 'title' => get_string('requiredelement', 'form'))); 57 $str .= html_writer::div($image, 'inline-req'); 58 } 59 $str .= '</label>'; 60 $str .= html_writer::select($options, 'field_'.$this->field->id, $content, array('' => get_string('menuchoose', 'data')), 61 array('id' => 'field_'.$this->field->id, 'class' => 'mod-data-input')); 62 63 $str .= '</div>'; 64 65 return $str; 66 } 67 68 function display_search_field($content = '') { 69 global $CFG, $DB; 70 71 $varcharcontent = $DB->sql_compare_text('content', 255); 72 $sql = "SELECT DISTINCT $varcharcontent AS content 73 FROM {data_content} 74 WHERE fieldid=? AND content IS NOT NULL"; 75 76 $usedoptions = array(); 77 if ($used = $DB->get_records_sql($sql, array($this->field->id))) { 78 foreach ($used as $data) { 79 $value = $data->content; 80 if ($value === '') { 81 continue; 82 } 83 $usedoptions[$value] = $value; 84 } 85 } 86 87 $options = array(); 88 foreach (explode("\n",$this->field->param1) as $option) { 89 $option = trim($option); 90 if (!isset($usedoptions[$option])) { 91 continue; 92 } 93 $options[$option] = $option; 94 } 95 if (!$options) { 96 // oh, nothing to search for 97 return ''; 98 } 99 100 $return = html_writer::label(get_string('namemenu', 'data'), 'menuf_'. $this->field->id, false, array('class' => 'accesshide')); 101 $return .= html_writer::select($options, 'f_'.$this->field->id, $content); 102 return $return; 103 } 104 105 function parse_search_field() { 106 return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS); 107 } 108 109 function generate_sql($tablealias, $value) { 110 global $DB; 111 112 static $i=0; 113 $i++; 114 $name = "df_menu_$i"; 115 $varcharcontent = $DB->sql_compare_text("{$tablealias}.content", 255); 116 117 return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name=>$value)); 118 } 119 120 /** 121 * Check if a field from an add form is empty 122 * 123 * @param mixed $value 124 * @param mixed $name 125 * @return bool 126 */ 127 function notemptyfield($value, $name) { 128 return strval($value) !== ''; 129 } 130 131 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |