';
return [
'html' => $table,
'countRows' => $totalRows,
'countPages' => $totalPages
];
}
catch (NotFoundException $e) {
$this->getLog()->info(sprintf('Request failed for dataSet id=%d. Widget=%d. Due to %s', $dataSetId, $this->getWidgetId(), $e->getMessage()));
$this->getLog()->debug($e->getTraceAsString());
return $this->noDataMessageOrDefault();
}
}
/**
* @param string|null $default
* @return array
* @throws \Xibo\Support\Exception\NotFoundException
*/
private function noDataMessageOrDefault($default = null)
{
if ($default === null) {
$default = __('Empty Result Set with filter criteria.');
}
if ($this->getRawNode('noDataMessage') == '') {
throw new NotFoundException($default);
} else {
return [
'html' => $this->getRawNode('noDataMessage'),
'countPages' => 1,
'countRows' => 1
];
}
}
/**
* Does this module have a DataSet yet?
* @return bool
*/
private function hasDataSet()
{
return (v::notEmpty()->validate($this->getOption('dataSetId')));
}
/** @inheritdoc */
public function isValid()
{
if ($this->getUseDuration() == 1 && $this->getDuration() == 0)
throw new InvalidArgumentException(__('Please enter a duration'), 'duration');
if (!is_numeric($this->getOption('upperLimit')) || !is_numeric($this->getOption('lowerLimit')))
throw new InvalidArgumentException(__('Limits must be numbers'), 'limit');
if ($this->getOption('upperLimit') < 0 || $this->getOption('lowerLimit') < 0)
throw new InvalidArgumentException(__('Limits cannot be lower than 0'), 'limit');
// Check the bounds of the limits
if ($this->getOption('upperLimit') != 0 && $this->getOption('upperLimit') < $this->getOption('lowerLimit'))
throw new InvalidArgumentException(__('Upper limit must be higher than lower limit'), 'limit');
if ($this->getOption('updateInterval') !== null && !v::intType()->min(0)->validate($this->getOption('updateInterval', 0)))
throw new InvalidArgumentException(__('Update Interval must be greater than or equal to 0'), 'updateInterval');
// Make sure we haven't entered a silly value in the filter
if (strstr($this->getOption('filter'), 'DESC'))
throw new InvalidArgumentException(__('Cannot user ordering criteria in the Filter Clause'), 'filter');
return ($this->hasDataSet()) ? self::$STATUS_VALID : self::$STATUS_INVALID;
}
/** @inheritdoc */
public function getModifiedDate($displayId)
{
$widgetModifiedDt = $this->widget->modifiedDt;
$dataSetId = $this->getOption('dataSetId');
$dataSet = $this->dataSetFactory->getById($dataSetId);
// Set the timestamp
$widgetModifiedDt = ($dataSet->lastDataEdit > $widgetModifiedDt) ? $dataSet->lastDataEdit : $widgetModifiedDt;
// Remote dataSets are kept "active" by required files
$dataSet->setActive();
return Carbon::createFromTimestamp($widgetModifiedDt);
}
/** @inheritdoc */
public function getCacheDuration()
{
return $this->getOption('updateInterval', 120) * 60;
}
/** @inheritdoc */
public function getCacheKey($displayId)
{
// DataSetViews are display specific
return $this->getWidgetId() . '_' . $displayId;
}
/** @inheritdoc */
public function isCacheDisplaySpecific()
{
return true;
}
/** @inheritdoc */
public function getLockKey()
{
// Lock to the dataSetId, because our dataSet might have external images which are downloaded.
return $this->getOption('dataSetId');
}
/** @inheritDoc */
public function hasTemplates()
{
return true;
}
}