mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
MDL-21227 - convert Feedback to new files api
This commit is contained in:
parent
aa1b682edf
commit
a59ff6b085
10 changed files with 642 additions and 289 deletions
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue