diff --git a/contao/dca/tl_survey.php b/contao/dca/tl_survey.php index cf58ea8..c322520 100644 --- a/contao/dca/tl_survey.php +++ b/contao/dca/tl_survey.php @@ -47,18 +47,15 @@ $GLOBALS['TL_DCA']['tl_survey'] = [ ], 'operations' => [ 'edit' => [ + 'label' => ['Fragen bearbeiten', 'Fragen der Umfrage bearbeiten'], 'href' => 'table=tl_survey_content', 'icon' => 'children.svg', ], 'editheader' => [ + 'label' => ['Umfrage bearbeiten', 'Umfrage bearbeiten'], 'href' => 'act=edit', 'icon' => 'header.svg', ], - 'publishedWarning' => [ - 'label' => &$GLOBALS['TL_LANG']['tl_survey']['publishedWarning'], - 'icon' => 'important.svg', - 'button_callback' => [SurveyDcaListener::class, 'generatePublishedWarningButton'], - ], 'toggle' => [ 'label' => &$GLOBALS['TL_LANG']['tl_survey']['toggleActive'], 'href' => 'act=toggle&field=isActive', @@ -66,12 +63,20 @@ $GLOBALS['TL_DCA']['tl_survey'] = [ 'primary' => true, 'showInHeader' => true, ], + 'publishedWarning' => [ + 'label' => &$GLOBALS['TL_LANG']['tl_survey']['publishedWarning'], + 'icon' => 'important.svg', + 'primary' => true, + 'button_callback' => [SurveyDcaListener::class, 'generatePublishedWarningButton'], + ], 'delete' => [ + 'label' => ['Löschen', 'Eintrag wirklich löschen?'], 'href' => 'act=delete', 'icon' => 'delete.svg', 'attributes' => 'onclick="if(!confirm(\'Eintrag wirklich löschen?\'))return false;Backend.getScrollOffset()"', ], 'show' => [ + 'label' => ['Details', 'Details des Elements ID %s anzeigen'], 'href' => 'act=show', 'icon' => 'show.svg', ], diff --git a/contao/templates/frontend/member_survey_edit.html.twig b/contao/templates/frontend/member_survey_edit.html.twig index ccccab6..4687abe 100644 --- a/contao/templates/frontend/member_survey_edit.html.twig +++ b/contao/templates/frontend/member_survey_edit.html.twig @@ -33,7 +33,6 @@ {% elseif createMode %}

{{ 'survey.edit.create_title'|trans }}

-

{{ 'survey.edit.create_text'|trans }}

{{ form_start(surveyForm, {attr: {class: 'survey-form-grid'}}) }} {{ form_widget(surveyForm._token) }} @@ -94,11 +93,6 @@ {{ question.question|striptags|trim ?: ('survey.edit.question_fallback'|trans({'%id%': question.id})) }} - - {{ ('survey.survey.question_type_' ~ question.type)|trans }} - {% if question.mandatory %}{{ 'survey.edit.mandatory_badge'|trans }}{% endif %} - {% if loop.first %}{{ 'survey.edit.start_badge'|trans }}{% endif %} -
@@ -240,9 +234,9 @@
{% set sourceLabel = (condition.sourceQuestionLabel|default('')|striptags|trim) ?: ('survey.edit.question_fallback'|trans({'%id%': condition.sourceQuestion})) %} {% set targetLabel = (condition.targetQuestionLabel|default('')|striptags|trim) ?: ('survey.edit.question_fallback'|trans({'%id%': condition.targetQuestion})) %} -
Frage {{ condition.sourceQuestion }}: {{ sourceLabel }}
+
Frage {{ condition.sourcePosition ?: condition.sourceQuestion }}: {{ sourceLabel }}
{{ 'survey.edit.condition_prefix'|trans({'%value%': condition.answerValue|default('')|striptags|trim|capitalize}) }}
-
weiter zu Frage {{ condition.targetQuestion }}: {{ targetLabel }}
+
weiter zu Frage {{ condition.targetPosition ?: condition.targetQuestion }}: {{ targetLabel }}
{% else %}
{{ 'survey.edit.no_conditions'|trans }}
diff --git a/src/Controller/FrontendModule/MemberSurveyEditController.php b/src/Controller/FrontendModule/MemberSurveyEditController.php index 4e6593e..09a0e64 100644 --- a/src/Controller/FrontendModule/MemberSurveyEditController.php +++ b/src/Controller/FrontendModule/MemberSurveyEditController.php @@ -337,7 +337,9 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController { $questionLabels = []; $questionSortings = []; + $questionPositions = []; $rules = []; + $position = 1; foreach ($questions as $question) { $questionId = (int) ($question->id ?? 0); @@ -348,6 +350,7 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController $questionLabels[$questionId] = (string) ($question->question ?? ''); $questionSortings[$questionId] = (int) ($question->sorting ?? 0); + $questionPositions[$questionId] = $position++; } foreach ($questions as $question) { @@ -371,6 +374,8 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController 'answerValue' => $answerValue, 'sourceQuestion' => $questionId, 'targetQuestion' => $targetQuestionId, + 'sourcePosition' => $questionPositions[$questionId] ?? 0, + 'targetPosition' => $questionPositions[$targetQuestionId] ?? 0, 'sourceQuestionLabel' => (string) ($question->question ?? ''), 'targetQuestionLabel' => $questionLabels[$targetQuestionId] ?? '', 'sourceSorting' => $questionSortings[$questionId] ?? 0, @@ -386,6 +391,8 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController 'answerValue' => (string) ($condition['answerValue'] ?? ''), 'sourceQuestion' => $sourceQuestionId, 'targetQuestion' => (int) ($condition['targetQuestion'] ?? 0), + 'sourcePosition' => $questionPositions[$sourceQuestionId] ?? 0, + 'targetPosition' => $questionPositions[(int) ($condition['targetQuestion'] ?? 0)] ?? 0, 'sourceQuestionLabel' => (string) ($condition['sourceQuestionLabel'] ?? ''), 'targetQuestionLabel' => (string) ($condition['targetQuestionLabel'] ?? ''), 'sourceSorting' => $questionSortings[$sourceQuestionId] ?? 0, diff --git a/src/EventListener/SurveyDcaListener.php b/src/EventListener/SurveyDcaListener.php index 52766e4..dca3311 100644 --- a/src/EventListener/SurveyDcaListener.php +++ b/src/EventListener/SurveyDcaListener.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Mummert\SurveyBundle\EventListener; use Contao\Config; +use Contao\CoreBundle\DataContainer\DataContainerOperation; use Contao\CoreBundle\Routing\ContentUrlGenerator; use Contao\CoreBundle\Framework\ContaoFramework; use Contao\DataContainer; @@ -37,18 +38,19 @@ final class SurveyDcaListener return $this->surveyRepository->ensurePublicAlias((string) $value, (int) ($dataContainer->id ?? 0)); } - public function generateCopyPublicLinkButton(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string + public function generateCopyPublicLinkButton(DataContainerOperation $operation): void { + $row = $operation->getRecord() ?? []; $publicUrl = $this->buildSurveyPageUrl((string) ($row['alias'] ?? ''), 'surveyReaderPage'); - $label = 'Link kopieren'; - $title = 'Den öffentlichen Link in die Zwischenablage kopieren'; if (null === $publicUrl) { - return sprintf( + $operation->setHtml(sprintf( '%s', htmlspecialchars('In den Contao-Einstellungen ist noch keine Reader-Seite hinterlegt oder der Link-Schlüssel ist ungültig.', ENT_QUOTES), - Image::getHtml($icon ?? 'copy.svg', $label) - ); + Image::getHtml('copy.svg', 'Link kopieren') + )); + + return; } $copyScript = sprintf( @@ -58,50 +60,58 @@ final class SurveyDcaListener json_encode('Bestätigung', JSON_THROW_ON_ERROR), ); - return sprintf( - '%s', - htmlspecialchars($title, ENT_QUOTES), - htmlspecialchars($copyScript, ENT_QUOTES), - $attributes, - Image::getHtml($icon ?? 'copy.svg', $label).' '.$label - ); + $operation->setUrl('#'); + $operation['label'] = 'Link kopieren'; + $operation['title'] = 'Den öffentlichen Link in die Zwischenablage kopieren'; + $operation['icon'] = 'copy.svg'; + $operation['attributes'] + ->set('onclick', $copyScript) + ->set('data-contao--tooltips-target', 'tooltip') + ; } - public function generateShowResultsButton(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string + public function generateShowResultsButton(DataContainerOperation $operation): void { + $row = $operation->getRecord() ?? []; $resultsUrl = $this->buildSurveyPageUrl((string) ($row['alias'] ?? ''), 'surveyResultsPage'); - $label = 'Ergebnisse anzeigen'; - $title = 'Die Ergebnisse dieser Umfrage im Frontend anzeigen'; if (null === $resultsUrl) { - return sprintf( + $operation->setHtml(sprintf( '%s', htmlspecialchars('In den Contao-Einstellungen ist noch keine Ergebnisseite hinterlegt oder der Link-Schlüssel ist ungültig.', ENT_QUOTES), - Image::getHtml($icon ?? 'show.svg', $label) - ); + Image::getHtml('show.svg', 'Ergebnisse anzeigen') + )); + + return; } - return sprintf( - '%s', - htmlspecialchars($resultsUrl, ENT_QUOTES), - htmlspecialchars($title, ENT_QUOTES), - $attributes, - Image::getHtml($icon ?? 'show.svg', $label).' '.$label - ); + $operation->setUrl($resultsUrl); + $operation['label'] = 'Ergebnisse anzeigen'; + $operation['title'] = 'Die Ergebnisse dieser Umfrage im Frontend anzeigen'; + $operation['icon'] = 'show.svg'; + $operation['attributes'] + ->set('target', '_blank') + ->set('rel', 'noreferrer') + ->set('data-contao--tooltips-target', 'tooltip') + ; } - public function generatePublishedWarningButton(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string + public function generatePublishedWarningButton(DataContainerOperation $operation): void { + $row = $operation->getRecord() ?? []; + if ('1' !== (string) ($row['published'] ?? '')) { - return ''; + $operation->setHtml(''); + + return; } - return sprintf( + $operation->setHtml(sprintf( '%s', htmlspecialchars('Umfrage bereits veröffentlicht, keine Änderungen an den Fragen vornehmen!', ENT_QUOTES), - $attributes, - Image::getHtml($icon ?? 'important.svg', $label) - ); + $operation['attributes'], + Image::getHtml('important.svg', 'Veröffentlichungshinweis') + )); } /** diff --git a/src/Repository/SurveyRepository.php b/src/Repository/SurveyRepository.php index 4887b7f..bc7b93a 100644 --- a/src/Repository/SurveyRepository.php +++ b/src/Repository/SurveyRepository.php @@ -76,7 +76,7 @@ final class SurveyRepository LEFT JOIN tl_survey_content q ON q.pid = s.id LEFT JOIN tl_survey_submission sub ON sub.survey = s.id GROUP BY s.id - ORDER BY s.updatedAt DESC, s.title ASC + ORDER BY s.title ASC, s.id ASC SQL, ['member' => $memberId], );