Browse Source

Minor updates from ofaj_dev

Julio Montoya 5 years ago
parent
commit
74abe4329e

+ 44 - 0
main/inc/lib/course.lib.php

@@ -6342,6 +6342,50 @@ class CourseManager
         return api_get_path(WEB_COURSE_PATH).$course->getDirectory().'/course-pic85x85.png';
     }
 
+    /**
+     * @return int
+     */
+    public static function getCountOpenCourses()
+    {
+        $visibility = [
+            COURSE_VISIBILITY_REGISTERED,
+            COURSE_VISIBILITY_OPEN_PLATFORM,
+            COURSE_VISIBILITY_OPEN_WORLD,
+        ];
+
+        $table = Database::get_main_table(TABLE_MAIN_COURSE);
+        $sql = "SELECT count(id) count 
+                FROM $table 
+                WHERE visibility IN (".implode(',', $visibility).")";
+        $result = Database::query($sql);
+        $row = Database::fetch_array($result);
+
+        return (int) $row['count'];
+    }
+
+    /**
+     * @return int
+     */
+    public static function getCountExercisesFromOpenCourse()
+    {
+        $visibility = [
+            COURSE_VISIBILITY_REGISTERED,
+            COURSE_VISIBILITY_OPEN_PLATFORM,
+            COURSE_VISIBILITY_OPEN_WORLD,
+        ];
+
+        $table = Database::get_main_table(TABLE_MAIN_COURSE);
+        $tableExercise = Database::get_course_table(TABLE_QUIZ_TEST);
+        $sql = "SELECT count(e.iid) count 
+                FROM $table c INNER JOIN $tableExercise e
+                ON (c.id = e.c_id)
+                WHERE e.active <> -1 AND visibility IN (".implode(',', $visibility).")";
+        $result = Database::query($sql);
+        $row = Database::fetch_array($result);
+
+        return (int) $row['count'];
+    }
+
     /**
      * Check if a specific access-url-related setting is a problem or not.
      *

+ 4 - 0
main/inc/lib/exercise_show_functions.lib.php

@@ -416,6 +416,10 @@ class ExerciseShowFunctions
         echo '</td>';
 
         if ($exercise->showExpectedChoice()) {
+            $status = Display::label(get_lang('Incorrect'), 'danger');
+            if ($answerCorrect || ($answerCorrect && $studentChoiceInt === $answerCorrectChoice)) {
+                $status = Display::label(get_lang('Correct'), 'success');
+            }
             echo '<td width="20%">';
             echo $status;
             echo '</td>';

+ 6 - 2
main/inc/lib/extra_field.lib.php

@@ -2447,7 +2447,11 @@ JAVASCRIPT;
 
                 return " $col {$this->ops[$oper]} $val ";
             } else {
-                $val = '%'.$val.'%';
+                if (is_string($val)) {
+                    $val = '%'.$val.'%';
+                } else {
+                    $val = '';
+                }
             }
         }
         $val = \Database::escape_string($val);
@@ -2516,7 +2520,7 @@ JAVASCRIPT;
                         }
                     } else {
                         if (isset($rule->data)) {
-                            if ($rule->data == -1) {
+                            if (isset($rule->data) && is_int($rule->data) && $rule->data == -1) {
                                 continue;
                             }
                             $condition_array[] = ' ('

+ 0 - 1
main/inc/lib/message.lib.php

@@ -2503,7 +2503,6 @@ class MessageManager
         $i = 1;
         while (!feof($file)) {
             $line = fgets($file);
-            // $line = trim($line);
 
             if (trim($line) == '') {
                 continue;

+ 1 - 1
main/inc/lib/notebook.lib.php

@@ -147,7 +147,7 @@ class NotebookManager
      */
     public static function update_note($values)
     {
-        if (!is_array($values) || empty($values['note_title'])) {
+        if (!is_array($values) or empty($values['note_title'])) {
             return false;
         }