Fixed bug: Attribute in_arbeit of <rodelbahn> was ignored.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 27 Jan 2014 22:44:42 +0000 (22:44 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 27 Jan 2014 22:44:42 +0000 (22:44 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/mediawiki_extensions/wrreport/trunk@1892 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrreport.body.php

index 73b419bc504a6e6cc8b6d370e3160a30ea270b83..e646978d1d21a25617b34cbdb1b46bbd3f85667f 100644 (file)
@@ -913,6 +913,10 @@ class WrReport {
                                $attributes = array();
                                foreach ($entry->attributes() as $key => $value) $attributes[(string) $key] = (string) $value;
 
+                               // is the tagname valid?
+                               if (!in_array($tagname, array('rodelbahn', 'rodelbahnen', 'region')))
+                                       throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-element', $tagname)->text());
+
                                // parse operation attribute
                                $operation = '+'; // '+' (append) or '-' (subtract)
                                if (array_key_exists('operation', $attributes)) {
@@ -937,41 +941,38 @@ class WrReport {
                                if (count($attributes) > 0)
                                        throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-attribute-name', $tagname, array_keys($attributes)[0])->text());
 
+
+                               // build SQL query
+                               $tables = array('wrsledruncache');
+                               $where = array();
+
+                               // <region>
+                               if ($tagname === 'region') {
+                                       // the following line would work if MySQL 5.5 would implement a real geospatial version of CONTAINS.
+                                       // $where[] = 'CONTAINS(GEOMFROMWKB(' . $dbr->addQuotes($region_border_wkb) . '), POINT(position_longitude, position_latitude))'
+                                       $tables[] = 'wrregion';
+                                       $tables[] = 'wrregioncache';
+                                       $where[] = 'wrregioncache.region_id=wrregion.id';
+                                       $where[] = 'wrregioncache.page_id=wrsledruncache.page_id';
+                                       $where['wrregion.name'] = $entry;
+                               }
+
                                // <rodelbahn>
                                if ($tagname == 'rodelbahn') {
-                                       $page_title = Title::newFromText(trim($entry));
-                                       if ($page_title && $page_title->exists()) $entry_page_ids[] = $page_title->getArticleID();
+                                       $where['page_title'] = trim($entry);
                                }
 
-                               // <region> and <rodelbahn>
-                               elseif ($tagname === 'region' || $tagname === 'rodelbahnen') {
-                                       $tables = array('wrsledruncache');
-                                       $where = array();
-
-                                       // region
-                                       if ($tagname === 'region') {
-                                               // the following line would work if MySQL 5.5 would implement a real geospatial version of CONTAINS.
-                                               // $where[] = 'CONTAINS(GEOMFROMWKB(' . $dbr->addQuotes($region_border_wkb) . '), POINT(position_longitude, position_latitude))'
-                                               $tables[] = 'wrregion';
-                                               $tables[] = 'wrregioncache';
-                                               $where[] = 'wrregioncache.region_id=wrregion.id';
-                                               $where[] = 'wrregioncache.page_id=wrsledruncache.page_id';
-                                               $where['wrregion.name'] = $entry;
-                                       }
-
-                                       // under contruction
-                                       if ($under_construction === true) $where[] = 'wrsledruncache.under_construction';
-                                       if ($under_construction === false) $where[] = 'not wrsledruncache.under_construction';
+                               // under contruction
+                               if ($under_construction === true) $where[] = 'wrsledruncache.under_construction';
+                               if ($under_construction === false) $where[] = 'not wrsledruncache.under_construction';
 
-                                       // query
-                                       $res = $dbr->select($tables, array('page_id' => 'wrsledruncache.page_id'), $where, __METHOD__, 'page_id');
-                                       foreach ($res as $row) {
-                                               $entry_page_ids[] = $row->page_id;
-                                       }
-                                       $dbr->freeResult($res);
+                               // query
+                               $res = $dbr->select($tables, array('page_id' => 'wrsledruncache.page_id'), $where, __METHOD__, 'page_id');
+                               foreach ($res as $row) {
+                                       $entry_page_ids[] = $row->page_id;
                                }
+                               $dbr->freeResult($res);
 
-                               else throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-element', $tagname)->text());
 
                                // merge the entry page_ids with the page_ids
                                if ($operation == '+') $page_ids = array_merge($page_ids, $entry_page_ids);