/** * Actual implementation of the reset course functionality, delete all the * questionnaire responses for course $data->courseid, if $data->reset_questionnaire_attempts is * set and true. * * @param object $data the data submitted from the reset course. * @return array status array */ function questionnaire_reset_userdata($data) { global $CFG, $DB; require_once $CFG->libdir . '/questionlib.php'; require_once $CFG->dirroot . '/mod/questionnaire/locallib.php'; $componentstr = get_string('modulenameplural', 'questionnaire'); $status = array(); if (!empty($data->reset_questionnaire)) { $surveys = questionnaire_get_survey_list($data->courseid, $type = ''); // Delete responses. foreach ($surveys as $survey) { // Get all responses for this questionnaire. $sql = "SELECT R.id, R.survey_id, R.submitted, R.username\n FROM {questionnaire_response} R\n WHERE R.survey_id = ?\n ORDER BY R.id"; $resps = $DB->get_records_sql($sql, array($survey->id)); if (!empty($resps)) { foreach ($resps as $response) { questionnaire_delete_response($response->id); } } // Remove this questionnaire's grades (and feedback) from gradebook (if any). $select = "itemmodule = 'questionnaire' AND iteminstance = " . $survey->qid; $fields = 'id'; if ($itemid = $DB->get_record_select('grade_items', $select, null, $fields)) { $itemid = $itemid->id; $DB->delete_records_select('grade_grades', 'itemid = ' . $itemid); } } $status[] = array('component' => $componentstr, 'item' => get_string('deletedallresp', 'questionnaire'), 'error' => false); $status[] = array('component' => $componentstr, 'item' => get_string('gradesdeleted', 'questionnaire'), 'error' => false); } return $status; }
function questionnaire_get_survey_select($instance, $courseid = 0, $sid = 0, $type = '') { global $OUTPUT; $surveylist = array(); if ($surveys = questionnaire_get_survey_list($courseid, $type)) { $strpreview = get_string('preview'); $strunknown = get_string('unknown', 'questionnaire'); $strpublic = get_string('public', 'questionnaire'); $strprivate = get_string('private', 'questionnaire'); $strtemplate = get_string('template', 'questionnaire'); $strviewresp = get_string('viewresponses', 'questionnaire'); foreach ($surveys as $survey) { if (empty($survey->realm)) { $stat = $strunknown; } else { if ($survey->realm == 'public') { $stat = $strpublic; } else { if ($survey->realm == 'private') { $stat = $strprivate; } else { if ($survey->realm == 'template') { $stat = $strtemplate; } else { $stat = $strunknown; } } } } // Prevent creation of a new questionnaire using a public questionnaire IN THE SAME COURSE! if ($type == 'public' && $survey->owner == $courseid) { continue; } else { $args = "sid={$survey->id}&popup=1"; if (!empty($survey->qid)) { $args .= "&qid={$survey->qid}"; } $link = new moodle_url("/mod/questionnaire/preview.php?{$args}"); $action = new popup_action('click', $link); $label = $OUTPUT->action_link($link, $survey->qname, $action, array('title' => $survey->title)); $surveylist[$type . '-' . $survey->id] = $label; } } } return $surveylist; }
function questionnaire_get_survey_select($courseid = 0, $type = '') { global $OUTPUT, $DB; $surveylist = array(); if ($surveys = questionnaire_get_survey_list($courseid, $type)) { $strpreview = get_string('preview_questionnaire', 'questionnaire'); foreach ($surveys as $survey) { $originalcourse = $DB->get_record('course', array('id' => $survey->owner)); if (!$originalcourse) { // This should not happen, but we found a case where a public survey // still existed in a course that had been deleted, and so this // code lead to a notice, and a broken link. Since that is useless // we just skip surveys like this. continue; } // Prevent creating a copy of a public questionnaire IN THE SAME COURSE as the original. if ($type == 'public' && $survey->owner == $courseid) { continue; } else { $args = "sid={$survey->id}&popup=1"; if (!empty($survey->qid)) { $args .= "&qid={$survey->qid}"; } $link = new moodle_url("/mod/questionnaire/preview.php?{$args}"); $action = new popup_action('click', $link); $label = $OUTPUT->action_link($link, $survey->qname . ' [' . $originalcourse->fullname . ']', $action, array('title' => $strpreview)); $surveylist[$type . '-' . $survey->id] = $label; } } } return $surveylist; }
function questionnaire_get_survey_select($instance, $courseid = 0, $sid = 0, $type = '') { global $CFG; $surveylist = array(); if ($surveys = questionnaire_get_survey_list($courseid, $type)) { $strpreview = get_string('preview'); $strunknown = get_string('unknown', 'questionnaire'); $strpublic = get_string('public', 'questionnaire'); $strprivate = get_string('private', 'questionnaire'); $strtemplate = get_string('template', 'questionnaire'); $strviewresp = get_string('viewresponses', 'questionnaire'); foreach ($surveys as $survey) { if (empty($survey->realm)) { $stat = $strunknown; } else { if ($survey->realm == 'public') { $stat = $strpublic; } else { if ($survey->realm == 'private') { $stat = $strprivate; } else { if ($survey->realm == 'template') { $stat = $strtemplate; } else { $stat = $strunknown; } } } } // prevent creation of a new questionnaire using a public questionnaire IN THE SAME COURSE! if ($type == 'public' && $survey->owner == $courseid) { continue; } else { $label = link_to_popup_window($CFG->wwwroot . '/mod/questionnaire/preview.php?sid=' . $survey->id . '&popup=1', null, $survey->title, 400, 500, $strpreview, null, true); $surveylist[$type . '-' . $survey->id] = $label; /// JR deprecated - waiting for preview function to be restored? /* link_to_popup_window('/mod/questionnaire/manage_survey.php?course='.$courseid. '&qact=preview&instance='.$instance.'&sid='.$survey->id, $strpreview, $survey->title.' ('.$stat.')', '', '', $strpreview, '', true);*/ } } } return $surveylist; }