Skip to content

Commit

Permalink
Survey: Allow tutors to access doodle past end date and cosmetic chan…
Browse files Browse the repository at this point in the history
…ges - BT#21622
  • Loading branch information
christianbeeznest committed May 3, 2024
1 parent 764d93a commit e457b0e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
35 changes: 20 additions & 15 deletions public/main/survey/meeting.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
}

$surveyId = $survey->getIid();

SurveyManager::checkTimeAvailability($survey);
$invitations = SurveyUtil::get_invited_users($survey);
$students = $invitations['course_users'] ?? [];

Expand All @@ -65,6 +63,10 @@
$url = api_get_self().'?survey_id='.$surveyId.'&invitationcode='.$invitationcode.'&'.api_get_cidreq();
$urlEdit = $url.'&action=edit';

if (!api_is_allowed_to_edit()) {
SurveyManager::checkTimeAvailability($survey);
}

$questions = $survey->getQuestions();

if (isset($_POST) && !empty($_POST)) {
Expand Down Expand Up @@ -110,10 +112,13 @@

$template = new Template();

$table = new HTML_Table(['class' => 'table']);
$table = new HTML_Table(['class' => 'table table-hover table-striped data_table mt-5']);
$row = 0;
$column = 1;
$column = 0;
$answerList = [];

$table->setHeaderContents($row, $column, "");
$column++;
foreach ($questions as $item) {
$questionId = $item->getIid();
$answers = SurveyUtil::get_answers_of_question_by_user($surveyId, $questionId);
Expand Down Expand Up @@ -142,18 +147,18 @@
}

$mainDate = api_format_date($mainDate, DATE_FORMAT_SHORT);
$table->setHeaderContents($row, $column, "<h4>$mainDate</h4> $startTime <br >$endTime");
$table->setHeaderContents($row, $column, "<h4>$mainDate</h4> <span class='text-lg'>$startTime <br >$endTime</span>");
$column++;
}

$row = 1;
$row = 0;
$column = 0;

// Total counter
$table->setHeaderContents(
$table->setCellContents(
$row,
0,
get_lang('Number of users').': '.count($students)
'<span class="text-bold font-extrabold text-xl">'.get_lang('Number of users').': '.count($students).'</span>'
);

foreach ($questions as $item) {
Expand All @@ -166,8 +171,8 @@
$questionsWithAnswer++;
}
}
$count = '<p style="color:cornflowerblue" >
<span class="fa fa-check fa-2x"></span>'.$questionsWithAnswer.'</p>';
$count = '<p class="text-info text-center p-2 text-bold font-extrabold text-2xl">
<span class="mdi mdi-check text-3xl"></span>'.$questionsWithAnswer.'</p>';
}
$table->setCellContents(
$row,
Expand All @@ -176,7 +181,7 @@
);
}

$row = 2;
$row = 1;
$column = 0;
$availableIcon = Display::getMdiIcon(StateIcon::ACTIVE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Available'));
$notAvailableIcon = Display::getMdiIcon(StateIcon::INACTIVE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Not available'));
Expand Down Expand Up @@ -210,7 +215,7 @@
}

if ('edit' === $action) {
$html = '<div class="alert alert-info"><input
$html = '<div class="alert alert-info text-center"><input
id="'.$questionId.'"
name="options['.$questionId.']"
class="question" '.$checked.'
Expand All @@ -220,7 +225,7 @@ class="question" '.$checked.'
$html = $checked;
}

$table->setHeaderContents(
$table->setCellContents(
$row,
$rowColumn,
$html
Expand All @@ -238,7 +243,7 @@ class="question" '.$checked.'
$checked = $notAvailableIcon;
}
}
$table->setHeaderContents(
$table->setCellContents(
$row,
$rowColumn,
$checked
Expand All @@ -247,7 +252,7 @@ class="question" '.$checked.'
}
}
$column = 0;
$table->setCellContents($row, $column, $name);
$table->setCellContents($row, $column, '<span class="text-bold font-extrabold text-lg">'.$name.'</span>');
$row++;
}
if ('edit' === $action) {
Expand Down
35 changes: 20 additions & 15 deletions public/main/survey/survey.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,7 @@ public static function getCountPages(CSurvey $survey)
/**
* Check whether this survey has ended. If so, display message and exit this script.
*/
public static function checkTimeAvailability(?CSurvey $survey)
public static function checkTimeAvailability(?CSurvey $survey): void
{
if (null === $survey) {
api_not_allowed(true);
Expand All @@ -2133,27 +2133,32 @@ public static function checkTimeAvailability(?CSurvey $survey)
$currentDate = new DateTime('now', $utcZone);
$currentDate->modify('today');

$returnMessage = false;
if ($currentDate < $startDate) {
api_not_allowed(
true,
Display:: return_message(
get_lang('This survey is not yet available. Please try again later. Thank you.'),
'warning',
false
)
$returnMessage = Display:: return_message(
get_lang('This survey is not yet available. Please try again later. Thank you.'),
'warning',
false
);
}

if ($currentDate > $endDate) {
api_not_allowed(
true,
Display:: return_message(
get_lang('Sorry, this survey is not available anymore. Thank you for trying.'),
'warning',
false
)
$returnMessage = Display:: return_message(
get_lang('Sorry, this survey is not available anymore. Thank you for trying.'),
'warning',
false
);
}

if (false !== $returnMessage) {
$content = Display::page_header($survey->getTitle());
$content .= $returnMessage;
$template = new Template();
$template->assign('actions', Display::toolbarAction('toolbar', []));
$template->assign('content', $content);
$template->display_one_col_template();
exit;
}
}

/**
Expand Down

0 comments on commit e457b0e

Please sign in to comment.