From 4728968fc7237f5249124de99dfd0a8ec105cf81 Mon Sep 17 00:00:00 2001 From: vyshane Date: Wed, 1 Feb 2006 05:08:51 +0000 Subject: [PATCH] Checkbox field support --- mod/data/field/checkbox/field.class.php | 168 ++++++++++++++++++++++++ mod/data/field/checkbox/icon.gif | Bin 0 -> 159 bytes mod/data/field/checkbox/mod.html | 32 +++++ 3 files changed, 200 insertions(+) create mode 100755 mod/data/field/checkbox/field.class.php create mode 100755 mod/data/field/checkbox/icon.gif create mode 100755 mod/data/field/checkbox/mod.html diff --git a/mod/data/field/checkbox/field.class.php b/mod/data/field/checkbox/field.class.php new file mode 100755 index 00000000000..8b41569109c --- /dev/null +++ b/mod/data/field/checkbox/field.class.php @@ -0,0 +1,168 @@ +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 .= ''.$field->description.' '; + } + + foreach (explode("\n",$field->param1) as $checkbox) { + $checkbox = ltrim(rtrim($checkbox)); + $str .= ''; + } + 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_checkbox_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_checkbox_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_checkbox_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 . "
\n"; + } + return $str; + } + return false; + } +} +?> diff --git a/mod/data/field/checkbox/icon.gif b/mod/data/field/checkbox/icon.gif new file mode 100755 index 0000000000000000000000000000000000000000..e75b283b47ceeb92d5b688a6a70ac6c040d0bb05 GIT binary patch literal 159 zcmZ?wbhEHb6krfw*v!B%b0))?Gim?-&;0-Y%>Oep|DQSY|Nnmm28II%4gg6^p!k!8 zk%57OK?fuSGJ}D|N8qIA>b(}>2Y#MxFyv`ss1XxblXIa|$l%-;4VL*a@Af!6;D|l% u&cfBsGJoO`Z>xOEw8=lZ-*N48+!Vl@wKBvh{HoUGfc7m_d)-_Z7_0$8usFs5 literal 0 HcmV?d00001 diff --git a/mod/data/field/checkbox/mod.html b/mod/data/field/checkbox/mod.html new file mode 100755 index 00000000000..8ced798c079 --- /dev/null +++ b/mod/data/field/checkbox/mod.html @@ -0,0 +1,32 @@ +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + name()); ?> +
Name:
Description:
Options (Line Separated)
  + + +
+