Don't show "unknown" sledrun state anymore.
[philipp/winterrodeln/mediawiki_extensions/wrreport.git] / wrreport_body.php
index 8937e543db23208172a2c11be680ed695b02a68d..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'
 //     $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:
 //
 //
 // The following tags are supported:
@@ -766,13 +768,15 @@ class WrReport {
                                                        $where_array,
                                                        'bahnentabelleParserHook',
                                                        ['ORDER BY' => 'p.page_title'],
                                                        $where_array,
                                                        'bahnentabelleParserHook',
                                                        ['ORDER BY' => 'p.page_title'],
-                                                       ['p' => ['JOIN', 'p.page_id=c.page_id'], 'r' => ['JOIN', 's.intermaps_sledrun_id=r.intermaps_sledrun_id'], 'AA' => ['LEFT OUTER JOIN', 'p.page_id=s.wr_page_id']]
+                                                       ['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 $wgUser;
                global $wgWrReportMode; // e.g. 'summer'
                global $wgWrReportBlackListAll;
                global $wgWrReportBlackListStrangers;
+               global $wgWrReportEnableIntermaps;
+               global $wgWrReportIntermapsValidDays;
 
                // Determine, whether the user is allowed to make a new report
                $userMayReport = ($wgWrReportMode == 'allow' || ($wgWrReportMode == 'loggedin' && $wgUser->isLoggedIn()));
 
                // Determine, whether the user is allowed to make a new report
                $userMayReport = ($wgWrReportMode == 'allow' || ($wgWrReportMode == 'loggedin' && $wgUser->isLoggedIn()));
@@ -788,7 +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()));
                $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') $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()));
+               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());
                $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());
@@ -797,6 +801,7 @@ class WrReport {
                $tr->appendElement('th')->appendText(wfMessage('wrreport-sledrun-length')->text());
 
                // Rows
                $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');
                while ($row = $dbr->fetchObject($res)) {
                        $title = Title::newFromRow($row);
                        $tr = $table->appendElement('tr');
@@ -820,20 +825,20 @@ 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()));
 
                        $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') {
+                       if ($wgWrReportMode != 'summer' && $wgWrReportEnableIntermaps) {
                                $td = $tr->appendElement('td');
                                if ($row->show_status) {
                                $td = $tr->appendElement('td');
                                if ($row->show_status) {
-                                       if ($row->status == 'open') {
-                                               $td->appendElement('img', array('src' => '/vorlagen/s_open.png', 'alt' => wfMessage('wrreport-icon-intermaps-open')->text(), 'title' => wfMessage('wrreport-icon-intermaps-open')->text()));
-                                       } elseif ($row->status == 'closed') {
-                                               $td->appendElement('img', array('src' => '/vorlagen/s_closed.png', 'alt' => wfMessage('wrreport-icon-intermaps-closed')->text(), 'title' => wfMessage('wrreport-icon-intermaps-closed')->text()));
-                                       } else {
-                                               $td->appendText($row->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));
+                                               }
                                        }
                                }
                                        }
                                }
-                               // s_closed
-                               // no info
-                               // check whether info should be shown at all
                        }
 
                        $tr->appendElement('td')->appendElement('a', array('href' => $title->getLocalURL()))->appendText($title->getPrefixedText());
                        }
 
                        $tr->appendElement('td')->appendElement('a', array('href' => $title->getLocalURL()))->appendText($title->getPrefixedText());