MDL-21227 - convert Feedback to new files api

This commit is contained in:
Andreas Grabs 2010-04-23 21:25:27 +00:00
parent aa1b682edf
commit a59ff6b085
10 changed files with 642 additions and 289 deletions

View file

@ -4,63 +4,72 @@ require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_captcha_form extends feedback_item_form {
var $type = "captcha";
var $requiredcheck;
var $itemname;
var $itemlabel;
var $select;
function definition() {
$item = $this->_customdata['item'];
$common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist'];
$position = $this->_customdata['position'];
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
$mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
$mform->addElement('text', 'name', get_string('item_name', 'feedback'), array('size="'.FEEDBACK_ITEM_NAME_TEXTBOX_SIZE.'"','maxlength="255"'));
$mform->addElement('text', 'label', get_string('item_label', 'feedback'), array('size="'.FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE.'"','maxlength="255"'));
$this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="'.FEEDBACK_ITEM_NAME_TEXTBOX_SIZE.'"','maxlength="255"'));
$this->itemlabel = $mform->addElement('text', 'itemlabel', get_string('item_label', 'feedback'), array('size="'.FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE.'"','maxlength="255"'));
$this->select = $mform->addElement('select',
'count_of_nums',
get_string('count_of_nums', 'feedback').' ',
array_slice(range(0,10),3,10,true));
$mform->addElement('select',
'presentation',
get_string('count_of_nums', 'feedback').' ',
array_slice(range(0,10),3,10,true));
////////////////////////////////////////////////////////////////////////
//the following is used in all itemforms
////////////////////////////////////////////////////////////////////////
$item = $this->_customdata['item'];
$common = $this->_customdata['common'];
$mform->addElement('hidden', 'cmid', $common['cmid']);
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'id', $common['id']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'typ', $common['typ']);
$mform->setType('typ', PARAM_ALPHA);
$mform->addElement('hidden', 'feedbackid', $common['feedbackid']);
$mform->setType('feedbackid', PARAM_INT);
$position_select = $mform->addElement('select',
'position',
get_string('position', 'feedback').' ',
$this->_customdata['positionlist']);
$position_select->setValue($this->_customdata['position']);
$positionlist);
$position_select->setValue($position);
$mform->addElement('hidden', 'cmid', $common['cmid']);
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'id', $common['id']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'feedback', $common['feedback']);
$mform->setType('feedback', PARAM_INT);
$mform->addElement('hidden', 'template', 0);
$mform->setType('template', PARAM_INT);
$mform->addElement('hidden', 'name', 'label');
$mform->setType('template', PARAM_ALPHA);
$mform->addElement('hidden', 'label', '-');
$mform->setType('label', PARAM_ALPHA);
$mform->addElement('hidden', 'typ', $this->type);
$mform->setType('typ', PARAM_ALPHA);
$mform->addElement('hidden', 'hasvalue', 0);
$mform->setType('hasvalue', PARAM_INT);
$buttonarray = array();
if(!empty($item->id)){
$mform->addElement('hidden', 'updateitem', '1');
$mform->setType('updateitem', PARAM_INT);
// $i_form->addElement('submit', 'update_item', get_string('update_item', 'feedback'));
$buttonarray[] = &$mform->createElement('submit', 'update_item', get_string('update_item', 'feedback'));
}else{
$mform->addElement('hidden', 'saveitem', '1');
$mform->setType('saveitem', PARAM_INT);
// $i_form->addElement('submit', 'save_item', get_string('save_item', 'feedback'));
$buttonarray[] = &$mform->createElement('submit', 'save_item', get_string('save_item', 'feedback'));
}
// $i_form->addElement('cancel');
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', ' ', array(' '), false);
$this->set_data($item);
}
}

View file

@ -4,41 +4,74 @@ require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_captcha extends feedback_item_base {
var $type = "captcha";
var $commonparams;
var $item_form;
var $item;
function init() {
}
/**
* Build the editform for the item
*
* @global object
* @param object $item the instance of the recordset feedback_item
* @param array $commonparams all hidden values needed in the form
* @param array $positionlist this array build the selection list for itemposition
* @param int $position the current itemposition
* @return object instance of the built form
*/
function show_edit($item, $commonparams, $positionlist, $position) {
global $CFG;
function build_editform($item, $feedback, $cm) {
global $DB, $CFG;
require_once('captcha_form.php');
$item_form = new feedback_captcha_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position));
$item->presentation = empty($item->presentation) ? 3 : $item->presentation;
$item->name = empty($item->name) ? '' : $item->name;
$item->label = empty($item->label) ? '' : $item->label;
$item->required = isset($item->required) ? $item->required : 1;
if($item->required) {
$item_form->requiredcheck->setValue(true);
//get the lastposition number of the feedback_items
$position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){
$i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1;
}else {
$i_formselect_last = $lastposition;
$i_formselect_value = $item->position;
}
//the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true);
$item->presentation = empty($item->presentation) ? 3 : $item->presentation;
$item->required = 1;
$item_form->itemname->setValue($item->name);
$item_form->itemlabel->setValue($item->label);
$commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL,
'typ'=>$item->typ,
'feedback'=>$feedback->id);
$item_form->select->setValue($item->presentation);
return $item_form;
//build the form
$this->item_form = new feedback_captcha_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position));
}
//this function only can used after the call of build_editform()
function show_editform() {
$this->item_form->display();
}
function is_cancelled() {
return $this->item_form->is_cancelled();
}
function get_data() {
if($this->item = $this->item_form->get_data()) {
return true;
}
return false;
}
function save_item() {
global $DB;
if(!$item = $this->item_form->get_data()) {
return false;
}
if(!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item);
}else {
$DB->update_record('feedback_item', $item);
}
return $DB->get_record('feedback_item', array('id'=>$item->id));
}
//liefert eine Struktur ->name, ->data = array(mit Antworten)

View file

@ -4,65 +4,74 @@ require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_info_form extends feedback_item_form {
var $type = "info";
var $requiredcheck;
var $itemname;
var $itemlabel;
var $infotype;
function definition() {
$item = $this->_customdata['item'];
$common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist'];
$position = $this->_customdata['position'];
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$this->requiredcheck = &$mform->addElement('hidden', 'required');
$mform->addElement('hidden', 'required', 0);
$mform->setType('required', PARAM_INT);
$this->itemname = &$mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="'.FEEDBACK_ITEM_NAME_TEXTBOX_SIZE.'"','maxlength="255"'));
$this->itemlabel = $mform->addElement('text', 'itemlabel', get_string('item_label', 'feedback'), array('size="'.FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE.'"','maxlength="255"'));
$mform->addElement('text', 'name', get_string('item_name', 'feedback'), array('size="'.FEEDBACK_ITEM_NAME_TEXTBOX_SIZE.'"','maxlength="255"'));
$mform->addElement('text', 'label', get_string('item_label', 'feedback'), array('size="'.FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE.'"','maxlength="255"'));
$options=array();
$options[1] = get_string('responsetime', 'feedback');
$options[2] = get_string('coursename', 'feedback');
$options[3] = get_string('coursecategory', 'feedback');
$this->infotype = &$mform->addElement('select', 'infotype', get_string('infotype', 'feedback'), $options);
$this->infotype = &$mform->addElement('select', 'presentation', get_string('infotype', 'feedback'), $options);
////////////////////////////////////////////////////////////////////////
//the following is used in all itemforms
////////////////////////////////////////////////////////////////////////
$item = $this->_customdata['item'];
$common = $this->_customdata['common'];
$mform->addElement('hidden', 'cmid', $common['cmid']);
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'id', $common['id']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'typ', $common['typ']);
$mform->setType('typ', PARAM_ALPHA);
$mform->addElement('hidden', 'feedbackid', $common['feedbackid']);
$mform->setType('feedbackid', PARAM_INT);
$position_select = $mform->addElement('select',
'position',
get_string('position', 'feedback').' ',
$this->_customdata['positionlist']);
$position_select->setValue($this->_customdata['position']);
$positionlist);
$position_select->setValue($position);
$mform->addElement('hidden', 'cmid', $common['cmid']);
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'id', $common['id']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'feedback', $common['feedback']);
$mform->setType('feedback', PARAM_INT);
$mform->addElement('hidden', 'template', 0);
$mform->setType('template', PARAM_INT);
$mform->addElement('hidden', 'name', 'label');
$mform->setType('template', PARAM_ALPHA);
$mform->addElement('hidden', 'label', '-');
$mform->setType('label', PARAM_ALPHA);
$mform->addElement('hidden', 'typ', $this->type);
$mform->setType('typ', PARAM_ALPHA);
$mform->addElement('hidden', 'hasvalue', 0);
$mform->setType('hasvalue', PARAM_INT);
$buttonarray = array();
if(!empty($item->id)){
$mform->addElement('hidden', 'updateitem', '1');
$mform->setType('updateitem', PARAM_INT);
// $i_form->addElement('submit', 'update_item', get_string('update_item', 'feedback'));
$buttonarray[] = &$mform->createElement('submit', 'update_item', get_string('update_item', 'feedback'));
}else{
$mform->addElement('hidden', 'saveitem', '1');
$mform->setType('saveitem', PARAM_INT);
// $i_form->addElement('submit', 'save_item', get_string('save_item', 'feedback'));
$buttonarray[] = &$mform->createElement('submit', 'save_item', get_string('save_item', 'feedback'));
}
// $i_form->addElement('cancel');
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', ' ', array(' '), false);
$this->set_data($item);
}
}

View file

@ -4,29 +4,74 @@ require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_info extends feedback_item_base {
var $type = "info";
var $commonparams;
var $item_form;
var $item;
function init() {
}
function show_edit($item, $commonparams, $positionlist, $position) {
global $CFG;
function build_editform($item, $feedback, $cm) {
global $DB, $CFG;
require_once('info_form.php');
$item_form = new feedback_info_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position));
//get the lastposition number of the feedback_items
$position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){
$i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1;
}else {
$i_formselect_last = $lastposition;
$i_formselect_value = $item->position;
}
//the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true);
$item->presentation = empty($item->presentation) ? 1 : $item->presentation;
$item->required = 0;
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
$item->name = empty($item->name) ? '' : htmlspecialchars($item->name);
$item->label = empty($item->label) ? '' : $item->label;
$commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL,
'typ'=>$item->typ,
'feedback'=>$feedback->id);
$item_form->requiredcheck->setValue(false);
//build the form
$this->item_form = new feedback_info_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position));
}
$item_form->itemname->setValue($item->name);
$item_form->itemlabel->setValue($item->label);
//this function only can used after the call of build_editform()
function show_editform() {
$this->item_form->display();
}
function is_cancelled() {
return $this->item_form->is_cancelled();
}
$item_form->infotype->setValue($item->presentation);
function get_data() {
if($this->item = $this->item_form->get_data()) {
return true;
}
return false;
}
return $item_form;
function save_item() {
global $DB;
if(!$item = $this->item_form->get_data()) {
return false;
}
if(!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item);
}else {
$DB->update_record('feedback_item', $item);
}
return $DB->get_record('feedback_item', array('id'=>$item->id));
}
//liefert eine Struktur ->name, ->data = array(mit Antworten)

View file

@ -7,69 +7,72 @@ class feedback_label_form extends feedback_item_form {
var $area;
function definition() {
global $CFG;
$item = $this->_customdata['item'];
$common = $this->_customdata['common'];
$presentationoptions = $this->_customdata['presentationoptions'];
$positionlist = $this->_customdata['positionlist'];
$position = $this->_customdata['position'];
$context = get_context_instance(CONTEXT_MODULE, $common['cmid']);
$mform =& $this->_form;
$mform->addElement('hidden', 'required', 0);
$mform->setType('required', PARAM_INT);
$mform->addElement('hidden', 'name', 'label');
$mform->setType('template', PARAM_ALPHA);
$mform->addElement('hidden', 'label', '-');
$mform->setType('label', PARAM_ALPHA);
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$mform->addElement('hidden', 'itemname', $this->type);
$mform->setType('itemname', PARAM_INT);
$mform->addElement('editor', 'presentation', '', null, null);
$mform->setType('presentation', PARAM_CLEANHTML);
$mform->addElement('editor', 'presentation_editor', '', null, $presentationoptions);
$mform->setType('presentation_editor', PARAM_CLEANHTML);
////////////////////////////////////////////////////////////////////////
//the following is used in all itemforms
////////////////////////////////////////////////////////////////////////
$item = $this->_customdata['item'];
$common = $this->_customdata['common'];
$mform->addElement('hidden', 'cmid', $common['cmid']);
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'id', $common['id']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'typ', $common['typ']);
$mform->setType('typ', PARAM_ALPHA);
$mform->addElement('hidden', 'feedbackid', $common['feedbackid']);
$mform->setType('feedbackid', PARAM_INT);
$position_select = $mform->addElement('select',
'position',
get_string('position', 'feedback').' ',
$this->_customdata['positionlist']);
$position_select->setValue($this->_customdata['position']);
$positionlist);
$position_select->setValue($position);
$mform->addElement('hidden', 'cmid', $common['cmid']);
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'id', $common['id']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'feedback', $common['feedback']);
$mform->setType('feedback', PARAM_INT);
$mform->addElement('hidden', 'template', 0);
$mform->setType('template', PARAM_INT);
$mform->addElement('hidden', 'typ', $this->type);
$mform->setType('typ', PARAM_ALPHA);
$mform->addElement('hidden', 'hasvalue', 0);
$mform->setType('hasvalue', PARAM_INT);
$buttonarray = array();
if(!empty($item->id)){
$mform->addElement('hidden', 'updateitem', '1');
$mform->setType('updateitem', PARAM_INT);
// $i_form->addElement('submit', 'update_item', get_string('update_item', 'feedback'));
$buttonarray[] = &$mform->createElement('submit', 'update_item', get_string('update_item', 'feedback'));
}else{
$mform->addElement('hidden', 'saveitem', '1');
$mform->setType('saveitem', PARAM_INT);
// $i_form->addElement('submit', 'save_item', get_string('save_item', 'feedback'));
$buttonarray[] = &$mform->createElement('submit', 'save_item', get_string('save_item', 'feedback'));
}
// $i_form->addElement('cancel');
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', ' ', array(' '), false);
$this->set_data($item);
}
function get_data() {
$data = parent::get_data();
if ($data) {
$data->presentation = $data->presentation['text'];
}
return $data;
}
function set_data($data) {
if(isset($data->presentation)) {
$data->presentation = array('text'=>$data->presentation, 'format'=>FORMAT_HTML, 'itemid'=>0);
}
return parent::set_data($data);
}
}

View file

@ -4,24 +4,113 @@ require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_label extends feedback_item_base {
var $type = "label";
var $presentationoptions = null;
var $commonparams;
var $item_form;
var $context;
var $item;
function init() {
global $CFG;
$this->presentationoptions = array('trusttext'=>true, 'subdirs'=>false, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true);
}
function show_edit($item, $commonparams, $positionlist, $position) {
global $CFG;
function build_editform($item, $feedback, $cm) {
global $DB, $CFG;
require_once('label_form.php');
$item_form = new feedback_label_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position));
//get the lastposition number of the feedback_items
$position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){
$i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1;
}else {
$i_formselect_last = $lastposition;
$i_formselect_value = $item->position;
}
//the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true);
$commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL,
'typ'=>$item->typ,
'feedback'=>$feedback->id);
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
return $item_form;
//preparing the editor for new file-api
$item->presentationformat = FORMAT_HTML;
$item->presentationtrust = 1;
$item = file_prepare_standard_editor($item,
'presentation', //name of the form element
$this->presentationoptions,
$this->context,
'feedback_item', //the filearea
$item->id);
//build the form
$this->item_form = new feedback_label_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position, 'presentationoptions'=>$this->presentationoptions));
}
//this function only can used after the call of build_editform()
function show_editform() {
$this->item_form->display();
}
function is_cancelled() {
return $this->item_form->is_cancelled();
}
function get_data() {
if($this->item = $this->item_form->get_data()) {
return true;
}
return false;
}
function save_item() {
global $DB;
if(!$item = $this->item_form->get_data()) {
return false;
}
$item->presentation = '';
if(!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item);
}else {
$DB->update_record('feedback_item', $item);
}
$item = file_postupdate_standard_editor($item,
'presentation',
$this->presentationoptions,
$this->context,
'feedback_item',
$item->id);
$DB->update_record('feedback_item', $item);
return $DB->get_record('feedback_item', array('id'=>$item->id));
}
function print_item($item){
global $DB;
$cm = get_coursemodule_from_instance('feedback', $item->feedback);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$item->presentationformat = FORMAT_HTML;
$item->presentationtrust = 1;
?>
<td colspan="2">
<?php echo format_text($item->presentation, FORMAT_HTML);?>
<?php
$output = file_rewrite_pluginfile_urls($item->presentation, 'pluginfile.php', $context->id,'feedback_item',$item->id);
echo format_text($output, FORMAT_HTML);
?>
</td>
<?php
}
@ -69,9 +158,34 @@ class feedback_item_label extends feedback_item_base {
//used by create_item and update_item functions,
//when provided $data submitted from feedback_show_edit
function get_presentation($data) {
return $data->presentation;
// $context = get_context_instance(CONTEXT_MODULE, $data->cmid);
// $presentation = new object();
// $presentation->id = null;
// $presentation->definition = '';
// $presentation->format = FORMAT_HTML;
// $draftid_editor = file_get_submitted_draft_itemid('presentation');
// $currenttext = file_prepare_draft_area($draftid_editor, $context->id, 'feedback_item_label', $presentation->id, array('subdirs'=>true), $presentation->definition);
// $presentation->entry = array('text'=>$currenttext, 'format'=>$presentation->format, 'itemid'=>$draftid_editor);
// return $data->presentation;
}
function postupdate($item) {
global $DB;
$context = get_context_instance(CONTEXT_MODULE, $item->cmid);
$item = file_postupdate_standard_editor($item, 'presentation', $this->presentationoptions, $context, 'feedback_item', $item->id);
// $item = new object();
// $item->id = $data->id
if($DB->update_record('feedback_item', $item)) {
return $item->id;
}
return false;
}
function get_hasvalue() {
return 0;
}

View file

@ -8,10 +8,76 @@ define('FEEDBACK_MULTICHOICE_ADJUST_SEP', '<<<<<');
class feedback_item_multichoice extends feedback_item_base {
var $type = "multichoice";
var $commonparams;
var $item_form;
var $item;
function init() {
}
function build_editform($item, $feedback, $cm) {
global $DB, $CFG;
require_once('multichoice_form.php');
//get the lastposition number of the feedback_items
$position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){
$i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1;
}else {
$i_formselect_last = $lastposition;
$i_formselect_value = $item->position;
}
//the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true);
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
$info = $this->get_info($item);
$commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL,
'typ'=>$item->typ,
'feedback'=>$feedback->id);
//build the form
$this->item_form = new feedback_multichoice_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position, 'info'=>$info));
}
//this function only can used after the call of build_editform()
function show_editform() {
$this->item_form->display();
}
function is_cancelled() {
return $this->item_form->is_cancelled();
}
function get_data() {
if($this->item = $this->item_form->get_data()) {
return true;
}
return false;
}
function save_item() {
global $DB;
if(!$item = $this->item_form->get_data()) {
return false;
}
if(!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item);
}else {
$DB->update_record('feedback_item', $item);
}
return $DB->get_record('feedback_item', array('id'=>$item->id));
}
function show_edit($item, $commonparams, $positionlist, $position) {
global $CFG;

View file

@ -12,70 +12,116 @@ class feedback_multichoice_form extends feedback_item_form {
var $values;
function definition() {
$item = $this->_customdata['item'];
$common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist'];
$position = $this->_customdata['position'];
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
$mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
$this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="'.FEEDBACK_ITEM_NAME_TEXTBOX_SIZE.'"','maxlength="255"'));
$this->itemlabel = $mform->addElement('text', 'itemlabel', get_string('item_label', 'feedback'), array('size="'.FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE.'"','maxlength="255"'));
$mform->addElement('text', 'name', get_string('item_name', 'feedback'), array('size="'.FEEDBACK_ITEM_NAME_TEXTBOX_SIZE.'"','maxlength="255"'));
$mform->addElement('text', 'label', get_string('item_label', 'feedback'), array('size="'.FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE.'"','maxlength="255"'));
$this->selectadjust = $mform->addElement('select',
'horizontal',
get_string('adjustment', 'feedback').'&nbsp;',
array(0 => get_string('vertical', 'feedback'), 1 => get_string('horizontal', 'feedback')));
$mform->addElement('select',
'horizontal',
get_string('adjustment', 'feedback').'&nbsp;',
array(0 => get_string('vertical', 'feedback'), 1 => get_string('horizontal', 'feedback')));
$this->selecttype = $mform->addElement('select',
'subtype',
get_string('multichoicetype', 'feedback').'&nbsp;',
array('r'=>get_string('radio', 'feedback'),
'c'=>get_string('check', 'feedback'),
'd'=>get_string('dropdown', 'feedback')));
$mform->addElement('select',
'subtype',
get_string('multichoicetype', 'feedback').'&nbsp;',
array('r'=>get_string('radio', 'feedback'),
'c'=>get_string('check', 'feedback'),
'd'=>get_string('dropdown', 'feedback')));
$mform->addElement('static', 'hint', get_string('multichoice_values', 'feedback'), get_string('use_one_line_for_each_value', 'feedback'));
$this->values = $mform->addElement('textarea', 'itemvalues', '', 'wrap="virtual" rows="10" cols="65"');
$mform->addElement('textarea', 'values', '', 'wrap="virtual" rows="10" cols="65"');
////////////////////////////////////////////////////////////////////////
//the following is used in all itemforms
////////////////////////////////////////////////////////////////////////
$item = $this->_customdata['item'];
$common = $this->_customdata['common'];
$mform->addElement('hidden', 'cmid', $common['cmid']);
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'id', $common['id']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'typ', $common['typ']);
$mform->setType('typ', PARAM_ALPHA);
$mform->addElement('hidden', 'feedbackid', $common['feedbackid']);
$mform->setType('feedbackid', PARAM_INT);
$position_select = $mform->addElement('select',
'position',
get_string('position', 'feedback').'&nbsp;',
$this->_customdata['positionlist']);
$position_select->setValue($this->_customdata['position']);
$positionlist);
$position_select->setValue($position);
$mform->addElement('hidden', 'cmid', $common['cmid']);
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'id', $common['id']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'feedback', $common['feedback']);
$mform->setType('feedback', PARAM_INT);
$mform->addElement('hidden', 'template', 0);
$mform->setType('template', PARAM_INT);
$mform->addElement('hidden', 'name', 'label');
$mform->setType('template', PARAM_ALPHA);
$mform->addElement('hidden', 'label', '-');
$mform->setType('label', PARAM_ALPHA);
$mform->addElement('hidden', 'typ', $this->type);
$mform->setType('typ', PARAM_ALPHA);
$mform->addElement('hidden', 'hasvalue', 0);
$mform->setType('hasvalue', PARAM_INT);
$buttonarray = array();
if(!empty($item->id)){
$mform->addElement('hidden', 'updateitem', '1');
$mform->setType('updateitem', PARAM_INT);
// $i_form->addElement('submit', 'update_item', get_string('update_item', 'feedback'));
$buttonarray[] = &$mform->createElement('submit', 'update_item', get_string('update_item', 'feedback'));
}else{
$mform->addElement('hidden', 'saveitem', '1');
$mform->setType('saveitem', PARAM_INT);
// $i_form->addElement('submit', 'save_item', get_string('save_item', 'feedback'));
$buttonarray[] = &$mform->createElement('submit', 'save_item', get_string('save_item', 'feedback'));
}
// $i_form->addElement('cancel');
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '&nbsp;', array(' '), false);
$this->set_data($item);
}
function set_data($item) {
$info = $this->_customdata['info'];
$item->horizontal = $info->horizontal;
$item->subtype = $info->subtype;
$itemvalues = str_replace(FEEDBACK_MULTICHOICE_LINE_SEP, "\n", $info->presentation);
$itemvalues = str_replace("\n\n", "\n", $itemvalues);
$item->values = $itemvalues;
return parent::set_data($item);
}
function get_data() {
if(!$item = parent::get_data()) {
return false;
}
$presentation = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($item->values));
if(!isset($item->subtype)) {
$subtype = 'r';
}else {
$subtype = substr($item->subtype, 0, 1);
}
if(isset($item->horizontal) AND $item->horizontal == 1 AND $subtype != 'd') {
$presentation .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1';
}
$item->presentation = $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$presentation;
return $item;
}
}