Don't show "unknown" sledrun state anymore.
[philipp/winterrodeln/mediawiki_extensions/wrreport.git] / wrreport_body.php
index 7492b258016248cee8d8bbf158c28ca88de271d9..824307c2aecb16509617b4c796c22def83d905d5 100644 (file)
@@ -7,7 +7,9 @@
 //     $wgWrReportBlackListAll = array(); // array of page names where reports disallowed for all users. Example: array('Birgitzer Alm (vom Adelshof)');
 //     $wgWrReportBlackListStrangers = array(); // array of page names where reports are disallowed for not logged in users
 //     $wgWrReportDeleteMode = 'loggedin'; // 'allow', 'loggedin', 'deny'
-//     $wgWrReportFeedRoot = 'http://www.winterrodeln.org/feed'; // root URL of the Winterrodeln feed without trailing slash
+//     $wgWrReportFeedRoot = 'https://www.winterrodeln.org/feed'; // root URL of the Winterrodeln feed without trailing slash
+//     $wgWrReportEnableIntermaps = true; // show Intermaps sledrun information column
+//     $wgWrReportIntermapsValidDays = 1; // number of days the last check of the Intermaps data may be in the past
 //
 //
 // The following tags are supported:
@@ -748,20 +750,33 @@ class WrReport {
        private static function createBahnentabelle($page_titles) {
                $dbr = wfGetDB(DB_REPLICA);
 
-               // SELECT p.page_id,p.page_title, c.length, c.walkup_time, c.top_elevation, c.bottom_elevation, c.walkup_separate, c.lift, c.night_light, c.public_transport, c.sled_rental, c.information_phone FROM `page` p, wrsledruncache c WHERE (p.page_title in ('Birgitzer_Alm_(vom_Adelshof)', 'Kemater_Alm', 'Axamer_Lizum') and p.page_id=c.page_id) ORDER BY page_title
-               $where_array = array('page.page_id = wrsledruncache.page_id');
+               // SELECT p.page_id, p.page_title, c.length, c.walkup_time, c.top_elevation, c.bottom_elevation, c.walkup_separate, c.lift, c.night_light, c.public_transport,
+               // c.sled_rental, c.information_phone, s.show_status, r.status, r.last_check, r.last_update
+               // FROM (`page` p JOIN  wrsledruncache c ON p.page_id=c.page_id) LEFT OUTER JOIN (wrintermapssledrun s JOIN wrintermapsreport r ON s.intermaps_sledrun_id=r.intermaps_sledrun_id) ON p.page_id=s.wr_page_id
+               // WHERE p.page_title in ('Birgitzer_Alm_(vom_Adelshof)', 'Mutterer_Alm_-_Sportrodelbahn', 'Axamer_Lizum') ORDER BY page_title;
+               $where_array = array();
                if (count($page_titles) > 0) {
                        $mysql_page_ids = array();
                        foreach ($page_titles as $page_title) $mysql_page_ids[] = $page_title->getArticleID();
-                       $where_array[] = 'page.page_id in (' . implode(', ', $mysql_page_ids) . ')';
+                       $where_array[] = 'p.page_id in (' . implode(', ', $mysql_page_ids) . ')';
                } else $where_array[] = 'false';
-               $res = $dbr->select(array('page', 'wrsledruncache'), array('page.page_id', 'page.page_title', 'page_namespace', 'length', 'walkup_time', 'top_elevation', 'bottom_elevation', 'walkup_possible', 'walkup_separate', 'lift', 'night_light', 'public_transport', 'sled_rental', 'information_phone', 'information_web'), $where_array, 'bahnentabelleParserHook', array('ORDER BY' => 'page.page_title'));
+               $res = $dbr->select(['AA' => ['p' => 'page', 'c' => 'wrsledruncache'], 'BB' => ['r' => 'wrintermapsreport', 's' => 'wrintermapssledrun']],
+                                                       ['p.page_id', 'p.page_title', 'p.page_namespace',
+                                                        'c.length', 'c.walkup_time', 'c.top_elevation', 'c.bottom_elevation', 'c.walkup_possible', 'c.walkup_separate',
+                                                        'c.lift', 'c.night_light', 'c.public_transport', 'c.sled_rental', 'c.information_phone', 'c.information_web',
+                                                        's.show_status', 'r.status', 'r.last_check', 'r.last_update'],
+                                                       $where_array,
+                                                       'bahnentabelleParserHook',
+                                                       ['ORDER BY' => 'p.page_title'],
+                                                       ['c' => ['JOIN', 'p.page_id=c.page_id'], 's' => ['JOIN', 's.intermaps_sledrun_id=r.intermaps_sledrun_id'], 'BB' => ['LEFT OUTER JOIN', 'p.page_id=s.wr_page_id']]
+                                               );
 
                global $wgUser;
                global $wgWrReportMode; // e.g. 'summer'
                global $wgWrReportBlackListAll;
                global $wgWrReportBlackListStrangers;
-               global $wgDBtype;
+               global $wgWrReportEnableIntermaps;
+               global $wgWrReportIntermapsValidDays;
 
                // Determine, whether the user is allowed to make a new report
                $userMayReport = ($wgWrReportMode == 'allow' || ($wgWrReportMode == 'loggedin' && $wgUser->isLoggedIn()));
@@ -777,6 +792,7 @@ class WrReport {
                $tr->appendElement('th')->appendElement('img', array('src' => '/vorlagen/s_lift.png', 'alt' => wfMessage('wrreport-icon-lift')->text(), 'title' => wfMessage('wrreport-icon-lift')->text()));
                $tr->appendElement('th')->appendElement('img', array('src' => '/vorlagen/s_walk.png', 'alt' => wfMessage('wrreport-icon-walkupseparate')->text(), 'title' => wfMessage('wrreport-icon-walkupseparate')->text()));
                $tr->appendElement('th')->appendElement('img', array('src' => '/vorlagen/s_bus.png', 'alt' => wfMessage('wrreport-icon-publictransport')->text(), 'title' => wfMessage('wrreport-icon-publictransport')->text()));
+               if ($wgWrReportMode != 'summer' && $wgWrReportEnableIntermaps) $tr->appendElement('th')->appendElement('img', array('src' => '/vorlagen/s_open.png', 'alt' => wfMessage('wrreport-icon-intermaps-status')->text(), 'title' => wfMessage('wrreport-icon-intermaps-status')->text()));
                $tr->appendElement('th')->appendText(wfMessage('wrreport-sledrun')->text());
                if ($wgWrReportMode != 'summer') $tr->appendElement('th')->appendText(wfMessage('wrreport-newreport-condition')->text());
                $tr->appendElement('th')->appendText(wfMessage('wrreport-sledrun-information')->text());
@@ -785,6 +801,7 @@ class WrReport {
                $tr->appendElement('th')->appendText(wfMessage('wrreport-sledrun-length')->text());
 
                // Rows
+               $now = new DateTime();
                while ($row = $dbr->fetchObject($res)) {
                        $title = Title::newFromRow($row);
                        $tr = $table->appendElement('tr');
@@ -808,6 +825,22 @@ class WrReport {
                        $td = $tr->appendElement('td');
                        if ($row->public_transport and $row->public_transport != 5) $td->appendElement('img', array('src' => '/vorlagen/s_bus.png', 'alt' => wfMessage('wrreport-icon-publictransport')->text(), 'title' => wfMessage('wrreport-icon-publictransport')->text()));
 
+                       if ($wgWrReportMode != 'summer' && $wgWrReportEnableIntermaps) {
+                               $td = $tr->appendElement('td');
+                               if ($row->show_status) {
+                                       $date_last_check = new DateTime($row->last_check);
+                                       if ($date_last_check->diff($now)->days <= $wgWrReportIntermapsValidDays) {
+                                               if ($row->status == 'open') {
+                                                       $msg = wfMessage('wrreport-icon-intermaps-open', $row->last_update)->text();
+                                                       $td->appendElement('img', array('src' => '/vorlagen/s_open.png', 'alt' => $msg, 'title' => $msg));
+                                               } elseif ($row->status == 'closed') {
+                                                       $msg = wfMessage('wrreport-icon-intermaps-closed', $row->last_update)->text();
+                                                       $td->appendElement('img', array('src' => '/vorlagen/s_closed.png', 'alt' => $msg, 'title' => $msg));
+                                               }
+                                       }
+                               }
+                       }
+
                        $tr->appendElement('td')->appendElement('a', array('href' => $title->getLocalURL()))->appendText($title->getPrefixedText());
 
                        if ($wgWrReportMode != 'summer') {