//This is the "graphical" structure of the choice mod:
//
- // choice
+ // choice
// (CL,pk->id)----------|
// | |
// | |
// | |
// choice_options |
- // (UL,pk->id, fk->choiceid) |
+ // (UL,pk->id, fk->choiceid) |
// | |
// | |
// | |
// choice_answers |
- // (UL,pk->id, fk->choiceid, fk->optionid)
+ // (UL,pk->id, fk->choiceid, fk->optionid)
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
//-----------------------------------------------------------
function choice_backup_mods($bf,$preferences) {
-
- global $CFG;
+
+ global $CFG, $DB;
$status = true;
//Iterate over choice table
- $choices = get_records ("choice","course",$preferences->backup_course,"id");
+ $choices = $DB->get_records("choice", array("course" => $preferences->backup_course), "id");
if ($choices) {
foreach ($choices as $choice) {
if (backup_mod_selected($preferences,'choice',$choice->id)) {
function choice_backup_one_mod($bf,$preferences,$choice) {
- global $CFG;
-
+ global $CFG, $DB;
+
if (is_numeric($choice)) {
- $choice = get_record('choice','id',$choice);
+ $choice = $DB->get_record('choice',array('id' => $choice));
}
-
+
$status = true;
//Start mod
//Backup choice_answers contents (executed from choice_backup_mods)
function backup_choice_answers ($bf,$preferences,$choice) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
- $choice_answers = get_records("choice_answers","choiceid",$choice,"id");
+ $choice_answers = $DB->get_records("choice_answers", array("choiceid" => $choice),"id");
//If there is answers
if ($choice_answers) {
//Write start tag
//backup choice_options contents (executed from choice_backup_mods)
function backup_choice_options ($bf,$preferences,$choice) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
-
- $choice_options = get_records("choice_options","choiceid",$choice,"id");
+
+ $choice_answers = $DB->get_records("choice_options", array("choiceid" => $choice),"id");
//If there is options
- if ($choice_options) {
+ if ($choice_options) {
//Write start tag
$status =fwrite ($bf,start_tag("OPTIONS",4,true));
//Iterate over each answer
}
return $status;
}
-
+
////Return an array of info (name,value)
function choice_check_backup_mods($course,$user_data=false,$backup_unique_code,$instances=null) {
//Returns an array of choices id
function choice_ids ($course) {
- global $CFG;
+ global $CFG, $DB;
- return get_records_sql ("SELECT a.id, a.course
- FROM {$CFG->prefix}choice a
- WHERE a.course = '$course'");
+ return $DB->get_records_sql ("SELECT a.id, a.course
+ FROM {choice} a
+ WHERE a.course = ?", array($course));
}
-
+
//Returns an array of choice_answers id
function choice_answer_ids_by_course ($course) {
- global $CFG;
+ global $CFG, $DB;
- return get_records_sql ("SELECT s.id , s.choiceid
- FROM {$CFG->prefix}choice_answers s,
- {$CFG->prefix}choice a
- WHERE a.course = '$course' AND
- s.choiceid = a.id");
+ return $DB->get_records_sql ("SELECT s.id , s.choiceid
+ FROM {choice_answers} s,
+ {choice} a
+ WHERE a.course = ? AND
+ s.choiceid = a.id", array($course));
}
//Returns an array of choice_answers id
function choice_answer_ids_by_instance ($instanceid) {
- global $CFG;
+ global $CFG, $DB;
- return get_records_sql ("SELECT s.id , s.choiceid
- FROM {$CFG->prefix}choice_answers s
- WHERE s.choiceid = $instanceid");
+ return $DB->get_records_sql ("SELECT s.id , s.choiceid
+ FROM {choice_answers} s
+ WHERE s.choiceid = ?", array($instanceid));
}
?>
}
$sql = "SELECT cha.*
- FROM {$CFG->prefix}choice ch, {$CFG->prefix}choice_answers cha
+ FROM {choice} ch, {choice_answers} cha
WHERE cha.choiceid = ch.id AND
- ch.course = $course->id AND cha.userid = $USER->id";
+ ch.course = ? AND cha.userid = ?";
$answers = array () ;
- if (isloggedin() and !isguestuser() and $allanswers = get_records_sql($sql)) {
+ if (isloggedin() and !isguestuser() and $allanswers = $DB->get_records_sql($sql, array($course->id, $USER->id))) {
foreach ($allanswers as $aa) {
$answers[$aa->choiceid] = $aa;
}
}
$currentsection = $choice->section;
}
-
+
//Calculate the href
if (!$choice->visible) {
//Show dimmed if the mod is hidden
/// Standard functions /////////////////////////////////////////////////////////
function choice_user_outline($course, $user, $mod, $choice) {
- if ($answer = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user->id)) {
+ global $DB;
+ if ($answer = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $user->id))) {
$result->info = "'".format_string(choice_get_option_text($choice, $answer->optionid))."'";
$result->time = $answer->timemodified;
return $result;
function choice_user_complete($course, $user, $mod, $choice) {
- if ($answer = get_record('choice_answers', "choiceid", $choice->id, "userid", $user->id)) {
+ global $DB;
+ if ($answer = $DB->get_record('choice_answers', array("choiceid" => $choice->id, "userid" => $user->id))) {
$result->info = "'".format_string(choice_get_option_text($choice, $answer->optionid))."'";
$result->time = $answer->timemodified;
echo get_string("answered", "choice").": $result->info. ".get_string("updated", '', userdate($result->time));
}
function choice_show_form($choice, $user, $cm, $allresponses) {
-
+ global $DB;
//$cdisplay is an array of the display info for a choice $cdisplay[$optionid]->text - text name of option.
// ->maxanswers -maxanswers for this option
// ->full - whether this option is full or not. 0=not full, 1=full
} else {
$cdisplay[$aid]->countanswers = 0;
}
- if ($current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user->id, 'optionid', $optionid)) {
+ if ($current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $user->id, 'optionid' => $optionid))) {
$cdisplay[$aid]->checked = ' checked="checked" ';
} else {
$cdisplay[$aid]->checked = '';
}
- if ( $choice->limitanswers &&
- ($cdisplay[$aid]->countanswers >= $cdisplay[$aid]->maxanswers) &&
+ if ( $choice->limitanswers &&
+ ($cdisplay[$aid]->countanswers >= $cdisplay[$aid]->maxanswers) &&
(empty($cdisplay[$aid]->checked)) ) {
$cdisplay[$aid]->disabled = ' disabled="disabled" ';
} else {
} else {
echo "<input type=\"submit\" value=\"".get_string("savemychoice","choice")."\" />";
}
- if ($choice->allowupdate && $aaa = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user->id)) {
+ if ($choice->allowupdate && $aaa = $DB->get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user->id)) {
echo "<br /><a href='view.php?id=".$cm->id."&action=delchoice'>".get_string("removemychoice","choice")."</a>";
}
} else {
}
function choice_user_submit_response($formanswer, $choice, $userid, $courseid, $cm) {
-
- $current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $userid);
+ global $DB;
+ $current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $userid));
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$countanswers=0;
// If groups are being used, retrieve responses only for users in
// current group
global $CFG;
- $answers = get_records_sql("
-SELECT
+ $answers = $DB->get_records_sql("
+SELECT
ca.*
-FROM
- {$CFG->prefix}choice_answers ca
- INNER JOIN {$CFG->prefix}groups_members gm ON ca.userid=gm.userid
+FROM
+ {choice_answers} ca
+ INNER JOIN {groups_members} gm ON ca.userid=gm.userid
WHERE
- optionid=$formanswer
- AND gm.groupid=$currentgroup");
+ optionid=?
+ AND gm.groupid=?", array($formanswer, $currentgroup));
} else {
// Groups are not used, retrieve all answers for this option ID
- $answers = get_records("choice_answers", "optionid", $formanswer);
+ $answers = $DB->get_records("choice_answers", array("optionid" => $formanswer));
}
if ($answers) {
$newanswer = $current;
$newanswer->optionid = $formanswer;
$newanswer->timemodified = time();
- if (! update_record("choice_answers", $newanswer)) {
+ if (! $DB->update_record("choice_answers", $newanswer)) {
print_error('cannotupdatechoice', 'choice');
}
add_to_log($courseid, "choice", "choose again", "view.php?id=$cm->id", $choice->id, $cm->id);
$newanswer->userid = $userid;
$newanswer->optionid = $formanswer;
$newanswer->timemodified = time();
- if (! insert_record("choice_answers", $newanswer)) {
+ if (! $DB->insert_record("choice_answers", $newanswer)) {
print_error('cannotsavechoice', 'choice');
}
add_to_log($courseid, "choice", "choose", "view.php?id=$cm->id", $choice->id, $cm->id);
function choice_show_results($choice, $course, $cm, $allresponses, $forcepublish='') {
global $CFG, $COLUMN_HEIGHT;
-
+
print_heading(get_string("responses", "choice"));
if (empty($forcepublish)) { //alow the publish setting to be overridden
$forcepublish = $choice->publish;
$totalresponsecount += count($userlist);
}
}
-
+
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$hascapfullnames = has_capability('moodle/site:viewfullnames', $context);
-
- $viewresponses = has_capability('mod/choice:readresponses', $context);
+
+ $viewresponses = has_capability('mod/choice:readresponses', $context);
switch ($forcepublish) {
case CHOICE_PUBLISH_NAMES:
echo '<div id="tablecontainer">';
echo "<table cellpadding=\"5\" cellspacing=\"10\" class=\"results names\">";
echo "<tr>";
-
+
$columncount = array(); // number of votes in each column
if ($choice->showunanswered) {
$columncount[0] = 0;
}
echo "</tr><tr>";
$count = 0;
-
+
if ($choice->showunanswered) {
echo "<td></td>";
}
-
+
foreach ($choice->option as $optionid => $optiontext) {
echo "<td align=\"center\" class=\"count\">";
if ($choice->limitanswers) {
echo $columncount[$optionid];
echo "<br/>";
echo get_string("limit", "choice").":";
- $choice_option = get_record("choice_options", "id", $optionid);
+ $choice_option = $DB->get_record("choice_options", array("id" => $optionid));
echo $choice_option->maxanswers;
} else {
if (isset($columncount[$optionid])) {
$count++;
}
echo "</tr>";
-
+
/// Print "Select all" etc.
if ($viewresponses and has_capability('mod/choice:deleteresponses',$context)) {
echo '<tr><td></td><td>';
echo '<script type="text/javascript">'."\n<!--\n".'document.getElementById("noscriptmenuaction").style.display = "none";'."\n-->\n".'</script>';
echo '</td><td></td></tr>';
}
-
+
echo "</table>";
if ($viewresponses) {
echo "</div></form></div>";
}
break;
-
-
+
+
case CHOICE_PUBLISH_ANONYMOUS:
echo "<table cellpadding=\"5\" cellspacing=\"0\" class=\"results anonymous\">";
echo "<th class=\"col$count header\" scope=\"col\">";
echo format_string($optiontext);
echo "</th>";
-
+
$column[$optionid] = 0;
if (isset($allresponses[$optionid])) {
$column[$optionid] = count($allresponses[$optionid]);
echo get_string("taken", "choice").":";
echo $column[$optionid].'<br />';
echo get_string("limit", "choice").":";
- $choice_option = get_record("choice_options", "id", $optionid);
+ $choice_option = $DB->get_record("choice_options", array("id" => $optionid));
echo $choice_option->maxanswers;
} else {
echo $column[$optionid];
$count++;
}
echo "</tr></table>";
-
+
break;
}
}
function choice_delete_responses($attemptids, $choiceid) {
-
+ global $DB;
if(!is_array($attemptids) || empty($attemptids)) {
return false;
}
}
foreach($attemptids as $attemptid) {
- if ($todelete = get_record('choice_answers', 'choiceid', $choiceid, 'userid', $attemptid)) {
- delete_records('choice_answers', 'choiceid', $choiceid, 'userid', $attemptid);
+ if ($todelete = $DB->get_record('choice_answers', array('choiceid' => $choiceid, 'userid' => $attemptid))) {
+ $DB->delete_records('choice_answers', array('choiceid' => $choiceid, 'userid' => $attemptid));
}
}
return true;
global $CFG;
//Get students
- $students = get_records_sql("SELECT DISTINCT u.id, u.id
- FROM {$CFG->prefix}user u,
- {$CFG->prefix}choice_answers a
- WHERE a.choiceid = '$choiceid' and
- u.id = a.userid");
+ $students = $DB->get_records_sql("SELECT DISTINCT u.id, u.id
+ FROM {user} u,
+ {choice_answers} a
+ WHERE a.choiceid = ? AND
+ u.id = a.userid", array($choiceid));
//Return students array (it contains an array of unique users)
return ($students);
function choice_get_option_text($choice, $id) {
+ global $DB;
// Returns text string which is the answer that matches the id
- if ($result = get_record("choice_options", "id", $id)) {
+ if ($result = $DB->get_record("choice_options", array("id" => $id))) {
return $result->text;
} else {
return get_string("notanswered", "choice");
}
function choice_get_choice($choiceid) {
+ global $DB;
// Gets a full choice record
- if ($choice = get_record("choice", "id", $choiceid)) {
- if ($options = get_records("choice_options", "choiceid", $choiceid, "id")) {
+ if ($choice = $DB->get_record("choice", array("id" => $choiceid))) {
+ if ($options = $DB->get_records("choice_options", array("choiceid" => $choiceid), "id")) {
foreach ($options as $option) {
$choice->option[$option->id] = $option->text;
$choice->maxanswers[$option->id] = $option->maxanswers;
* @return array status array
*/
function choice_reset_userdata($data) {
- global $CFG;
+ global $CFG, $DB;
$componentstr = get_string('modulenameplural', 'choice');
$status = array();
if (!empty($data->reset_choice)) {
$choicessql = "SELECT ch.id
- FROM {$CFG->prefix}choice ch
- WHERE ch.course={$data->courseid}";
+ FROM {choice} ch
+ WHERE ch.course=?";
- delete_records_select('choice_answers', "choiceid IN ($choicessql)");
+ $DB->delete_records_select('choice_answers', "choiceid IN ($choicessql)", array($data->courseid));
$status[] = array('component'=>$componentstr, 'item'=>get_string('removeresponses', 'choice'), 'error'=>false);
}
}
function choice_get_response_data($choice, $cm, $groupmode) {
- global $CFG, $USER;
+ global $CFG, $USER, $DB;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$allresponses[0] = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC', '', '', $currentgroup, '', false, true);
/// Get all the recorded responses for this choice
- $rawresponses = get_records('choice_answers', 'choiceid', $choice->id);
+ $rawresponses = $DB->get_records('choice_answers', array('choiceid' => $choice->id));
/// Use the responses to move users into the correct column
print_error("invalidcoursemodule");
}
- if (! $course = get_record("course", "id", $cm->course)) {
+ if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
print_error("coursemisconf");
}
require_login($course->id, false, $cm);
-
+
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
+
require_capability('mod/choice:readresponses', $context);
-
+
if (!$choice = choice_get_choice($cm->instance)) {
print_error('invalidcoursemodule');
}
$strresponses = get_string("responses", "choice");
add_to_log($course->id, "choice", "report", "report.php?id=$cm->id", "$choice->id",$cm->id);
-
+
if ($action == 'delete' && has_capability('mod/choice:deleteresponses',$context)) {
$attemptids = isset($_POST['attemptid']) ? $_POST['attemptid'] : array(); //get array of repsonses to delete.
choice_delete_responses($attemptids, $choice->id); //delete responses.
redirect("report.php?id=$cm->id");
}
-
+
if (!$download) {
$navigation = build_navigation($strresponses, $cm);
if ($download == "ods" && has_capability('mod/choice:downloadresponses', $context)) {
require_once("$CFG->libdir/odslib.class.php");
-
- /// Calculate file name
+
+ /// Calculate file name
$filename = clean_filename("$course->shortname ".strip_tags(format_string($choice->name,true))).'.ods';
/// Creating a workbook
$workbook = new MoodleODSWorkbook("-");
$myxls->write_string(0,4,get_string("choice","choice"));
/// generate the data for the body of the spreadsheet
- $i=0;
+ $i=0;
$row=1;
if ($users) {
foreach ($users as $option => $userid) {
$myxls->write_string($row,3,$ug2);
if (isset($option_text)) {
- $myxls->write_string($row,4,format_string($useroption,true));
+ $myxls->write_string($row,4,format_string($option_text,true));
}
$row++;
$pos=4;
//print spreadsheet if one is asked for:
if ($download == "xls" && has_capability('mod/choice:downloadresponses', $context)) {
require_once("$CFG->libdir/excellib.class.php");
-
- /// Calculate file name
+
+ /// Calculate file name
$filename = clean_filename("$course->shortname ".strip_tags(format_string($choice->name,true))).'.xls';
/// Creating a workbook
$workbook = new MoodleExcelWorkbook("-");
$myxls->write_string(0,2,get_string("idnumber"));
$myxls->write_string(0,3,get_string("group"));
$myxls->write_string(0,4,get_string("choice","choice"));
-
-
+
+
/// generate the data for the body of the spreadsheet
- $i=0;
+ $i=0;
$row=1;
if ($users) {
foreach ($users as $option => $userid) {
exit;
}
- // print text file
+ // print text file
if ($download == "txt" && has_capability('mod/choice:downloadresponses', $context)) {
$filename = clean_filename("$course->shortname ".strip_tags(format_string($choice->name,true))).'.txt';
echo get_string("firstname")."\t".get_string("lastname") . "\t". get_string("idnumber") . "\t";
echo get_string("group"). "\t";
- echo get_string("choice","choice"). "\n";
+ echo get_string("choice","choice"). "\n";
/// generate the data for the body of the spreadsheet
- $i=0;
+ $i=0;
if ($users) {
foreach ($users as $option => $userid) {
$option_text = choice_get_option_text($choice, $option);
}
choice_show_results($choice, $course, $cm, $users, $format); //show table with students responses.
- //now give links for downloading spreadsheets.
+ //now give links for downloading spreadsheets.
if (has_capability('mod/choice:downloadresponses',$context)) {
echo "<br />\n";
echo "<table class=\"downloadreport\"><tr>\n";
echo "<td>";
$options = array();
- $options["id"] = "$cm->id";
+ $options["id"] = "$cm->id";
$options["download"] = "ods";
print_single_button("report.php", $options, get_string("downloadods"));
echo "</td><td>";
$options["download"] = "xls";
print_single_button("report.php", $options, get_string("downloadexcel"));
echo "</td><td>";
- $options["download"] = "txt";
+ $options["download"] = "txt";
print_single_button("report.php", $options, get_string("downloadtext"));
echo "</td></tr></table>";
// | |
// | |
// choice_answers |
- // (UL,pk->id, fk->choiceid, fk->optionid)
+ // (UL,pk->id, fk->choiceid, fk->optionid)
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
$choice->display = backup_todb($info['MOD']['#']['DISPLAY']['0']['#']);
$choice->allowupdate = backup_todb($info['MOD']['#']['ALLOWUPDATE']['0']['#']);
$choice->showunanswered = backup_todb($info['MOD']['#']['SHOWUNANSWERED']['0']['#']);
- $choice->limitanswers = backup_todb($info['MOD']['#']['LIMITANSWERS']['0']['#']);
+ $choice->limitanswers = backup_todb($info['MOD']['#']['LIMITANSWERS']['0']['#']);
$choice->timeopen = backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
$choice->timeclose = backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
$choice->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
if (! isset($info['MOD']['#']['SHOWRESULTS']['0']['#'])) { //check for previous versions
if (! isset($info['MOD']['#']['RELEASE']['0']['#'])) { //It's a pre-14 backup filea
//Set the allowupdate field
- if ($choice->publish == 0) {
+ if ($choice->publish == 0) {
$choice->allowupdate = 1;
}
//Set the showresults field as defined by the old publish field
}
//The structure is equal to the db, so insert the choice
$newid = $DB->insert_record ("choice",$choice);
-
+
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,$mod->modtype,
$mod->id, $newid);
-
- //Check to see how answers (curently choice_options) are stored in the table
+
+ //Check to see how answers (curently choice_options) are stored in the table
//If answer1 - answer6 exist, this is a pre 1.5 version of choice
- if (isset($info['MOD']['#']['ANSWER1']['0']['#']) ||
- isset($info['MOD']['#']['ANSWER2']['0']['#']) ||
- isset($info['MOD']['#']['ANSWER3']['0']['#']) ||
- isset($info['MOD']['#']['ANSWER4']['0']['#']) ||
- isset($info['MOD']['#']['ANSWER5']['0']['#']) ||
+ if (isset($info['MOD']['#']['ANSWER1']['0']['#']) ||
+ isset($info['MOD']['#']['ANSWER2']['0']['#']) ||
+ isset($info['MOD']['#']['ANSWER3']['0']['#']) ||
+ isset($info['MOD']['#']['ANSWER4']['0']['#']) ||
+ isset($info['MOD']['#']['ANSWER5']['0']['#']) ||
isset($info['MOD']['#']['ANSWER6']['0']['#']) ) {
-
+
//This is a pre 1.5 choice backup, special work begins
$options = array();
$options[1] = backup_todb($info['MOD']['#']['ANSWER1']['0']['#']);
$options[4] = backup_todb($info['MOD']['#']['ANSWER4']['0']['#']);
$options[5] = backup_todb($info['MOD']['#']['ANSWER5']['0']['#']);
$options[6] = backup_todb($info['MOD']['#']['ANSWER6']['0']['#']);
-
- for($i = 1; $i < 7; $i++) { //insert old answers (in 1.4) as choice_options (1.5) to db.
+
+ for($i = 1; $i < 7; $i++) { //insert old answers (in 1.4) as choice_options (1.5) to db.
if (!empty($options[$i])) { //make sure this option has something in it!
$option->choiceid = $newid;
$option->text = $options[$i];
//now restore the answers for this choice.
if (restore_userdata_selected($restore,'choice',$mod->id)) {
//Restore choice_answers
- $status = choice_answers_restore_mods($newid,$info,$restore);
- }
+ $status = choice_answers_restore_mods($newid,$info,$restore);
+ }
} else {
$status = false;
}
- //Do some output
+ //Do some output
if (!defined('RESTORE_SILENTLY')) {
echo "<li>".get_string("modulename","choice")." \"".format_string($choice->name,true)."\"</li>";
}
//choice_decode_content_links_caller() function in each module
//in the restore process
function choice_decode_content_links ($content,$restore) {
-
+
global $CFG;
-
+
$result = $content;
-
+
//Link to the list of choices
-
+
$searchstring='/\$@(CHOICEINDEX)\*([0-9]+)@\$/';
//We look for it
preg_match_all($searchstring,$content,$foundset);
if($rec->new_id) {
//Now replace it
$result= preg_replace($searchstring,$CFG->wwwroot.'/mod/choice/index.php?id='.$rec->new_id,$result);
- } else {
+ } else {
//It's a foreign link so leave it as original
$result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/choice/index.php?id='.$old_id,$result);
}
//working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process
function choice_decode_content_links_caller($restore) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
-
+
if ($choices = $DB->get_records('chat', array('course'=>$restore->course_id), '', "id,text")) {
//Iterate over each choice->text
$i = 0; //Counter to send some output to the browser to avoid timeouts
//This function returns a log record with all the necessay transformations
//done. It's used by restore_log_module() to restore modules log.
function choice_restore_logs($restore,$log) {
-
+
$status = false;
-
+
//Depending of the action, we recode different things
switch ($log->action) {
case "add":
$id = required_param('id', PARAM_INT); // Course Module ID
$action = optional_param('action', '', PARAM_ALPHA);
$attemptids = optional_param('attemptid', array(), PARAM_INT); // array of attempt ids for delete action
-
+
if (! $cm = get_coursemodule_from_id('choice', $id)) {
print_error('invalidcoursemodule');
}
- if (! $course = get_record("course", "id", $cm->course)) {
+ if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
print_error('coursemisconf');
}
if (!$choice = choice_get_choice($cm->instance)) {
print_error('invalidcoursemodule');
}
-
+
$strchoice = get_string('modulename', 'choice');
$strchoices = get_string('modulenameplural', 'choice');
}
if ($action == 'delchoice') {
- if ($answer = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $USER->id)) {
+ if ($answer = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) {
//print_object($answer);
- delete_records('choice_answers', 'id', $answer->id);
+ $DB->delete_records('choice_answers', array('id' => $answer->id));
}
}
if ($form = data_submitted() && has_capability('mod/choice:choose', $context)) {
$timenow = time();
if (has_capability('mod/choice:deleteresponses', $context)) {
- if ($action == 'delete') { //some responses need to be deleted
+ if ($action == 'delete') { //some responses need to be deleted
choice_delete_responses($attemptids); //delete responses.
redirect("view.php?id=$cm->id");
}
/// Check to see if groups are being used in this choice
$groupmode = groups_get_activity_groupmode($cm);
-
+
if ($groupmode) {
groups_get_activity_group($cm, true);
groups_print_activity_menu($cm, 'view.php?id='.$id);
}
$allresponses = choice_get_response_data($choice, $cm, $groupmode); // Big function, approx 6 SQL calls per user
-
+
if (has_capability('mod/choice:readresponses', $context)) {
choice_show_reportlink($allresponses, $cm);
}
$current = false; // Initialise for later
//if user has already made a selection, and they are not allowed to update it, show their selected answer.
- if (!empty($USER->id) && ($current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $USER->id)) &&
+ if (!empty($USER->id) && ($current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) &&
empty($choice->allowupdate) ) {
print_simple_box(get_string("yourselection", "choice", userdate($choice->timeopen)).": ".format_string(choice_get_option_text($choice, $current->optionid)), "center");
}
}
}
- if ( (!$current or $choice->allowupdate) and
- ($choice->timeclose >= time() or $choice->timeclose == 0) and
+ if ( (!$current or $choice->allowupdate) and
+ ($choice->timeclose >= time() or $choice->timeclose == 0) and
has_capability('mod/choice:choose', $context) ) {
// They haven't made their choice yet or updates allowed and choice is open
- echo '<form id="form" method="post" action="view.php">';
+ echo '<form id="form" method="post" action="view.php">';
choice_show_form($choice, $USER, $cm, $allresponses);
print_simple_box_start('center', '60%', '', 5, 'generalbox', 'notice');
echo '<p align="center">'. get_string('noguestchoose', 'choice') .'</p>';
echo '<div class="continuebutton">';
- print_single_button($CFG->wwwroot.'/course/enrol.php?id='.$course->id, NULL,
+ print_single_button($CFG->wwwroot.'/course/enrol.php?id='.$course->id, NULL,
get_string('enrolme', '', format_string($course->shortname)), 'post', $CFG->framename);
echo '</div>'."\n";
print_simple_box_end();
} else if (!$choiceformshown) {
print_simple_box(get_string('noresultsviewable', 'choice'), 'center');
- }
+ }
print_footer($course);