Use latest Repository feature to replace static model calls.

This commit is contained in:
David Molineus
2017-10-18 15:30:24 +02:00
parent edb4ac9eeb
commit dd23d386eb
7 changed files with 93 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer;
use Netzmacht\Contao\Leaflet\Model\MarkerModel;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/**
@@ -24,6 +25,23 @@ use Symfony\Component\Translation\TranslatorInterface as Translator;
*/
final class MarkersLabelRenderer extends AbstractLabelRenderer
{
/**
* Repository manager.
*
* @var RepositoryManager
*/
private $repositoryManager;
/**
* FileLabelRenderer constructor.
*
* @param RepositoryManager $repositoryManager Repository manager.
*/
public function __construct(RepositoryManager $repositoryManager)
{
$this->repositoryManager = $repositoryManager;
}
/**
* {@inheritdoc}
*/
@@ -37,8 +55,9 @@ final class MarkersLabelRenderer extends AbstractLabelRenderer
*/
public function render(array $row, string $label, Translator $translator): string
{
$count = MarkerModel::countBy('pid', $row['id']);
$label .= sprintf(
$repository = $this->repositoryManager->getRepository(MarkerModel::class);
$count = $repository->countBy(['pid'], [$row['pid']]);
$label .= sprintf(
'<span class="tl_gray"> (%s %s)</span>',
$count,
$translator->trans('countEntries', [], 'contao_tl_leaflet_layer')