Ver Fonte

Fix typo, add int casting,

jmontoyaa há 8 anos atrás
pai
commit
bc8e013df1
1 ficheiros alterados com 8 adições e 7 exclusões
  1. 8 7
      main/survey/surveyUtil.class.php

+ 8 - 7
main/survey/surveyUtil.class.php

@@ -3323,27 +3323,28 @@ class SurveyUtil
     /**
      * Check if the current survey has answers
      *
-     * @param $surveyId
+     * @param int $surveyId
      * @return boolean return true if the survey has answers, false otherwise
      */
     public static function checkIfSurveyHasAnswers($surveyId)
     {
         $tableSurveyAnswer = Database::get_course_table(TABLE_SURVEY_ANSWER);
         $courseId = api_get_course_int_id();
+        $surveyId = (int)$surveyId;
+
+        if (empty($courseId) || empty($surveyId)) {
+            return false;
+        }
 
         $sql = "SELECT * FROM $tableSurveyAnswer
                 WHERE
                     c_id = $courseId AND
-                    survey_id='".$surveyId."'
+                    survey_id = '".$surveyId."'
                 ORDER BY answer_id, user ASC";
         $result = Database::query($sql);
 
         $response = Database::affected_rows($result);
 
-        if ($response > 0) {
-            return true;
-        }
-
-        return false;
+        return $response > 0;
     }
 }