diff --git a/layout/backend/survey.scss b/layout/backend/survey.scss index 7bf5e1e..1c0a727 100644 --- a/layout/backend/survey.scss +++ b/layout/backend/survey.scss @@ -1,10 +1,18 @@ .tl_listing_container { counter-reset: question; + $color-muted: #999; + $default-margin: .3em; + .survey_question_title::before { counter-increment: question; content: counter(question) ") "; - color: #999; - margin-right: .3em; + color: $color-muted; + margin-right: $default-margin; + } + + .survey_answer_count { + color: $color-muted; + margin-left: $default-margin; } } diff --git a/src/EventListener/DataContainer/Survey.php b/src/EventListener/DataContainer/Survey.php new file mode 100644 index 0000000..9847969 --- /dev/null +++ b/src/EventListener/DataContainer/Survey.php @@ -0,0 +1,34 @@ +recordRepository = $recordRepository; + } + + /** + * @Callback(table="tl_survey", target="list.label.label") + */ + public function listSurveys(array $row, string $label): string + { + $submittedRecordsCount = $this->recordRepository->countBySurveyId((int) $row['id']); + + return sprintf('%s (%d)', $label, $submittedRecordsCount); + } +} diff --git a/src/Repository/RecordRepository.php b/src/Repository/RecordRepository.php index 1ca9625..1a71a33 100644 --- a/src/Repository/RecordRepository.php +++ b/src/Repository/RecordRepository.php @@ -25,4 +25,11 @@ public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Record::class); } + + public function countBySurveyId(int $surveyId): int + { + return $this->count([ + 'survey' => $surveyId, + ]); + } } diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index e8c070b..f236d92 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -123,6 +123,13 @@ services: tags: - { name: 'terminal42_service_annotation' } + mvo.survey.listener.datacontainer.survey: + class: Mvo\ContaoSurvey\EventListener\DataContainer\Survey + tags: + - { name: 'terminal42_service_annotation' } + arguments: + - '@mvo.survey.repository.record' + mvo.survey.listener.datacontainer.question: class: Mvo\ContaoSurvey\EventListener\DataContainer\SurveyQuestion tags: diff --git a/src/Resources/public/survey_backend.css b/src/Resources/public/survey_backend.css index 3b81c13..0f80d06 100644 --- a/src/Resources/public/survey_backend.css +++ b/src/Resources/public/survey_backend.css @@ -4,4 +4,7 @@ counter-increment: question; content: counter(question) ") "; color: #999; - margin-right: .3em; } + margin-right: 0.3em; } + .tl_listing_container .survey_answer_count { + color: #999; + margin-left: 0.3em; }