Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions assets/vue/components/layout/TopbarLoggedIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ const notification = useNotification()
const cidReqStore = useCidReqStore()
const securityStore = useSecurityStore()

const showPendingSurveys = computed(() => {
return platformConfigStore.getSetting("survey.show_pending_survey_in_menu") === "true"
})

const pendingSurveysUrl = computed(() => {
try {
const r = router.resolve({ name: "SurveyPending" })
if (r?.href) return r.href
} catch {}
return "/main/survey/pending.php"
})

const isAnonymous = computed(() => {
const u = props.currentUser || securityStore.user || {}
const roles = Array.isArray(u.roles) ? u.roles : []
Expand Down Expand Up @@ -121,6 +133,13 @@ const userSubmenuItems = computed(() => {
},
]

if (showPendingSurveys.value) {
items[0].items.push({
label: t("Pending surveys"),
url: pendingSurveysUrl.value,
})
}

const tabs = platformConfigStore.getSetting("display.show_tabs") || ""
if (tabs.indexOf("topbar_certificate") > -1) {
items[0].items.push({
Expand Down
26 changes: 20 additions & 6 deletions public/main/survey/pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,29 @@
$session = $pending->getSession();
$survey = $pending->getSurvey();

//$course = $course ? ['id' => $course->getId(), 'title' => $course->getTitle(), 'code' => $course->getCode()] : null;
$session = $session ? ['id' => $session->getId(), 'name' => $session->getTitle()] : null;
$courseInfo = api_get_course_info_by_id($course->getId());
$surveysData[$survey->getIid()] = [
$courseArr = null;
if ($course) {
$courseArr = [
'id' => $course->getId(),
'code' => $course->getCode(),
'title' => $course->getTitle(),
];
}

$sessionArr = null;
if ($session) {
$sessionArr = [
'id' => $session->getId(),
'name' => $session->getTitle(),
];
}

$surveysData[] = [
'title' => $survey->getTitle(),
'avail_from' => $survey->getAvailFrom(),
'avail_till' => $survey->getAvailTill(),
'course' => $course,
'session' => $session,
'course' => $courseArr,
'session' => $sessionArr,
'link' => SurveyUtil::generateFillSurveyLink(
$survey,
$pending->getInvitationCode(),
Expand Down
27 changes: 13 additions & 14 deletions public/main/template/default/survey/pending.html.twig
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object" src="{{ user | illustration }}" alt="{{ user.completeName }}">
<img class="media-object" src="{{ user | illustration }}" alt="{{ user.fullName }}">
</a>
</div>
<div class="media-body">
<h3 class="media-heading">{{ user.completeName }}</h3>
<h3 class="media-heading">{{ user.fullName }}</h3>
<p>{{ user.username }}</p>
</div>
</div>
<br>
{% for survey in surveys %}
{% set course_code = survey.course ? survey.course.code : '' %}
{% set session_id = survey.session ? survey.session.id : 0 %}

<div class="panel panel-default">
<div class="panel-body">
<div>
<a href="/main/survey/fillsurvey.php?'{{ { 'course': course_code, 'invitationcode': survey.invitation_code, 'cid': survey.course.id, 'sid': session_id}|url_encode }}">
<a href="{{ survey.link }}">
{{ survey.title }}
</a>
</div>
<ul class="list-inline">
{% if survey.course %}
<li>
<span class="label" style="background-color: {{ survey.session ? '#00496D' : '#458B00' }}">
{{ survey.course.title }}

{% if survey.session %}
({{ survey.session.title }})
{% endif %}
</span>
<span class="label" style="background-color: {{ survey.session ? '#00496D' : '#458B00' }}">
{{ survey.course.title }}
{% if survey.session %}
({{ survey.session.name }})
{% endif %}
</span>
</li>
{% endif %}
<li>
{{ 'From %s to %s'|get_lang|format(survey.avail_from|api_convert_and_format_date(2), survey.avail_till|api_convert_and_format_date(2)) }}
{{ 'From %s to %s'|get_lang|format(
survey.avail_from|api_convert_and_format_date(2),
survey.avail_till|api_convert_and_format_date(2)
) }}
</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public function list(
'display.table_row_list',
'social.allow_social_tool',
'chat.allow_global_chat',
'survey.show_pending_survey_in_menu',
];

$user = $this->userHelper->getCurrent();
Expand Down
5 changes: 5 additions & 0 deletions src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -3440,6 +3440,11 @@ public static function getNewConfigurationSettings(): array
],
],
'survey' => [
[
'name' => 'show_pending_survey_in_menu',
'title' => 'Show "Pending surveys" in menu',
'comment' => 'Display a menu item that lets users access their pending surveys.',
],
[
'name' => 'hide_survey_edition',
'title' => 'Prevent survey edition',
Expand Down
62 changes: 62 additions & 0 deletions src/CoreBundle/Migrations/Schema/V200/Version20251006172700.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

/* For licensing terms, see /license.txt */

namespace Chamilo\CoreBundle\Migrations\Schema\V200;

use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;

final class Version20251006172700 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return "Add survey setting: show_pending_survey_in_menu=false";
}

public function up(Schema $schema): void
{
$variable = 'show_pending_survey_in_menu';
$title = addslashes('Show "Pending surveys" in menu');
$comment = addslashes('Display a menu item that lets users access their pending surveys.');
$category = 'survey';
$default = 'false';

$sqlCheck = "SELECT COUNT(*) AS c FROM settings WHERE variable = '$variable'";
$result = $this->connection->executeQuery($sqlCheck)->fetchAssociative();

if ($result && (int)$result['c'] > 0) {
$this->addSql("
UPDATE settings
SET title = '$title',
comment = '$comment',
category = '$category',
type = COALESCE(type, 'radio'),
selected_value = COALESCE(selected_value, '$default')
WHERE variable = '$variable'
");
$this->write("Updated setting: $variable");
} else {
$this->addSql("
INSERT INTO settings
(variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url)
VALUES
('$variable', NULL, 'radio', '$category', '$default', '$title', '$comment', 1, 0, 1)
");
$this->write("Inserted setting: $variable ($default)");
}
}

public function down(Schema $schema): void
{
$this->addSql("
DELETE FROM settings
WHERE variable = 'show_pending_survey_in_menu'
AND subkey IS NULL
AND access_url = 1
");
$this->write("Removed setting: show_pending_survey_in_menu");
}
}
2 changes: 2 additions & 0 deletions src/CoreBundle/Settings/SurveySettingsSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function buildSettings(AbstractSettingsBuilder $builder): void
'hide_survey_edition' => '',
'survey_additional_teacher_modify_actions' => '',
'show_surveys_base_in_sessions' => 'false',
'show_pending_survey_in_menu' => 'false',
]);
}

Expand All @@ -50,6 +51,7 @@ public function buildForm(FormBuilderInterface $builder): void
->add('hide_survey_edition', TextareaType::class)
->add('survey_additional_teacher_modify_actions', TextareaType::class)
->add('show_surveys_base_in_sessions', YesNoType::class)
->add('show_pending_survey_in_menu', YesNoType::class)
;

$this->updateFormFieldsFromSettingsInfo($builder);
Expand Down
Loading