diff --git a/src/Resources/views/Admin/Grid/Action/setono_facebook_reset_failed_events.html.twig b/src/Resources/views/Admin/Grid/Action/setono_facebook_reset_failed_events.html.twig index 3a6ad88..b69478e 100644 --- a/src/Resources/views/Admin/Grid/Action/setono_facebook_reset_failed_events.html.twig +++ b/src/Resources/views/Admin/Grid/Action/setono_facebook_reset_failed_events.html.twig @@ -1,3 +1,5 @@ +{# @var \Setono\SyliusFacebookPlugin\Model\PixelInterface data #} + {% import '@SetonoSyliusFacebookPlugin/Admin/Macro/buttons.html.twig' as buttons %} {% set path = options.link.url|default(path( @@ -5,9 +7,12 @@ options.link.parameters|default({'id': data.id}) )) %} -{{ buttons.resetFailedEvents( - path, - action.label|default('setono_sylius_facebook.ui.reset_failed_events'), - true, - data.id -) }} +{% set failedCount = setono_facebook_events_count_by_state(data, constant('Setono\\SyliusFacebookPlugin\\Model\\PixelEventInterface::STATE_FAILED')) %} +{% if options.visible|default(failedCount > 0) %} + {{ buttons.resetFailedEvents( + path, + action.label|default('setono_sylius_facebook.ui.reset_failed_events'), + true, + data.id + ) }} +{% endif %} diff --git a/src/Twig/EventsPushingStatisticsExtension.php b/src/Twig/EventsPushingStatisticsExtension.php index dfdee42..bdf773b 100644 --- a/src/Twig/EventsPushingStatisticsExtension.php +++ b/src/Twig/EventsPushingStatisticsExtension.php @@ -23,6 +23,7 @@ public function getFunctions(): array { return [ new TwigFunction('setono_facebook_events_pushing_statistics', [$this, 'getEventsPushingStatistics']), + new TwigFunction('setono_facebook_events_count_by_state', [$this, 'getEventsCountByState']), ]; } @@ -43,4 +44,9 @@ public function getEventsPushingStatistics(PixelInterface $pixel): array return $result; } + + public function getEventsCountByState(PixelInterface $pixel, string $state): int + { + return $this->pixelEventRepository->getCountByPixelAndState($pixel, $state); + } }