mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +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
|
@ -17,6 +17,7 @@ feedback_init_feedback_session();
|
|||
$cmid = required_param('cmid', PARAM_INT);
|
||||
$typ = optional_param('typ', false, PARAM_ALPHA);
|
||||
$id = optional_param('id', false, PARAM_INT);
|
||||
$action = optional_param('action', false, PARAM_ALPHA);
|
||||
|
||||
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cmid));
|
||||
|
||||
|
@ -70,16 +71,14 @@ if($typ == 'pagebreak') {
|
|||
// $formdata->itemid = isset($formdata->itemid) ? $formdata->itemid : NULL;
|
||||
if($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) {
|
||||
$typ = $item->typ;
|
||||
$position = $item->position;
|
||||
}else {
|
||||
$position = -1;
|
||||
$item = new stdClass();
|
||||
if ($position == '') {
|
||||
$position = 0;
|
||||
}
|
||||
$item->id = null;
|
||||
$item->position = -1;
|
||||
if (!$typ) {
|
||||
print_error('typemissing', 'feedback', $editurl->out(false));
|
||||
}
|
||||
$item->typ = $typ;
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/mod/feedback/item/'.$typ.'/lib.php');
|
||||
|
@ -87,55 +86,19 @@ require_once($CFG->dirroot.'/mod/feedback/item/'.$typ.'/lib.php');
|
|||
$itemclass = 'feedback_item_'.$typ;
|
||||
$itemobj = new $itemclass();
|
||||
|
||||
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
|
||||
if($position == -1){
|
||||
$i_formselect_last = $lastposition + 1;
|
||||
$i_formselect_value = $lastposition + 1;
|
||||
}else {
|
||||
$i_formselect_last = $lastposition;
|
||||
$i_formselect_value = $item->position;
|
||||
$itemobj->build_editform($item, $feedback, $cm);
|
||||
|
||||
if($itemobj->is_cancelled()) {
|
||||
redirect($editurl->out(false));
|
||||
exit;
|
||||
}
|
||||
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true);
|
||||
|
||||
$commonarams = array('cmid'=>$cmid,
|
||||
'id'=>isset($item->id) ? $item->id : NULL,
|
||||
'typ'=>$typ,
|
||||
'feedbackid'=>$feedback->id);
|
||||
|
||||
$item_form = &$itemobj->show_edit($item, $commonarams, $positionlist, $i_formselect_value);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
$item_form->set_data($item);
|
||||
if ($formdata = $item_form->get_data()) {
|
||||
if (isset($formdata->cancel)){
|
||||
if($itemobj->get_data()) {
|
||||
if($item = $itemobj->save_item()) {
|
||||
feedback_move_item($item, $item->position);
|
||||
redirect($editurl->out(false));
|
||||
} else if (isset($formdata->saveitem) AND $formdata->saveitem == 1) {
|
||||
$newposition = $formdata->position;
|
||||
$formdata->position = $newposition + 1;
|
||||
|
||||
if (!$newitemid = feedback_create_item($formdata)) {
|
||||
$SESSION->feedback->errors[] = get_string('item_creation_failed', 'feedback');
|
||||
}else {
|
||||
$newitem = $DB->get_record('feedback_item', array('id'=>$newitemid));
|
||||
if (!feedback_move_item($newitem, $newposition)){
|
||||
$SESSION->feedback->errors[] = get_string('item_creation_failed', 'feedback');
|
||||
}else {
|
||||
redirect($editurl->out(false));
|
||||
}
|
||||
}
|
||||
} else if (isset($formdata->updateitem) AND $formdata->updateitem == 1) {
|
||||
//update the item and go back
|
||||
if (!feedback_update_item($item, $formdata)) {
|
||||
$SESSION->feedback->errors[] = get_string('item_update_failed', 'feedback');
|
||||
} else {
|
||||
if (!feedback_move_item($item, $formdata->position)){
|
||||
$SESSION->feedback->errors[] = get_string('item_update_failed', 'feedback');
|
||||
}else {
|
||||
redirect($editurl->out(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Print the page header
|
||||
$strfeedbacks = get_string("modulenameplural", "feedback");
|
||||
|
@ -155,7 +118,7 @@ if(isset($error)) {
|
|||
echo $error;
|
||||
}
|
||||
feedback_print_errors();
|
||||
$item_form->display();
|
||||
$itemobj->show_editform();
|
||||
|
||||
/*
|
||||
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
|
||||
|
|
|
@ -4,64 +4,73 @@ 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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
//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->name = empty($item->name) ? '' : $item->name;
|
||||
$item->label = empty($item->label) ? '' : $item->label;
|
||||
$item->required = 1;
|
||||
|
||||
$item->required = isset($item->required) ? $item->required : 1;
|
||||
if($item->required) {
|
||||
$item_form->requiredcheck->setValue(true);
|
||||
$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_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;
|
||||
}
|
||||
|
||||
$item_form->itemname->setValue($item->name);
|
||||
$item_form->itemlabel->setValue($item->label);
|
||||
if(!$item->id) {
|
||||
$item->id = $DB->insert_record('feedback_item', $item);
|
||||
}else {
|
||||
$DB->update_record('feedback_item', $item);
|
||||
}
|
||||
|
||||
$item_form->select->setValue($item->presentation);
|
||||
return $item_form;
|
||||
return $DB->get_record('feedback_item', array('id'=>$item->id));
|
||||
}
|
||||
|
||||
//liefert eine Struktur ->name, ->data = array(mit Antworten)
|
||||
|
|
|
@ -4,66 +4,75 @@ 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) ? '' : $item->presentation;
|
||||
$item->name = empty($item->name) ? '' : htmlspecialchars($item->name);
|
||||
$item->label = empty($item->label) ? '' : $item->label;
|
||||
$item->presentation = empty($item->presentation) ? 1 : $item->presentation;
|
||||
$item->required = 0;
|
||||
|
||||
$item_form->requiredcheck->setValue(false);
|
||||
$commonparams = array('cmid'=>$cm->id,
|
||||
'id'=>isset($item->id) ? $item->id : NULL,
|
||||
'typ'=>$item->typ,
|
||||
'feedback'=>$feedback->id);
|
||||
|
||||
$item_form->itemname->setValue($item->name);
|
||||
$item_form->itemlabel->setValue($item->label);
|
||||
//build the form
|
||||
$this->item_form = new feedback_info_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position));
|
||||
}
|
||||
|
||||
$item_form->infotype->setValue($item->presentation);
|
||||
//this function only can used after the call of build_editform()
|
||||
function show_editform() {
|
||||
$this->item_form->display();
|
||||
}
|
||||
|
||||
return $item_form;
|
||||
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)
|
||||
|
|
|
@ -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('header', 'general', get_string($this->type, 'feedback'));
|
||||
$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('hidden', 'itemname', $this->type);
|
||||
$mform->setType('itemname', PARAM_INT);
|
||||
$mform->addElement('editor', 'presentation', '', null, null);
|
||||
$mform->setType('presentation', PARAM_CLEANHTML);
|
||||
|
||||
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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";
|
||||
function init() {
|
||||
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);
|
||||
|
||||
return $item_form;
|
||||
$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);
|
||||
|
||||
|
||||
//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,7 +158,32 @@ 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() {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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').' ',
|
||||
array(0 => get_string('vertical', 'feedback'), 1 => get_string('horizontal', 'feedback')));
|
||||
$mform->addElement('select',
|
||||
'horizontal',
|
||||
get_string('adjustment', 'feedback').' ',
|
||||
array(0 => get_string('vertical', 'feedback'), 1 => get_string('horizontal', 'feedback')));
|
||||
|
||||
$this->selecttype = $mform->addElement('select',
|
||||
'subtype',
|
||||
get_string('multichoicetype', 'feedback').' ',
|
||||
array('r'=>get_string('radio', 'feedback'),
|
||||
'c'=>get_string('check', 'feedback'),
|
||||
'd'=>get_string('dropdown', 'feedback')));
|
||||
$mform->addElement('select',
|
||||
'subtype',
|
||||
get_string('multichoicetype', 'feedback').' ',
|
||||
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').' ',
|
||||
$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);
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -132,6 +132,67 @@ function feedback_update_instance($feedback) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves the files included in feedback items like label. Implements needed access control ;-)
|
||||
*
|
||||
* @param object $course
|
||||
* @param object $cminfo
|
||||
* @param object $context
|
||||
* @param string $filearea
|
||||
* @param array $args
|
||||
* @param bool $forcedownload
|
||||
* @return bool false if file not found, does not return if found - justsend the file
|
||||
*/
|
||||
function feedback_pluginfile($course, $cminfo, $context, $filearea, $args, $forcedownload) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (!$cminfo->uservisible) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($filearea === 'feedback_item') {
|
||||
$itemid = (int)array_shift($args);
|
||||
|
||||
if (!$cm = get_coursemodule_from_instance('feedback', $cminfo->instance, $course->id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
require_course_login($course, true, $cm);
|
||||
|
||||
if (!$item = $DB->get_record('feedback_item', array('id'=>$itemid))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$feedback = $DB->get_record('feedback', array('id'=>$cminfo->instance))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!has_capability('mod/feedback:view', $context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($item->feedback == $cminfo->instance) {
|
||||
$filecontext = $context;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$relativepath = '/'.implode('/', $args);
|
||||
$fullpath = $filecontext->id.$filearea.$itemid.$relativepath;
|
||||
|
||||
$fs = get_file_storage();
|
||||
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// finally send the file
|
||||
send_stored_file($file, 0, 0, true); // download MUST be forced - security!
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this will delete a given instance.
|
||||
* all referenced data also will be deleted
|
||||
|
@ -748,7 +809,7 @@ function feedback_save_as_template($feedback, $name, $ispublic = 0) {
|
|||
unset($item->id);
|
||||
$item->feedback = 0;
|
||||
$item->template = $newtempl;
|
||||
$DB->insert_record('feedback_item', $nitem);
|
||||
$DB->insert_record('feedback_item', $item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -917,7 +978,8 @@ function feedback_create_item($data) {
|
|||
$itemclass = 'feedback_item_'.$data->typ;
|
||||
//get the instance of the item class
|
||||
$itemobj = new $itemclass();
|
||||
$item->presentation = $itemobj->get_presentation($data);
|
||||
// $item->presentation = $itemobj->get_presentation($data);
|
||||
$item->presentation = ''; //the date comes from postupdate() of the itemobj
|
||||
|
||||
$item->hasvalue = $itemobj->get_hasvalue();
|
||||
|
||||
|
@ -929,7 +991,15 @@ function feedback_create_item($data) {
|
|||
$item->required = $data->required;
|
||||
}
|
||||
|
||||
return $DB->insert_record('feedback_item', $item);
|
||||
$item->id = $DB->insert_record('feedback_item', $item);
|
||||
|
||||
//move all itemdata to the data
|
||||
$data->id = $item->id;
|
||||
$data->feedback = $item->feedback;
|
||||
$data->name = $item->name;
|
||||
$data->label = $item->label;
|
||||
$data->required = $item->required;
|
||||
return $itemobj->postupdate($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -940,34 +1010,8 @@ function feedback_create_item($data) {
|
|||
* @param object $data the data from edit_item_form
|
||||
* @return boolean
|
||||
*/
|
||||
function feedback_update_item($item, $data = null){
|
||||
function feedback_update_item($item){
|
||||
global $DB;
|
||||
|
||||
if($data != null){
|
||||
$itemname = trim($data->itemname);
|
||||
$item->name = ($itemname ? $data->itemname : get_string('no_itemname', 'feedback'));
|
||||
|
||||
if (!empty($data->itemlabel)) {
|
||||
$item->label = trim($data->itemlabel);
|
||||
} else {
|
||||
$item->label = get_string('no_itemlabel', 'feedback');
|
||||
}
|
||||
|
||||
//get the used class from item-typ
|
||||
$itemclass = 'feedback_item_'.$data->typ;
|
||||
//get the instance of the item class
|
||||
$itemobj = new $itemclass();
|
||||
$item->presentation = $itemobj->get_presentation($data);
|
||||
|
||||
$item->required=0;
|
||||
if (isset($data->required)) {
|
||||
$item->required=$data->required;
|
||||
}
|
||||
}else {
|
||||
$item->name = $item->name;
|
||||
$item->presentation = $item->presentation;
|
||||
}
|
||||
|
||||
return $DB->update_record("feedback_item", $item);
|
||||
}
|
||||
|
||||
|
@ -1062,12 +1106,30 @@ function feedback_renumber_items($feedbackid){
|
|||
function feedback_moveup_item($item){
|
||||
global $DB;
|
||||
|
||||
if($item->position == 1) return;
|
||||
$item_before = $DB->get_record('feedback_item', array('feedback'=>$item->feedback, 'position'=>$item->position-1));
|
||||
$item_before->position = $item->position;
|
||||
$item->position--;
|
||||
feedback_update_item($item_before);
|
||||
feedback_update_item($item);
|
||||
if($item->position == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!$items = $DB->get_records('feedback_item', array('feedback'=>$item->feedback), 'position')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$itembefore = null;
|
||||
foreach($items as $i) {
|
||||
if($i->id == $item->id) {
|
||||
if(is_null($itembefore)) {
|
||||
return true;
|
||||
}
|
||||
$itembefore->position = $item->position;
|
||||
$item->position--;
|
||||
feedback_update_item($itembefore);
|
||||
feedback_update_item($item);
|
||||
feedback_renumber_items($item->feedback);
|
||||
return true;
|
||||
}
|
||||
$itembefore = $i;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1080,14 +1142,23 @@ function feedback_moveup_item($item){
|
|||
function feedback_movedown_item($item){
|
||||
global $DB;
|
||||
|
||||
if(!$item_after = $DB->get_record('feedback_item', array('feedback'=>$item->feedback, 'position'=>$item->position+1))) {
|
||||
return;
|
||||
if(!$items = $DB->get_records('feedback_item', array('feedback'=>$item->feedback), 'position')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$item_after->position = $item->position;
|
||||
$item->position++;
|
||||
feedback_update_item($item_after);
|
||||
feedback_update_item($item);
|
||||
$movedownitem = null;
|
||||
foreach($items as $i) {
|
||||
if(!is_null($movedownitem) AND $movedownitem->id == $item->id) {
|
||||
$movedownitem->position = $i->position;
|
||||
$i->position--;
|
||||
feedback_update_item($movedownitem);
|
||||
feedback_update_item($i);
|
||||
feedback_renumber_items($item->feedback);
|
||||
return true;
|
||||
}
|
||||
$movedownitem = $i;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1101,30 +1172,24 @@ function feedback_movedown_item($item){
|
|||
function feedback_move_item($moveitem, $pos){
|
||||
global $DB;
|
||||
|
||||
if ($moveitem->position == $pos) {
|
||||
return true;
|
||||
}
|
||||
if (!$allitems = $DB->get_records('feedback_item', array('feedback'=>$moveitem->feedback), 'position')) {
|
||||
return false;
|
||||
}
|
||||
if (is_array($allitems)) {
|
||||
$index = 1;
|
||||
foreach($allitems as $item) {
|
||||
if($item->id == $moveitem->id) continue; //the moving item is handled special
|
||||
|
||||
if($index == $pos) {
|
||||
$moveitem->position = $index;
|
||||
feedback_update_item($moveitem);
|
||||
$index++;
|
||||
}
|
||||
if($item->id == $moveitem->id) {
|
||||
$moveitem->position = $pos;
|
||||
feedback_update_item($moveitem);
|
||||
continue;
|
||||
}
|
||||
$item->position = $index;
|
||||
feedback_update_item($item);
|
||||
$index++;
|
||||
}
|
||||
if($pos >= count($allitems)) {
|
||||
$moveitem->position = $index;
|
||||
feedback_update_item($moveitem);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue