Survey: Update from 1.11.x + fixes

pull/3733/head
Julio Montoya 4 years ago
parent 2050b8d1e5
commit 39ba658338
  1. 10
      public/main/inc/lib/SurveyTree.php
  2. 35
      public/main/survey/create_meeting.php
  3. 25
      public/main/survey/fillsurvey.php
  4. 6
      public/main/survey/surveyUtil.class.php
  5. 17
      public/main/survey/survey_invite.php

@ -29,18 +29,18 @@ class SurveyTree
$course_id = api_get_course_int_id();
$sql = "SELECT
survey.survey_id,
survey.iid survey_id,
survey.parent_id,
survey_version,
survey.code as name
FROM $table_survey survey
LEFT JOIN $table_survey_question survey_question
ON survey.survey_id = survey_question.survey_id , $table_user user
ON survey.iid = survey_question.survey_id , $table_user user
WHERE
survey.c_id = $course_id AND
survey_question.c_id = $course_id AND
survey.author = user.id
GROUP BY survey.survey_id";
GROUP BY survey.iid";
$res = Database::query($sql);
$refs = [];
@ -81,9 +81,9 @@ class SurveyTree
$node = $this->plainsurveylist[$id];
if (is_array($node) && !empty($node['parent_id'])) {
return $node['parent_id'];
} else {
return -1;
}
return -1;
}
/**

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../inc/global.inc.php';
@ -29,32 +30,19 @@ $form = new FormValidator(
api_get_self().'?action=add&'.api_get_cidreq()
);
$form->addElement('header', $tool_name);
$form->addHeader($tool_name);
$form->addHidden('anonymous', 0);
$form->addHidden('survey_language', $courseInfo['language']);
$form->addHidden('survey_subtitle', '');
$form->addHidden('survey_thanks', '');
$form->addHidden('visible_results', '0');
$form->addHidden('survey_type', 3);
$text = $form->addText('survey_title', get_lang('Title'));
$text = $form->addText(
'survey_title',
get_lang('Title')
);
$allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
if ($allowSurveyAvailabilityDatetime) {
$startDateElement = $form->addDateTimePicker('start_date', get_lang('Start Date'));
$endDateElement = $form->addDateTimePicker('end_date', get_lang('End Date'));
$form->addRule('start_date', get_lang('Invalid date'), 'datetime');
$form->addRule('end_date', get_lang('Invalid date'), 'datetime');
} else {
$startDateElement = $form->addElement('date_picker', 'start_date', get_lang('Start Date'));
$endDateElement = $form->addElement('date_picker', 'end_date', get_lang('End Date'));
$form->addRule('start_date', get_lang('Invalid date'), 'date');
$form->addRule('end_date', get_lang('Invalid date'), 'date');
}
$startDateElement = $form->addDateTimePicker('start_date', get_lang('Start Date'));
$endDateElement = $form->addDateTimePicker('end_date', get_lang('End Date'));
$form->addRule('start_date', get_lang('Invalid date'), 'datetime');
$form->addRule('end_date', get_lang('Invalid date'), 'datetime');
$form->addRule(
['start_date', 'end_date'],
@ -152,7 +140,7 @@ if ($form->validate()) {
$questionTable = Database::get_course_table(TABLE_SURVEY_QUESTION);
$counter = 1;
if (!empty($surveyData['id'])) {
if (!empty($surveyData['iid'])) {
foreach ($dates as $date) {
$params = [
'c_id' => api_get_course_int_id(),
@ -165,12 +153,7 @@ if ($form->validate()) {
'shared_question_id' => '0',
'max_value' => 0,
];
$questionId = Database::insert($questionTable, $params);
if ($questionId) {
$sql = "UPDATE $questionTable SET question_id = $questionId
WHERE iid = $questionId";
Database::query($sql);
}
Database::insert($questionTable, $params);
$counter++;
}
}

@ -5,6 +5,7 @@
use ChamiloSession as Session;
$lastQuestion = 0;
/**
* @author unknown, the initial survey that did not make it in 1.8 because of bad code
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup,
@ -92,7 +93,7 @@ if ((!isset($_GET['course']) || !isset($_GET['invitationcode'])) && !isset($_GET
$invitationcode = $_GET['invitationcode'];
// Start auto-invitation feature FS#3403 (all-users-can-do-the-survey-URL handling)
if ('auto' == $invitationcode && isset($_GET['scode'])) {
if ('auto' === $invitationcode && isset($_GET['scode'])) {
$userid = api_get_user_id();
// Survey_code of the survey
$surveyCode = $_GET['scode'];
@ -213,7 +214,7 @@ if (Database::num_rows($result) > 1) {
}
} else {
$row = Database::fetch_array($result, 'ASSOC');
$survey_invitation['survey_id'] = $row['survey_id'];
$survey_invitation['survey_id'] = $row['iid'];
}
// Getting the survey information
@ -252,8 +253,8 @@ if (count($_POST) > 0) {
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
$types[$row['question_id']] = $row['type'];
$required[$row['question_id']] = $allowRequiredSurveyQuestions && $row['is_required'];
$types[$row['iid']] = $row['type'];
$required[$row['iid']] = $allowRequiredSurveyQuestions && $row['is_required'];
}
// Looping through all the post values
@ -286,7 +287,7 @@ if (count($_POST) > 0) {
);
foreach ($value as $answer_key => &$answer_value) {
if ('score' == $types[$survey_question_id]) {
if ('score' === $types[$survey_question_id]) {
$option_id = $answer_key;
$option_value = $answer_value;
} else {
@ -316,9 +317,7 @@ if (count($_POST) > 0) {
$option_value = $row['option_text'];
} else {
$option_value = 0;
if (isset($types[$survey_question_id]) &&
'open' == $types[$survey_question_id]
) {
if (isset($types[$survey_question_id]) && 'open' === $types[$survey_question_id]) {
$option_value = $value;
}
}
@ -358,7 +357,7 @@ if (count($_POST) > 0) {
$result = Database::query($sql);
// There is only one question type for conditional surveys
while ($row = Database::fetch_array($result, 'ASSOC')) {
$types[$row['question_id']] = $row['type'];
$types[$row['iid']] = $row['type'];
}
// Looping through all the post values
@ -702,17 +701,17 @@ if ((isset($_GET['show']) && '' != $_GET['show']) ||
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
if (1 == $survey_data['one_question_per_page']) {
if ('pagebreak' != $row['type']) {
$paged_questions[$counter][] = $row['question_id'];
if ('pagebreak' !== $row['type']) {
$paged_questions[$counter][] = $row['iid'];
$counter++;
continue;
}
} else {
if ('pagebreak' == $row['type']) {
if ('pagebreak' === $row['type']) {
$counter++;
$pageBreakText[$counter] = $row['survey_question'];
} else {
$paged_questions[$counter][] = $row['question_id'];
$paged_questions[$counter][] = $row['iid'];
}
}
}

@ -2798,11 +2798,11 @@ class SurveyUtil
if (!empty($defaults['course_users'])) {
$user_ids = implode("','", $defaults['course_users']);
$sql = "SELECT user_id FROM $table_user WHERE user_id IN ('$user_ids') $order_clause";
$sql = "SELECT id FROM $table_user WHERE id IN ('$user_ids') $order_clause";
$result = Database::query($sql);
$fixed_users = [];
while ($row = Database::fetch_array($result)) {
$fixed_users[] = $row['user_id'];
$fixed_users[] = $row['id'];
}
$defaults['course_users'] = $fixed_users;
}
@ -3545,7 +3545,7 @@ class SurveyUtil
." AS col4,
survey.avail_from AS col5,
survey.avail_till AS col6,
CONCAT('<a href=\"survey_invitation.php?view=answered&survey_id=',survey.iid,'\">',survey.answered,'</a> / <a href=\"survey_invitation.php?view=invited&survey_id=',survey.survey_id,'\">',survey.invited, '</a>') AS col7,
CONCAT('<a href=\"survey_invitation.php?view=answered&survey_id=',survey.iid,'\">',survey.answered,'</a> / <a href=\"survey_invitation.php?view=invited&survey_id=',survey.iid,'\">',survey.invited, '</a>') AS col7,
survey.anonymous AS col8,
survey.iid AS col9
FROM $table_survey survey

@ -87,12 +87,12 @@ if (Database::num_rows($result) > 1) {
if ($survey_data['invited'] > 0 && !isset($_POST['submit'])) {
$message = Display::url(
$survey_data['answered'],
api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey_data['survey_id'].'&'.api_get_cidreq()
api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey_data['iid'].'&'.api_get_cidreq()
);
$message .= ' '.get_lang('have answered').' ';
$message .= Display::url(
$survey_data['invited'],
api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey_data['survey_id'].'&'.api_get_cidreq());
api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey_data['iid'].'&'.api_get_cidreq());
$message .= ' '.get_lang('were invited');
echo Display::return_message($message, 'normal', false);
}
@ -164,7 +164,10 @@ if ($form->validate()) {
if ($sendMail) {
if (empty($values['mail_title']) || empty($values['mail_text'])) {
echo Display::return_message(get_lang('The form contains incorrect or incomplete data. Please check your input.'), 'error');
echo Display::return_message(
get_lang('The form contains incorrect or incomplete data. Please check your input.'),
'error'
);
// Getting the invited users
$defaults = SurveyUtil::get_invited_users($survey_data['code']);
@ -184,7 +187,7 @@ if ($form->validate()) {
}
$repo = Container::getSurveyRepository();
$survey = $repo->find($survey_data['survey_id']);
$survey = $repo->find($survey_data['iid']);
// Save the invitation mail
SurveyUtil::saveInviteMail(
@ -196,7 +199,7 @@ if ($form->validate()) {
// Saving the invitations for the course users
$count_course_users = SurveyUtil::saveInvitations(
$survey_data['survey_id'],
$survey_data['iid'],
$users,
$values['mail_title'],
$values['mail_text'],
@ -216,7 +219,7 @@ if ($form->validate()) {
}
$counter_additional_users = SurveyUtil::saveInvitations(
$survey_data['survey_id'],
$survey_data['iid'],
$additional_users,
$values['mail_title'],
$values['mail_text'],
@ -230,7 +233,7 @@ if ($form->validate()) {
// Counting the number of people that are invited
$total_invited = SurveyUtil::update_count_invited($survey_data['code']);
$total_count = $count_course_users + $counter_additional_users;
$invitationUrl = api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?survey_id='.$survey_data['survey_id'].'&'.api_get_cidreq();
$invitationUrl = api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?survey_id='.$survey_data['iid'].'&'.api_get_cidreq();
if ($total_invited > 0) {
$message = '<a href="'.$invitationUrl.'&view=answered">'.
$survey_data['answered'].'</a> ';

Loading…
Cancel
Save