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
@@ -272,16 +272,6 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
}
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) {
$this->surveyEditorService->deleteQuestion($survey, $itemId);
$this->addFlash('success', 'Die Frage wurde gelöscht.');
@@ -90,6 +90,16 @@ final class MemberSurveyListController extends AbstractFrontendModuleController
$survey = $this->resolveEditableSurvey($surveyId, $memberId);
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) {
$this->surveyEditorService->deleteSurvey($survey);
$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'] ?? '')) {
return sprintf(
'<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)
);
if ('1' !== (string) ($row['published'] ?? '')) {
return '';
}
return sprintf(
'<a href="%s" title="%s" onclick="if(!confirm(\'%s\'))return false;Backend.getScrollOffset()"%s>%s</a>',
htmlspecialchars(Backend::addToUrl(($href ?? '').'&amp;id='.(int) ($row['id'] ?? 0)), ENT_QUOTES),
htmlspecialchars($title, ENT_QUOTES),
StringUtil::specialchars('Wirklich sicher? Nachdem die Umfrage veröffentlicht wurde sind keine Änderungen mehr möglich!'),
'<span title="%s"%s>%s</span>',
htmlspecialchars('Umfrage bereits veröffentlicht, keine Änderungen an den Fragen vornehmen!', ENT_QUOTES),
$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
{
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'] ?? '');
$icon = $isActive ? 'visible.svg' : 'invisible.svg';
$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>
*/
@@ -303,15 +250,11 @@ final class SurveyDcaListener
public function guardContentSave(mixed $value, DataContainer $dataContainer): mixed
{
$this->assertSurveyUnlocked($this->resolveSurveyId('tl_survey_content', $dataContainer));
return $value;
}
public function guardConditionSave(mixed $value, DataContainer $dataContainer): mixed
{
$this->assertSurveyUnlocked($this->resolveSurveyId('tl_survey_condition', $dataContainer));
return $value;
}
@@ -454,7 +397,6 @@ final class SurveyDcaListener
public function guardContentDelete(DataContainer $dataContainer): void
{
$this->assertSurveyUnlocked($this->resolveSurveyId('tl_survey_content', $dataContainer));
}
public function touchSurveyContentParent(DataContainer $dataContainer): void
@@ -468,7 +410,6 @@ final class SurveyDcaListener
public function guardConditionDelete(DataContainer $dataContainer): void
{
$this->assertSurveyUnlocked($this->resolveSurveyId('tl_survey_condition', $dataContainer));
}
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
{
$surveyId = (int) ($dataContainer->id ?? 0);
$this->assertSurveyUnlocked($surveyId);
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
{
if ($dataContainer?->activeRecord) {
@@ -584,10 +476,6 @@ final class SurveyDcaListener
return 0;
}
if ($table === (string) Input::get('table') && '' === (string) Input::get('act')) {
return $recordId;
}
if ('survey' === $table) {
$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
{
if ('1' !== (string) $survey->published) {
throw new \RuntimeException('Die Umfrage muss zuerst veröffentlicht werden.');
}
$isActive = '1' !== (string) ($survey->isActive ?? '');
$this->surveyRepository->setActive((int) $survey->id, $memberId, $isActive);