';
// Process days
if ($this->getOption('weatherType') == 'forecast') {
$numDays = $this->getOption('numDays');
$daysOffset = $this->getOption('dayOffset');
$daysCols = intval($this->getOption('daysCols'));
$daysRows = intval($this->getOption('daysRows'));
$stopPosition = (($numDays+$daysOffset) > 7) ? 7 : $numDays+$daysOffset;
for ($i=$daysOffset; $i < $stopPosition; $i++) {
$this->getLog()->debug('Substitution for Daily, day ' . $i);
$template .= '
';
$template .= $this->makeSubstitutions($daily[$i], $body, $foreCast->getTimezone(), $lang);
$template .= '
';
}
} else {
$template .= $this->makeSubstitutions($currently, $body, $foreCast->getTimezone(), $lang);
}
// Close main div in template and add the footer
$template .= '
';
// Run replace over the main template ( if type is forecast, it will replace at least the background image)
$data['body'] = $this->makeSubstitutions($currently, $template, $foreCast->getTimezone(), $lang);
// JavaScript to control the size (override the original width and height so that the widget gets blown up )
$options = array(
'originalWidth' => $this->region->width,
'originalHeight' => $this->region->height,
'widgetDesignWidth' => $widgetOriginalWidth,
'widgetDesignHeight'=> $widgetOriginalHeight
);
if($this->getOption('weatherType') == 'forecast') {
$options['numCols'] = $daysCols;
$options['numRows'] = $daysRows;
}
$javaScriptContent = '';
$javaScriptContent .= '';
$javaScriptContent .= '';
$javaScriptContent .= '';
$javaScriptContent .= '';
$javaScriptContent .= '';
$javaScriptContent .= '';
$javaScriptContent .= $javaScript;
// Replace the After body Content
$data['javaScript'] = $javaScriptContent;
// Return that content.
return $this->renderTemplate($data);
}
/** @inheritdoc */
public function isValid()
{
if ($this->getOption('overrideTemplate') == 0 && ( $this->getOption('templateId') == '' || $this->getOption('templateId') == null))
throw new InvalidArgumentException(__('Please choose a template'), 'templateId');
if ($this->getOption('weatherType') == 'forecast') {
if ($this->getOption('numDays') == '' || $this->getOption('numDays') <= 0) {
throw new InvalidArgumentException(__('Please enter a positive number of days.'), 'numDays');
}
if ($this->getOption('daysRows') == '' || $this->getOption('daysRows') <= 0) {
throw new InvalidArgumentException(__('Please enter a positive number of rows.'), 'daysRows');
}
if ($this->getOption('daysCols') == '' || $this->getOption('daysCols') <= 0) {
throw new InvalidArgumentException(__('Please enter a positive number of columns.'), 'daysCols');
}
}
if ($this->getUseDuration() == 1 && $this->getDuration() == 0)
throw new InvalidArgumentException(__('Please enter a duration'), 'duration');
if ($this->getOption('useDisplayLocation') == 0) {
// Validate lat/long
if (!v::latitude()->validate($this->getOption('latitude')))
throw new InvalidArgumentException(__('The latitude entered is not valid.'), 'latitude');
if (!v::longitude()->validate($this->getOption('longitude')))
throw new InvalidArgumentException(__('The longitude entered is not valid.'), 'longitude');
}
return self::$STATUS_VALID;
}
/** @inheritdoc */
public function getCacheDuration()
{
$cachePeriod = $this->getSetting('cachePeriod', 3600);
$updateInterval = $this->getOption('updateInterval', 60) * 60;
return max($cachePeriod, $updateInterval);
}
/** @inheritdoc */
public function getCacheKey($displayId)
{
return $this->getWidgetId() . (($displayId === 0 || $this->getOption('useDisplayLocation') == 1) ? '_' . $displayId : '');
}
/** @inheritdoc */
public function isCacheDisplaySpecific()
{
return ($this->getOption('useDisplayLocation') == 1);
}
/**
* @return false|string
*/
public function getWeatherLanguage()
{
$supportedLanguages[] = $this->supportedLanguages();
foreach ($supportedLanguages as $language) {
foreach ($language as $lang) {
if ($lang['id'] === strtolower(translate::getJsLocale())) {
return strtolower(translate::getJsLocale());
}
else {
continue;
}
}
}
if (strlen(translate::getJsLocale()) > 2 && Str::contains(translate::getJsLocale(), '-')) {
return substr(translate::getJsLocale(), 0, 2);
} else {
return 'en';
}
}
/**
* @return array
*/
public function getBackgroundList()
{
return self::WEATHER_BACKGROUNDS;
}
/**
* @return \Xibo\Entity\Media[]
* @throws \Xibo\Support\Exception\NotFoundException
*/
public function getBackgroundOptions()
{
$initBackgrounds = [];
foreach (self::WEATHER_BACKGROUNDS as $background) {
if($this->getOption($background) != $background) {
$initBackgrounds[] = $this->getOption($background);
}
}
return $this->mediaFactory->query(null, array('disableUserCheck' => 1, 'id' => $initBackgrounds, 'allModules' => 1, 'type' => 'image'));
}
/**
* @return mixed
*/
public function getWeatherSnippets()
{
$snippets['current'] = self::WEATHER_SNIPPETS_CURRENT;
$snippets['forecast'] = self::WEATHER_SNIPPETS_FORECAST;
return $snippets;
}
/** @inheritDoc */
public function hasTemplates()
{
return true;
}
/** @inheritDoc */
public function hasHtmlEditor()
{
return true;
}
/** @inheritDoc */
public function getHtmlWidgetOptions()
{
return ['template'];
}
}