$coursesummary = restore_decode_content_links_worker($coursesummary, $restore);
if ($coursesummary != $course->summary) {
$course->summary = $coursesummary;
- if (!$DB->update_record('course', $course)) {
- $status = false;
- }
+ $DB->update_record('course', $course);
}
if (!defined('RESTORE_SILENTLY')) {
echo '</li>';
$sectionsummary = restore_decode_content_links_worker($section->summary, $restore);
if ($sectionsummary != $section->summary) {
$section->summary = $sectionsummary;
- if (!$DB->update_record('course_sections', $section)) {
- $status = false;
- }
+ $DB->update_record('course_sections', $section);
}
}
if (!defined('RESTORE_SILENTLY')) {
}
$dataobject->url = $url;
- if (!$DB->update_record('block_rss_client', $dataobject)) {
- print_error('updatersserror', 'error', '', $rssid);
- }
+ $DB->update_record('block_rss_client', $dataobject);
$message .= '<br />'. get_string('feedupdated', 'block_rss_client');
redirect($referrer, $message);
if (!empty($rss->channel['title'])) {
$dataobject->title = $rss->channel['title'];
}
- if (!$DB->update_record('block_rss_client', $dataobject)) {
- print_error('updatersserror', 'error', '', $rssid);
- }
+ $DB->update_record('block_rss_client', $dataobject);
$message .= '<br />'. get_string('feedadded', 'block_rss_client');
}
redirect($referrer, $message);
if ($mod->section != $section->id) {
$mod->section = $section->id;
- if (!$DB->update_record("course_modules", $mod)) {
- return false;
- }
+ $DB->update_record("course_modules", $mod);
// if moving to a hidden section then hide module
if (!$section->visible) {
set_coursemodule_visible($mod->id, 0);
$course->category = $categoryid;
$course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - $i++;
- if (!$DB->update_record('course', $course)) {
- notify("An error occurred - course not moved!");
- }
+ $DB->update_record('course', $course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
$newcourse = new object;
$newcourse->id = $course->id;
$newcourse->marker = $value;
- if (!$DB->update_record('course', $newcourse)) {
- error_log('AJAX commands.php: Failed to update course marker for course '.$newcourse->id);
- die;
- }
+ $DB->update_record('course', $newcourse);
break;
}
break;
$order->status = AN_STATUS_UNDERREVIEW;
}
- if (!$DB->update_record('enrol_authorize', $order)) {
- message_to_admin("Error while trying to update data in table enrol_authorize. Please edit manually this record: ID=$order->id.", $order);
- }
+ $DB->update_record('enrol_authorize', $order);
}
break;
$string['cannotupdateprofile'] = 'Error updating user record';
$string['cannotupdaterss'] = 'Cannot update RSS';
$string['cannotupdatesecret'] = 'Error resetting user secret string';
-$string['cannotupdatesubcate'] = 'Could not update a child category!';
$string['cannotupdatesubcourse'] = 'Could not update a child course!';
$string['cannotuploadfile'] = 'Error processing upload file';
$string['cannotunassignrolefrom'] = 'Cannot unassign this user from role id: $a';
$string['badbase'] = 'Bad base before **: $a**';
$string['broken'] = 'This is a \"broken link\", it points to a nonexistent file.';
$string['byandon'] = 'by <em>$a->user</em> on <em>$a->time</em>';
-$string['cannotinsert'] = 'Could not insert entry in question_sessions';
$string['cannotcreate'] = 'Could not create new entry in question_attempts table';
-$string['cannotcreatedataset'] = 'Unable to create dataset $a';
-$string['cannotcreaterelation'] = 'Unable to create relation to dataset $a[0] $a[1]';
$string['cannotcreatepath'] = 'Cannot create path: $a';
$string['cannotcopybackup'] = 'Could not copy backup file';
$string['cannotdeletecate'] = 'You can\'t delete that category it is the default category for this context.';
$string['cannotenable'] = 'Question type $a cannot be created directly.';
$string['cannotfindcate'] = 'Could not find category record';
-$string['cannotinsertitem'] = 'Unable to insert dataset item $a[0] with $a[1] for $a[2]';
-$string['cannotinsert'] = 'Error: Unable to insert dataset item';
$string['cannotinsertquestion'] = 'Could not insert new question!';
$string['cannotinsertquestioncatecontext'] = 'Could not insert the new question category $a[0] illegal contextid $a[1]';
-$string['cannotinsertquestioncate'] = 'Could not insert the new question category: $a';
$string['cannotimportformat'] = 'Sorry, importing this format is not yet implemented!';
$string['cannotfindquestionfile'] = 'Could not find question data file in zip';
$string['cannotgetdsforquestion'] = 'Cannot get the specified dataset for a calculated question! (question: {$a})';
$string['cannotloadquestion'] = 'Could not load question';
$string['cannotpreview'] = 'You can\'t preview these questions!';
$string['cannotretrieveqcat'] = 'Could retrieve question category';
-$string['cannotupdatecount'] = 'Error: Unable to update itemcount';
-$string['cannotupdatecate'] = 'Could not update the category $a';
-$string['cannotmovecate'] = 'Cannot move the category $a. It is the last in this context.';
-$string['cannotmovefromto'] = 'Could not move the category $a[0] to $a[1]';
$string['cannotmovequestion'] = 'You can\'t use this script to move questions that have files associated with them from different areas.';
$string['cannotopenforwriting'] = 'Cannot open for writing: $a';
$string['cannotunhidequestion'] = 'Failed to unhide the question.';
$string['cannotunzip'] = 'Could not unzip file.';
-$string['cannotupdatesubcate'] = 'Could not update a child category!';
-$string['cannotupdaterandomqname'] = 'Could not update random question name';
-$string['cannotupdateitem'] = 'Error: Unable to update dataset item';
-$string['cannotupdatequestion'] = 'Could not update question!';
-$string['cannotupdatequestionver'] = 'Could not update question version field';
-$string['cannotsavequiz'] = 'Failed to save the current quiz attempt!';
$string['cannotwriteto'] = 'Cannot write exported questions to $a';
$string['categorydoesnotexist'] = 'This category does not exist';
$string['categorycurrent'] = 'Current Category';
$string['cannotacceptbin'] = 'This wiki does not accept binaries';
$string['cannotaddentry'] = 'Could not add wiki entry.';
$string['cannotchangepage'] = 'This page cannot be changed.';
-$string['cannotdeletelockrecored'] = 'Unable to delete lock record';
-$string['cannotinsertlockrecored'] = 'Unable to insert lock record';
$string['cannotgetentry'] = 'Cannot get entry.';
$string['cannotstartwith'] = 'Binary entry does not start with ($a)';
$string['changes'] = '$a changes';
$ra->timemodified = $timemodified;
$ra->modifierid = empty($USER->id) ? 0 : $USER->id;
- if (!$DB->update_record('role_assignments', $ra)) {
- return false;
- }
+ $DB->update_record('role_assignments', $ra);
}
/// mark context as dirty - modules might use has_capability() in xxx_role_assing()
$session->manualcomment = $session->manualcomment;
}
$session->flagged = !empty($state->newflaggedstate);
- if (!$DB->update_record('question_sessions', $session)) {
- return false;
- }
+ $DB->update_record('question_sessions', $session);
}
unset($state->answer);
if ($grade !== '' && (abs($state->last_graded->grade - $grade) > 0.002 || $state->last_graded->event != QUESTION_EVENTMANUALGRADE)) {
$attempt->sumgrades = $attempt->sumgrades - $state->last_graded->grade + $grade;
$attempt->timemodified = time();
- if (!$DB->update_record('quiz_attempts', $attempt)) {
- return get_string('errorupdatingattempt', 'question', $attempt);
- }
+ $DB->update_record('quiz_attempts', $attempt);
// We want to update existing state (rather than creating new one) if it
// was itself created by a manual grading event.
return array(false,$lock);
} else {
// Not locked any more. Get rid of the old lock record.
- if(!$DB->delete_records('wiki_locks', array('pagename'=>$pagename,'wikiid'=>$wikiid))) {
- print_error('cannotdeletelockrecored', 'wiki');
- }
+ $DB->delete_records('wiki_locks', array('pagename'=>$pagename,'wikiid'=>$wikiid));
}
}
$newlock->lockedseen=$newlock->lockedsince;
$newlock->wikiid=$wikiid;
$newlock->pagename=$pagename;
- if(!$lockid=$DB->insert_record('wiki_locks',$newlock)) {
- print_error('cannotinsertlockrecored', 'wiki');
- }
+ $lockid = $DB->insert_record('wiki_locks',$newlock);
}
// Store lock information in session so we can clear it later
if(array_key_exists($key,$_SESSION[SESSION_WIKI_LOCKS])) {
$lockid=$_SESSION[SESSION_WIKI_LOCKS][$key];
unset($_SESSION[SESSION_WIKI_LOCKS][$key]);
- if (!$DB->delete_records('wiki_locks', array('id'=>$lockid))) {
- print_error('cannotdeletelockrecored', 'wiki');
- }
+ $DB->delete_records('wiki_locks', array('id'=>$lockid));
}
}
print_error('invalidpageval', 'wiki');
}
$pagename=$actions[1];
-if(!$DB->delete_records('wiki_locks', array('pagename'=>$pagename, 'wikiid'=>$wiki->id))) {
- print_error('cannotdeletelockrecored', 'wiki');
-}
+$DB->delete_records('wiki_locks', array('pagename'=>$pagename, 'wikiid'=>$wiki->id));
redirect("view.php?id=$id&page=".urlencode($page));
?>
print_error('unknowcategory');
}
/// Send the children categories to live with their grandparent
- if (!$DB->set_field("question_categories", "parent", $category->parent, array("parent" => $category->id))) {
- print_error('cannotupdatesubcate', 'question');
- }
+ $DB->set_field("question_categories", "parent", $category->parent, array("parent" => $category->id));
/// Finally delete the category itself
$DB->delete_records("question_categories", array("id" => $category->id));
$cat->info = $newinfo;
$cat->sortorder = 999;
$cat->stamp = make_unique_id_code();
- if (!$categoryid=$DB->insert_record("question_categories", $cat)) {
- print_error('cannotinsertquestioncate', 'question', '', $newcategory);
+ $categoryid = $DB->insert_record("question_categories", $cat);
+ if ($return) {
+ return $categoryid;
} else {
- if($return){
- return $categoryid;
- }else{
- redirect($this->pageurl->out());//always redirect after successful action
- }
+ redirect($this->pageurl->out());//always redirect after successful action
}
}
$cat->info = $newinfo;
$cat->parent = $parentid;
// We don't change $cat->contextid here, if necessary we redirect to contextmove.php later.
- if (!$DB->update_record('question_categories', $cat)) {
- print_error('cannotupdatecate', 'question', $this->pageurl->out(), $newname);
- }
+ $DB->update_record('question_categories', $cat);
// If the category name has changed, rename any random questions in that category.
if ($oldcat->name != $cat->name) {
list($usql, $params) = $DB->get_in_or_equal(explode(',', $cattomove->categorylist));
$params = array_merge(array($contextto->id), $params);
- if (!$DB->execute("UPDATE {question_categories} SET contextid = ? WHERE id $usql", $params)){
- print_error('cannotmovefromto', 'question', $onerrorurl, array($newname, $contexttostring));
- }
+ $DB->execute("UPDATE {question_categories} SET contextid = ? WHERE id $usql", $params);
//finally set the new parent id
- if (!$DB->update_record("question_categories", $cat)) {
- print_error('cannotupdatecate', 'question', $onerrorurl, $updatename);
- }
+ $DB->update_record("question_categories", $cat);
$thispageurl->remove_params('cattomove', 'toparent', 'totop');
redirect($CFG->wwwroot."/question/category.php?".$thispageurl->get_query_string(array('cat'=>"{$cattomove->id},{$contextto->id}")));
}
$question->createdby = $USER->id;
$question->timecreated = time();
- if (!$question->id = $DB->insert_record("question", $question)) {
- print_error('cannotinsert','quiz');
- }
+ $question->id = $DB->insert_record("question", $question);
$this->questionids[] = $question->id;
if ($questiontext != $question->questiontext || $generalfeedback != $question->generalfeedback) {
$question->questiontext = $questiontext;
$question->generalfeedback = $generalfeedback;
- if (!$DB->update_record('question', $question)) {
- $status = false;
- }
+ $DB->update_record('question', $question);
}
// Do some output.
unset($answer->qtype);
$answer->feedback = $feedback;
$answer->answer = $answertext;
- if (!$DB->update_record('question_answers', $answer)) {
- $status = false;
- }
+ $DB->update_record('question_answers', $answer);
}
// Do some output.
}
}
if ( $todo=='create'){
- if (!$datasetdef->id = $DB->insert_record( 'question_dataset_definitions', $datasetdef)) {
- print_error('cannotcreatedataset', 'question', '', $defid);
- }
+ $datasetdef->id = $DB->insert_record( 'question_dataset_definitions', $datasetdef);
}
// Create relation to the dataset:
$questiondataset = new stdClass;
$questiondataset->question = $question->id;
$questiondataset->datasetdefinition = $datasetdef->id;
- if (!$DB->insert_record('question_datasets', $questiondataset)) {
- print_error("cannotcreaterelation", 'question', '',
- array($dataset->name, $todo));
- }
+ $DB->insert_record('question_datasets', $questiondataset);
if ($todo=='create'){ // add the items
foreach ($dataset->datasetitem as $dataitem ){
$datasetitem = new stdClass;
$datasetitem->definition=$datasetdef->id ;
$datasetitem->itemnumber = $dataitem->itemnumber ;
$datasetitem->value = $dataitem->value ;
- if (!$DB->insert_record('question_dataset_items', $datasetitem)) {
- print_error('cannotinsertitem', 'question', '',
- array($item->itemnumber, $item->value, $datasetdef->name));
- }
+ $DB->insert_record('question_dataset_items', $datasetitem);
}
}
}
if ($fromform->itemid[$i]) {
// Reuse any previously used record
$addeditem->id = $fromform->itemid[$i];
- if (!$DB->update_record('question_dataset_items', $addeditem)) {
- print_error('cannotupdateitem', 'question');
- }
+ $DB->update_record('question_dataset_items', $addeditem);
} else {
- if (!$DB->insert_record('question_dataset_items', $addeditem)) {
- print_error('cannotinsert', 'question');
- }
+ $DB->insert_record('question_dataset_items', $addeditem);
}
$i++;
$datasetitem->definition = $datasetdef->id ;
$datasetitem->itemnumber = $numberadded;
$datasetitem->value = $this->generate_dataset_item($datasetdef->options);
- if (!$DB->update_record('question_dataset_items', $datasetitem)) {
- print_error('cannotupdateitem', 'question');
- }
+ $DB->update_record('question_dataset_items', $datasetitem);
}
//if not regenerate do nothing as there is already a record
} else {
} else {
$datasetitem->value = '';
}
- if (!$DB->insert_record('question_dataset_items', $datasetitem)) {
- print_error('cannotinsert', 'question');
- }
+ $DB->insert_record('question_dataset_items', $datasetitem);
}
}//for number added
}// datasetsdefs end
foreach ($datasetdefs as $datasetdef) {
if ($datasetdef->itemcount == $maxnumber) {
$datasetdef->itemcount= $newmaxnumber ;
- if (!$DB->update_record('question_dataset_definitions',
- $datasetdef)) {
- print_error('cannotupdatecount', 'question');
- }
+ $DB->update_record('question_dataset_definitions', $datasetdef);
}
}
}
continue;
}
- if (!$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef)) {
- print_error("cannotcreatedataset", 'question', '', $defid);
- }
+ $datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
if (0 != $datasetdef->category) {
// We need to look for already existing
$questiondataset = new stdClass;
$questiondataset->question = $form->id;
$questiondataset->datasetdefinition = $datasetdef->id;
- if (!$DB->insert_record('question_datasets', $questiondataset)) {
- print_error('cannotcreaterelation', 'question', '', $name);
- }
+ $DB->insert_record('question_datasets', $questiondataset);
unset($datasetdefinitions[$defid]);
}
$olddatasetid = $datasetdef->id ;
$olditemcount = $datasetdef->itemcount ;
$datasetdef->itemcount =0;
- if (!$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef)) {
- print_error('cannotcreatedataset', 'question', '', $defid);
- }
+ $datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
//copy the dataitems
$olditems = $this->get_database_dataset_items($olddatasetid);
if (count($olditems) > 0 ) {
$itemcount = 0;
foreach($olditems as $item ){
$item->definition = $datasetdef->id;
- if (!$DB->insert_record('question_dataset_items', $item)) {
- print_error('cannotinsertitem', 'question', '', array($item->itemnumber, $item->value, $datasetdef->name));
- }
- $itemcount++;
+ $DB->insert_record('question_dataset_items', $item);
+ $itemcount++;
}
//update item count
$datasetdef->itemcount =$itemcount;
$questiondataset = new stdClass;
$questiondataset->question = $form->id;
$questiondataset->datasetdefinition = $datasetdef->id;
- if (!$DB->insert_record('question_datasets', $questiondataset)) {
- print_error('cannotcreaterelation', 'question', '', $name);
- }
+ $DB->insert_record('question_datasets', $questiondataset);
unset($datasetdefinitions[$defid]);
continue;
}// end of datasetdefs from the initial question
// really new one code similar to save_dataset_definitions()
- if (!$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef)) {
- print_error('cannotcreatedataset', 'question', '', $defid);
- }
+ $datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
if (0 != $datasetdef->category) {
// We need to look for already existing
$questiondataset = new stdClass;
$questiondataset->question = $form->id;
$questiondataset->datasetdefinition = $datasetdef->id;
- if (!$DB->insert_record('question_datasets', $questiondataset)) {
- print_error('cannotcreaterelation', 'question', '', $name);
- }
+ $DB->insert_record('question_datasets', $questiondataset);
unset($datasetdefinitions[$defid]);
}
unset($datasetdefinitions[$defid]);
continue;
}
- if (!$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef)) {
- print_error("cannotcreatedataset", 'question', '', $defid);
- }
+ $datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
$datasetdefs[]= clone($datasetdef);
$questiondataset = new stdClass;
$questiondataset->question = $question->id;
$questiondataset->datasetdefinition = $datasetdef->id;
- if (!$DB->insert_record('question_datasets', $questiondataset)) {
- print_error('cannotcreaterelation', 'question', '', $name);
- }
+ $DB->insert_record('question_datasets', $questiondataset);
unset($datasetdefinitions[$defid]);
}
// Remove local obsolete datasets as well as relations
if (empty($question->makecopy) && $question->itemid[$i]) {
// Reuse any previously used record
$addeditem->id = $question->itemid[$i];
- if (!$DB->update_record('question_dataset_items', $addeditem)) {
- print_error('cannotupdateitem', 'question');
- }
+ $DB->update_record('question_dataset_items', $addeditem);
} else {
- if (!$DB->insert_record('question_dataset_items', $addeditem)) {
- print_error('cannotinsert', 'question');
- }
+ $DB->insert_record('question_dataset_items', $addeditem);
}
$i++;
}
}
// Report any problems.
//convert to calculated
- if(!empty($question->makecopy) && !empty($question->convert) ){
- if (!$DB->set_field('question', 'qtype', 'calculated', array('id'=> $question->id))) {
- print_error('cannotupdateitem', 'question');
- }
- }
+ if(!empty($question->makecopy) && !empty($question->convert)) {
+ $DB->set_field('question', 'qtype', 'calculated', array('id'=> $question->id));
+ }
if (!empty($result->notice)) {
return $result;
}
$answer->feedback = $question->feedback;
$answer->fraction = $question->fraction;
if ($update) {
- if (!$DB->update_record("question_answers", $answer)) {
- $result = new stdClass;
- $result->error = "Could not update quiz answer!";
- }
+ $DB->update_record("question_answers", $answer);
} else {
- if (!$answer->id = $DB->insert_record("question_answers", $answer)) {
- $result = new stdClass;
- $result->error = "Could not insert quiz answer!";
- }
+ $answer->id = $DB->insert_record("question_answers", $answer);
}
return $result;
}
if ($subquestion = array_shift($oldsubquestions)) { // Existing answer, so reuse it
$subquestion->questiontext = $questiontext;
$subquestion->answertext = $answertext;
- if (!$DB->update_record("question_match_sub", $subquestion)) {
- $result->error = "Could not insert match subquestion! (id=$subquestion->id)";
- return $result;
- }
+ $DB->update_record("question_match_sub", $subquestion);
} else {
$subquestion = new stdClass;
// Determine a unique random code
$subquestion->question = $question->id;
$subquestion->questiontext = $questiontext;
$subquestion->answertext = $answertext;
- if (!$subquestion->id = $DB->insert_record("question_match_sub", $subquestion)) {
- $result->error = "Could not insert match subquestion!";
- return $result;
- }
+ $subquestion->id = $DB->insert_record("question_match_sub", $subquestion);
}
$subquestions[] = $subquestion->id;
}
if ($options = $DB->get_record("question_match", array("question" => $question->id))) {
$options->subquestions = implode(",",$subquestions);
$options->shuffleanswers = $question->shuffleanswers;
- if (!$DB->update_record("question_match", $options)) {
- $result->error = "Could not update match options! (id=$options->id)";
- return $result;
- }
+ $DB->update_record("question_match", $options);
} else {
unset($options);
$options->question = $question->id;
$options->subquestions = implode(",",$subquestions);
$options->shuffleanswers = $question->shuffleanswers;
- if (!$DB->insert_record("question_match", $options)) {
- $result->error = "Could not insert match options!";
- return $result;
- }
+ $DB->insert_record("question_match", $options);
}
if (!empty($result->notice)) {
$questiontext = restore_decode_content_links_worker($subquestion->questiontext, $restore);
if ($questiontext != $subquestion->questiontext) {
$subquestion->questiontext = $questiontext;
- if (!$DB->update_record('question_match_sub', $subquestion)) {
- $status = false;
- }
+ $DB->update_record('question_match_sub', $subquestion);
}
// Do some output.
$subquestionchanged = false;
$subquestion->questiontext = question_replace_file_links_in_html($subquestion->questiontext, $fromcourseid, $tocourseid, $url, $destination, $subquestionchanged);
if ($subquestionchanged){//need to update rec in db
- if (!$DB->update_record('question_match_sub', $subquestion)) {
- print_error('Couldn\'t update \'question_match_sub\' record '.$subquestion->id);
- }
-
+ $DB->update_record('question_match_sub', $subquestion);
}
}
}
$multianswer->sequence = implode(',', $sequence);
if ($oldid = $DB->get_field('question_multianswer', 'id', array('question' => $question->id))) {
$multianswer->id = $oldid;
- if (!$DB->update_record("question_multianswer", $multianswer)) {
- $result->error = "Could not update cloze question options! " .
- "(id=$multianswer->id)";
- return $result;
- }
+ $DB->update_record("question_multianswer", $multianswer);
} else {
- if (!$DB->insert_record("question_multianswer", $multianswer)) {
- $result->error = "Could not insert cloze question options!";
- return $result;
- }
+ $DB->insert_record("question_multianswer", $multianswer);
}
}
}
$answer->answer = $dataanswer;
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
- if (!$DB->update_record("question_answers", $answer)) {
- $result->error = "Could not update quiz answer! (id=$answer->id)";
- return $result;
- }
+ $DB->update_record("question_answers", $answer);
} else {
unset($answer);
$answer->answer = $dataanswer;
$answer->question = $question->id;
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
- if (!$answer->id = $DB->insert_record("question_answers", $answer)) {
- $result->error = "Could not insert quiz answer! ";
- return $result;
- }
+ $answer->id = $DB->insert_record("question_answers", $answer);
}
$answers[] = $answer->id;
$options->partiallycorrectfeedback = trim($question->partiallycorrectfeedback);
$options->incorrectfeedback = trim($question->incorrectfeedback);
if ($update) {
- if (!$DB->update_record("question_multichoice", $options)) {
- $result->error = "Could not update quiz multichoice options! (id=$options->id)";
- return $result;
- }
+ $DB->update_record("question_multichoice", $options)
} else {
- if (!$DB->insert_record("question_multichoice", $options)) {
- $result->error = "Could not insert quiz multichoice options!";
- return $result;
- }
+ $DB->insert_record("question_multichoice", $options);
}
// delete old answer records
$subquestion->correctfeedback = $correctfeedback;
$subquestion->partiallycorrectfeedback = $partiallycorrectfeedback;
$subquestion->incorrectfeedback = $incorrectfeedback;
- if (!$DB->update_record('question_multichoice', $multichoice)) {
- $status = false;
- }
+ $DB->update_record('question_multichoice', $multichoice);
}
// Do some output.
$newoptions->partiallycorrectfeedback = question_replace_file_links_in_html($question->options->partiallycorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
$newoptions->incorrectfeedback = question_replace_file_links_in_html($question->options->incorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
if ($optionschanged){
- if (!$DB->update_record('question_multichoice', $newoptions)) {
- print_error('Couldn\'t update \'question_multichoice\' record '.$newoptions->id);
- }
+ $DB->update_record('question_multichoice', $newoptions);
}
$answerchanged = false;
foreach ($question->options->answers as $answer) {
$answer->answer = question_replace_file_links_in_html($answer->answer, $fromcourseid, $tocourseid, $url, $destination, $answerchanged);
if ($answerchanged){
- if (!$DB->update_record('question_answers', $answer)){
- print_error('Couldn\'t update \'question_answers\' record '.$answer->id);
- }
+ $DB->update_record('question_answers', $answer);
}
}
}
/// Question already exists, update.
$question->modifiedby = $USER->id;
$question->timemodified = time();
- if (!$DB->update_record('question', $question)) {
- print_error('cannotupdatequestion', 'question');
- }
+ $DB->update_record('question', $question);
} else {
/// New question.
$question->modifiedby = $USER->id;
$question->timecreated = time();
$question->timemodified = time();
- if (!$question->id = $DB->insert_record('question', $question)) {
- print_error('cannotinsertquestion', 'question');
- }
+ $question->id = $DB->insert_record('question', $question);
}
// Now to save all the answers and type-specific options
}
// Give the question a unique version stamp determined by question_hash()
- if (!$DB->set_field('question', 'version', question_hash($question), array('id' => $question->id))) {
- print_error('cannotupdatequestionver', 'question');
- }
+ $DB->set_field('question', 'version', question_hash($question), array('id' => $question->id));
return $question;
}
/// If anything has changed, update it in the database.
if ($updateqrec){
- if (!$DB->update_record('question', $question)){
- print_error('cannotupdatequestion', 'question');
- }
+ $DB->update_record('question', $question);
}
$answer->feedback = question_replace_file_links_in_html($answer->feedback, $fromcourseid, $tocourseid, $url, $destination, $answerchanged);
/// If anything has changed, update it in the database.
if ($answerchanged){
- if (!$DB->update_record('question_answers', $answer)){
- print_error('cannotupdatequestion', 'question');
- }
+ $DB->update_record('question_answers', $answer);
}
}
}
if ($existing = $DB->get_record("question_randomsamatch", array("question" => $options->question))) {
$options->id = $existing->id;
- if (!$DB->update_record("question_randomsamatch", $options)) {
- $result->error = "Could not update quiz randomsamatch options!";
- return $result;
- }
+ $DB->update_record("question_randomsamatch", $options);
} else {
- if (!$DB->insert_record("question_randomsamatch", $options)) {
- $result->error = "Could not insert quiz randomsamatch options!";
- return $result;
- }
+ $DB->insert_record("question_randomsamatch", $options);
}
return true;
}
$answer->answer = trim($dataanswer);
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
- if (!$DB->update_record("question_answers", $answer)) {
- $result->error = "Could not update quiz answer! (id=$answer->id)";
- return $result;
- }
+ $DB->update_record("question_answers", $answer);
} else { // This is a completely new answer
$answer = new stdClass;
$answer->answer = trim($dataanswer);
$answer->question = $question->id;
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
- if (!$answer->id = $DB->insert_record("question_answers", $answer)) {
- $result->error = "Could not insert quiz answer!";
- return $result;
- }
+ $answer->id = $DB->insert_record("question_answers", $answer);
}
$answers[] = $answer->id;
if ($question->fraction[$key] > $maxfraction) {
$true->answer = get_string("true", "quiz");
$true->fraction = $question->correctanswer;
$true->feedback = $question->feedbacktrue;
- if (!$DB->update_record("question_answers", $true)) {
- $result->error = "Could not update quiz answer \"true\")!";
- return $result;
- }
+ $DB->update_record("question_answers", $true);
} else {
unset($true);
$true->answer = get_string("true", "quiz");
$true->question = $question->id;
$true->fraction = $question->correctanswer;
$true->feedback = $question->feedbacktrue;
- if (!$true->id = $DB->insert_record("question_answers", $true)) {
- $result->error = "Could not insert quiz answer \"true\")!";
- return $result;
- }
+ $true->id = $DB->insert_record("question_answers", $true);
}
// Save answer 'False'
$false->answer = get_string("false", "quiz");
$false->fraction = 1 - (int)$question->correctanswer;
$false->feedback = $question->feedbackfalse;
- if (!$DB->update_record("question_answers", $false)) {
- $result->error = "Could not insert quiz answer \"false\")!";
- return $result;
- }
+ $DB->update_record("question_answers", $false);
} else {
unset($false);
$false->answer = get_string("false", "quiz");
$false->question = $question->id;
$false->fraction = 1 - (int)$question->correctanswer;
$false->feedback = $question->feedbackfalse;
- if (!$false->id = $DB->insert_record("question_answers", $false)) {
- $result->error = "Could not insert quiz answer \"false\")!";
- return $result;
- }
+ $false->id = $DB->insert_record("question_answers", $false);
}
// delete any leftover old answer records (there couldn't really be any, but who knows)
// But we'll do it anyway, just for robustness
$options->trueanswer = $true->id;
$options->falseanswer = $false->id;
- if (!$DB->update_record("question_truefalse", $options)) {
- $result->error = "Could not update quiz truefalse options! (id=$options->id)";
- return $result;
- }
+ $DB->update_record("question_truefalse", $options);
} else {
unset($options);
$options->question = $question->id;
$options->trueanswer = $true->id;
$options->falseanswer = $false->id;
- if (!$DB->insert_record("question_truefalse", $options)) {
- $result->error = "Could not insert quiz truefalse options!";
- return $result;
- }
+ $DB->insert_record("question_truefalse", $options);
}
return true;
}