Browse Source

Validate mandatory survey to access to course - refs BT#12915

Angel Fernando Quiroz Campos 7 years ago
parent
commit
d718afec43
2 changed files with 9 additions and 4 deletions
  1. 1 1
      main/inc/local.inc.php
  2. 8 3
      main/survey/survey.lib.php

+ 1 - 1
main/inc/local.inc.php

@@ -1526,6 +1526,6 @@ if ((isset($cas_login) && $cas_login && exist_firstpage_parameter()) ||
 
 Redirect::session_request_uri($logging_in, $user_id);
 
-if (!ChamiloApi::isAjaxRequest()) {
+if (!ChamiloApi::isAjaxRequest() && api_get_configuration_value('survey_answered_at_field')) {
     SurveyManager::protectByMandatory();
 }

+ 8 - 3
main/survey/survey.lib.php

@@ -1745,20 +1745,25 @@ class SurveyManager
             $invitation = Database::getManager()
                 ->createQuery("
                     SELECT i FROM ChamiloCourseBundle:CSurveyInvitation i
-                    INNER JOIN ChamiloCourseBundle:CSurvey s WITH i.surveyCode = s.code
+                    INNER JOIN ChamiloCourseBundle:CSurvey s WITH s.code = i.surveyCode
+                    INNER JOIN ChamiloCoreBundle:ExtraFieldValues efv WITH efv.itemId = s.iid
+                    INNER JOIN ChamiloCoreBundle:ExtraField ef WITH efv.field = ef.id
                     WHERE i.answered = 0
                         AND i.cId = :course
                         AND i.user = :user
                         AND i.sessionId = :session
                         AND :now BETWEEN s.availFrom AND s.availTill
-                    ORDER BY i.invitationDate ASC
+                        AND ef.variable = :variable
+                        AND efv.value = 1
+                    ORDER BY s.availTill ASC
                 ")
                 ->setMaxResults(1)
                 ->setParameters([
                     'course' => $courseId,
                     'user' => $userId,
                     'session' => $sessionId,
-                    'now' => new DateTime('UTC', new DateTimeZone('UTC'))
+                    'now' => new DateTime('UTC', new DateTimeZone('UTC')),
+                    'variable' => 'is_mandatory'
                 ])
                 ->getSingleResult();
         } catch (Exception $e) {