Skip to content

Commit

Permalink
Widget: Stocks and Currencies use maxItemsPerPage instead of itemsPer…
Browse files Browse the repository at this point in the history
…Page. Also improve error responses from AlphaVantageConnector. (#2462)

fixes xibosignage/xibo#3368
  • Loading branch information
dasgarner committed Apr 4, 2024
1 parent 8026510 commit a467a2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/Connector/AlphaVantageConnector.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -117,7 +117,11 @@ public function onDataRequest(WidgetDataRequestEvent $event)
$event->getDataProvider()->setCacheTtl($this->getSetting('cachePeriod', 3600));
} catch (\Exception $exception) {
$this->getLogger()->error('onDataRequest: Failed to get results. e = ' . $exception->getMessage());
$dataProvider->addError(__('Unable to contact the AlphaVantage API'));
if ($exception instanceof InvalidArgumentException) {
$dataProvider->addError($exception->getMessage());
} else {
$dataProvider->addError(__('Unable to contact the AlphaVantage API'));
}
}
}
}
Expand Down Expand Up @@ -231,7 +235,7 @@ private function getStockResults(DataProviderInterface $dataProvider): void

if ($items == '') {
$this->getLogger()->error('Missing Items for Stocks Module with WidgetId ' . $dataProvider->getWidgetId());
throw new InvalidArgumentException(__('Missing Items for Stocks Module'), 'items');
throw new InvalidArgumentException(__('Add some stock symbols'), 'items');
}

// Parse items out into an array
Expand Down
2 changes: 1 addition & 1 deletion lib/Widget/CurrenciesAndStocksProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function fetchDuration(DurationProviderInterface $durationProvider): Widg

if ($numItems > 1) {
// If we have paging involved then work out the page count.
$itemsPerPage = $durationProvider->getWidget()->getOptionValue('itemsPerPage', 0);
$itemsPerPage = $durationProvider->getWidget()->getOptionValue('maxItemsPerPage', 0);
if ($itemsPerPage > 0) {
$numItems = ceil($numItems / $itemsPerPage);
}
Expand Down

0 comments on commit a467a2a

Please sign in to comment.