Skip to content

Commit

Permalink
improve BE listing - now includes record count
Browse files Browse the repository at this point in the history
  • Loading branch information
m-vo committed Aug 21, 2020
1 parent 100b989 commit 2753212
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
12 changes: 10 additions & 2 deletions layout/backend/survey.scss
Original file line number Diff line number Diff line change
@@ -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;
}
}
34 changes: 34 additions & 0 deletions src/EventListener/DataContainer/Survey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/*
* @author Moritz Vondano
* @license MIT
*/

namespace Mvo\ContaoSurvey\EventListener\DataContainer;

use Contao\CoreBundle\ServiceAnnotation\Callback;
use Mvo\ContaoSurvey\Repository\RecordRepository;
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;

class Survey implements ServiceAnnotationInterface
{
private RecordRepository $recordRepository;

public function __construct(RecordRepository $recordRepository)
{
$this->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 <span class="survey_answer_count">(%d)</span>', $label, $submittedRecordsCount);
}
}
7 changes: 7 additions & 0 deletions src/Repository/RecordRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}
7 changes: 7 additions & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion src/Resources/public/survey_backend.css
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

0 comments on commit 2753212

Please sign in to comment.