mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Added multi-selection menu field support.
This commit is contained in:
parent
4728968fc7
commit
2c5c1418bb
3 changed files with 202 additions and 0 deletions
170
mod/data/field/multimenu/field.class.php
Executable file
170
mod/data/field/multimenu/field.class.php
Executable file
|
@ -0,0 +1,170 @@
|
||||||
|
<?php ///Class file for textarea field, extends base_field
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.org //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
|
||||||
|
// //
|
||||||
|
// This program is free software; you can redistribute it and/or modify //
|
||||||
|
// it under the terms of the GNU General Public License as published by //
|
||||||
|
// the Free Software Foundation; either version 2 of the License, or //
|
||||||
|
// (at your option) any later version. //
|
||||||
|
// //
|
||||||
|
// This program is distributed in the hope that it will be useful, //
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||||
|
// GNU General Public License for more details: //
|
||||||
|
// //
|
||||||
|
// http://www.gnu.org/copyleft/gpl.html //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// Please refer to lib.php for method comments
|
||||||
|
|
||||||
|
class data_field_multimenu extends data_field_base {
|
||||||
|
|
||||||
|
var $type = 'multimenu';
|
||||||
|
var $id;
|
||||||
|
|
||||||
|
|
||||||
|
function data_field_multimenu($fid=0){
|
||||||
|
parent::data_field_base($fid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************
|
||||||
|
* Saves the field into the database *
|
||||||
|
***********************************************/
|
||||||
|
function insert_field($dataid, $type='multimenu', $name, $desc='', $options='') {
|
||||||
|
$newfield = new object;
|
||||||
|
$newfield->dataid = $dataid;
|
||||||
|
$newfield->type = $type;
|
||||||
|
$newfield->name = $name;
|
||||||
|
$newfield->description = $desc;
|
||||||
|
$newfield->param1 = $options;
|
||||||
|
|
||||||
|
if (!insert_record('data_fields', $newfield)) {
|
||||||
|
notify('Insertion of new field failed!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************
|
||||||
|
* Prints the form element in the add template *
|
||||||
|
***********************************************/
|
||||||
|
function display_add_field($id, $rid=0) {
|
||||||
|
global $CFG;
|
||||||
|
if (!$field = get_record('data_fields', 'id', $id)){
|
||||||
|
notify('That is not a valid field id!');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if ($rid) {
|
||||||
|
$content = get_record('data_content', 'fieldid', $id, 'recordid', $rid);
|
||||||
|
if (isset($content->content)) {
|
||||||
|
$content = $content->content;
|
||||||
|
$content = explode('##', $content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$content = array();
|
||||||
|
}
|
||||||
|
$str = '';
|
||||||
|
|
||||||
|
if ($field->description) {
|
||||||
|
$str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'" /> ';
|
||||||
|
}
|
||||||
|
|
||||||
|
$str .= '<select name="field_' . $field->id . '[]" id="field_' . $field->id . '" multiple="multiple">';
|
||||||
|
|
||||||
|
foreach (explode("\n",$field->param1) as $option) {
|
||||||
|
$option = ltrim(rtrim($option));
|
||||||
|
$str .= '<option value="' . $option . '"';
|
||||||
|
|
||||||
|
if (array_search($option, $content) !== false) {
|
||||||
|
// Selected by user.
|
||||||
|
$str .= ' selected >';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$str .= '>';
|
||||||
|
}
|
||||||
|
$str .= $option . '</option>';
|
||||||
|
}
|
||||||
|
$str .= '</select>';
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function display_edit_field($id, $mode=0) {
|
||||||
|
parent::display_edit_field($id, $mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function update($fieldobject) {
|
||||||
|
$fieldobject->param2 = trim($fieldobject->param1);
|
||||||
|
|
||||||
|
if (!update_record('data_fields',$fieldobject)){
|
||||||
|
notify ('upate failed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function store_data_content($fieldid, $recordid, $value) {
|
||||||
|
$content = new object;
|
||||||
|
$content->fieldid = $fieldid;
|
||||||
|
$content->recordid = $recordid;
|
||||||
|
$content->content = $this->format_data_field_multimenu_content($value);
|
||||||
|
insert_record('data_content', $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function update_data_content($fieldid, $recordid, $value) {
|
||||||
|
$content = new object;
|
||||||
|
$content->fieldid = $fieldid;
|
||||||
|
$content->recordid = $recordid;
|
||||||
|
$content->content = $this->format_data_field_multimenu_content($value);
|
||||||
|
|
||||||
|
if ($oldcontent = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)) {
|
||||||
|
$content->id = $oldcontent->id;
|
||||||
|
update_record('data_content', $content);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->store_data_content($fieldid, $recordid, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function format_data_field_multimenu_content($contentArr) {
|
||||||
|
$str = '';
|
||||||
|
foreach ($contentArr as $val) {
|
||||||
|
$str .= $val . '##';
|
||||||
|
}
|
||||||
|
$str = substr($str, 0, -2);
|
||||||
|
$str = clean_param($str, PARAM_NOTAGS);
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function display_browse_field($fieldid, $recordid) {
|
||||||
|
global $CFG, $USER, $course;
|
||||||
|
|
||||||
|
$field = get_record('data_fields', 'id', $fieldid);
|
||||||
|
|
||||||
|
if ($content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){
|
||||||
|
$contentArr = array();
|
||||||
|
if (!empty($content->content)) {
|
||||||
|
$contentArr = explode('##', $content->content);
|
||||||
|
}
|
||||||
|
$str = '';
|
||||||
|
foreach ($contentArr as $line) {
|
||||||
|
$str .= $line . "<br />\n";
|
||||||
|
}
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
BIN
mod/data/field/multimenu/icon.gif
Executable file
BIN
mod/data/field/multimenu/icon.gif
Executable file
Binary file not shown.
After Width: | Height: | Size: 159 B |
32
mod/data/field/multimenu/mod.html
Executable file
32
mod/data/field/multimenu/mod.html
Executable file
|
@ -0,0 +1,32 @@
|
||||||
|
<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="POST">
|
||||||
|
<table width="100%">
|
||||||
|
<tr>
|
||||||
|
<td span="2">
|
||||||
|
<input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
|
||||||
|
<input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
|
||||||
|
<input type="hidden" name="type" value="<?php echo $this->type; ?>" />
|
||||||
|
<input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden">
|
||||||
|
<?php echo ($this->name()); ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Name:</td>
|
||||||
|
<td><input type="text" name="name" id="name" value="<?php echo($field->name); ?>" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Description:</td>
|
||||||
|
<td><input type="text" name="description" id="description" value="<?php echo($field->description); ?>" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Options (Line Separated)</td>
|
||||||
|
<td><textarea name="param1" id="param1"><?php if($field->param1) {echo $field->param1;} ?></textarea></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td> </td>
|
||||||
|
<td>
|
||||||
|
<input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" \>
|
||||||
|
<input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" \>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
Loading…
Add table
Add a link
Reference in a new issue