/** * deletes all items of the given evaluationid * * @global object * @param int $evaluationid * @return void */ function evaluation_delete_all_items($evaluationid) { global $DB, $CFG; require_once($CFG->libdir . '/completionlib.php'); if (!$evaluation = $DB->get_record('local_evaluation', array('id' => $evaluationid))) { return false; } // //if (!$cm = get_coursemodule_from_instance('evaluation', $evaluation->id)) { // return false; //} //if (!$course = $DB->get_record('class', array('id'=>$evaluation->classid))) { // return false; //} if (!$items = $DB->get_records('evaluation_item', array('evaluation' => $evaluationid))) { return; } foreach ($items as $item) { evaluation_delete_item($item->id, false); } if ($completeds = $DB->get_records('evaluation_completed', array('evaluation' => $evaluation->id))) { $completion = new completion_info($course); foreach ($completeds as $completed) { // Update completion state if ($completion->is_enabled($cm) && $evaluation->completionsubmit) { $completion->update_state($cm, COMPLETION_INCOMPLETE, $completed->userid); } $DB->delete_records('evaluation_completed', array('id' => $completed->id)); } } $DB->delete_records('evaluation_completedtmp', array('evaluation' => $evaluationid)); }
//require_capability('mod/evaluation:edititems', $context); $mform = new evaluation_delete_item_form(); $newformdata = array('id' => $id, 'clid' => $classid, 'deleteitem' => $deleteitem, 'confirmdelete' => '1'); $mform->set_data($newformdata); $formdata = $mform->get_data(); if ($mform->is_cancelled()) { redirect('edit.php?id=' . $id . '&clid=' . $classid . ''); } if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) { evaluation_delete_item($formdata->deleteitem); redirect('edit.php?id=' . $id . '&clid=' . $classid . ''); } /// Print the page header $strevaluations = get_string("modulenameplural", "local_evaluations"); $strevaluation = get_string("modulename", "local_evaluations"); $PAGE->navbar->add(get_string('delete_item', 'local_evaluations')); //$PAGE->set_heading(format_string($course->fullname)); $PAGE->set_title(format_string($evaluation->name)); echo $OUTPUT->header(); /// Print the main part of the page ///////////////////////////////////////////////////////////////////////////