function hotpot_delete_selected_attempts(&$hotpot, $del) { global $DB; $select = ''; $params = array('hotpotid' => $hotpot->id); switch ($del) { case 'all': $select = "hotpot=:hotpotid"; break; case 'abandoned': $select = "hotpot=:hotpotid AND status=" . HOTPOT_STATUS_ABANDONED; break; case 'selection': $ids = array(); $data = (array) data_submitted(); foreach ($data as $name => $value) { if (preg_match('/^box\\d+$/', $name)) { $ids[] = intval($value); } } if (count($ids)) { list($ids, $idparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'crid0'); $params = array_merge($params, $idparams); $select = "hotpot=:hotpotid AND clickreportid {$ids}"; } break; } // delete attempts using $select, if it is set if ($select) { $table = 'hotpot_attempts'; if ($attempts = $DB->get_records_select($table, $select, $params)) { hotpot_delete_and_notify($table, $select, $params, get_string('attempts', 'quiz')); $select = 'attempt IN (' . implode(',', array_keys($attempts)) . ')'; $params = array(); hotpot_delete_and_notify('hotpot_details', $select, $params, get_string('rawdetails', 'hotpot')); hotpot_delete_and_notify('hotpot_responses', $select, $params, get_string('answer', 'quiz')); // update grades for all users for this hotpot hotpot_update_grades($hotpot); } } }
function hotpot_delete_selected_attempts(&$hotpot, $del) { $select = ''; switch ($del) { case 'all': $select = "hotpot='{$hotpot->id}'"; break; case 'abandoned': $select = "hotpot='{$hotpot->id}' AND status=" . HOTPOT_STATUS_ABANDONED; break; case 'selection': $ids = array(); $data = (array) data_submitted(); foreach ($data as $name => $value) { if (preg_match('/^box\\d+$/', $name)) { $ids[] = intval($value); } } if (count($ids)) { $select = "hotpot='{$hotpot->id}' AND clickreportid IN (" . implode(',', $ids) . ")"; } break; } // delete attempts using $select, if it is set if ($select) { $table = 'hotpot_attempts'; if ($attempts = get_records_select($table, $select)) { hotpot_delete_and_notify($table, $select, get_string('attempts', 'quiz')); $select = 'attempt IN (' . implode(',', array_keys($attempts)) . ')'; hotpot_delete_and_notify('hotpot_details', $select, get_string('rawdetails', 'hotpot')); hotpot_delete_and_notify('hotpot_responses', $select, get_string('answer', 'quiz')); // update grades for all users for this hotpot hotpot_update_grades($hotpot); } } }
print_simple_box_end(); print_footer($course); exit; } else { // regrade has been confirmed, so proceed // start hotpot counter and timer $hotpotstart = microtime(); $hotpotcount = 0; // regrade attempts for these hotpots foreach ($regrade_hotpots as $hotpot) { notify("<b>{$hotpot->name}</b>"); // delete questions and responses for this hotpot if ($records = $DB->get_records('hotpot_questions', array('hotpot' => $hotpot->id), '', 'id,hotpot')) { $questionids = implode(',', array_keys($records)); hotpot_delete_and_notify('hotpot_questions', "id IN ({$questionids})", array(), get_string('question', 'quiz')); hotpot_delete_and_notify('hotpot_responses', "question IN ({$questionids})", array(), get_string('answer', 'quiz')); } // start attempt counter and timer $attemptstart = microtime(); $attemptcount = 0; // regrade attempts, if any, for this hotpot if ($attempts = $DB->get_records('hotpot_attempts', array('hotpot' => $hotpot->id))) { foreach ($attempts as $attempt) { $attempt->details = $DB->get_field('hotpot_details', 'details', array('attempt' => $attempt->id)); if ($attempt->details) { hotpot_add_attempt_details($attempt); if (!$DB->update_record('hotpot_attempts', $attempt)) { print_error('cannotupdateattempt', 'hotpot', $next_url, $DB->get_last_error()); } } $attemptcount++;