diff --git a/Classes/Domain/Model/CurrentWeather.php b/Classes/Domain/Model/CurrentWeather.php
index e89e767..c260f2a 100644
--- a/Classes/Domain/Model/CurrentWeather.php
+++ b/Classes/Domain/Model/CurrentWeather.php
@@ -23,6 +23,11 @@ class CurrentWeather extends AbstractEntity
*/
protected $name = '';
+ /**
+ * @var string
+ */
+ protected $description = '';
+
/**
* @var \DateTime
*/
@@ -98,6 +103,16 @@ public function setName(string $name): void
$this->name = $name;
}
+ public function getDescription(): string
+ {
+ return $this->description;
+ }
+
+ public function setDescription(string $description): void
+ {
+ $this->description = $description;
+ }
+
public function getMeasureTimestamp(): ?\DateTime
{
return $this->measureTimestamp;
diff --git a/Classes/Task/OpenWeatherMapTask.php b/Classes/Task/OpenWeatherMapTask.php
index a80dd0d..60c710d 100644
--- a/Classes/Task/OpenWeatherMapTask.php
+++ b/Classes/Task/OpenWeatherMapTask.php
@@ -18,6 +18,7 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MailUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
+use TYPO3\CMS\Core\Site\SiteFinder;
/**
* OpenWeatherMapTask Class for Scheduler
@@ -55,6 +56,11 @@ class OpenWeatherMapTask extends WeatherAbstractTask
*/
public $apiKey = '';
+ /**
+ * @var string $apiKey
+ */
+ public $languages = '';
+
/**
* Comma seperated list of page UIDs to clear cache
*
@@ -126,12 +132,49 @@ public function execute(): bool
$this->removeOldRecordsFromDb();
- $this->url = sprintf(
- 'https://api.openweathermap.org/data/2.5/weather?q=%s,%s&units=%s&APPID=%s',
+ //Check if languages were set in scheduler task
+ //if there are languages set, we need to find the twoLetterIsoCode for each language to receive the request in the desired language
+ //No Language was default until now, so we set the parameter -1 in sys_language_uid so we cann access this data in all languages and prevent breaking changes
+ if($this->languages != ''){
+ $siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
+ $site = $siteFinder->getSiteByPageId($this->recordStoragePage);
+ $languages = explode(",",$this->languages);
+ foreach ($languages as $langId) {
+ $langId = (int)$langId;
+ $langCode = $site->getLanguageById($langId)->getTwoLetterIsoCode();
+ $this->getWeatherData($langCode);
+ $this->saveCurrentWeatherInstanceForResponseClass($this->responseClass, $langId);
+ }
+ }else{
+ $this->getWeatherData();
+ $this->saveCurrentWeatherInstanceForResponseClass($this->responseClass);
+ }
+
+ if (!empty($this->clearCache)) {
+ $cacheService = $this->getCacheService();
+ $cacheService->clearPageCache(GeneralUtility::intExplode(',', $this->clearCache));
+ }
+
+ return true;
+ }
+
+ /**
+ * Fetches data from openweathermap api
+ *
+ * @param string $langCode
+ * @return void
+ */
+ private function getWeatherData(string $langCode = 'en'){
+ $parameters = [
urlencode($this->city),
urlencode($this->country),
'metric',
- $this->apiKey
+ $this->apiKey,
+ $langCode
+ ];
+ $this->url = sprintf(
+ 'https://api.openweathermap.org/data/2.5/weather?q=%s,%s&units=%s&APPID=%s&lang=%s',
+ ...$parameters
);
try {
$response = $this->getRequestFactory()->request($this->url);
@@ -150,16 +193,6 @@ public function execute(): bool
$this->responseClass = json_decode((string)$response->getBody());
$this->logger->info(sprintf('Response class: %s', json_encode($this->responseClass)));
-
- // Changing the data save to query builder
- $this->saveCurrentWeatherInstanceForResponseClass($this->responseClass);
-
- if (!empty($this->clearCache)) {
- $cacheService = $this->getCacheService();
- $cacheService->clearPageCache(GeneralUtility::intExplode(',', $this->clearCache));
- }
-
- return true;
}
/**
@@ -215,13 +248,20 @@ private function checkResponseCode(ResponseInterface $response): bool
}
}
- public function saveCurrentWeatherInstanceForResponseClass(\stdClass $responseClass): int
+ /**
+ * Saves the current weather instance to the database
+ *
+ * @param \stdClass $responseClass
+ * @param int $langId
+ * @return int
+ */
+ public function saveCurrentWeatherInstanceForResponseClass(\stdClass $responseClass, int $langId = -1): int
{
$weatherObjectArray = [
'pid' => $this->recordStoragePage,
'name' => $this->name,
+ 'sys_language_uid' => $langId,
];
-
if (isset($responseClass->main->temp)) {
$weatherObjectArray['temperature_c'] = (double) $responseClass->main->temp;
}
@@ -260,6 +300,9 @@ public function saveCurrentWeatherInstanceForResponseClass(\stdClass $responseCl
if (isset($responseClass->weather[0]->icon)) {
$weatherObjectArray['icon'] = $responseClass->weather[0]->icon;
}
+ if (isset($responseClass->weather[0]->description)) {
+ $weatherObjectArray['description'] = $responseClass->weather[0]->description;
+ }
if (isset($responseClass->weather[0]->id)) {
$weatherObjectArray['condition_code'] = $responseClass->weather[0]->id;
}
diff --git a/Classes/Task/OpenWeatherMapTaskAdditionalFieldProvider.php b/Classes/Task/OpenWeatherMapTaskAdditionalFieldProvider.php
index 4886444..a26b800 100644
--- a/Classes/Task/OpenWeatherMapTaskAdditionalFieldProvider.php
+++ b/Classes/Task/OpenWeatherMapTaskAdditionalFieldProvider.php
@@ -69,6 +69,7 @@ class OpenWeatherMapTaskAdditionalFieldProvider extends AbstractAdditionalFieldP
'city',
'country',
'apiKey',
+ 'languages',
'clearCache',
'errorNotification',
'emailSenderName',
@@ -165,6 +166,13 @@ public function getAdditionalFields(
'label' => 'LLL:EXT:weather2/Resources/Private/Language/locallang_scheduler_openweatherapi.xlf:api_key',
];
+ $fieldID = 'languages';
+ $fieldCode = '';
+ $additionalFields[$fieldID] = [
+ 'code' => $fieldCode,
+ 'label' => 'LLL:EXT:weather2/Resources/Private/Language/locallang_scheduler_openweatherapi.xlf:languages',
+ ];
+
$fieldID = 'clearCache';
$fieldCode = '';
$additionalFields[$fieldID] = [
@@ -313,6 +321,7 @@ public function saveAdditionalFields(array $submittedData, AbstractTask $task):
$task->recordStoragePage = (int)($submittedData['recordStoragePage'] ?? 0);
$task->country = $submittedData['country'] ?? '';
$task->apiKey = $submittedData['apiKey'] ?? '';
+ $task->languages = $submittedData['languages'] ?? '';
$task->clearCache = $submittedData['clearCache'] ?? '0';
$task->errorNotification = $submittedData['errorNotification'] ?? '';
$task->emailSenderName = $submittedData['emailSenderName'] ?? '';
diff --git a/Configuration/TCA/tx_weather2_domain_model_currentweather.php b/Configuration/TCA/tx_weather2_domain_model_currentweather.php
index 8c1b078..866ab9b 100644
--- a/Configuration/TCA/tx_weather2_domain_model_currentweather.php
+++ b/Configuration/TCA/tx_weather2_domain_model_currentweather.php
@@ -11,6 +11,10 @@
'crdate' => 'crdate',
'rootLevel' => -1,
'delete' => 'deleted',
+ 'languageField' => 'sys_language_uid',
+ 'transOrigPointerField' => 'l10n_parent',
+ 'transOrigDiffSourceField' => 'l10n_diffsource',
+ 'translationSource' => 'l10n_source',
'enablecolumns' => [
'disabled' => 'hidden',
'starttime' => 'starttime',
@@ -23,9 +27,39 @@
],
],
'types' => [
- '1' => ['showitem' => 'name, measure_timestamp, temperature_c, pressure_hpa, humidity_percentage, min_temp_c, max_temp_c, wind_speed_m_p_s, wind_direction_deg, pop_percentage, rain_volume, snow_volume, clouds_percentage, icon, serialized_array, --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.access, starttime, endtime'],
+ '1' => ['showitem' => 'name, description, measure_timestamp, temperature_c, pressure_hpa, humidity_percentage, min_temp_c, max_temp_c, wind_speed_m_p_s, wind_direction_deg, pop_percentage, rain_volume, snow_volume, clouds_percentage, icon, serialized_array, --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.access, starttime, endtime'],
],
'columns' => [
+ 'sys_language_uid' => [
+ 'exclude' => true,
+ 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
+ 'config' => [
+ 'type' => 'language',
+ ],
+ ],
+ 'l10n_parent' => [
+ 'displayCond' => 'FIELD:sys_language_uid:>:0',
+ 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.l18n_parent',
+ 'config' => [
+ 'type' => 'group',
+ 'allowed' => 'tx_weather2_domain_model_currentweather',
+ 'size' => 1,
+ 'maxitems' => 1,
+ 'minitems' => 0,
+ 'default' => 0,
+ ],
+ ],
+ 'l10n_source' => [
+ 'config' => [
+ 'type' => 'passthrough',
+ ],
+ ],
+ 'l10n_diffsource' => [
+ 'config' => [
+ 'type' => 'passthrough',
+ 'default' => '',
+ ],
+ ],
'starttime' => [
'exclude' => 1,
'label' => 'EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.starttime',
@@ -65,6 +99,15 @@
'eval' => 'trim',
],
],
+ 'description' => [
+ 'exclude' => 1,
+ 'label' => 'LLL:EXT:weather2/Resources/Private/Language/locallang_db.xlf:tx_weather2_domain_model_currentweather.description',
+ 'config' => [
+ 'type' => 'input',
+ 'size' => 30,
+ 'eval' => 'trim',
+ ],
+ ],
'measure_timestamp' => [
'exclude' => 1,
'label' => 'LLL:EXT:weather2/Resources/Private/Language/locallang_db.xlf:tx_weather2_domain_model_currentweather.measure_timestamp',
diff --git a/Resources/Private/Language/de.locallang_scheduler_openweatherapi.xlf b/Resources/Private/Language/de.locallang_scheduler_openweatherapi.xlf
index fb2edbc..149ff47 100644
--- a/Resources/Private/Language/de.locallang_scheduler_openweatherapi.xlf
+++ b/Resources/Private/Language/de.locallang_scheduler_openweatherapi.xlf
@@ -20,6 +20,10 @@
API-Key
API-Key
+
+ Language IDs (comma separated list with IDs)
+ Sprach IDs (kommaseparierte Liste mit IDs)
+
Clear cache for pages (comma separated list with IDs)
Leere Cache für Seiten (kommaseparierte Liste mit IDs)
diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf
index 77f49b5..8d6d1e1 100644
--- a/Resources/Private/Language/locallang_db.xlf
+++ b/Resources/Private/Language/locallang_db.xlf
@@ -10,6 +10,9 @@
Name
+
+ Description
+
Measure Timestamp
diff --git a/Resources/Private/Language/locallang_scheduler_openweatherapi.xlf b/Resources/Private/Language/locallang_scheduler_openweatherapi.xlf
index f11df1a..cfa0cc6 100644
--- a/Resources/Private/Language/locallang_scheduler_openweatherapi.xlf
+++ b/Resources/Private/Language/locallang_scheduler_openweatherapi.xlf
@@ -16,6 +16,9 @@
API-Key
+
+ Language IDs (comma separated list with IDs)
+
Clear cache for pages (comma separated list with IDs)
diff --git a/ext_tables.sql b/ext_tables.sql
index b12ae5a..382c5ec 100644
--- a/ext_tables.sql
+++ b/ext_tables.sql
@@ -3,6 +3,7 @@
#
CREATE TABLE tx_weather2_domain_model_currentweather (
name varchar(255) DEFAULT '' NOT NULL,
+ description varchar(255) DEFAULT '' NOT NULL,
measure_timestamp int(11) DEFAULT '0' NOT NULL,
temperature_c double(4,2) DEFAULT '0.0' NOT NULL,
pressure_hpa double(4,2) DEFAULT '0' NOT NULL,