Surveys: Hide question number if survey has a dependency question

BT#15488
pull/3388/head
Julio Montoya 5 years ago
parent a40429bd75
commit 2a32a0ab55
  1. 15
      main/survey/fillsurvey.php
  2. 13
      main/survey/preview.php
  3. 52
      main/survey/survey.lib.php

@ -305,7 +305,7 @@ if (count($_POST) > 0) {
} else { } else {
// All the other question types (open question, multiple choice, percentage, ...) // All the other question types (open question, multiple choice, percentage, ...)
if (isset($types[$survey_question_id]) && if (isset($types[$survey_question_id]) &&
'percentage' == $types[$survey_question_id]) { 'percentage' === $types[$survey_question_id]) {
$sql = "SELECT * FROM $table_survey_question_option $sql = "SELECT * FROM $table_survey_question_option
WHERE WHERE
c_id = $course_id AND c_id = $course_id AND
@ -378,7 +378,6 @@ if (count($_POST) > 0) {
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC'); $row = Database::fetch_array($result, 'ASSOC');
$option_value = $row['value']; $option_value = $row['value'];
//$option_value = 0;
$survey_question_answer = $value; $survey_question_answer = $value;
// We save the answer after making sure that a possible previous attempt is deleted // We save the answer after making sure that a possible previous attempt is deleted
@ -406,7 +405,6 @@ if (count($_POST) > 0) {
} }
$user_id = api_get_user_id(); $user_id = api_get_user_id();
if ($user_id == 0) { if ($user_id == 0) {
$user_id = $survey_invitation['user']; $user_id = $survey_invitation['user'];
} }
@ -1079,7 +1077,7 @@ if ((isset($_GET['show']) && $_GET['show'] != '') ||
$questions = []; $questions = [];
while ($row = Database::fetch_array($result, 'ASSOC')) { while ($row = Database::fetch_array($result, 'ASSOC')) {
// If the type is not a pagebreak we store it in the $questions array // If the type is not a pagebreak we store it in the $questions array
if ('pagebreak' != $row['type']) { if ('pagebreak' !== $row['type']) {
$questions[$row['sort']]['question_id'] = $row['question_id']; $questions[$row['sort']]['question_id'] = $row['question_id'];
$questions[$row['sort']]['survey_id'] = $row['survey_id']; $questions[$row['sort']]['survey_id'] = $row['survey_id'];
$questions[$row['sort']]['survey_question'] = $row['survey_question']; $questions[$row['sort']]['survey_question'] = $row['survey_question'];
@ -1193,7 +1191,7 @@ if ((isset($_GET['show']) && $_GET['show'] != '') ||
$questions = []; $questions = [];
while ($row = Database :: fetch_array($result, 'ASSOC')) { while ($row = Database :: fetch_array($result, 'ASSOC')) {
// If the type is not a pagebreak we store it in the $questions array // If the type is not a pagebreak we store it in the $questions array
if ('pagebreak' != $row['type']) { if ('pagebreak' !== $row['type']) {
$questions[$row['sort']]['question_id'] = $row['question_id']; $questions[$row['sort']]['question_id'] = $row['question_id'];
$questions[$row['sort']]['survey_id'] = $row['survey_id']; $questions[$row['sort']]['survey_id'] = $row['survey_id'];
$questions[$row['sort']]['survey_question'] = $row['survey_question']; $questions[$row['sort']]['survey_question'] = $row['survey_question'];
@ -1270,6 +1268,11 @@ $form = new FormValidator(
); );
$form->addHidden('language', $p_l); $form->addHidden('language', $p_l);
$showNumber = true;
if (SurveyManager::hasDependency($survey_data)) {
$showNumber = false;
}
if (isset($questions) && is_array($questions)) { if (isset($questions) && is_array($questions)) {
$originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0; $originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0;
$questionCounter = 1; $questionCounter = 1;
@ -1306,7 +1309,9 @@ if (isset($questions) && is_array($questions)) {
// @todo move this in a function. // @todo move this in a function.
$form->addHtml('<div class="survey_question '.$ch_type.' '.$parentClass.'">'); $form->addHtml('<div class="survey_question '.$ch_type.' '.$parentClass.'">');
if ($showNumber) {
$form->addHtml('<div style="float:left; font-weight: bold; margin-right: 5px;"> '.$questionNumber.'. </div>'); $form->addHtml('<div style="float:left; font-weight: bold; margin-right: 5px;"> '.$questionNumber.'. </div>');
}
$form->addHtml('<div>'.Security::remove_XSS($question['survey_question']).'</div> '); $form->addHtml('<div>'.Security::remove_XSS($question['survey_question']).'</div> ');
$userAnswerData = SurveyUtil::get_answers_of_question_by_user($question['survey_id'], $question['question_id']); $userAnswerData = SurveyUtil::get_answers_of_question_by_user($question['survey_id'], $question['question_id']);

@ -93,13 +93,13 @@ if (isset($_GET['show'])) {
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
if (1 == $survey_data['one_question_per_page']) { if (1 == $survey_data['one_question_per_page']) {
if ('pagebreak' != $row['type']) { if ('pagebreak' !== $row['type']) {
$paged_questions[$counter][] = $row['question_id']; $paged_questions[$counter][] = $row['question_id'];
$counter++; $counter++;
continue; continue;
} }
} else { } else {
if ('pagebreak' == $row['type']) { if ('pagebreak' === $row['type']) {
$counter++; $counter++;
} else { } else {
$paged_questions[$counter][] = $row['question_id']; $paged_questions[$counter][] = $row['question_id'];
@ -143,7 +143,7 @@ if (isset($_GET['show'])) {
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
// If the type is not a pagebreak we store it in the $questions array // If the type is not a pagebreak we store it in the $questions array
if ('pagebreak' != $row['type']) { if ('pagebreak' !== $row['type']) {
$sort = $row['sort']; $sort = $row['sort'];
$questions[$sort]['question_id'] = $row['question_id']; $questions[$sort]['question_id'] = $row['question_id'];
$questions[$sort]['survey_id'] = $row['survey_id']; $questions[$sort]['survey_id'] = $row['survey_id'];
@ -191,6 +191,11 @@ if (is_array($questions) && count($questions) > 0) {
$counter = $before + 1; $counter = $before + 1;
} }
$showNumber = true;
if (SurveyManager::hasDependency($survey_data)) {
$showNumber = false;
}
$js = ''; $js = '';
foreach ($questions as $key => &$question) { foreach ($questions as $key => &$question) {
$ch_type = 'ch_'.$question['type']; $ch_type = 'ch_'.$question['type'];
@ -211,7 +216,9 @@ if (is_array($questions) && count($questions) > 0) {
$js .= survey_question::getQuestionJs($question); $js .= survey_question::getQuestionJs($question);
$form->addHtml('<div class="survey_question '.$ch_type.' '.$parentClass.'">'); $form->addHtml('<div class="survey_question '.$ch_type.' '.$parentClass.'">');
if ($showNumber) {
$form->addHtml('<div style="float:left; font-weight: bold; margin-right: 5px;"> '.$counter.'. </div>'); $form->addHtml('<div style="float:left; font-weight: bold; margin-right: 5px;"> '.$counter.'. </div>');
}
$form->addHtml('<div>'.Security::remove_XSS($question['survey_question']).'</div> '); $form->addHtml('<div>'.Security::remove_XSS($question['survey_question']).'</div> ');
$display->render($form, $question); $display->render($form, $question);
$form->addHtml('</div>'); $form->addHtml('</div>');

@ -2515,6 +2515,42 @@ class SurveyManager
return true; return true;
} }
public static function hasDependency($survey)
{
if (false === api_get_configuration_value('survey_question_dependency')) {
return false;
}
if (empty($survey)) {
return false;
}
if (!isset($survey['survey_id'])) {
return false;
}
$courseId = (int) $survey['c_id'];
$surveyId = (int) $survey['survey_id'];
$table = Database::get_course_table(TABLE_SURVEY_QUESTION);
$sql = "SELECT COUNT(iid) count FROM $table
WHERE
c_id = $courseId AND
survey_id = $surveyId AND
parent_option_id <> 0
LIMIT 1
";
$result = Database::query($sql);
$row = Database::fetch_array($result);
if ($row) {
return $row['count'] > 0;
}
return false;
}
/** /**
* @param array $survey * @param array $survey
* *
@ -2526,8 +2562,8 @@ class SurveyManager
return 0; return 0;
} }
$courseId = $survey['c_id']; $courseId = (int) $survey['c_id'];
$surveyId = $survey['survey_id']; $surveyId = (int) $survey['survey_id'];
$table = Database::get_course_table(TABLE_SURVEY_QUESTION); $table = Database::get_course_table(TABLE_SURVEY_QUESTION);
@ -2625,7 +2661,8 @@ class SurveyManager
$groupId = 0 $groupId = 0
) { ) {
$invitationRepo = Database::getManager()->getRepository('ChamiloCourseBundle:CSurveyInvitation'); $invitationRepo = Database::getManager()->getRepository('ChamiloCourseBundle:CSurveyInvitation');
$invitations = $invitationRepo->findBy(
return $invitationRepo->findBy(
[ [
'user' => $userId, 'user' => $userId,
'cId' => $courseId, 'cId' => $courseId,
@ -2635,8 +2672,6 @@ class SurveyManager
], ],
['invitationDate' => 'DESC'] ['invitationDate' => 'DESC']
); );
return $invitations;
} }
/** /**
@ -2694,7 +2729,12 @@ class SurveyManager
if (empty($sessionId)) { if (empty($sessionId)) {
$subscribe = CourseManager::is_user_subscribed_in_course($userId, $courseCode); $subscribe = CourseManager::is_user_subscribed_in_course($userId, $courseCode);
} else { } else {
$subscribe = CourseManager::is_user_subscribed_in_course($userId, $courseCode, true, $sessionId); $subscribe = CourseManager::is_user_subscribed_in_course(
$userId,
$courseCode,
true,
$sessionId
);
} }
// User is not subscribe skip! // User is not subscribe skip!

Loading…
Cancel
Save