Skip to content

Commit

Permalink
SSP Widget (#1983)
Browse files Browse the repository at this point in the history
* SSP: adjustments to allow for scheduling via a widget and add SSP widget. xibosignageltd/xibo-private#408
  • Loading branch information
dasgarner authored Aug 14, 2023
1 parent a780222 commit 289084e
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
40 changes: 38 additions & 2 deletions lib/Connector/XiboSspConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

// </editor-fold>
}
41 changes: 41 additions & 0 deletions modules/ssp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
~ Copyright (C) 2023 Xibo Signage Ltd
~
~ Xibo - Digital Signage - https://xibosignage.com
~
~ This file is part of Xibo.
~
~ Xibo is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ any later version.
~
~ Xibo is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with Xibo. If not, see <http://www.gnu.org/licenses/>.
-->
<module>
<id>core-ssp</id>
<name>SSP</name>
<author>Core</author>
<description>Manually schedule SSP content from the SSP connector via select partners.</description>
<type>ssp</type>
<dataType></dataType>
<schemaVersion>1</schemaVersion>
<assignable>1</assignable>
<regionSpecific>1</regionSpecific>
<renderAs>native</renderAs>
<defaultDuration>10</defaultDuration>
<settings></settings>
<properties>
<property id="partnerId" type="connectorProperties">
<title>Partner</title>
<helpText>Choose from the partners that support this type of scheduling.</helpText>
</property>
</properties>
<preview></preview>
</module>
8 changes: 7 additions & 1 deletion views/xibo-ssp-connector-form-settings.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{#
/**
* Copyright (C) 2022 Xibo Signage Ltd
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
Expand Down Expand Up @@ -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 %}

<div class="form-group" style="display: flex;">
<label class="col-sm-2 control-label" for="{{ partnerKey ~ "_sov" }}">{% trans "Share of Voice" %}</label>
<div class="col-sm-5">
Expand Down

0 comments on commit 289084e

Please sign in to comment.