mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
mod/glossary, mod/hotpot: use sql_concat() and sql_concat_join()
Cleaned up several dbtype conditionals too.
This commit is contained in:
parent
38e02f4c32
commit
d2715c70b6
@ -92,9 +92,9 @@
|
||||
break;
|
||||
case 'mysql':
|
||||
if ( $sqlsortkey == 'FIRSTNAME' ) {
|
||||
$usernamefield = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
|
||||
$usernamefield = sql_fullname('u.firstname' , 'u.lastname');
|
||||
} else {
|
||||
$usernamefield = "CONCAT(CONCAT(u.lastname,' '), u.firstname)";
|
||||
$usernamefield = sql_fullname('u.lastname' , 'u.firsttname');
|
||||
}
|
||||
$where = "AND left(ucase($usernamefield)," . $textlib->strlen($hook, current_charset()) . ") = '$hook'";
|
||||
break;
|
||||
|
@ -203,14 +203,8 @@
|
||||
$questions = false;
|
||||
$regradehotpots = array();
|
||||
|
||||
switch (strtolower($CFG->dbtype)) {
|
||||
case 'mysql' :
|
||||
$field = "CONCAT(hotpot, '_', name)";
|
||||
break;
|
||||
case 'postgres7' :
|
||||
$field = "hotpot||'_'||name";
|
||||
break;
|
||||
}
|
||||
$field = sql_concat('hotpot', "'_'", 'name');
|
||||
|
||||
if ($field) {
|
||||
$questions = get_records_sql("
|
||||
SELECT $field, COUNT(*), hotpot, name
|
||||
|
@ -1089,17 +1089,31 @@ function hotpot_get_grades($hotpot, $user_ids='') {
|
||||
break;
|
||||
case HOTPOT_GRADEMETHOD_FIRST:
|
||||
if ($CFG->dbtype=='postgres7') {
|
||||
$grade = "MIN(timestart||'_'||(CASE WHEN (score IS NULL) THEN '' ELSE TRIM(ROUND(score * $weighting, $precision)) END)) AS grade";
|
||||
$grade = "(CASE WHEN (score IS NULL)
|
||||
THEN ''
|
||||
ELSE TRIM(ROUND(score * $weighting, $precision))
|
||||
END)";
|
||||
} else {
|
||||
$grade = "MIN(CONCAT(timestart, '_', IF(score IS NULL, '', ROUND(score * $weighting, $precision)))) AS grade";
|
||||
$grade = "IF(score IS NULL,
|
||||
'',
|
||||
ROUND(score * $weighting, $precision))";
|
||||
}
|
||||
$grade = sql_concat('timestart', "'_'", $grade);
|
||||
$grade = "MIN($grade) AS grade";
|
||||
break;
|
||||
case HOTPOT_GRADEMETHOD_LAST:
|
||||
if ($CFG->dbtype=='postgres7') {
|
||||
$grade = "MAX(timestart||'_'||(CASE WHEN (score IS NULL) THEN '' ELSE TRIM(ROUND(score * $weighting, $precision)) END)) AS grade";
|
||||
$grade = "(CASE WHEN (score IS NULL)
|
||||
THEN ''
|
||||
ELSE TRIM(ROUND(score * $weighting, $precision))
|
||||
END)";
|
||||
} else {
|
||||
$grade = "MAX(CONCAT(timestart, '_', IF(score IS NULL, '', ROUND(score * $weighting, $precision)))) AS grade";
|
||||
$grade = "IF(score IS NULL,
|
||||
'',
|
||||
ROUND(score * $weighting, $precision))";
|
||||
}
|
||||
$grade = sql_concat('timestart', "'_'", $grade);
|
||||
$grade = "MAX($grade) AS grade";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -594,18 +594,8 @@ function hotpot_get_records_groupby($function, $fieldnames, $table, $select, $gr
|
||||
// $function is an SQL aggregate function (MAX or MIN)
|
||||
|
||||
global $CFG;
|
||||
|
||||
switch (strtolower($CFG->dbtype)) {
|
||||
case 'mysql':
|
||||
$fields = "$groupby, $function(CONCAT(".join(",'_',", $fieldnames).")) AS joinedvalues";
|
||||
break;
|
||||
case 'postgres7':
|
||||
$fields = "$groupby, $function(".join("||'_'||", $fieldnames).") AS joinedvalues";
|
||||
break;
|
||||
default:
|
||||
$fields = "";
|
||||
break;
|
||||
}
|
||||
$fields = sql_concat_join("'_'", $fieldnames);
|
||||
$fields = "$groupby, $function($fields) AS joinedvalues";
|
||||
|
||||
if ($fields) {
|
||||
$records = get_records_sql("SELECT $fields FROM $table WHERE $select GROUP BY $groupby");
|
||||
|
Loading…
x
Reference in New Issue
Block a user