diff --git a/admin/cron.php b/admin/cron.php new file mode 100644 index 0000000..0d788fe --- /dev/null +++ b/admin/cron.php @@ -0,0 +1,119 @@ +getPrefix(); +$availableTables = $db->setQuery('SHOW TABLES')->loadColumn(); +$tablesNotFound = false; + +if(!array_search($prefix.'tvo_teams', $availableTables) ) { + $tablesNotFound = true; +} +if(!array_search($prefix.'tvo_games', $availableTables) ) { + $tablesNotFound = true; +} +if(!array_search($prefix.'tvo_tables', $availableTables) ) { + $tablesNotFound = true; +} + +// Load all relevant (= published) teams from database +if( !$tablesNotFound ) { + $db = JFactory::getDBO(); + $query = $db->getQuery(true); + $query->select('*'); + $query->from('#__tvo_teams'); + $query->where('published = 1'); + $db->setQuery((string) $query); + $alleTeams = $db->loadObjectList(); +} +else { + die('ERROR: TABLES NOT FOUND'); +} + + + +/* + * + * + * UPDATE #__tvo_games + * + * + */ + +echo '

Games Data

'; +foreach($alleTeams as $team) { + $updateNulls = true; + + // Retrieve current data from BHV server + $team->gamesData = ComTvoHelper::getCurrentGamesData($team->teamGamesId); + + // Define new object to be stored in the database + $object = new stdClass; + $object->teamGamesId = $team->teamGamesId; + $object->gamesData = $team->gamesData; + $object->lastUpdated = date('Y-m-d H:i:s', time()); + + // Check if team exists in tvo_games table + $db = JFactory::getDBO(); + $query = $db->getQuery(true); + $query->select($db->quoteName('teamGamesId')); + $query->from($db->quoteName('#__tvo_games')); + $query->where($db->quoteName('teamGamesId') . '=' . $db->quote($team->teamGamesId) ); + $db->setQuery((string) $query); + $db->query(); + + // Check if team already exists as record in the database. If yes => update, if no => insert + if( $db->getNumRows() > 0 ) { + $result = JFactory::getDbo()->updateObject('#__tvo_games', $object, 'teamGamesId', $updateNulls); + print_r($team->teamGamesId.': UPDATE
'); + } + else { + $result = JFactory::getDbo()->insertObject('#__tvo_games', $object); + print_r($team->teamGamesId.': INSERT
'); + } + +} + +/* + * + * + * UPDATE #__tvo_tables + * + * + */ +echo '

Tables Data

'; +foreach($alleTeams as $team) { + // Define new object to be stored in the database + $team->tablesData = ComTvoHelper::getCurrentTableData($team->teamTableId); + $object = new stdClass; + $object->teamTableId = $team->teamTableId; + $object->tablesData = $team->tablesData; + $object->lastUpdated = date('Y-m-d H:i:s', time()); + + // Check if team exists in tvo_games table + $db = JFactory::getDBO(); + $query = $db->getQuery(true); + $query->select($db->quoteName('teamTableId')); + $query->from($db->quoteName('#__tvo_tables')); + $query->where($db->quoteName('teamTableId') . '=' . $db->quote($team->teamTableId) ); + $db->setQuery((string) $query); + $db->query(); + + // Check if team already exists as record in the database. If yes => update, if no => insert + if( $db->getNumRows() > 0 ) { + $result = JFactory::getDbo()->updateObject('#__tvo_tables', $object, 'teamTableId', $updateNulls); + print_r($team->teamTableId.': UPDATE
'); + } + else { + $result = JFactory::getDbo()->insertObject('#__tvo_tables', $object); + print_r($team->teamTableId.': INSERT
'); + } + + +} diff --git a/admin/helper.php b/admin/helper.php index 4f0534b..760d944 100644 --- a/admin/helper.php +++ b/admin/helper.php @@ -2,134 +2,72 @@ class ComTvoHelper { + // Retrieve the current API URL + public static function getCurrentUrl() + { + return "https://api.h4a.mobi/spo/spo-proxy_public.php"; + } - public static function getPathToDataFile() - { - return __DIR__ . '/data.json'; - } - - public static function getSeasonDataFromFile($file) - { - return json_decode(file_get_contents($file)); - } - - - public static function getSeasonDataForTeam($id) - { - $teams = self::getSeasonDataFromFile(self::getPathToDataFile()); - foreach($teams as $team) - { - if($team->lvIDPathStr == $id) - { - return $team; - } - } - } - - - - - /** - * Retrieves the hello message - * - * @param array $params An object containing the module parameters - * - * @access public - */ - public static function getCurrentIDs($id) - { + // Retrieve all team data for the given ID + public static function getCurrentGamesData($id) { // create curl ressource - $ch = curl_init(); + $ch = curl_init(); - // set url - curl_setopt($ch, CURLOPT_URL, self::getCurrentUrl()."?cmd=data&lvTypeNext=club&lvIDNext=" . $id); + // set url + // club (!) id = 986 + curl_setopt($ch, CURLOPT_URL, self::getCurrentUrl()."?cmd=data&lvTypeNext=team&lvIDNext=" . $id); - //return the transfer as a string - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + //return the transfer as a string + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); - // $output contains the output string - $output = curl_exec($ch); + // $output contains the output string + $output = curl_exec($ch); - // close curl resource to free up system resources - curl_close($ch); + // close curl resource to free up system resources + curl_close($ch); // Return the result return $output; - } - - public static function getCurrentGames($id) - { - // TVO: 986 - // HSG: 1005 - - // create curl ressource - $ch = curl_init(); - - // set url - // club (!) id = 986 - curl_setopt($ch, CURLOPT_URL, self::getCurrentUrl()."?cmd=data&lvTypeNext=club&lvIDNext=" . $id); - - //return the transfer as a string - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - // $output contains the output string - $output = curl_exec($ch); - - // close curl resource to free up system resources - curl_close($ch); - // Return the result - return json_decode($output)[0]; - } - + } - public static function getLatestScorings($id) - { + // Retrieve all table data for the given ID + public static function getCurrentTableData($id) { // create curl ressource - $ch = curl_init(); - - // set url - // club (!) id = 986 - curl_setopt($ch, CURLOPT_URL, self::getCurrentUrl()."?cmd=data&lvTypeNext=team&lvIDNext=" . $id); + $ch = curl_init(); - //return the transfer as a string - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + // set url + curl_setopt($ch, CURLOPT_URL, self::getCurrentUrl()."?cmd=data&lvTypeNext=class&subType=table&lvIDNext=" . $id); + //return the transfer as a string + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); - // $output contains the output string - $output = curl_exec($ch); + // $output contains the output string + $output = curl_exec($ch); - // close curl resource to free up system resources - curl_close($ch); - // Return the result - return json_decode($output)[0]; - } - - public static function getCurrentUrl() - { - // create curl ressource - $ch = curl_init(); - - // set url - curl_setopt($ch, CURLOPT_URL, "http://www.handball4all.de/api/url/spo_vereine-01.php"); - - //return the transfer as a string - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - // $output contains the output string - $output = curl_exec($ch); - - // close curl resource to free up system resources - curl_close($ch); + // close curl resource to free up system resources + curl_close($ch); // Return the result return $output; - } + } + // User defined comparison and sort function public static function cmp($a, $b) { return strcmp($a->gDateTS, $b->gDateTS); } + + public static function varDump($var) + { + echo '
';
+	var_dump($var);
+	echo '
'; + return; + } + + public static function getTimestamp($game) { @@ -143,7 +81,7 @@ public static function getTimestamp($game) } - /* + /* * * Create current score * @@ -169,11 +107,5 @@ public static function score($homegoals, $guestgoals, $homegoals1, $guestgoals1) return $return; } - public static function varDump($var) - { - echo '
';
-		var_dump($var);
-		echo '
'; - return; - } + } diff --git a/admin/tvo.xml b/admin/tvo.xml deleted file mode 100644 index ca09579..0000000 --- a/admin/tvo.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - TVO - - September 2021 - Stefan Herzog - joomla@devel.stefan-herzog.com - https://github.com/alve89 - Copyright Info - License Info - - 0.0.11 - - BESCHREIBUNG DER KOMPONENTE FOLGT - - - - sql/install.mysql.utf8mb4.sql - - - - - sql/uninstall.mysql.utf8mb4.sql - - - - - - sql/updates/mysql - - - - - - - index.html - tvo.php - controller.php - views - models - - - - - TV Oberflockenbach - - - - - index.html - tvo.php - controller.php - - sql - - tables - - models - - views - - - - https://raw.githubusercontent.com/alve89/j_com_tvo/master/updates.xml - - diff --git a/tvo.xml b/tvo.xml index f4547eb..27e6e37 100644 --- a/tvo.xml +++ b/tvo.xml @@ -10,7 +10,7 @@ Copyright Info License Info - 0.0.12 + 0.0.13 BESCHREIBUNG DER KOMPONENTE FOLGT @@ -54,13 +54,19 @@ index.html tvo.php + controller.php + cron.php sql + + tables models + + views - https://raw.githubusercontent.com/alve89/j_com_tvo/master/updates.xml + https://raw.githubusercontent.com/alve89/j_com_tvo/master/updates.xml diff --git a/updates.xml b/updates.xml index 06ffd71..c7d6012 100644 --- a/updates.xml +++ b/updates.xml @@ -4,14 +4,14 @@ com_tvo component - 0.0.12 + 0.0.13 administrator - https://github.com/alve89/j_com_tvo/archive/v0.0.12.zip + https://github.com/alve89/j_com_tvo/archive/v0.0.13.zip