本文整理汇总了PHP中quiz_after_add_or_update函数的典型用法代码示例。如果您正苦于以下问题:PHP quiz_after_add_or_update函数的具体用法?PHP quiz_after_add_or_update怎么用?PHP quiz_after_add_or_update使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quiz_after_add_or_update函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quizcopy_add_instance
function quizcopy_add_instance(&$quizcopy)
{
$cmid = $quizcopy->quiz;
$name = $quizcopy->name;
$cm = get_coursemodule_from_id('quiz', $cmid);
if (!($quiz = get_record('quiz', 'id', $cm->instance))) {
print_error('error', 'quizcopy');
}
$origquiz = $quiz->id;
unset($quiz->id);
// remove single quote to prevent SQL errors (nadavkav 11-6-11)
$quiz->name = str_replace("'", '', $name);
$quiz->intro = str_replace("'", '', $quiz->intro);
if (!($quiz->id = insert_record('quiz', $quiz))) {
print_error('error', 'quizcopy');
}
$newquestions = array();
if (!is_null($quiz->questions) && !empty($quiz->questions)) {
$questions = explode(',', $quiz->questions);
foreach ($questions as $question) {
$newquestions[] = $question;
if ($question != 0) {
if (!($instance_object = get_record('quiz_question_instances', 'quiz', $origquiz, 'question', $question))) {
print_error('error', 'quizcopy');
}
unset($instance_object->id);
$instance_object->quiz = $quiz->id;
if (!insert_record('quiz_question_instances', $instance_object)) {
print_error('error', 'quizcopy');
}
}
}
}
if ($feedbacks = get_records('quiz_feedback', 'quizid', $origquiz, 'maxgrade DESC')) {
$i = 0;
$quiz->feedbacktext = array();
$quiz->feedbackboundaries = array();
foreach ($feedbacks as $feedback) {
$quiz->feedbacktext[$i] = $feedback->feedbacktext;
$quiz->feedbackboundaries[$i] = $feedback->mingrade;
$quiz->feedbackboundaries[$i - 1] = $feedback->maxgrade;
$i++;
}
$quiz->feedbackboundarycount = $i - 1;
}
$quiz->questions = implode(',', $newquestions);
if (!update_record('quiz', $quiz)) {
print_error('error', 'quizcopy');
}
$quizcopy->timecreated = time();
$quizcopy->module = $cm->module;
$quizcopy->modulename = 'quiz';
$quizcopy->visible = $cm->visible;
$quizcopy->groupmode = $cm->groupmode;
$quizcopy->groupmembersonly = $cm->groupmembersonly;
$quizcopy->module = $cm->module;
quiz_after_add_or_update($quiz);
return $quiz->id;
}
示例2: quiz_update_instance
/**
* Given an object containing all the necessary data,
* (defined by the form in mod.html) this function
* will update an existing instance with new data.
*
* @param object $quiz the data that came from the form.
* @return mixed true on success, false or a string error message on failure.
*/
function quiz_update_instance($quiz)
{
// Process the options from the form.
$result = quiz_process_options($quiz);
if ($result && is_string($result)) {
return $result;
}
// Update the database.
$quiz->id = $quiz->instance;
if (!update_record("quiz", $quiz)) {
return false;
// some error occurred
}
// Do the processing required after an add or an update.
quiz_after_add_or_update($quiz);
// Delete any previous preview attempts
delete_records('quiz_attempts', 'preview', '1', 'quiz', $quiz->id);
return true;
}
示例3: quiz_update_instance
/**
* 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.
*
* @param object $quiz the data that came from the form.
* @return mixed true on success, false or a string error message on failure.
*/
function quiz_update_instance($quiz, $mform) {
global $CFG, $DB;
// Process the options from the form.
$result = quiz_process_options($quiz);
if ($result && is_string($result)) {
return $result;
}
$oldquiz = $DB->get_record('quiz', array('id' => $quiz->instance));
// Repaginate, if asked to.
if (!$quiz->shufflequestions && !empty($quiz->repaginatenow)) {
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
$quiz->questions = quiz_repaginate(quiz_clean_layout($oldquiz->questions, true),
$quiz->questionsperpage);
}
unset($quiz->repaginatenow);
// Update the database.
$quiz->id = $quiz->instance;
$DB->update_record('quiz', $quiz);
// Do the processing required after an add or an update.
quiz_after_add_or_update($quiz);
if ($oldquiz->grademethod != $quiz->grademethod) {
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
$quiz->sumgrades = $oldquiz->sumgrades;
$quiz->grade = $oldquiz->grade;
quiz_update_all_final_grades($quiz);
quiz_update_grades($quiz);
}
// Delete any previous preview attempts.
quiz_delete_previews($quiz);
return true;
}
示例4: quiz_update_instance
/**
* 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.
*
* @param object $quiz the data that came from the form.
* @return mixed true on success, false or a string error message on failure.
*/
function quiz_update_instance($quiz, $mform)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
// Process the options from the form.
$result = quiz_process_options($quiz);
if ($result && is_string($result)) {
return $result;
}
// Get the current value, so we can see what changed.
$oldquiz = $DB->get_record('quiz', array('id' => $quiz->instance));
// We need two values from the existing DB record that are not in the form,
// in some of the function calls below.
$quiz->sumgrades = $oldquiz->sumgrades;
$quiz->grade = $oldquiz->grade;
// Repaginate, if asked to.
if (!$quiz->shufflequestions && !empty($quiz->repaginatenow)) {
$quiz->questions = quiz_repaginate(quiz_clean_layout($oldquiz->questions, true), $quiz->questionsperpage);
}
unset($quiz->repaginatenow);
// Update the database.
$quiz->id = $quiz->instance;
$DB->update_record('quiz', $quiz);
// Do the processing required after an add or an update.
quiz_after_add_or_update($quiz);
if ($oldquiz->grademethod != $quiz->grademethod) {
quiz_update_all_final_grades($quiz);
quiz_update_grades($quiz);
}
$quizdateschanged = $oldquiz->timelimit != $quiz->timelimit || $oldquiz->timeclose != $quiz->timeclose || $oldquiz->graceperiod != $quiz->graceperiod;
if ($quizdateschanged) {
quiz_update_open_attempts(array('quizid' => $quiz->id));
}
// Delete any previous preview attempts.
quiz_delete_previews($quiz);
return true;
}