Separate survey list controls from editor view

This commit is contained in:
Jürgen Mummert
2026-06-07 20:31:31 +02:00
parent 1174410c1b
commit 59514c6911
14 changed files with 170 additions and 267 deletions
+4 -7
View File
@@ -54,11 +54,10 @@ $GLOBALS['TL_DCA']['tl_survey'] = [
'href' => 'act=edit', 'href' => 'act=edit',
'icon' => 'header.svg', 'icon' => 'header.svg',
], ],
'publishSurvey' => [ 'publishedWarning' => [
'label' => &$GLOBALS['TL_LANG']['tl_survey']['publishSurvey'], 'label' => &$GLOBALS['TL_LANG']['tl_survey']['publishedWarning'],
'href' => 'act=toggle&field=published', 'icon' => 'important.svg',
'icon' => 'visible.svg', 'button_callback' => [SurveyDcaListener::class, 'generatePublishedWarningButton'],
'button_callback' => [SurveyDcaListener::class, 'generatePublishSurveyButton'],
], ],
'toggleActive' => [ 'toggleActive' => [
'label' => &$GLOBALS['TL_LANG']['tl_survey']['toggleActive'], 'label' => &$GLOBALS['TL_LANG']['tl_survey']['toggleActive'],
@@ -141,13 +140,11 @@ $GLOBALS['TL_DCA']['tl_survey'] = [
'label' => &$GLOBALS['TL_LANG']['tl_survey']['published'], 'label' => &$GLOBALS['TL_LANG']['tl_survey']['published'],
'inputType' => 'checkbox', 'inputType' => 'checkbox',
'eval' => ['tl_class' => 'w50 m12'], 'eval' => ['tl_class' => 'w50 m12'],
'save_callback' => [[SurveyDcaListener::class, 'savePublishedState']],
'sql' => "char(1) NOT NULL default ''", 'sql' => "char(1) NOT NULL default ''",
], ],
'isActive' => [ 'isActive' => [
'label' => &$GLOBALS['TL_LANG']['tl_survey']['isActive'], 'label' => &$GLOBALS['TL_LANG']['tl_survey']['isActive'],
'inputType' => 'checkbox', 'inputType' => 'checkbox',
'save_callback' => [[SurveyDcaListener::class, 'saveActiveState']],
'sql' => "char(1) NOT NULL default ''", 'sql' => "char(1) NOT NULL default ''",
], ],
'isTemplate' => [ 'isTemplate' => [
-3
View File
@@ -12,9 +12,6 @@ $GLOBALS['TL_DCA']['tl_survey_condition'] = [
'dataContainer' => DC_Table::class, 'dataContainer' => DC_Table::class,
'ptable' => 'tl_survey', 'ptable' => 'tl_survey',
'enableVersioning' => true, 'enableVersioning' => true,
'onload_callback' => [
[SurveyDcaListener::class, 'restrictSurveyConditionEditing'],
],
'onsubmit_callback' => [ 'onsubmit_callback' => [
[SurveyDcaListener::class, 'touchSurveyConditionParent'], [SurveyDcaListener::class, 'touchSurveyConditionParent'],
], ],
-3
View File
@@ -12,9 +12,6 @@ $GLOBALS['TL_DCA']['tl_survey_content'] = [
'dataContainer' => DC_Table::class, 'dataContainer' => DC_Table::class,
'ptable' => 'tl_survey', 'ptable' => 'tl_survey',
'enableVersioning' => true, 'enableVersioning' => true,
'onload_callback' => [
[SurveyDcaListener::class, 'restrictSurveyContentEditing'],
],
'onsubmit_callback' => [ 'onsubmit_callback' => [
[SurveyDcaListener::class, 'touchSurveyContentParent'], [SurveyDcaListener::class, 'touchSurveyContentParent'],
], ],
+1
View File
@@ -19,6 +19,7 @@ $GLOBALS['TL_LANG']['tl_survey']['published'] = ['Veröffentlicht', 'Die Umfrage
$GLOBALS['TL_LANG']['tl_survey']['isActive'] = ['Vorübergehend aktiv', 'Schaltet eine bereits veröffentlichte Umfrage öffentlich an oder aus.']; $GLOBALS['TL_LANG']['tl_survey']['isActive'] = ['Vorübergehend aktiv', 'Schaltet eine bereits veröffentlichte Umfrage öffentlich an oder aus.'];
$GLOBALS['TL_LANG']['tl_survey']['isLocked'] = ['Gesperrt', 'Struktur ist wegen vorhandener Antworten gesperrt.']; $GLOBALS['TL_LANG']['tl_survey']['isLocked'] = ['Gesperrt', 'Struktur ist wegen vorhandener Antworten gesperrt.'];
$GLOBALS['TL_LANG']['tl_survey']['publishSurvey'] = ['Umfrage veröffentlichen', 'Veröffentlicht die Umfrage endgültig.']; $GLOBALS['TL_LANG']['tl_survey']['publishSurvey'] = ['Umfrage veröffentlichen', 'Veröffentlicht die Umfrage endgültig.'];
$GLOBALS['TL_LANG']['tl_survey']['publishedWarning'] = ['Veröffentlichungshinweis', 'Zeigt einen Warnhinweis bei veröffentlichten Umfragen.'];
$GLOBALS['TL_LANG']['tl_survey']['toggleActive'] = ['Sichtbarkeit umschalten', 'Schaltet die veröffentlichte Umfrage vorübergehend an oder aus.']; $GLOBALS['TL_LANG']['tl_survey']['toggleActive'] = ['Sichtbarkeit umschalten', 'Schaltet die veröffentlichte Umfrage vorübergehend an oder aus.'];
$GLOBALS['TL_LANG']['tl_survey']['assignedMembers'] = ['Zugewiesene Mitglieder', 'Wählen Sie die Mitglieder aus, die diese Umfrage bearbeiten dürfen.']; $GLOBALS['TL_LANG']['tl_survey']['assignedMembers'] = ['Zugewiesene Mitglieder', 'Wählen Sie die Mitglieder aus, die diese Umfrage bearbeiten dürfen.'];
$GLOBALS['TL_LANG']['tl_survey']['assignedMembersFilter'] = ['Zugewiesene Benutzer', 'Filtert die Liste nach einem zugewiesenen Benutzer.']; $GLOBALS['TL_LANG']['tl_survey']['assignedMembersFilter'] = ['Zugewiesene Benutzer', 'Filtert die Liste nach einem zugewiesenen Benutzer.'];
+1
View File
@@ -19,6 +19,7 @@ $GLOBALS['TL_LANG']['tl_survey']['published'] = ['Published', 'Make the survey p
$GLOBALS['TL_LANG']['tl_survey']['isActive'] = ['Temporarily active', 'Turns an already published survey on or off publicly.']; $GLOBALS['TL_LANG']['tl_survey']['isActive'] = ['Temporarily active', 'Turns an already published survey on or off publicly.'];
$GLOBALS['TL_LANG']['tl_survey']['isLocked'] = ['Locked', 'Structure is locked because answers already exist.']; $GLOBALS['TL_LANG']['tl_survey']['isLocked'] = ['Locked', 'Structure is locked because answers already exist.'];
$GLOBALS['TL_LANG']['tl_survey']['publishSurvey'] = ['Publish survey', 'Publishes the survey permanently.']; $GLOBALS['TL_LANG']['tl_survey']['publishSurvey'] = ['Publish survey', 'Publishes the survey permanently.'];
$GLOBALS['TL_LANG']['tl_survey']['publishedWarning'] = ['Publication warning', 'Shows a warning hint for already published surveys.'];
$GLOBALS['TL_LANG']['tl_survey']['toggleActive'] = ['Toggle visibility', 'Temporarily switches the published survey on or off.']; $GLOBALS['TL_LANG']['tl_survey']['toggleActive'] = ['Toggle visibility', 'Temporarily switches the published survey on or off.'];
$GLOBALS['TL_LANG']['tl_survey']['assignedMembers'] = ['Assigned members', 'Choose the members who are allowed to edit this survey.']; $GLOBALS['TL_LANG']['tl_survey']['assignedMembers'] = ['Assigned members', 'Choose the members who are allowed to edit this survey.'];
$GLOBALS['TL_LANG']['tl_survey']['assignedMembersFilter'] = ['Assigned users', 'Filters the list by an assigned user.']; $GLOBALS['TL_LANG']['tl_survey']['assignedMembersFilter'] = ['Assigned users', 'Filters the list by an assigned user.'];
@@ -311,29 +311,21 @@
margin: 0; margin: 0;
} }
.survey-list-card__toggle-form { .survey-list-card__head-actions {
flex-shrink: 0; display: flex;
align-self: flex-start; align-items: flex-start;
justify-content: flex-end;
gap: 0.6rem;
margin-left: auto;
} }
.survey-publish-toggle--compact { .survey-list-card__stats {
min-height: 2.8rem; display: flex;
padding: 0.45rem 0.65rem 0.45rem 0.85rem; flex-wrap: wrap;
gap: 0.7rem; gap: 0.85rem;
} color: var(--survey-gray-dark);
font-weight: 600;
.survey-publish-toggle--compact .survey-publish-toggle__track { margin-top: 0.3rem;
width: 3rem;
height: 1.7rem;
}
.survey-publish-toggle--compact .survey-publish-toggle__thumb {
width: 1.4rem;
height: 1.4rem;
}
.survey-publish-toggle--compact.is-on .survey-publish-toggle__thumb {
transform: translateX(1.25rem);
} }
.survey-meta { .survey-meta {
@@ -343,21 +335,92 @@
align-items: center; align-items: center;
} }
.survey-badge { .survey-list-publish-form,
display: inline-flex; .survey-list-eye-form {
align-items: center; margin: 0;
padding: 0.25rem 0.65rem;
border-radius: 999px;
font-size: 0.75rem;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
background: rgba(162, 168, 180, 0.16);
} }
.survey-badge.success { background: rgba(0, 174, 151, 0.16); color: var(--survey-green); } .survey-list-publish-form {
.survey-badge.warning { background: rgba(236, 124, 50, 0.16); color: var(--survey-orange); } position: relative;
.survey-badge.neutral { background: rgba(162, 168, 180, 0.16); color: var(--survey-gray-dark); } }
.survey-list-publish-button[disabled] {
opacity: 1;
background: rgba(162, 168, 180, 0.4);
border-color: rgba(162, 168, 180, 0.65);
color: var(--survey-gray-dark);
pointer-events: none;
}
.survey-list-publish-help {
position: absolute;
right: 0;
top: calc(100% + 0.35rem);
width: 19rem;
max-width: min(72vw, 19rem);
border-radius: 0.75rem;
background: rgba(52, 58, 69, 0.94);
color: #fff;
padding: 0.5rem 0.65rem;
font-size: 0.8rem;
line-height: 1.3;
box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
opacity: 0;
visibility: hidden;
transform: translateY(-0.25rem);
transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
pointer-events: none;
}
.survey-list-publish-form:hover .survey-list-publish-help,
.survey-list-publish-form:focus-within .survey-list-publish-help {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
.survey-visibility-eye {
width: 2.75rem;
height: 2.75rem;
border-radius: 999px;
border: 1px solid rgba(162, 168, 180, 0.62);
background: rgba(162, 168, 180, 0.22);
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: background 0.18s ease, border-color 0.18s ease;
}
.survey-visibility-eye__icon {
width: 1.25rem;
height: 0.8rem;
border: 2px solid currentColor;
border-radius: 99px;
position: relative;
color: #7f8793;
}
.survey-visibility-eye__icon::after {
content: "";
position: absolute;
width: 0.34rem;
height: 0.34rem;
border-radius: 50%;
background: currentColor;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.survey-visibility-eye.is-on {
background: rgba(0, 174, 151, 0.2);
border-color: rgba(0, 174, 151, 0.68);
}
.survey-visibility-eye.is-on .survey-visibility-eye__icon {
color: #0a8378;
}
.survey-button-row { .survey-button-row {
display: flex; display: flex;
@@ -376,18 +439,6 @@
align-items: center; align-items: center;
} }
.survey-action-stack {
display: grid;
gap: 0.35rem;
}
.survey-action-help {
color: var(--survey-gray-dark);
font-size: 0.92rem;
line-height: 1.35;
max-width: 28rem;
}
.survey-publish-toggle-form { .survey-publish-toggle-form {
margin: 0; margin: 0;
} }
@@ -783,14 +834,16 @@
flex-direction: column; flex-direction: column;
} }
.survey-list-card__toggle-form { .survey-list-card__head-actions {
width: auto; margin-left: 0;
max-width: 100%; justify-content: flex-start;
width: 100%;
} }
.survey-list-card__toggle-form .survey-publish-toggle { .survey-list-publish-help {
width: auto; left: 0;
max-width: 100%; right: auto;
width: min(92vw, 19rem);
} }
.survey-brand-strip { .survey-brand-strip {
@@ -824,10 +877,6 @@
padding: 0.95rem 1rem; padding: 0.95rem 1rem;
} }
.survey-publish-toggle:not(.survey-publish-toggle--compact) {
width: 100%;
justify-content: space-between;
}
} }
</style> </style>
<script> <script>
@@ -48,27 +48,6 @@
{% else %} {% else %}
<div class="survey-button-row survey-button-row--editor-actions"> <div class="survey-button-row survey-button-row--editor-actions">
{% if backUrl %}<a class="survey-button secondary" href="{{ backUrl }}">{{ 'survey.edit.back_to_list'|trans }}</a>{% endif %} {% if backUrl %}<a class="survey-button secondary" href="{{ backUrl }}">{{ 'survey.edit.back_to_list'|trans }}</a>{% endif %}
<div class="survey-action-stack">
{% if not survey.published %}
<form method="post" class="survey-action-form">
<input type="hidden" name="REQUEST_TOKEN" value="{{ contao.request_token }}">
<input type="hidden" name="_survey_action" value="publish-survey">
<input type="hidden" name="item_id" value="{{ survey.id }}">
<input type="hidden" name="_token" value="{{ csrf_token('publish-survey-' ~ survey.id) }}">
<button class="survey-button primary" onclick="return confirm('{{ 'survey.edit.publish_confirm'|trans|e('js') }}');">{{ 'survey.edit.publish_survey'|trans }}</button>
</form>
<div class="survey-action-help">{{ 'survey.edit.publish_help'|trans }}</div>
{% else %}
<form method="post" class="survey-action-form">
<input type="hidden" name="REQUEST_TOKEN" value="{{ contao.request_token }}">
<input type="hidden" name="_survey_action" value="toggle-active">
<input type="hidden" name="item_id" value="{{ survey.id }}">
<input type="hidden" name="_token" value="{{ csrf_token('toggle-active-' ~ survey.id) }}">
<button class="survey-button secondary">{{ survey.isActive ? 'survey.edit.deactivate_survey'|trans : 'survey.edit.activate_survey'|trans }}</button>
</form>
<div class="survey-action-help">{{ survey.isActive ? 'survey.edit.deactivate_help'|trans : 'survey.edit.activate_help'|trans }}</div>
{% endif %}
</div>
</div> </div>
{% if structureLocked|default(false) %} {% if structureLocked|default(false) %}
@@ -81,37 +60,6 @@
<div class="survey-grid-columns survey-editor-layout"> <div class="survey-grid-columns survey-editor-layout">
<div class="survey-question-editor-shell" data-survey-question-editor> <div class="survey-question-editor-shell" data-survey-question-editor>
<div class="survey-accordion-list handorgel" data-survey-handorgel> <div class="survey-accordion-list handorgel" data-survey-handorgel>
<article id="survey-metadata" class="survey-accordion-item">
<h4 class="survey-accordion-header handorgel__header">
<button
type="button"
class="survey-accordion-toggle handorgel__header__button"
>
<span class="survey-accordion-heading">
<span class="survey-accordion-copy">
<strong>Metadaten bearbeiten</strong>
</span>
</span>
</button>
</h4>
<div class="survey-accordion-panel handorgel__content">
<div class="handorgel__content__inner">
{{ form_start(surveyForm, {action: metadataFormActionUrl, attr: {class: 'survey-form-grid', id: surveyMetaFormId, 'data-survey-dirty-form': '1'}}) }}
<input type="hidden" name="REQUEST_TOKEN" value="{{ contao.request_token }}">
<input type="hidden" name="{{ surveyForm.published.vars.full_name }}" value="{{ survey.published ? '1' : '0' }}">
{{ form_widget(surveyForm._token) }}
{{ form_errors(surveyForm) }}
<label class="survey-label">{{ 'survey.edit.label_survey_title'|trans }}{{ form_widget(surveyForm.title) }}{{ form_errors(surveyForm.title) }}</label>
<label class="survey-label">{{ 'survey.edit.label_description'|trans }}{{ form_widget(surveyForm.description) }}</label>
<div class="survey-button-row survey-button-row--form-actions">
<button class="survey-button primary">{{ 'survey.edit.save_metadata'|trans }}</button>
<div class="survey-dirty-hint" data-survey-dirty-hint-for="{{ surveyMetaFormId }}" hidden>{{ 'survey.edit.dirty_metadata'|trans }}</div>
</div>
{{ form_end(surveyForm, {render_rest: false}) }}
</div>
</div>
</article>
{% for question in questions %} {% for question in questions %}
{% set questionAnchor = 'survey-question-' ~ question.id %} {% set questionAnchor = 'survey-question-' ~ question.id %}
{% set isOpen = activeQuestionId == question.id %} {% set isOpen = activeQuestionId == question.id %}
@@ -35,28 +35,51 @@
<div class="survey-list-card__head"> <div class="survey-list-card__head">
<div class="survey-list-card__title-wrap"> <div class="survey-list-card__title-wrap">
<h3>{{ survey.title|striptags|trim }}</h3> <h3>{{ survey.title|striptags|trim }}</h3>
<div class="survey-meta"> </div>
<span class="survey-badge {{ survey.published ? 'success' : 'warning' }}">{{ survey.published ? 'survey.list.published'|trans : 'survey.list.draft'|trans }}</span> <div class="survey-list-card__head-actions">
{% if survey.published %} <form method="post" class="survey-list-publish-form">
<span class="survey-badge {{ survey.isActive ? 'success' : 'warning' }}">{{ survey.isActive ? 'survey.list.active'|trans : 'survey.list.inactive'|trans }}</span> <input type="hidden" name="REQUEST_TOKEN" value="{{ contao.request_token }}">
{% elseif survey.isLocked %} <input type="hidden" name="_survey_action" value="publish-survey">
<span class="survey-badge warning">{{ 'survey.list.locked'|trans }}</span> <input type="hidden" name="item_id" value="{{ survey.id }}">
<input type="hidden" name="_token" value="{{ csrf_token('publish-survey-' ~ survey.id) }}">
<button
type="submit"
class="survey-button primary survey-list-publish-button"
{% if survey.published %}disabled{% endif %}
{% if not survey.published %}onclick="return confirm('{{ 'survey.edit.publish_confirm'|trans|e('js') }}');"{% endif %}
>
{{ survey.published ? 'survey.list.publish_done'|trans : 'survey.list.publish'|trans }}
</button>
{% if not survey.published %}
<span class="survey-list-publish-help">{{ 'survey.list.publish_help'|trans }}</span>
{% endif %} {% endif %}
</form>
<form method="post" class="survey-list-eye-form">
<input type="hidden" name="REQUEST_TOKEN" value="{{ contao.request_token }}">
<input type="hidden" name="_survey_action" value="toggle-active">
<input type="hidden" name="item_id" value="{{ survey.id }}">
<input type="hidden" name="_token" value="{{ csrf_token('toggle-active-' ~ survey.id) }}">
<button type="submit" class="survey-visibility-eye{{ survey.isActive ? ' is-on' : '' }}" title="{{ survey.isActive ? 'survey.edit.deactivate_survey'|trans : 'survey.edit.activate_survey'|trans }}" aria-label="{{ survey.isActive ? 'survey.edit.deactivate_survey'|trans : 'survey.edit.activate_survey'|trans }}">
<span class="survey-visibility-eye__icon" aria-hidden="true"></span>
</button>
</form>
</div> </div>
</div> </div>
</div> <div class="survey-list-card__stats">
<div class="survey-meta survey-list-card__stats"> <span>{{ 'survey.list.questions'|trans({'%count%': survey.questionCount}) }}</span>
<span class="survey-badge neutral">{{ 'survey.list.questions'|trans({'%count%': survey.questionCount}) }}</span> <span>{{ 'survey.list.participations'|trans({'%count%': survey.participationCount}) }}</span>
<span class="survey-badge neutral">{{ 'survey.list.participations'|trans({'%count%': survey.participationCount}) }}</span>
</div> </div>
<div class="survey-button-row survey-list-card__actions"> <div class="survey-button-row survey-list-card__actions">
{% if survey.editUrl %} {% if survey.editUrl %}
{% if survey.published %}
<span class="survey-button primary is-disabled" aria-disabled="true">{{ 'survey.list.edit'|trans }}</span>
{% else %}
<a class="survey-button primary" href="{{ survey.editUrl }}">{{ 'survey.list.edit'|trans }}</a> <a class="survey-button primary" href="{{ survey.editUrl }}">{{ 'survey.list.edit'|trans }}</a>
{% endif %} {% endif %}
{% if survey.publicUrl and survey.published and survey.isActive %} {% endif %}
{% if survey.publicUrl and survey.published %}
<a class="survey-button secondary" href="{{ survey.publicUrl }}" target="_blank" rel="noreferrer">{{ 'survey.list.public_view'|trans }}</a> <a class="survey-button secondary" href="{{ survey.publicUrl }}" target="_blank" rel="noreferrer">{{ 'survey.list.public_view'|trans }}</a>
{% elseif survey.publicUrl %}
<span class="survey-button secondary is-disabled" aria-disabled="true">{{ 'survey.list.public_view'|trans }}</span>
{% endif %} {% endif %}
{% if survey.draftUrl and not survey.published %} {% if survey.draftUrl and not survey.published %}
<a class="survey-button secondary" href="{{ survey.draftUrl }}" target="_blank" rel="noreferrer">{{ 'survey.list.draft_view'|trans }}</a> <a class="survey-button secondary" href="{{ survey.draftUrl }}" target="_blank" rel="noreferrer">{{ 'survey.list.draft_view'|trans }}</a>
@@ -272,16 +272,6 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
} }
try { try {
if ('publish-survey' === $action) {
$this->surveyEditorService->publishSurvey($survey, $memberId);
$this->addFlash('success', 'Die Umfrage ist jetzt veröffentlicht.');
}
if ('toggle-active' === $action) {
$isActive = $this->surveyEditorService->toggleSurveyActive($survey, $memberId);
$this->addFlash('success', $isActive ? 'Die Umfrage ist jetzt wieder aktiv.' : 'Die Umfrage wurde vorübergehend deaktiviert.');
}
if ('delete-question' === $action) { if ('delete-question' === $action) {
$this->surveyEditorService->deleteQuestion($survey, $itemId); $this->surveyEditorService->deleteQuestion($survey, $itemId);
$this->addFlash('success', 'Die Frage wurde gelöscht.'); $this->addFlash('success', 'Die Frage wurde gelöscht.');
@@ -90,6 +90,16 @@ final class MemberSurveyListController extends AbstractFrontendModuleController
$survey = $this->resolveEditableSurvey($surveyId, $memberId); $survey = $this->resolveEditableSurvey($surveyId, $memberId);
try { try {
if ('publish-survey' === $action) {
$this->surveyEditorService->publishSurvey($survey, $memberId);
$this->addFlash('success', 'Die Umfrage ist jetzt veröffentlicht.');
}
if ('toggle-active' === $action) {
$isActive = $this->surveyEditorService->toggleSurveyActive($survey, $memberId);
$this->addFlash('success', $isActive ? 'Die Umfrage ist jetzt wieder aktiv.' : 'Die Umfrage wurde vorübergehend deaktiviert.');
}
if ('delete-survey' === $action) { if ('delete-survey' === $action) {
$this->surveyEditorService->deleteSurvey($survey); $this->surveyEditorService->deleteSurvey($survey);
$this->addFlash('success', 'Die Umfrage mit allen Fragen, Antworten und Ergebnissen wurde gelöscht.'); $this->addFlash('success', 'Die Umfrage mit allen Fragen, Antworten und Ergebnissen wurde gelöscht.');
+6 -118
View File
@@ -91,36 +91,22 @@ final class SurveyDcaListener
); );
} }
public function generatePublishSurveyButton(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string public function generatePublishedWarningButton(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string
{ {
if ('1' === (string) ($row['published'] ?? '')) { if ('1' !== (string) ($row['published'] ?? '')) {
return sprintf( return '';
'<span title="%s">%s</span>',
htmlspecialchars('Die Umfrage ist bereits veröffentlicht.', ENT_QUOTES),
Image::getHtml(str_replace('.svg', '--disabled.svg', $icon ?? 'visible.svg'), $label)
);
} }
return sprintf( return sprintf(
'<a href="%s" title="%s" onclick="if(!confirm(\'%s\'))return false;Backend.getScrollOffset()"%s>%s</a>', '<span title="%s"%s>%s</span>',
htmlspecialchars(Backend::addToUrl(($href ?? '').'&amp;id='.(int) ($row['id'] ?? 0)), ENT_QUOTES), htmlspecialchars('Umfrage bereits veröffentlicht, keine Änderungen an den Fragen vornehmen!', ENT_QUOTES),
htmlspecialchars($title, ENT_QUOTES),
StringUtil::specialchars('Wirklich sicher? Nachdem die Umfrage veröffentlicht wurde sind keine Änderungen mehr möglich!'),
$attributes, $attributes,
Image::getHtml($icon ?? 'visible.svg', $label) Image::getHtml($icon ?? 'important.svg', $label)
); );
} }
public function generateToggleActiveButton(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string public function generateToggleActiveButton(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string
{ {
if ('1' !== (string) ($row['published'] ?? '')) {
return sprintf(
'<span title="%s">%s</span>',
htmlspecialchars('Die Umfrage muss zuerst veröffentlicht werden.', ENT_QUOTES),
Image::getHtml('visible--disabled.svg', $label)
);
}
$isActive = '1' === (string) ($row['isActive'] ?? ''); $isActive = '1' === (string) ($row['isActive'] ?? '');
$icon = $isActive ? 'visible.svg' : 'invisible.svg'; $icon = $isActive ? 'visible.svg' : 'invisible.svg';
$title = $isActive ? 'Umfrage vorübergehend deaktivieren' : 'Umfrage wieder aktivieren'; $title = $isActive ? 'Umfrage vorübergehend deaktivieren' : 'Umfrage wieder aktivieren';
@@ -134,45 +120,6 @@ final class SurveyDcaListener
); );
} }
public function savePublishedState(mixed $value, DataContainer $dataContainer): string
{
$surveyId = (int) ($dataContainer->id ?? 0);
$survey = $this->surveyRepository->findById($surveyId);
if (null === $survey) {
return !empty($value) ? '1' : '';
}
if ('1' === (string) $survey->published) {
return '1';
}
if (!empty($value)) {
$now = time();
$this->connection->update('tl_survey', [
'isActive' => '1',
'isLocked' => '1',
'tstamp' => $now,
'updatedAt' => $now,
], ['id' => $surveyId]);
return '1';
}
return '';
}
public function saveActiveState(mixed $value, DataContainer $dataContainer): string
{
$survey = $this->surveyRepository->findById((int) ($dataContainer->id ?? 0));
if (null === $survey || '1' !== (string) $survey->published) {
return '';
}
return !empty($value) ? '1' : '';
}
/** /**
* @return array<int, string> * @return array<int, string>
*/ */
@@ -303,15 +250,11 @@ final class SurveyDcaListener
public function guardContentSave(mixed $value, DataContainer $dataContainer): mixed public function guardContentSave(mixed $value, DataContainer $dataContainer): mixed
{ {
$this->assertSurveyUnlocked($this->resolveSurveyId('tl_survey_content', $dataContainer));
return $value; return $value;
} }
public function guardConditionSave(mixed $value, DataContainer $dataContainer): mixed public function guardConditionSave(mixed $value, DataContainer $dataContainer): mixed
{ {
$this->assertSurveyUnlocked($this->resolveSurveyId('tl_survey_condition', $dataContainer));
return $value; return $value;
} }
@@ -454,7 +397,6 @@ final class SurveyDcaListener
public function guardContentDelete(DataContainer $dataContainer): void public function guardContentDelete(DataContainer $dataContainer): void
{ {
$this->assertSurveyUnlocked($this->resolveSurveyId('tl_survey_content', $dataContainer));
} }
public function touchSurveyContentParent(DataContainer $dataContainer): void public function touchSurveyContentParent(DataContainer $dataContainer): void
@@ -468,7 +410,6 @@ final class SurveyDcaListener
public function guardConditionDelete(DataContainer $dataContainer): void public function guardConditionDelete(DataContainer $dataContainer): void
{ {
$this->assertSurveyUnlocked($this->resolveSurveyId('tl_survey_condition', $dataContainer));
} }
public function touchSurveyConditionParent(DataContainer $dataContainer): void public function touchSurveyConditionParent(DataContainer $dataContainer): void
@@ -489,35 +430,8 @@ final class SurveyDcaListener
} }
} }
public function restrictSurveyContentEditing(): void
{
if (!$this->isSurveyStructureLocked($this->resolveSurveyId('tl_survey_content'))) {
return;
}
$GLOBALS['TL_DCA']['tl_survey_content']['config']['notCreatable'] = true;
$GLOBALS['TL_DCA']['tl_survey_content']['config']['notCopyable'] = true;
$GLOBALS['TL_DCA']['tl_survey_content']['config']['notEditable'] = true;
$GLOBALS['TL_DCA']['tl_survey_content']['config']['notDeletable'] = true;
}
public function restrictSurveyConditionEditing(): void
{
if (!$this->isSurveyStructureLocked($this->resolveSurveyId('tl_survey_condition'))) {
return;
}
$GLOBALS['TL_DCA']['tl_survey_condition']['config']['notCreatable'] = true;
$GLOBALS['TL_DCA']['tl_survey_condition']['config']['notCopyable'] = true;
$GLOBALS['TL_DCA']['tl_survey_condition']['config']['notEditable'] = true;
$GLOBALS['TL_DCA']['tl_survey_condition']['config']['notDeletable'] = true;
}
public function guardSurveyStructureSave(mixed $value, DataContainer $dataContainer): mixed public function guardSurveyStructureSave(mixed $value, DataContainer $dataContainer): mixed
{ {
$surveyId = (int) ($dataContainer->id ?? 0);
$this->assertSurveyUnlocked($surveyId);
return $value; return $value;
} }
@@ -538,28 +452,6 @@ final class SurveyDcaListener
}; };
} }
private function assertSurveyUnlocked(int $surveyId): void
{
if ($this->isSurveyStructureLocked($surveyId)) {
throw new \RuntimeException('Die Fragen dieser Umfrage können nach der Veröffentlichung oder nach ersten Teilnahmen nicht mehr geändert werden.');
}
}
private function isSurveyStructureLocked(int $surveyId): bool
{
if ($surveyId <= 0) {
return false;
}
$survey = $this->surveyRepository->findById($surveyId);
if (null === $survey) {
return false;
}
return '1' === (string) $survey->published || '1' === (string) $survey->isLocked;
}
private function resolveSurveyId(string $table, ?DataContainer $dataContainer = null): int private function resolveSurveyId(string $table, ?DataContainer $dataContainer = null): int
{ {
if ($dataContainer?->activeRecord) { if ($dataContainer?->activeRecord) {
@@ -584,10 +476,6 @@ final class SurveyDcaListener
return 0; return 0;
} }
if ($table === (string) Input::get('table') && '' === (string) Input::get('act')) {
return $recordId;
}
if ('survey' === $table) { if ('survey' === $table) {
$value = $this->connection->fetchOne(sprintf('SELECT %s FROM %s WHERE id = ?', 'id', $table), [$recordId]); $value = $this->connection->fetchOne(sprintf('SELECT %s FROM %s WHERE id = ?', 'id', $table), [$recordId]);
-4
View File
@@ -52,10 +52,6 @@ final class SurveyEditorService
public function toggleSurveyActive(SurveyModel $survey, int $memberId): bool public function toggleSurveyActive(SurveyModel $survey, int $memberId): bool
{ {
if ('1' !== (string) $survey->published) {
throw new \RuntimeException('Die Umfrage muss zuerst veröffentlicht werden.');
}
$isActive = '1' !== (string) ($survey->isActive ?? ''); $isActive = '1' !== (string) ($survey->isActive ?? '');
$this->surveyRepository->setActive((int) $survey->id, $memberId, $isActive); $this->surveyRepository->setActive((int) $survey->id, $memberId, $isActive);
+3
View File
@@ -16,6 +16,9 @@ survey:
public_view: "Öffentliche Ansicht" public_view: "Öffentliche Ansicht"
draft_view: "Entwurfs-Ansicht" draft_view: "Entwurfs-Ansicht"
show_results: "Ergebnisse anzeigen" show_results: "Ergebnisse anzeigen"
publish: "Umfrage veröffentlichen"
publish_done: "Umfrage veröffentlicht"
publish_help: "Umfrage veröffentlichen. Danach sind keine Änderungen mehr möglich."
empty: "Dem eingeloggten Mitglied ist aktuell keine Umfrage zugewiesen." empty: "Dem eingeloggten Mitglied ist aktuell keine Umfrage zugewiesen."
edit: edit:
login_required: "Dieses Frontendmodul ist für eingeloggte Mitglieder gedacht. Nutzen Sie den normalen Contao-Mitgliederlogin auf einer geschützten Seite." login_required: "Dieses Frontendmodul ist für eingeloggte Mitglieder gedacht. Nutzen Sie den normalen Contao-Mitgliederlogin auf einer geschützten Seite."
+3
View File
@@ -16,6 +16,9 @@ survey:
public_view: "Public view" public_view: "Public view"
draft_view: "Draft view" draft_view: "Draft view"
show_results: "Show results" show_results: "Show results"
publish: "Publish survey"
publish_done: "Survey published"
publish_help: "Publish survey. No further changes will be possible afterwards."
empty: "There is currently no survey assigned to the logged-in member." empty: "There is currently no survey assigned to the logged-in member."
edit: edit:
login_required: "This frontend module is intended for logged-in members. Please use the regular Contao member login on a protected page." login_required: "This frontend module is intended for logged-in members. Please use the regular Contao member login on a protected page."