]> git.mjollnir.org Git - moodle.git/commitdiff
mod/glossary, mod/hotpot: use sql_concat() and sql_concat_join()
authormartinlanghoff <martinlanghoff>
Tue, 26 Sep 2006 05:06:44 +0000 (05:06 +0000)
committermartinlanghoff <martinlanghoff>
Tue, 26 Sep 2006 05:06:44 +0000 (05:06 +0000)
Cleaned up several dbtype conditionals too.

mod/glossary/sql.php
mod/hotpot/index.php
mod/hotpot/lib.php
mod/hotpot/report.php

index c2ba24e93eea55c5e2ecbff00f2604cbe6f3ba12..16ef6da89d77397684b9e0354e024c8cd00383dd 100644 (file)
@@ -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;
index 4a0051e6a27486b7e8d90722684c63ae069ef216..4ad23d6ec9054e742abaa3cdf45122f6638c25b3 100644 (file)
         $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
index 336ca4b4510bcd430816d8dd5b92774bc9668668..cb807fe1af90a39b3fb1a7a39d725e5984058bc0 100644 (file)
@@ -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;
     }
 
index 2ed7d2feb36ff94b8eb6d5f0c4967b16db0a9f06..ba7e1e213c0593bce43d8098b8a92db80951028d 100644 (file)
@@ -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");