2009-05-28 06:32:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @package mod-survey
|
|
|
|
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Graph size
|
|
|
|
* @global int $SURVEY_GHEIGHT
|
|
|
|
*/
|
2009-06-19 14:25:56 +00:00
|
|
|
global $SURVEY_GHEIGHT;
|
2002-08-01 04:49:26 +00:00
|
|
|
$SURVEY_GHEIGHT = 500;
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* Graph size
|
|
|
|
* @global int $SURVEY_GWIDTH
|
|
|
|
*/
|
2009-06-19 14:25:56 +00:00
|
|
|
global $SURVEY_GWIDTH;
|
2002-08-01 04:49:26 +00:00
|
|
|
$SURVEY_GWIDTH = 900;
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* Question Type
|
|
|
|
* @global array $SURVEY_QTYPE
|
|
|
|
*/
|
2009-06-19 14:25:56 +00:00
|
|
|
global $SURVEY_QTYPE;
|
2002-08-01 04:49:26 +00:00
|
|
|
$SURVEY_QTYPE = array (
|
2001-11-22 06:23:56 +00:00
|
|
|
"-3" => "Virtual Actual and Preferred",
|
|
|
|
"-2" => "Virtual Preferred",
|
|
|
|
"-1" => "Virtual Actual",
|
|
|
|
"0" => "Text",
|
|
|
|
"1" => "Actual",
|
|
|
|
"2" => "Preferred",
|
|
|
|
"3" => "Actual and Preferred",
|
|
|
|
);
|
|
|
|
|
2004-05-13 08:57:39 +00:00
|
|
|
|
|
|
|
define("SURVEY_COLLES_ACTUAL", "1");
|
|
|
|
define("SURVEY_COLLES_PREFERRED", "2");
|
|
|
|
define("SURVEY_COLLES_PREFERRED_ACTUAL", "3");
|
|
|
|
define("SURVEY_ATTLS", "4");
|
|
|
|
define("SURVEY_CIQ", "5");
|
|
|
|
|
|
|
|
|
2002-09-22 04:27:45 +00:00
|
|
|
// STANDARD FUNCTIONS ////////////////////////////////////////////////////////
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* Given an object containing all the necessary data,
|
|
|
|
* (defined by the form in mod_form.php) this function
|
|
|
|
* will create a new instance and return the id number
|
|
|
|
* of the new instance.
|
|
|
|
*
|
|
|
|
* @global object
|
|
|
|
* @param object $survey
|
|
|
|
* @return int|bool
|
|
|
|
*/
|
2002-08-03 02:29:21 +00:00
|
|
|
function survey_add_instance($survey) {
|
2008-06-01 21:36:11 +00:00
|
|
|
global $DB;
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if (!$template = $DB->get_record("survey", array("id"=>$survey->template))) {
|
2002-08-03 02:29:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-01 15:24:58 +00:00
|
|
|
$survey->questions = $template->questions;
|
2002-08-03 02:29:21 +00:00
|
|
|
$survey->timecreated = time();
|
|
|
|
$survey->timemodified = $survey->timecreated;
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
return $DB->insert_record("survey", $survey);
|
2002-08-03 02:29:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* Given an object containing all the necessary data,
|
|
|
|
* (defined by the form in mod_form.php) this function
|
|
|
|
* will update an existing instance with new data.
|
|
|
|
*
|
|
|
|
* @global object
|
|
|
|
* @param object $survey
|
|
|
|
* @return bool
|
|
|
|
*/
|
2002-08-03 02:29:21 +00:00
|
|
|
function survey_update_instance($survey) {
|
2008-06-01 21:36:11 +00:00
|
|
|
global $DB;
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if (!$template = $DB->get_record("survey", array("id"=>$survey->template))) {
|
2002-08-03 02:29:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-01 15:24:58 +00:00
|
|
|
$survey->id = $survey->instance;
|
|
|
|
$survey->questions = $template->questions;
|
2002-08-03 02:29:21 +00:00
|
|
|
$survey->timemodified = time();
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
return $DB->update_record("survey", $survey);
|
2002-08-03 02:29:21 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* Given an ID of an instance of this module,
|
|
|
|
* this function will permanently delete the instance
|
2009-11-01 15:24:58 +00:00
|
|
|
* and any data that depends on it.
|
2009-05-28 06:32:35 +00:00
|
|
|
*
|
|
|
|
* @global object
|
|
|
|
* @param int $id
|
|
|
|
* @return bool
|
|
|
|
*/
|
2002-08-03 02:29:21 +00:00
|
|
|
function survey_delete_instance($id) {
|
2008-06-01 21:36:11 +00:00
|
|
|
global $DB;
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if (! $survey = $DB->get_record("survey", array("id"=>$id))) {
|
2002-08-03 02:29:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = true;
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if (! $DB->delete_records("survey_analysis", array("survey"=>$survey->id))) {
|
2002-08-03 02:29:21 +00:00
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if (! $DB->delete_records("survey_answers", array("survey"=>$survey->id))) {
|
2002-08-03 02:29:21 +00:00
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if (! $DB->delete_records("survey", array("id"=>$survey->id))) {
|
2002-08-03 02:29:21 +00:00
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @param object $course
|
|
|
|
* @param object $user
|
|
|
|
* @param object $mod
|
|
|
|
* @param object $survey
|
|
|
|
* @return $result
|
|
|
|
*/
|
2002-09-22 04:27:45 +00:00
|
|
|
function survey_user_outline($course, $user, $mod, $survey) {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
2002-09-22 04:27:45 +00:00
|
|
|
|
2008-06-08 14:43:39 +00:00
|
|
|
if ($answers = $DB->get_records("survey_answers", array('survey'=>$survey->id, 'userid'=>$user->id))) {
|
2002-09-22 04:27:45 +00:00
|
|
|
$lastanswer = array_pop($answers);
|
|
|
|
|
2008-06-08 14:43:39 +00:00
|
|
|
$result = new object();
|
2002-09-22 04:27:45 +00:00
|
|
|
$result->info = get_string("done", "survey");
|
|
|
|
$result->time = $lastanswer->time;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global stdObject
|
|
|
|
* @global object
|
|
|
|
* @uses SURVEY_CIQ
|
|
|
|
* @param object $course
|
|
|
|
* @param object $user
|
|
|
|
* @param object $mod
|
|
|
|
* @param object $survey
|
|
|
|
*/
|
2002-09-22 04:27:45 +00:00
|
|
|
function survey_user_complete($course, $user, $mod, $survey) {
|
2009-08-20 08:46:16 +00:00
|
|
|
global $CFG, $DB, $OUTPUT;
|
2002-09-22 04:27:45 +00:00
|
|
|
|
|
|
|
if (survey_already_done($survey->id, $user->id)) {
|
2004-05-13 08:57:39 +00:00
|
|
|
if ($survey->template == SURVEY_CIQ) { // print out answers for critical incidents
|
2009-08-20 08:46:16 +00:00
|
|
|
$table = new html_table();
|
2004-05-13 08:57:39 +00:00
|
|
|
$table->align = array("left", "left");
|
|
|
|
|
2008-06-01 15:42:48 +00:00
|
|
|
$questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
|
2004-05-13 08:57:39 +00:00
|
|
|
$questionorder = explode(",", $survey->questions);
|
2009-11-01 15:24:58 +00:00
|
|
|
|
2004-05-13 08:57:39 +00:00
|
|
|
foreach ($questionorder as $key=>$val) {
|
|
|
|
$question = $questions[$val];
|
|
|
|
$questiontext = get_string($question->shorttext, "survey");
|
2009-11-01 15:24:58 +00:00
|
|
|
|
2004-05-13 08:57:39 +00:00
|
|
|
if ($answer = survey_get_user_answer($survey->id, $question->id, $user->id)) {
|
|
|
|
$answertext = "$answer->answer1";
|
|
|
|
} else {
|
|
|
|
$answertext = "No answer";
|
|
|
|
}
|
|
|
|
$table->data[] = array("<b>$questiontext</b>", $answertext);
|
|
|
|
}
|
2010-03-20 22:15:54 +00:00
|
|
|
echo html_writer::table($table);
|
2009-11-01 15:24:58 +00:00
|
|
|
|
2004-05-13 08:57:39 +00:00
|
|
|
} else {
|
2009-11-01 15:24:58 +00:00
|
|
|
|
2004-09-16 17:13:57 +00:00
|
|
|
survey_print_graph("id=$mod->id&sid=$user->id&type=student.png");
|
2004-05-13 08:57:39 +00:00
|
|
|
}
|
2009-11-01 15:24:58 +00:00
|
|
|
|
2002-09-22 04:27:45 +00:00
|
|
|
} else {
|
|
|
|
print_string("notdone", "survey");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global stdClass
|
|
|
|
* @global object
|
|
|
|
* @param object $course
|
|
|
|
* @param mixed $viewfullnames
|
|
|
|
* @param int $timestamp
|
|
|
|
* @return bool
|
|
|
|
*/
|
2008-01-24 20:33:50 +00:00
|
|
|
function survey_print_recent_activity($course, $viewfullnames, $timestart) {
|
2009-08-06 01:36:45 +00:00
|
|
|
global $CFG, $DB, $OUTPUT;
|
2002-09-22 03:51:28 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$modinfo = get_fast_modinfo($course);
|
|
|
|
$ids = array();
|
|
|
|
foreach ($modinfo->cms as $cm) {
|
|
|
|
if ($cm->modname != 'survey') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!$cm->uservisible) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$ids[$cm->instance] = $cm->instance;
|
|
|
|
}
|
2002-09-22 03:51:28 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if (!$ids) {
|
2003-04-26 15:08:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$slist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right?
|
|
|
|
|
2008-06-08 14:43:39 +00:00
|
|
|
if (!$rs = $DB->get_recordset_sql("SELECT sa.userid, sa.survey, MAX(sa.time) AS time,
|
|
|
|
u.firstname, u.lastname, u.email, u.picture
|
|
|
|
FROM {survey_answers} sa
|
|
|
|
JOIN {user} u ON u.id = sa.userid
|
|
|
|
WHERE sa.survey IN ($slist) AND sa.time > ?
|
|
|
|
GROUP BY sa.userid, sa.survey, u.firstname, u.lastname, u.email, u.picture
|
|
|
|
ORDER BY time ASC", array($timestart))) {
|
2008-01-24 20:33:50 +00:00
|
|
|
return false;
|
2002-09-22 03:51:28 +00:00
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$surveys = array();
|
|
|
|
|
2008-06-08 14:43:39 +00:00
|
|
|
foreach ($rs as $survey) {
|
2008-01-24 20:33:50 +00:00
|
|
|
$cm = $modinfo->instances['survey'][$survey->survey];
|
|
|
|
$survey->name = $cm->name;
|
|
|
|
$survey->cmid = $cm->id;
|
|
|
|
$surveys[] = $survey;
|
2009-11-01 15:24:58 +00:00
|
|
|
}
|
2008-06-08 14:43:39 +00:00
|
|
|
$rs->close();
|
2008-01-24 20:33:50 +00:00
|
|
|
|
|
|
|
if (!$surveys) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-06 01:36:45 +00:00
|
|
|
echo $OUTPUT->heading(get_string('newsurveyresponses', 'survey').':');
|
2008-01-24 20:33:50 +00:00
|
|
|
foreach ($surveys as $survey) {
|
2008-05-21 04:02:53 +00:00
|
|
|
$url = $CFG->wwwroot.'/mod/survey/view.php?id='.$survey->cmid;
|
2008-01-24 20:33:50 +00:00
|
|
|
print_recent_activity_note($survey->time, $survey, $survey->name, $url, false, $viewfullnames);
|
2002-09-22 03:51:28 +00:00
|
|
|
}
|
2009-11-01 15:24:58 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
return true;
|
2002-09-22 03:51:28 +00:00
|
|
|
}
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* Returns the users with data in one survey
|
|
|
|
* (users with records in survey_analysis and survey_answers, students)
|
|
|
|
*
|
|
|
|
* @global object
|
|
|
|
* @param int $surveyid
|
|
|
|
* @return array
|
|
|
|
*/
|
2003-09-29 15:27:30 +00:00
|
|
|
function survey_get_participants($surveyid) {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
2003-09-29 15:27:30 +00:00
|
|
|
|
|
|
|
//Get students from survey_analysis
|
2008-06-08 14:43:39 +00:00
|
|
|
$st_analysis = $DB->get_records_sql("SELECT DISTINCT u.id, u.id
|
|
|
|
FROM {user} u, {survey_analysis} a
|
|
|
|
WHERE a.survey = ? AND
|
|
|
|
u.id = a.userid", array($surveyid));
|
2003-09-29 15:27:30 +00:00
|
|
|
//Get students from survey_answers
|
2008-06-08 14:43:39 +00:00
|
|
|
$st_answers = $DB->get_records_sql("SELECT DISTINCT u.id, u.id
|
|
|
|
FROM {user} u, {survey_answers} a
|
|
|
|
WHERE a.survey = ? AND
|
|
|
|
u.id = a.userid", array($surveyid));
|
2003-09-29 15:27:30 +00:00
|
|
|
|
|
|
|
//Add st_answers to st_analysis
|
|
|
|
if ($st_answers) {
|
|
|
|
foreach ($st_answers as $st_answer) {
|
|
|
|
$st_analysis[$st_answer->id] = $st_answer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Return st_analysis array (it contains an array of unique users)
|
|
|
|
return ($st_analysis);
|
|
|
|
}
|
2002-09-22 04:27:45 +00:00
|
|
|
|
2002-12-23 05:57:05 +00:00
|
|
|
// SQL FUNCTIONS ////////////////////////////////////////////////////////
|
2002-09-22 04:27:45 +00:00
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @param sting $log
|
|
|
|
* @return array
|
|
|
|
*/
|
2002-12-23 05:57:05 +00:00
|
|
|
function survey_log_info($log) {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
|
|
|
return $DB->get_record_sql("SELECT s.name, u.firstname, u.lastname, u.picture
|
|
|
|
FROM {survey} s, {user} u
|
|
|
|
WHERE s.id = ? AND u.id = ?", array($log->info, $log->userid));
|
2002-12-23 05:57:05 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @param int $surveyid
|
|
|
|
* @param int $groupid
|
|
|
|
* @param int $groupingid
|
|
|
|
* @return array
|
|
|
|
*/
|
2007-08-28 00:12:01 +00:00
|
|
|
function survey_get_responses($surveyid, $groupid, $groupingid) {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
|
|
|
|
2009-11-01 15:24:58 +00:00
|
|
|
$params = array('surveyid'=>$surveyid, 'groupid'=>$groupid, 'groupingid'=>$groupingid);
|
2004-02-20 16:03:05 +00:00
|
|
|
|
|
|
|
if ($groupid) {
|
2008-06-08 14:43:39 +00:00
|
|
|
$groupsjoin = "JOIN {groups_members} gm ON u.id = gm.userid AND gm.groupid = :groupid ";
|
2007-08-15 19:28:11 +00:00
|
|
|
|
2007-08-28 00:12:01 +00:00
|
|
|
} else if ($groupingid) {
|
2008-06-08 14:43:39 +00:00
|
|
|
$groupsjoin = "JOIN {groups_members} gm ON u.id = gm.userid
|
|
|
|
JOIN {groupings_groups} gg ON gm.groupid = gg.groupid AND gg.groupingid = :groupingid ";
|
2004-02-20 16:03:05 +00:00
|
|
|
} else {
|
2007-08-28 00:12:01 +00:00
|
|
|
$groupsjoin = "";
|
2004-02-20 16:03:05 +00:00
|
|
|
}
|
|
|
|
|
2008-06-08 14:43:39 +00:00
|
|
|
return $DB->get_records_sql("SELECT u.id, u.firstname, u.lastname, u.picture, MAX(a.time) as time
|
|
|
|
FROM {survey_answers} a
|
|
|
|
JOIN {user} u ON a.userid = u.id
|
|
|
|
$groupsjoin
|
|
|
|
WHERE a.survey = :surveyid
|
|
|
|
GROUP BY u.id, u.firstname, u.lastname, u.picture
|
|
|
|
ORDER BY time ASC", $params);
|
2002-12-23 05:57:05 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @param int $survey
|
|
|
|
* @param int $user
|
|
|
|
* @return array
|
|
|
|
*/
|
2002-12-23 05:57:05 +00:00
|
|
|
function survey_get_analysis($survey, $user) {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
2002-12-23 05:57:05 +00:00
|
|
|
|
2009-11-01 15:24:58 +00:00
|
|
|
return $DB->get_record_sql("SELECT notes
|
2008-06-08 14:43:39 +00:00
|
|
|
FROM {survey_analysis}
|
|
|
|
WHERE survey=? AND userid=?", array($survey, $user));
|
2002-12-23 05:57:05 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @param int $survey
|
|
|
|
* @param int $user
|
|
|
|
* @param string $notes
|
|
|
|
*/
|
2002-12-23 05:57:05 +00:00
|
|
|
function survey_update_analysis($survey, $user, $notes) {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
2002-12-23 05:57:05 +00:00
|
|
|
|
2008-06-08 14:43:39 +00:00
|
|
|
return $DB->execute("UPDATE {survey_analysis}
|
2009-11-01 15:24:58 +00:00
|
|
|
SET notes=?
|
|
|
|
WHERE survey=?
|
2008-06-08 14:43:39 +00:00
|
|
|
AND userid=?", array($notes, $survey, $user));
|
2002-12-23 05:57:05 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @param int $surveyid
|
|
|
|
* @param int $groupid
|
|
|
|
* @param string $sort
|
|
|
|
* @return array
|
|
|
|
*/
|
2004-02-20 16:03:05 +00:00
|
|
|
function survey_get_user_answers($surveyid, $questionid, $groupid, $sort="sa.answer1,sa.answer2 ASC") {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$params = array('surveyid'=>$surveyid, 'questionid'=>$questionid, 'groupid'=>$groupid);
|
2002-12-23 05:57:05 +00:00
|
|
|
|
2004-02-20 16:03:05 +00:00
|
|
|
if ($groupid) {
|
2008-06-08 14:43:39 +00:00
|
|
|
$groupsql = "AND gm.groupid = :groupid AND u.id = gm.userid";
|
2004-02-20 16:03:05 +00:00
|
|
|
} else {
|
|
|
|
$groupsql = "";
|
|
|
|
}
|
|
|
|
|
2009-11-01 15:24:58 +00:00
|
|
|
return $DB->get_records_sql("SELECT sa.*,u.firstname,u.lastname,u.picture
|
|
|
|
FROM {survey_answers} sa, {user} u, {groups_members} gm
|
|
|
|
WHERE sa.survey = :surveyid
|
|
|
|
AND sa.question = :questionid
|
2008-06-08 14:43:39 +00:00
|
|
|
AND u.id = sa.userid $groupsql
|
|
|
|
ORDER BY $sort", $params);
|
2004-02-16 16:13:31 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @param int $surveyid
|
|
|
|
* @param int $questionid
|
|
|
|
* @param int $userid
|
|
|
|
* @return array
|
|
|
|
*/
|
2004-02-16 16:13:31 +00:00
|
|
|
function survey_get_user_answer($surveyid, $questionid, $userid) {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
2004-02-16 16:13:31 +00:00
|
|
|
|
2009-11-01 15:24:58 +00:00
|
|
|
return $DB->get_record_sql("SELECT sa.*
|
2008-06-08 14:43:39 +00:00
|
|
|
FROM {survey_answers} sa
|
2009-11-01 15:24:58 +00:00
|
|
|
WHERE sa.survey = ?
|
|
|
|
AND sa.question = ?
|
2008-06-08 14:43:39 +00:00
|
|
|
AND sa.userid = ?", array($surveyid, $questionid, $userid));
|
2002-12-23 05:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MODULE FUNCTIONS ////////////////////////////////////////////////////////
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @param int $survey
|
|
|
|
* @param int $user
|
|
|
|
* @param string $notes
|
|
|
|
* @return bool|int
|
|
|
|
*/
|
2002-12-23 09:39:26 +00:00
|
|
|
function survey_add_analysis($survey, $user, $notes) {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
2002-12-23 09:39:26 +00:00
|
|
|
|
2008-06-08 14:43:39 +00:00
|
|
|
$record = new object();
|
2002-12-23 09:39:26 +00:00
|
|
|
$record->survey = $survey;
|
|
|
|
$record->userid = $user;
|
|
|
|
$record->notes = $notes;
|
|
|
|
|
2008-06-08 14:43:39 +00:00
|
|
|
return $DB->insert_record("survey_analysis", $record, false);
|
2002-12-23 09:39:26 +00:00
|
|
|
}
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @param int $survey
|
|
|
|
* @param int $user
|
|
|
|
* @return bool
|
|
|
|
*/
|
2002-12-23 05:57:05 +00:00
|
|
|
function survey_already_done($survey, $user) {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
|
|
|
|
|
|
|
return $DB->record_exists("survey_answers", array("survey"=>$survey, "userid"=>$user));
|
2002-08-01 04:49:26 +00:00
|
|
|
}
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @param int $surveyid
|
|
|
|
* @param int $groupid
|
|
|
|
* @param int $groupingid
|
|
|
|
* @return int
|
|
|
|
*/
|
2007-08-28 00:12:01 +00:00
|
|
|
function survey_count_responses($surveyid, $groupid, $groupingid) {
|
|
|
|
if ($responses = survey_get_responses($surveyid, $groupid, $groupingid)) {
|
2002-08-01 04:49:26 +00:00
|
|
|
return count($responses);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @param int $cmid
|
|
|
|
* @param array $results
|
|
|
|
* @param int $courseid
|
|
|
|
*/
|
2004-02-16 16:13:31 +00:00
|
|
|
function survey_print_all_responses($cmid, $results, $courseid) {
|
2009-08-20 08:46:16 +00:00
|
|
|
global $OUTPUT;
|
|
|
|
$table = new html_table();
|
2004-03-13 13:33:20 +00:00
|
|
|
$table->head = array ("", get_string("name"), get_string("time"));
|
|
|
|
$table->align = array ("", "left", "left");
|
|
|
|
$table->size = array (35, "", "" );
|
2002-06-25 07:10:01 +00:00
|
|
|
|
|
|
|
foreach ($results as $a) {
|
2009-12-27 19:47:21 +00:00
|
|
|
$table->data[] = array($OUTPUT->user_picture($a, array('courseid'=>$courseid)),
|
2010-02-11 18:50:55 +00:00
|
|
|
html_writer::link("report.php?action=student&student=$a->id&id=$cmid", fullname($a)),
|
2004-03-13 13:33:20 +00:00
|
|
|
userdate($a->time));
|
2002-06-25 07:10:01 +00:00
|
|
|
}
|
2004-02-16 16:13:31 +00:00
|
|
|
|
2010-03-20 22:15:54 +00:00
|
|
|
echo html_writer::table($table);
|
2002-06-25 07:10:01 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @param int $templateid
|
|
|
|
* @return string
|
|
|
|
*/
|
2002-08-01 04:49:26 +00:00
|
|
|
function survey_get_template_name($templateid) {
|
2008-05-31 22:18:41 +00:00
|
|
|
global $DB;
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if ($templateid) {
|
2008-06-08 14:43:39 +00:00
|
|
|
if ($ss = $DB->get_record("surveys", array("id"=>$templateid))) {
|
2002-12-23 05:57:05 +00:00
|
|
|
return $ss->name;
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-25 13:48:14 +00:00
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param array $numwords
|
|
|
|
* @return string
|
|
|
|
*/
|
2002-08-01 05:18:07 +00:00
|
|
|
function survey_shorten_name ($name, $numwords) {
|
|
|
|
$words = explode(" ", $name);
|
|
|
|
for ($i=0; $i < $numwords; $i++) {
|
|
|
|
$output .= $words[$i]." ";
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @todo Check this function
|
|
|
|
*
|
|
|
|
* @global object
|
|
|
|
* @global object
|
|
|
|
* @global int
|
|
|
|
* @global void This is never defined
|
|
|
|
* @global object This is defined twice?
|
|
|
|
* @param object $question
|
|
|
|
*/
|
2002-08-01 05:18:07 +00:00
|
|
|
function survey_print_multi($question) {
|
2009-08-06 08:22:15 +00:00
|
|
|
global $USER, $DB, $qnum, $checklist, $DB, $OUTPUT;
|
2002-08-01 05:18:07 +00:00
|
|
|
|
2002-08-12 17:54:13 +00:00
|
|
|
$stripreferthat = get_string("ipreferthat", "survey");
|
|
|
|
$strifoundthat = get_string("ifoundthat", "survey");
|
2010-04-23 05:58:43 +00:00
|
|
|
$strdefault = get_string('notyetanswered', 'survey');
|
2007-11-21 14:50:32 +00:00
|
|
|
$strresponses = get_string('responses', 'survey');
|
|
|
|
|
2009-08-06 08:22:15 +00:00
|
|
|
echo $OUTPUT->heading($question->text, 3, 'questiontext');
|
2010-03-25 06:38:21 +00:00
|
|
|
echo "\n<table width=\"90%\" cellpadding=\"4\" cellspacing=\"1\" border=\"0\" class=\"surveytable\">";
|
2002-08-01 05:18:07 +00:00
|
|
|
|
|
|
|
$options = explode( ",", $question->options);
|
|
|
|
$numoptions = count($options);
|
|
|
|
|
|
|
|
$oneanswer = ($question->type == 1 || $question->type == 2) ? true : false;
|
2005-05-16 23:42:48 +00:00
|
|
|
if ($question->type == 2) {
|
|
|
|
$P = "P";
|
|
|
|
} else {
|
|
|
|
$P = "";
|
|
|
|
}
|
2002-08-01 05:18:07 +00:00
|
|
|
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "<tr class=\"smalltext\"><th scope=\"row\">$strresponses</th>";
|
2010-04-23 05:58:43 +00:00
|
|
|
echo "<th scope=\"col\" class=\"hresponse\">". get_string('notyetanswered', 'survey'). "</th>";
|
2002-08-01 05:18:07 +00:00
|
|
|
while (list ($key, $val) = each ($options)) {
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "<th scope=\"col\" class=\"hresponse\">$val</th>\n";
|
|
|
|
}
|
2010-04-23 05:58:43 +00:00
|
|
|
echo "</tr>\n";
|
2007-11-21 14:50:32 +00:00
|
|
|
|
|
|
|
if ($oneanswer) {
|
2010-04-23 05:58:43 +00:00
|
|
|
echo "<tr><th scope=\"col\" colspan=\"7\">$question->intro</th></tr>\n";
|
2007-11-21 14:50:32 +00:00
|
|
|
} else {
|
2009-11-01 15:24:58 +00:00
|
|
|
echo "<tr><th scope=\"col\" colspan=\"7\">$question->intro</th></tr>\n";
|
2002-08-01 05:18:07 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 15:42:48 +00:00
|
|
|
$subquestions = $DB->get_records_list("survey_questions", "id", explode(',', $question->multi));
|
2007-11-21 14:50:32 +00:00
|
|
|
|
2002-08-01 05:18:07 +00:00
|
|
|
foreach ($subquestions as $q) {
|
|
|
|
$qnum++;
|
2005-02-10 10:41:22 +00:00
|
|
|
$rowclass = survey_question_rowclass($qnum);
|
2002-11-09 06:22:57 +00:00
|
|
|
if ($q->text) {
|
|
|
|
$q->text = get_string($q->text, "survey");
|
|
|
|
}
|
|
|
|
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "<tr class=\"$rowclass rblock\">";
|
2002-08-01 05:18:07 +00:00
|
|
|
if ($oneanswer) {
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "<th scope=\"row\" class=\"optioncell\">";
|
|
|
|
echo "<b class=\"qnumtopcell\">$qnum</b> ";
|
|
|
|
echo $q->text ."</th>\n";
|
2010-04-23 05:58:43 +00:00
|
|
|
|
|
|
|
$default = get_accesshide($strdefault);
|
|
|
|
echo "<td class=\"whitecell\"><label for=\"q$P$q->id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"q$P" . $q->id . "_D\" value=\"0\" checked=\"checked\" />$default</label></td>";
|
|
|
|
|
2007-11-21 14:50:32 +00:00
|
|
|
for ($i=1;$i<=$numoptions;$i++) {
|
|
|
|
$hiddentext = get_accesshide($options[$i-1]);
|
|
|
|
$id = "q$P" . $q->id . "_$i";
|
|
|
|
echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
|
2010-04-23 05:58:43 +00:00
|
|
|
}
|
|
|
|
$checklist["q$P$q->id"] = 0;
|
2009-11-01 15:24:58 +00:00
|
|
|
|
2010-04-23 05:58:43 +00:00
|
|
|
} else {
|
2006-11-22 03:58:00 +00:00
|
|
|
// yu : fix for MDL-7501, possibly need to use user flag as this is quite ugly.
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "<th scope=\"row\" class=\"optioncell\">";
|
|
|
|
echo "<b class=\"qnumtopcell\">$qnum</b> ";
|
2006-11-23 03:01:16 +00:00
|
|
|
$qnum++;
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "<span class=\"preferthat smalltext\">$stripreferthat</span> ";
|
|
|
|
echo "<span class=\"option\">$q->text</span></th>\n";
|
2010-04-23 05:58:43 +00:00
|
|
|
|
|
|
|
$default = get_accesshide($strdefault);
|
|
|
|
echo '<td class="whitecell"><label for="qP'. $P.$q->id .'"><input type="radio" name="qP'.$P.$q->id. '" id="qP'. $q->id .'" value="0" checked="checked" />'.$default.'</label></td>';
|
|
|
|
|
|
|
|
|
2002-08-01 05:18:07 +00:00
|
|
|
for ($i=1;$i<=$numoptions;$i++) {
|
2007-11-21 14:50:32 +00:00
|
|
|
$hiddentext = get_accesshide($options[$i-1]);
|
|
|
|
$id = "qP" . $q->id . "_$i";
|
|
|
|
echo "<td><label for=\"$id\"><input type=\"radio\" name=\"qP$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
|
2002-08-01 05:18:07 +00:00
|
|
|
}
|
2004-09-12 17:34:35 +00:00
|
|
|
echo "</tr>";
|
2002-08-01 05:18:07 +00:00
|
|
|
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "<tr class=\"$rowclass rblock\">";
|
|
|
|
echo "<th scope=\"row\" class=\"optioncell\">";
|
|
|
|
echo "<b class=\"qnumtopcell\">$qnum</b> ";
|
|
|
|
echo "<span class=\"foundthat smalltext\">$strifoundthat</span> ";
|
|
|
|
echo "<span class=\"option\">$q->text</span></th>\n";
|
2010-04-23 05:58:43 +00:00
|
|
|
|
|
|
|
$default = get_accesshide($strdefault);
|
|
|
|
echo '<td class="whitecell"><label for="q'. $q->id .'"><input type="radio" name="q'.$q->id. '" id="q'. $q->id .'" value="0" checked="checked" />'.$default.'</label></td>';
|
|
|
|
|
2002-08-01 05:18:07 +00:00
|
|
|
for ($i=1;$i<=$numoptions;$i++) {
|
2007-11-21 14:50:32 +00:00
|
|
|
$hiddentext = get_accesshide($options[$i-1]);
|
|
|
|
$id = "q" . $q->id . "_$i";
|
|
|
|
echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
|
2002-08-01 05:18:07 +00:00
|
|
|
}
|
2010-04-23 05:58:43 +00:00
|
|
|
|
|
|
|
$checklist["qP$q->id"] = 0;
|
|
|
|
$checklist["q$q->id"] = 0;
|
2002-08-01 05:18:07 +00:00
|
|
|
}
|
2004-09-12 17:34:35 +00:00
|
|
|
echo "</tr>\n";
|
2002-08-01 05:18:07 +00:00
|
|
|
}
|
2004-09-12 17:34:35 +00:00
|
|
|
echo "</table>";
|
2002-08-01 05:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @global int
|
|
|
|
* @param object $question
|
|
|
|
*/
|
2002-08-01 05:18:07 +00:00
|
|
|
function survey_print_single($question) {
|
2009-08-18 05:17:04 +00:00
|
|
|
global $DB, $qnum, $OUTPUT;
|
2002-08-01 05:18:07 +00:00
|
|
|
|
2005-02-10 10:41:22 +00:00
|
|
|
$rowclass = survey_question_rowclass(0);
|
2002-08-01 05:18:07 +00:00
|
|
|
|
|
|
|
$qnum++;
|
|
|
|
|
2004-11-26 07:07:06 +00:00
|
|
|
echo "<br />\n";
|
2007-01-08 05:47:12 +00:00
|
|
|
echo "<table width=\"90%\" cellpadding=\"4\" cellspacing=\"0\">\n";
|
2005-02-10 10:41:22 +00:00
|
|
|
echo "<tr class=\"$rowclass\">";
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "<th scope=\"row\" class=\"optioncell\"><label for=\"q$question->id\"><b class=\"qnumtopcell\">$qnum</b> ";
|
|
|
|
echo "<span class=\"questioncell\">$question->text</span></label></th>\n";
|
|
|
|
echo "<td class=\"questioncell smalltext\">\n";
|
2002-08-01 05:18:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
if ($question->type == 0) { // Plain text field
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "<textarea rows=\"3\" cols=\"30\" name=\"q$question->id\" id=\"q$question->id\">$question->options</textarea>";
|
2002-08-01 05:18:07 +00:00
|
|
|
|
|
|
|
} else if ($question->type > 0) { // Choose one of a number
|
2002-08-12 17:54:13 +00:00
|
|
|
$strchoose = get_string("choose");
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "<select name=\"q$question->id\" id=\"q$question->id\">";
|
2004-09-14 20:39:28 +00:00
|
|
|
echo "<option value=\"0\" selected=\"selected\">$strchoose...</option>";
|
2002-08-01 05:18:07 +00:00
|
|
|
$options = explode( ",", $question->options);
|
|
|
|
foreach ($options as $key => $val) {
|
|
|
|
$key++;
|
2004-09-12 17:34:35 +00:00
|
|
|
echo "<option value=\"$key\">$val</option>";
|
2002-08-01 05:18:07 +00:00
|
|
|
}
|
2004-09-12 17:34:35 +00:00
|
|
|
echo "</select>";
|
2002-08-01 05:18:07 +00:00
|
|
|
|
|
|
|
} else if ($question->type < 0) { // Choose several of a number
|
|
|
|
$options = explode( ",", $question->options);
|
2009-08-18 05:17:04 +00:00
|
|
|
echo $OUTPUT->notification("This question type not supported yet");
|
2002-08-01 05:18:07 +00:00
|
|
|
}
|
|
|
|
|
2007-11-21 14:50:32 +00:00
|
|
|
echo "</td></tr></table>";
|
2002-08-01 05:18:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param int $qnum
|
|
|
|
* @return string
|
|
|
|
*/
|
2005-02-10 10:41:22 +00:00
|
|
|
function survey_question_rowclass($qnum) {
|
2002-08-01 05:18:07 +00:00
|
|
|
|
|
|
|
if ($qnum) {
|
2005-02-10 10:41:22 +00:00
|
|
|
return $qnum % 2 ? 'r0' : 'r1';
|
2002-08-01 05:18:07 +00:00
|
|
|
} else {
|
2005-02-10 10:41:22 +00:00
|
|
|
return 'r0';
|
2002-08-01 05:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @global object
|
|
|
|
* @global int
|
|
|
|
* @global int
|
|
|
|
* @param string $url
|
|
|
|
*/
|
2003-01-05 06:45:20 +00:00
|
|
|
function survey_print_graph($url) {
|
|
|
|
global $CFG, $SURVEY_GHEIGHT, $SURVEY_GWIDTH;
|
|
|
|
|
|
|
|
if (empty($CFG->gdversion)) {
|
|
|
|
echo "(".get_string("gdneed").")";
|
|
|
|
|
|
|
|
} else {
|
2007-01-08 05:47:12 +00:00
|
|
|
echo "<img class='resultgraph' height=\"$SURVEY_GHEIGHT\" width=\"$SURVEY_GWIDTH\"".
|
2006-11-26 16:20:19 +00:00
|
|
|
" src=\"$CFG->wwwroot/mod/survey/graph.php?$url\" alt=\"".get_string("surveygraph", "survey")."\" />";
|
2003-01-05 06:45:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2005-09-01 04:14:31 +00:00
|
|
|
function survey_get_view_actions() {
|
|
|
|
return array('download','view all','view form','view graph','view report');
|
|
|
|
}
|
|
|
|
|
2009-05-28 06:32:35 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2005-09-01 04:14:31 +00:00
|
|
|
function survey_get_post_actions() {
|
|
|
|
return array('submit');
|
|
|
|
}
|
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the function for printing the form elements that control
|
|
|
|
* whether the course reset functionality affects the survey.
|
2009-11-01 15:24:58 +00:00
|
|
|
*
|
2009-05-28 06:32:35 +00:00
|
|
|
* @param object $mform form passed by reference
|
2007-11-29 14:43:04 +00:00
|
|
|
*/
|
|
|
|
function survey_reset_course_form_definition(&$mform) {
|
|
|
|
$mform->addElement('header', 'surveyheader', get_string('modulenameplural', 'survey'));
|
|
|
|
$mform->addElement('checkbox', 'reset_survey_answers', get_string('deleteallanswers','survey'));
|
|
|
|
$mform->addElement('checkbox', 'reset_survey_analysis', get_string('deleteanalysis','survey'));
|
|
|
|
$mform->disabledIf('reset_survey_analysis', 'reset_survey_answers', 'checked');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Course reset form defaults.
|
2009-05-28 06:32:35 +00:00
|
|
|
* @return array
|
2007-11-29 14:43:04 +00:00
|
|
|
*/
|
|
|
|
function survey_reset_course_form_defaults($course) {
|
|
|
|
return array('reset_survey_answers'=>1, 'reset_survey_analysis'=>1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actual implementation of the rest coures functionality, delete all the
|
|
|
|
* survey responses for course $data->courseid.
|
2009-05-28 06:32:35 +00:00
|
|
|
*
|
|
|
|
* @global object
|
2007-11-29 14:43:04 +00:00
|
|
|
* @param $data the data submitted from the reset course.
|
|
|
|
* @return array status array
|
|
|
|
*/
|
|
|
|
function survey_reset_userdata($data) {
|
2008-06-08 14:43:39 +00:00
|
|
|
global $DB;
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
$componentstr = get_string('modulenameplural', 'survey');
|
|
|
|
$status = array();
|
|
|
|
|
|
|
|
$surveyssql = "SELECT ch.id
|
2008-06-08 14:43:39 +00:00
|
|
|
FROM {survey} ch
|
|
|
|
WHERE ch.course=?";
|
|
|
|
$params = array($data->courseid);
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
if (!empty($data->reset_survey_answers)) {
|
2008-06-08 14:43:39 +00:00
|
|
|
$DB->delete_records_select('survey_answers', "survey IN ($surveyssql)", $params);
|
|
|
|
$DB->delete_records_select('survey_analysis', "survey IN ($surveyssql)", $params);
|
2007-11-29 14:43:04 +00:00
|
|
|
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallanswers', 'survey'), 'error'=>false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($data->reset_survey_analysis)) {
|
2008-06-08 14:43:39 +00:00
|
|
|
$DB->delete_records_select('survey_analysis', "survey IN ($surveyssql)", $params);
|
2007-11-29 14:43:04 +00:00
|
|
|
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallanswers', 'survey'), 'error'=>false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// no date shifting
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
2008-07-24 21:59:13 +00:00
|
|
|
/**
|
|
|
|
* Returns all other caps used in module
|
2009-05-28 06:32:35 +00:00
|
|
|
*
|
|
|
|
* @return array
|
2008-07-24 21:59:13 +00:00
|
|
|
*/
|
|
|
|
function survey_get_extra_capabilities() {
|
|
|
|
return array('moodle/site:accessallgroups');
|
|
|
|
}
|
|
|
|
|
2009-04-21 08:57:20 +00:00
|
|
|
/**
|
2009-05-28 06:32:35 +00:00
|
|
|
* @uses FEATURE_GROUPS
|
|
|
|
* @uses FEATURE_GROUPINGS
|
|
|
|
* @uses FEATURE_GROUPMEMBERSONLY
|
|
|
|
* @uses FEATURE_MOD_INTRO
|
|
|
|
* @uses FEATURE_COMPLETION_TRACKS_VIEWS
|
|
|
|
* @uses FEATURE_GRADE_HAS_GRADE
|
|
|
|
* @uses FEATURE_GRADE_OUTCOMES
|
2009-04-21 08:57:20 +00:00
|
|
|
* @param string $feature FEATURE_xx constant for requested feature
|
2009-05-28 06:32:35 +00:00
|
|
|
* @return mixed True if module supports feature, false if not, null if doesn't know
|
2009-04-21 08:57:20 +00:00
|
|
|
*/
|
|
|
|
function survey_supports($feature) {
|
|
|
|
switch($feature) {
|
|
|
|
case FEATURE_GROUPS: return true;
|
|
|
|
case FEATURE_GROUPINGS: return true;
|
|
|
|
case FEATURE_GROUPMEMBERSONLY: return true;
|
2009-04-21 21:17:21 +00:00
|
|
|
case FEATURE_MOD_INTRO: return true;
|
2009-04-21 08:57:20 +00:00
|
|
|
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
|
|
|
|
case FEATURE_GRADE_HAS_GRADE: return true;
|
|
|
|
case FEATURE_GRADE_OUTCOMES: return true;
|
2010-05-05 13:16:25 +00:00
|
|
|
case FEATURE_BACKUP_MOODLE2: return true;
|
2009-04-21 08:57:20 +00:00
|
|
|
|
|
|
|
default: return null;
|
|
|
|
}
|
2009-06-19 14:25:56 +00:00
|
|
|
}
|
2009-09-17 04:11:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This fucntion extends the global navigaiton for the site.
|
|
|
|
* It is important to note that you should not rely on PAGE objects within this
|
|
|
|
* body of code as there is no guarantee that during an AJAX request they are
|
|
|
|
* available
|
|
|
|
*
|
|
|
|
* @param navigation_node $navigation The quiz node within the global navigation
|
|
|
|
* @param stdClass $course The course object returned from the DB
|
|
|
|
* @param stdClass $module The module object returned from the DB
|
|
|
|
* @param stdClass $cm The course module isntance returned from the DB
|
|
|
|
*/
|
|
|
|
function survey_extend_navigation($navigation, $course, $module, $cm) {
|
|
|
|
/**
|
|
|
|
* This is currently just a stub so that it can be easily expanded upon.
|
|
|
|
* When expanding just remove this comment and the line below and then add
|
|
|
|
* you content.
|
|
|
|
*/
|
|
|
|
$navigation->nodetype = navigation_node::NODETYPE_LEAF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function extends the settings navigation block for the site.
|
|
|
|
*
|
|
|
|
* It is safe to rely on PAGE here as we will only ever be within the module
|
|
|
|
* context when this is called
|
|
|
|
*
|
|
|
|
* @param navigation_node $settings
|
2010-03-22 03:04:00 +00:00
|
|
|
* @param navigation_node $surveynode
|
|
|
|
*/
|
|
|
|
function survey_extend_settings_navigation($settings, $surveynode) {
|
|
|
|
global $PAGE;
|
2009-09-17 04:11:46 +00:00
|
|
|
|
|
|
|
if (has_capability('mod/survey:readresponses', $PAGE->cm->context)) {
|
2010-04-19 06:30:30 +00:00
|
|
|
$responsesnode = $surveynode->add(get_string("responsereports", "survey"));
|
2009-09-17 04:11:46 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'summary'));
|
2010-04-19 06:30:30 +00:00
|
|
|
$responsesnode->add(get_string("summary", "survey"), $url);
|
2009-09-17 04:11:46 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'scales'));
|
2010-04-19 06:30:30 +00:00
|
|
|
$responsesnode->add(get_string("scales", "survey"), $url);
|
2009-09-17 04:11:46 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'questions'));
|
2010-04-19 06:30:30 +00:00
|
|
|
$responsesnode->add(get_string("question", "survey"), $url);
|
2009-09-17 04:11:46 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'students'));
|
2010-04-19 06:30:30 +00:00
|
|
|
$responsesnode->add(get_string('participants'), $url);
|
2009-09-17 04:11:46 +00:00
|
|
|
|
|
|
|
if (has_capability('mod/survey:download', $PAGE->cm->context)) {
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'download'));
|
2010-03-22 03:04:00 +00:00
|
|
|
$surveynode->add(get_string('downloadresults', 'survey'), $url);
|
2009-09-17 04:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-05 13:16:25 +00:00
|
|
|
}
|