From 289084e8d2d513a6daaa81d1dd318838af95d9ed Mon Sep 17 00:00:00 2001 From: Dan Garner Date: Mon, 14 Aug 2023 13:43:52 +0100 Subject: [PATCH] SSP Widget (#1983) * SSP: adjustments to allow for scheduling via a widget and add SSP widget. xibosignageltd/xibo-private#408 --- lib/Connector/XiboSspConnector.php | 40 +++++++++++++++++++- modules/ssp.xml | 41 +++++++++++++++++++++ views/xibo-ssp-connector-form-settings.twig | 8 +++- 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 modules/ssp.xml diff --git a/lib/Connector/XiboSspConnector.php b/lib/Connector/XiboSspConnector.php index ee91495554..45b109e03c 100644 --- a/lib/Connector/XiboSspConnector.php +++ b/lib/Connector/XiboSspConnector.php @@ -2,7 +2,7 @@ /* * Copyright (C) 2023 Xibo Signage Ltd * - * Xibo - Digital Signage - http://www.xibo.org.uk + * Xibo - Digital Signage - https://xibosignage.com * * This file is part of Xibo. * @@ -29,8 +29,10 @@ use Xibo\Event\ConnectorDeletingEvent; use Xibo\Event\ConnectorEnabledChangeEvent; use Xibo\Event\MaintenanceRegularEvent; +use Xibo\Event\WidgetEditOptionRequestEvent; use Xibo\Support\Exception\GeneralException; use Xibo\Support\Exception\InvalidArgumentException; +use Xibo\Support\Exception\NotFoundException; use Xibo\Support\Sanitizer\SanitizerInterface; class XiboSspConnector implements ConnectorInterface @@ -61,6 +63,7 @@ public function registerWithDispatcher(EventDispatcherInterface $dispatcher): Co $dispatcher->addListener(MaintenanceRegularEvent::$NAME, [$this, 'onRegularMaintenance']); $dispatcher->addListener(ConnectorDeletingEvent::$NAME, [$this, 'onDeleting']); $dispatcher->addListener(ConnectorEnabledChangeEvent::$NAME, [$this, 'onEnabledChange']); + $dispatcher->addListener(WidgetEditOptionRequestEvent::$NAME, [$this, 'onWidgetEditOption']); return $this; } @@ -133,6 +136,7 @@ public function processSettingsForm(SanitizerInterface $params, array $settings) 'name' => $partnerId, 'enabled' => $params->getCheckbox($partnerId . '_enabled'), 'isTest' => $params->getCheckbox($partnerId . '_isTest'), + 'isUseWidget' => $params->getCheckbox($partnerId . '_isUseWidget'), 'currency' => $params->getString($partnerId . '_currency'), 'key' => $params->getString($partnerId . '_key'), 'sov' => $params->getInt($partnerId . '_sov'), @@ -333,7 +337,7 @@ private function setDisplays(string $apiKey, string $cmsUrl, array $partners, ar 'authorised' => 1, ]) as $display) { if (!array_key_exists($display->displayId, $displays)) { - $resolution = explode('x', $display->resolution); + $resolution = explode('x', $display->resolution ?? ''); $displays[$display->displayId] = [ 'displayId' => $display->displayId, 'hardwareKey' => $display->license, @@ -499,5 +503,37 @@ public function onEnabledChange(ConnectorEnabledChangeEvent $event) $event->getConfigService()->changeSetting('isAdspaceEnabled', $event->getConnector()->isEnabled); } + public function onWidgetEditOption(WidgetEditOptionRequestEvent $event) + { + $this->getLogger()->debug('onWidgetEditOption'); + + // Pull the widget we're working with. + $widget = $event->getWidget(); + if ($widget === null) { + throw new NotFoundException(); + } + + // We handle the dashboard widget and the property with id="type" + if ($widget->type === 'ssp' && $event->getPropertyId() === 'partnerId') { + // Pull in existing information + $partnerFilter = $event->getPropertyValue(); + $options = $event->getOptions(); + + foreach ($this->getAvailablePartners() as $partnerId => $partner) { + if ((empty($partnerFilter) || $partnerId === $partnerFilter) + && $this->getPartnerSetting($partnerId, 'enabled') == 1 + ) { + $options[] = [ + 'id' => $partnerId, + 'type' => $partnerId, + 'name' => $partner['name'], + ]; + } + } + + $event->setOptions($options); + } + } + // } diff --git a/modules/ssp.xml b/modules/ssp.xml new file mode 100644 index 0000000000..472101f780 --- /dev/null +++ b/modules/ssp.xml @@ -0,0 +1,41 @@ + + + core-ssp + SSP + Core + Manually schedule SSP content from the SSP connector via select partners. + ssp + + 1 + 1 + 1 + native + 10 + + + + Partner + Choose from the partners that support this type of scheduling. + + + + \ No newline at end of file diff --git a/views/xibo-ssp-connector-form-settings.twig b/views/xibo-ssp-connector-form-settings.twig index e0b20e2a8f..2e12302bb3 100644 --- a/views/xibo-ssp-connector-form-settings.twig +++ b/views/xibo-ssp-connector-form-settings.twig @@ -1,6 +1,6 @@ {# /** - * Copyright (C) 2022 Xibo Signage Ltd + * Copyright (C) 2023 Xibo Signage Ltd * * Xibo - Digital Signage - http://www.xibo.org.uk * @@ -112,6 +112,12 @@ {% set helpText %}{% trans "Should we connect to this partners test or production system?" %}{% endset %} {{ forms.checkbox(partnerKey ~ "_isTest", title, interface.getPartnerSetting(partnerKey, "isTest"), helpText) }} + {% if available.isWidgetSupported %} + {% set title %}{% trans "Use the SSP widget to schedule ad requests manually?" %}{% endset %} + {% set helpText %}{% trans "When using the SSP widget you do not need to congigure a share of voice, duration or min/max duration." %}{% endset %} + {{ forms.checkbox(partnerKey ~ "_isUseWidget", title, interface.getPartnerSetting(partnerKey, "isUseWidget"), helpText) }} + {% endif %} +