Browse Source

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

Julio Montoya 6 years ago
parent
commit
9a8b1d447f

+ 2 - 0
main/install/configuration.dist.php

@@ -525,6 +525,8 @@ ALTER TABLE c_survey_question ADD is_required TINYINT(1) DEFAULT 0 NOT NULL;
 // Allow add additional actions (as links) in survey list for teachers.
 // e.g. ['myplugin' => ['MyPlugin', 'urlGeneratorCallback']]
 //$_configuration['survey_additional_teacher_modify_actions'] = [];
+// Allow show answers in anonymous surveys
+//$_configuration['survey_anonymous_show_answered'] = false;
 // ------
 
 // Allow career diagram, requires a DB change:

+ 9 - 0
main/survey/survey.lib.php

@@ -1790,6 +1790,15 @@ class SurveyManager
         } else {
             $sql = "SELECT DISTINCT user FROM $table_survey_answer
 			        WHERE c_id = $course_id AND survey_id= '".$survey_id."'  ";
+
+            if (api_get_configuration_value('survey_anonymous_show_answered')) {
+                $tblInvitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
+                $tblSurvey = Database::get_course_table(TABLE_SURVEY);
+
+                $sql = "SELECT i.user FROM $tblInvitation i
+                    INNER JOIN $tblSurvey s ON i.survey_code = s.code
+                    WHERE i.answered IS TRUE AND s.iid = $survey_id";
+            }
         }
 
         $res = Database::query($sql);

+ 28 - 0
main/survey/surveyUtil.class.php

@@ -3850,4 +3850,32 @@ class SurveyUtil
 
         return $pendingSurveys;
     }
+
+    /**
+     * @param string $surveyCode
+     * @param int    $courseId
+     * @param int    $sessionId
+     *
+     * @return array
+     */
+    public static function getSentInvitations($surveyCode, $courseId, $sessionId = 0)
+    {
+        $tblUser = Database::get_main_table(TABLE_MAIN_USER);
+        $tblSurveyInvitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
+
+        $sessionCondition = api_get_session_condition($sessionId);
+        $surveyCode = Database::escape_string($surveyCode);
+
+        $sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email
+            FROM $tblSurveyInvitation survey_invitation
+            LEFT JOIN $tblUser user
+            ON (survey_invitation.user = user.id AND survey_invitation.c_id = $courseId)
+            WHERE
+                survey_invitation.survey_code = '$surveyCode'
+                $sessionCondition";
+
+        $query = Database::query($sql);
+
+        return Database::store_result($query);
+    }
 }

+ 7 - 13
main/survey/survey_invitation.php

@@ -55,7 +55,7 @@ Display::display_header($tool_name);
 
 // Getting all the people who have filled this survey
 $answered_data = SurveyManager::get_people_who_filled_survey($survey_id);
-if ($survey_data['anonymous'] == 1) {
+if ($survey_data['anonymous'] == 1 && !api_get_configuration_value('survey_anonymous_show_answered')) {
     echo Display::return_message(
         get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.count(
             $answered_data
@@ -95,20 +95,13 @@ echo '	</tr>';
 
 $course_id = api_get_course_int_id();
 $sessionId = api_get_session_id();
-$sessionCondition = api_get_session_condition($sessionId);
 
-$sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email
-        FROM $table_survey_invitation survey_invitation
-        LEFT JOIN $table_user user
-        ON (survey_invitation.user = user.id AND survey_invitation.c_id = $course_id)
-        WHERE
-            survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."' $sessionCondition";
+$sentIntitations = SurveyUtil::getSentInvitations($survey_data['code'], $course_id, $sessionId);
 
-$res = Database::query($sql);
-while ($row = Database::fetch_assoc($res)) {
+foreach ($sentIntitations as $row) {
     if (!$_GET['view'] || $_GET['view'] == 'invited' ||
-        ($_GET['view'] == 'answered' && in_array($row['user'], $answered_data)) ||
-        ($_GET['view'] == 'unanswered' && !in_array($row['user'], $answered_data))
+        ($_GET['view'] == 'answered' && in_array($row['user'], $answered_data) && count($answered_data) > 1) ||
+        ($_GET['view'] == 'unanswered' && !in_array($row['user'], $answered_data) && count($answered_data) > 1)
     ) {
         echo '<tr>';
         if (is_numeric($row['user'])) {
@@ -122,7 +115,8 @@ while ($row = Database::fetch_assoc($res)) {
         echo '	<td>'.Display::dateToStringAgoAndLongDate($row['invitation_date']).'</td>';
         echo '	<td>';
 
-        if (in_array($row['user'], $answered_data) && !api_get_configuration_value('hide_survey_reporting_button')) {
+        if (in_array($row['user'], $answered_data) && !api_get_configuration_value('hide_survey_reporting_button') &&
+            !api_get_configuration_value('survey_anonymous_show_answered')) {
             echo '<a href="'.
                 api_get_path(WEB_CODE_PATH).
                 'survey/reporting.php?action=userreport&survey_id='.$survey_id.'&user='.$row['user'].'&'.api_get_cidreq().'">'.

+ 1 - 1
main/survey/survey_invite.php

@@ -142,7 +142,7 @@ $form->addHtmlEditor(
 );
 $form->addElement('html', '</div>');
 // You cab send a reminder to unanswered people if the survey is not anonymous
-if ($survey_data['anonymous'] != 1) {
+if ($survey_data['anonymous'] != 1 || api_get_configuration_value('survey_anonymous_show_answered')) {
     $form->addElement('checkbox', 'remindUnAnswered', '', get_lang('RemindUnanswered'));
 }
 // Allow resending to all selected users