/** * load the available item plugins to use as dropdown-options * * @global object * @return array pluginnames as string */ function feedback_load_feedback_items_options() { global $CFG; $feedback_options = array("pagebreak" => get_string('add_pagebreak', 'feedback')); if (!$feedback_names = feedback_load_feedback_items('mod/feedback/item')) { return array(); } foreach ($feedback_names as $fn) { $feedback_options[$fn] = get_string($fn, 'feedback'); } asort($feedback_options); $feedback_options = array_merge( array(' ' => get_string('select')), $feedback_options ); return $feedback_options; }
function feedback_import_loaded_data(&$data, $feedbackid) { global $CFG, $DB; feedback_load_feedback_items(); $deleteolditems = optional_param('deleteolditems', 0, PARAM_INT); $error = new stdClass(); $error->stat = true; $error->msg = array(); if (!is_array($data)) { $error->msg[] = get_string('data_is_not_an_array', 'feedback'); $error->stat = false; return $error; } if ($deleteolditems) { feedback_delete_all_items($feedbackid); $position = 0; } else { //items will be add to the end of the existing items $position = $DB->count_records('feedback_item', array('feedback'=>$feedbackid)); } //depend items we are storing temporary in an mapping list array(new id => dependitem) //we also store a mapping of all items array(oldid => newid) $dependitemsmap = array(); $itembackup = array(); foreach ($data as $item) { $position++; //check the typ $typ = $item['@']['TYPE']; //check oldtypes first switch($typ) { case 'radio': $typ = 'multichoice'; $oldtyp = 'radio'; break; case 'dropdown': $typ = 'multichoice'; $oldtyp = 'dropdown'; break; case 'check': $typ = 'multichoice'; $oldtyp = 'check'; break; case 'radiorated': $typ = 'multichoicerated'; $oldtyp = 'radiorated'; break; case 'dropdownrated': $typ = 'multichoicerated'; $oldtyp = 'dropdownrated'; break; default: $oldtyp = $typ; } $itemclass = 'feedback_item_'.$typ; if ($typ != 'pagebreak' AND !class_exists($itemclass)) { $error->stat = false; $error->msg[] = 'type ('.$typ.') not found'; continue; } $itemobj = new $itemclass(); $newitem = new stdClass(); $newitem->feedback = $feedbackid; $newitem->template = 0; $newitem->typ = $typ; $newitem->name = trim($item['#']['ITEMTEXT'][0]['#']); $newitem->label = trim($item['#']['ITEMLABEL'][0]['#']); $newitem->options = trim($item['#']['OPTIONS'][0]['#']); $newitem->presentation = trim($item['#']['PRESENTATION'][0]['#']); //check old types of radio, check, and so on switch($oldtyp) { case 'radio': $newitem->presentation = 'r>>>>>'.$newitem->presentation; break; case 'dropdown': $newitem->presentation = 'd>>>>>'.$newitem->presentation; break; case 'check': $newitem->presentation = 'c>>>>>'.$newitem->presentation; break; case 'radiorated': $newitem->presentation = 'r>>>>>'.$newitem->presentation; break; case 'dropdownrated': $newitem->presentation = 'd>>>>>'.$newitem->presentation; break; } if (isset($item['#']['DEPENDITEM'][0]['#'])) { $newitem->dependitem = intval($item['#']['DEPENDITEM'][0]['#']); } else { $newitem->dependitem = 0; } if (isset($item['#']['DEPENDVALUE'][0]['#'])) { $newitem->dependvalue = trim($item['#']['DEPENDVALUE'][0]['#']); } else { $newitem->dependvalue = ''; } $olditemid = intval($item['#']['ITEMID'][0]['#']); if ($typ != 'pagebreak') { $newitem->hasvalue = $itemobj->get_hasvalue(); } else { $newitem->hasvalue = 0; } $newitem->required = intval($item['@']['REQUIRED']); $newitem->position = $position; $newid = $DB->insert_record('feedback_item', $newitem); $itembackup[$olditemid] = $newid; if ($newitem->dependitem) { $dependitemsmap[$newid] = $newitem->dependitem; } } //remapping the dependency foreach ($dependitemsmap as $key => $dependitem) { $newitem = $DB->get_record('feedback_item', array('id'=>$key)); $newitem->dependitem = $itembackup[$newitem->dependitem]; $DB->update_record('feedback_item', $newitem); } return $error; }
<?php /** * prints an analysed excel-spreadsheet of the feedback * * @author Andreas Grabs * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package feedback */ require_once "../../config.php"; require_once "lib.php"; // require_once('easy_excel.php'); require_once "{$CFG->libdir}/excellib.class.php"; feedback_load_feedback_items(); $id = required_param('id', PARAM_INT); //the POST dominated the GET $coursefilter = optional_param('coursefilter', '0', PARAM_INT); $url = new moodle_url('/mod/feedback/analysis_to_excel.php', array('id' => $id)); if ($coursefilter !== '0') { $url->param('coursefilter', $coursefilter); } $PAGE->set_url($url); $formdata = data_submitted(); if (!($cm = get_coursemodule_from_id('feedback', $id))) { print_error('invalidcoursemodule'); } if (!($course = $DB->get_record("course", array("id" => $cm->course)))) { print_error('coursemisconf'); } if (!($feedback = $DB->get_record("feedback", array("id" => $cm->instance)))) { print_error('invalidcoursemodule');