Skip to content

Commit

Permalink
remove DB dependant code and references to NULL in field values mdl-8169
Browse files Browse the repository at this point in the history
  • Loading branch information
gbateson committed Jan 24, 2007
1 parent 727929f commit 4d4b237
Showing 1 changed file with 18 additions and 43 deletions.
61 changes: 18 additions & 43 deletions mod/hotpot/lib.php
Expand Up @@ -1153,30 +1153,12 @@ function hotpot_get_grades($hotpot, $user_ids='') {
$grade = "ROUND(SUM(score)/COUNT(id) * $weighting, $precision) AS grade"; $grade = "ROUND(SUM(score)/COUNT(id) * $weighting, $precision) AS grade";
break; break;
case HOTPOT_GRADEMETHOD_FIRST: case HOTPOT_GRADEMETHOD_FIRST:
if ($CFG->dbtype=='postgres7') { $grade = "ROUND(score * $weighting, $precision)";
$grade = "(CASE WHEN (score IS NULL)
THEN ''
ELSE TRIM(ROUND(score * $weighting, $precision))
END)";
} else {
$grade = "IF(score IS NULL,
'',
ROUND(score * $weighting, $precision))";
}
$grade = sql_concat('timestart', "'_'", $grade); $grade = sql_concat('timestart', "'_'", $grade);
$grade = "MIN($grade) AS grade"; $grade = "MIN($grade) AS grade";
break; break;
case HOTPOT_GRADEMETHOD_LAST: case HOTPOT_GRADEMETHOD_LAST:
if ($CFG->dbtype=='postgres7') { $grade = "ROUND(score * $weighting, $precision)";
$grade = "(CASE WHEN (score IS NULL)
THEN ''
ELSE TRIM(ROUND(score * $weighting, $precision))
END)";
} else {
$grade = "IF(score IS NULL,
'',
ROUND(score * $weighting, $precision))";
}
$grade = sql_concat('timestart', "'_'", $grade); $grade = sql_concat('timestart', "'_'", $grade);
$grade = "MAX($grade) AS grade"; $grade = "MAX($grade) AS grade";
break; break;
Expand Down Expand Up @@ -1249,37 +1231,30 @@ function hotpot_scale_used ($hotpotid, $scaleid) {


function hotpot_add_attempt($hotpotid) { function hotpot_add_attempt($hotpotid) {
global $db, $CFG, $USER; global $db, $CFG, $USER;

// get start time of this attempt
$time = time(); $time = time();
switch (strtolower($CFG->dbtype)) {
case 'mysql':
$timefinish = "IF(a.timefinish IS NULL, '$time', a.timefinish)";
$clickreportid = "IF(a.clickreportid IS NULL, a.id, a.clickreportid)";
break;
case 'postgres7':
$timefinish = "WHEN(a.timefinish IS NULL) THEN '$time' ELSE a.timefinish";
$clickreportid = "WHEN(a.clickreportid IS NULL) THEN a.id ELSE a.clickreportid";
break;
}


// set all previous "in progress" attempts at this quiz to "abandoned" // set all previous "in progress" attempts at this quiz to "abandoned"
$db->Execute(" if ($attempts = get_records_select('hotpot_attempts', "hotpot='$hotpotid' AND userid='$USER->id' AND status='".HOTPOT_STATUS_INPROGRESS."'")) {
UPDATE foreach ($attempts as $attempt) {
{$CFG->prefix}hotpot_attempts a if ($attempt->timefinish==0) {
SET $attempt->timefinish = $time;
a.timefinish = $timefinish, }
a.status = '".HOTPOT_STATUS_ABANDONED."', if ($attempt->clickreportid==0) {
a.clickreportid = $clickreportid $attempt->clickreportid = $attempt->id;
WHERE }
a.hotpot='$hotpotid' $attempt->status = HOTPOT_STATUS_ABANDONED;
AND a.userid='$USER->id' update_record('hotpot_attempts', $attempt);
AND a.status='".HOTPOT_STATUS_INPROGRESS."' }
"); }


// create and add new attempt record // create and add new attempt record
$attempt = new stdClass();
$attempt->hotpot = $hotpotid; $attempt->hotpot = $hotpotid;
$attempt->userid = $USER->id; $attempt->userid = $USER->id;
$attempt->attempt = hotpot_get_next_attempt($hotpotid); $attempt->attempt = hotpot_get_next_attempt($hotpotid);
$attempt->timestart = time(); $attempt->timestart = $time;


return insert_record("hotpot_attempts", $attempt); return insert_record("hotpot_attempts", $attempt);
} }
Expand Down

0 comments on commit 4d4b237

Please sign in to comment.