/** * load the available item plugins to use as dropdown-options * * @global object * @return array pluginnames as string */ function evaluation_load_evaluation_items_options() { global $CFG; $evaluation_options = array("pagebreak" => get_string('add_pagebreak', 'local_evaluations')); if (!$evaluation_names = evaluation_load_evaluation_items('local/evaluations/item')) { return array(); } foreach ($evaluation_names as $fn) { $evaluation_options[$fn] = get_string($fn, 'local_evaluations'); } asort($evaluation_options); $evaluation_options = array_merge(array(' ' => get_string('select')), $evaluation_options); return $evaluation_options; }
function evaluation_import_loaded_data(&$data, $evaluationid) { global $CFG, $DB; evaluation_load_evaluation_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', 'local_evaluations'); $error->stat = false; return $error; } if ($deleteolditems) { evaluation_delete_all_items($evaluationid); $position = 0; } else { //items will be add to the end of the existing items $position = $DB->count_records('evaluation_item', array('evaluation' => $evaluationid)); } //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 = 'evaluation_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->evaluation = $evaluationid; $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('evaluation_item', $newitem); $itembackup[$olditemid] = $newid; if ($newitem->dependitem) { $dependitemsmap[$newid] = $newitem->dependitem; } } //remapping the dependency foreach ($dependitemsmap as $key => $dependitem) { $newitem = $DB->get_record('evaluation_item', array('id' => $key)); $newitem->dependitem = $itembackup[$newitem->dependitem]; $DB->update_record('evaluation_item', $newitem); } return $error; }
// // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * prints an analysed excel-spreadsheet of the evaluation * * @author Andreas Grabs * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package evaluation */ require_once("../../config.php"); require_once("lib.php"); require_once("$CFG->libdir/excellib.class.php"); evaluation_load_evaluation_items(); $id = required_param('id', PARAM_INT); //the POST dominated the GET $classid = required_param('clid', PARAM_INT); $classfilter = optional_param('classfilter', '0', PARAM_INT); $url = new moodle_url('/local/evaluations/analysis_to_excel.php', array('id' => $id, 'clid' => $classid)); //if ($classfilter !== '0') { // $url->param('classfilter', $classfilter); //} $PAGE->set_url($url); $formdata = data_submitted(); //if (! $cm = get_classmodule_from_id('local_evaluations', $id)) { // print_error('invalidclassmodule');