Completed
Pull Request — master (#981)
by
unknown
02:04
created
model/sparql/GenericSparql.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
     protected function query($query) {
89 89
         $queryId = sprintf("%05d", rand(0, 99999));
90 90
         $logger = $this->model->getLogger();
91
-        $logger->info("[qid $queryId] SPARQL query:\n" . $this->generateQueryPrefixes($query) . "\n$query\n");
91
+        $logger->info("[qid $queryId] SPARQL query:\n".$this->generateQueryPrefixes($query)."\n$query\n");
92 92
         $starttime = microtime(true);
93 93
         $result = $this->client->query($query);
94 94
         $elapsed = intval(round((microtime(true) - $starttime) * 1000));
95
-        if(method_exists($result, 'numRows')) {
95
+        if (method_exists($result, 'numRows')) {
96 96
             $numRows = $result->numRows();
97 97
             $logger->info("[qid $queryId] result: $numRows rows returned in $elapsed ms");
98 98
         } else { // graph result
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      * @param Vocabulary[]|null $vocabs
109 109
      * @return string
110 110
      */
111
-    protected function generateFromClause($vocabs=null) {
111
+    protected function generateFromClause($vocabs = null) {
112 112
         $clause = '';
113 113
         if (!$vocabs) {
114 114
             return $this->graph !== '?graph' && $this->graph !== NULL ? "FROM <$this->graph>" : '';
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 
236 236
 	$quote_string = function($val) { return "'$val'"; };
237 237
 	$quoted_values = array_map($quote_string, $langs);
238
-	$langFilter = "FILTER(?lang IN (" . implode(',', $quoted_values) . "))";
238
+	$langFilter = "FILTER(?lang IN (".implode(',', $quoted_values)."))";
239 239
 
240 240
         $values = $this->formatValues('?type', $classes, 'uri');
241 241
         $valuesProp = $this->formatValues('?prop', $props, null);
@@ -661,9 +661,9 @@  discard block
 block discarded – undo
661 661
                 $conceptscheme['title'] = $row->title->getValue();
662 662
             }
663 663
             // add dct:subject and their labels in the result
664
-            if(isset($row->domain) && isset($row->domainLabel)){
665
-                $conceptscheme['subject']['uri']=$row->domain->getURI();
666
-                $conceptscheme['subject']['prefLabel']=$row->domainLabel->getValue();
664
+            if (isset($row->domain) && isset($row->domainLabel)) {
665
+                $conceptscheme['subject']['uri'] = $row->domain->getURI();
666
+                $conceptscheme['subject']['prefLabel'] = $row->domainLabel->getValue();
667 667
             }
668 668
 
669 669
             $ret[$row->cs->getURI()] = $conceptscheme;
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
           $values[] = "<$graph>";
731 731
         }
732 732
         if (count($values)) {
733
-          return "FILTER (?graph IN (" . implode(',', $values) . "))";
733
+          return "FILTER (?graph IN (".implode(',', $values)."))";
734 734
         }
735 735
     }
736 736
 
@@ -741,16 +741,16 @@  discard block
 block discarded – undo
741 741
      * @return string sparql query clauses
742 742
      */
743 743
     protected function formatLimitAndOffset($limit, $offset) {
744
-        $limit = ($limit) ? 'LIMIT ' . $limit : '';
745
-        $offset = ($offset) ? 'OFFSET ' . $offset : '';
744
+        $limit = ($limit) ? 'LIMIT '.$limit : '';
745
+        $offset = ($offset) ? 'OFFSET '.$offset : '';
746 746
         // eliminating whitespace and line changes when the conditions aren't needed.
747 747
         $limitandoffset = '';
748 748
         if ($limit && $offset) {
749
-            $limitandoffset = "\n" . $limit . "\n" . $offset;
749
+            $limitandoffset = "\n".$limit."\n".$offset;
750 750
         } elseif ($limit) {
751
-            $limitandoffset = "\n" . $limit;
751
+            $limitandoffset = "\n".$limit;
752 752
         } elseif ($offset) {
753
-            $limitandoffset = "\n" . $offset;
753
+            $limitandoffset = "\n".$offset;
754 754
         }
755 755
 
756 756
         return $limitandoffset;
@@ -902,14 +902,14 @@  discard block
 block discarded – undo
902 902
         // if search language and UI/display language differ, must also consider case where there is no prefLabel in
903 903
         // the display language; in that case, should use the label with the same language as the matched label
904 904
         $labelcondFallback = ($searchLang != $lang) ?
905
-          "OPTIONAL { # in case previous OPTIONAL block gives no labels\n" .
905
+          "OPTIONAL { # in case previous OPTIONAL block gives no labels\n".
906 906
           "?s skos:prefLabel ?label . FILTER (LANGMATCHES(LANG(?label), LANG(?match))) }" : "";
907 907
 
908 908
         //  Including the labels if there is no query term given.
909 909
         if ($rawterm === '') {
910 910
           $labelClause = "?s skos:prefLabel ?label .";
911
-          $labelClause = ($lang) ? $labelClause . " FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause . "";
912
-          return $labelClause . " BIND(?label AS ?match)";
911
+          $labelClause = ($lang) ? $labelClause." FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause."";
912
+          return $labelClause." BIND(?label AS ?match)";
913 913
         }
914 914
 
915 915
         /*
@@ -981,20 +981,20 @@  discard block
 block discarded – undo
981 981
         $schemecond = '';
982 982
         if (!empty($schemes)) {
983 983
             $conditions = array();
984
-            foreach($schemes as $scheme) {
984
+            foreach ($schemes as $scheme) {
985 985
                 $conditions[] = "{?s skos:inScheme <$scheme>}";
986 986
             }
987
-            $schemecond = '{'.implode(" UNION ",$conditions).'}';
987
+            $schemecond = '{'.implode(" UNION ", $conditions).'}';
988 988
         }
989
-        $filterDeprecated="";
989
+        $filterDeprecated = "";
990 990
         //show or hide deprecated concepts
991
-        if(!$showDeprecated){
992
-            $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }";
991
+        if (!$showDeprecated) {
992
+            $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }";
993 993
         }
994 994
         // extra conditions for parent and group, if specified
995
-        $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <" . $params->getParentLimit() . "> ." : "";
996
-        $groupcond = ($params->getGroupLimit()) ? "<" . $params->getGroupLimit() . "> skos:member ?s ." : "";
997
-        $pgcond = $parentcond . $groupcond;
995
+        $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <".$params->getParentLimit()."> ." : "";
996
+        $groupcond = ($params->getGroupLimit()) ? "<".$params->getGroupLimit()."> skos:member ?s ." : "";
997
+        $pgcond = $parentcond.$groupcond;
998 998
 
999 999
         $orderextra = $this->isDefaultEndpoint() ? $this->graph : '';
1000 1000
 
@@ -1080,9 +1080,9 @@  discard block
 block discarded – undo
1080 1080
             $hit['type'][] = $this->shortenUri($typeuri);
1081 1081
         }
1082 1082
 
1083
-        if(!empty($fields)) {
1083
+        if (!empty($fields)) {
1084 1084
             foreach ($fields as $prop) {
1085
-                $propname = $prop . 's';
1085
+                $propname = $prop.'s';
1086 1086
                 if (isset($row->$propname)) {
1087 1087
                     foreach (explode("\n", $row->$propname->getValue()) as $line) {
1088 1088
                         $rdata = str_getcsv($line, ',', '"', '"');
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
                             $propvals = $rdata[2];
1098 1098
                         }
1099 1099
 
1100
-                        $hit['skos:' . $prop][] = $propvals;
1100
+                        $hit['skos:'.$prop][] = $propvals;
1101 1101
                     }
1102 1102
                 }
1103 1103
             }
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
      * @return array query result object
1174 1174
      */
1175 1175
     public function queryConcepts($vocabs, $fields = null, $unique = false, $params, $showDeprecated = false) {
1176
-        $query = $this->generateConceptSearchQuery($fields, $unique, $params,$showDeprecated);
1176
+        $query = $this->generateConceptSearchQuery($fields, $unique, $params, $showDeprecated);
1177 1177
         $results = $this->query($query);
1178 1178
         return $this->transformConceptSearchResults($results, $vocabs, $fields);
1179 1179
     }
@@ -1228,10 +1228,10 @@  discard block
 block discarded – undo
1228 1228
         $conditions = $this->formatFilterConditions($letter, $lang);
1229 1229
         $filtercondLabel = $conditions['filterpref'];
1230 1230
         $filtercondALabel = $conditions['filteralt'];
1231
-        $qualifierClause = $qualifier ? "OPTIONAL { ?s <" . $qualifier->getURI() . "> ?qualifier }" : "";
1232
-        $filterDeprecated="";
1233
-        if(!$showDeprecated){
1234
-            $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }";
1231
+        $qualifierClause = $qualifier ? "OPTIONAL { ?s <".$qualifier->getURI()."> ?qualifier }" : "";
1232
+        $filterDeprecated = "";
1233
+        if (!$showDeprecated) {
1234
+            $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }";
1235 1235
         }
1236 1236
         $query = <<<EOQ
1237 1237
 SELECT DISTINCT ?s ?label ?alabel ?qualifier $fcl
@@ -1466,13 +1466,13 @@  discard block
 block discarded – undo
1466 1466
 
1467 1467
         if (!empty($altLabels)) {
1468 1468
             $ret['altLabel'] = array();
1469
-            foreach($altLabels as $label) {
1469
+            foreach ($altLabels as $label) {
1470 1470
                 $ret['altLabel'][] = $label;
1471 1471
             }
1472 1472
         }
1473 1473
         if (!empty($hiddenLabels)) {
1474 1474
             $ret['hiddenLabel'] = array();
1475
-            foreach($hiddenLabels as $label) {
1475
+            foreach ($hiddenLabels as $label) {
1476 1476
                 $ret['hiddenLabel'][] = $label;
1477 1477
             }
1478 1478
         }return $ret;
@@ -1702,7 +1702,7 @@  discard block
 block discarded – undo
1702 1702
                 if (!isset($row->label) || $row->label->getLang() === $lang) {
1703 1703
                     $ret[$row->object->getUri()] = $val;
1704 1704
                 } elseif ($row->label->getLang() === $fallbacklang) {
1705
-                    $val['label'] .= ' (' . $row->label->getLang() . ')';
1705
+                    $val['label'] .= ' ('.$row->label->getLang().')';
1706 1706
                     $ret[$row->object->getUri()] = $val;
1707 1707
                 }
1708 1708
             }
@@ -1798,10 +1798,10 @@  discard block
 block discarded – undo
1798 1798
 
1799 1799
             $label = null;
1800 1800
             if (isset($row->label)) {
1801
-                if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) {
1801
+                if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) {
1802 1802
                     $label = $row->label->getValue();
1803 1803
                 } else {
1804
-                    $label = $row->label->getValue() . " (" . $row->label->getLang() . ")";
1804
+                    $label = $row->label->getValue()." (".$row->label->getLang().")";
1805 1805
                 }
1806 1806
 
1807 1807
             }
@@ -1877,8 +1877,8 @@  discard block
 block discarded – undo
1877 1877
         foreach ($result as $row) {
1878 1878
             if (isset($row->top) && isset($row->label)) {
1879 1879
                 $label = $row->label->getValue();
1880
-                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) {
1881
-                    $label .= ' (' . $row->label->getLang() . ')';
1880
+                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) {
1881
+                    $label .= ' ('.$row->label->getLang().')';
1882 1882
                 }
1883 1883
                 $top = array('uri' => $row->top->getUri(), 'topConceptOf' => $row->topuri->getUri(), 'label' => $label, 'hasChildren' => filter_var($row->children->getValue(), FILTER_VALIDATE_BOOLEAN));
1884 1884
                 if (isset($row->notation)) {
@@ -1971,7 +1971,7 @@  discard block
 block discarded – undo
1971 1971
                 $ret[$uri]['exact'] = $row->exact->getUri();
1972 1972
             }
1973 1973
             if (isset($row->tops)) {
1974
-               $topConceptsList=explode(" ", $row->tops->getValue());
1974
+               $topConceptsList = explode(" ", $row->tops->getValue());
1975 1975
                // sort to garantee an alphabetical ordering of the URI
1976 1976
                sort($topConceptsList);
1977 1977
                $ret[$uri]['tops'] = $topConceptsList;
@@ -1984,8 +1984,8 @@  discard block
 block discarded – undo
1984 1984
                 $label = null;
1985 1985
                 if (isset($row->childlabel)) {
1986 1986
                     $label = $row->childlabel->getValue();
1987
-                    if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang . "-") !== 0) {
1988
-                        $label .= " (" . $row->childlabel->getLang() . ")";
1987
+                    if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang."-") !== 0) {
1988
+                        $label .= " (".$row->childlabel->getLang().")";
1989 1989
                     }
1990 1990
 
1991 1991
                 }
@@ -2006,8 +2006,8 @@  discard block
 block discarded – undo
2006 2006
             }
2007 2007
             if (isset($row->label)) {
2008 2008
                 $preflabel = $row->label->getValue();
2009
-                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) {
2010
-                    $preflabel .= ' (' . $row->label->getLang() . ')';
2009
+                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) {
2010
+                    $preflabel .= ' ('.$row->label->getLang().')';
2011 2011
                 }
2012 2012
 
2013 2013
                 $ret[$uri]['prefLabel'] = $preflabel;
@@ -2128,9 +2128,9 @@  discard block
 block discarded – undo
2128 2128
      */
2129 2129
     private function generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated = false) {
2130 2130
         $fcl = $this->generateFromClause();
2131
-        $filterDeprecated="";
2132
-        if(!$showDeprecated){
2133
-            $filterDeprecated="  FILTER NOT EXISTS { ?conc owl:deprecated true }";
2131
+        $filterDeprecated = "";
2132
+        if (!$showDeprecated) {
2133
+            $filterDeprecated = "  FILTER NOT EXISTS { ?conc owl:deprecated true }";
2134 2134
         }
2135 2135
         $query = <<<EOQ
2136 2136
 SELECT ?conc ?super ?label ?members ?type ?notation $fcl
@@ -2169,10 +2169,10 @@  discard block
 block discarded – undo
2169 2169
                     'type' => array($row->type->shorten()),
2170 2170
                 );
2171 2171
                 if (isset($row->label)) {
2172
-                    if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) {
2172
+                    if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) {
2173 2173
                         $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue();
2174 2174
                     } else {
2175
-                        $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue() . " (" . $row->label->getLang() . ")";
2175
+                        $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue()." (".$row->label->getLang().")";
2176 2176
                     }
2177 2177
 
2178 2178
                 }
@@ -2200,8 +2200,8 @@  discard block
 block discarded – undo
2200 2200
      * @param boolean $showDeprecated whether to include deprecated concepts in search results
2201 2201
      * @return array Result array with concept URI as key and concept label as value
2202 2202
      */
2203
-    public function listConceptGroupContents($groupClass, $group, $lang,$showDeprecated = false) {
2204
-        $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang,$showDeprecated);
2203
+    public function listConceptGroupContents($groupClass, $group, $lang, $showDeprecated = false) {
2204
+        $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated);
2205 2205
         $result = $this->query($query);
2206 2206
         return $this->transformConceptGroupContentsResults($result, $lang);
2207 2207
     }
@@ -2214,7 +2214,7 @@  discard block
 block discarded – undo
2214 2214
      */
2215 2215
     private function generateChangeListQuery($lang, $offset, $prop) {
2216 2216
         $fcl = $this->generateFromClause();
2217
-        $offset = ($offset) ? 'OFFSET ' . $offset : '';
2217
+        $offset = ($offset) ? 'OFFSET '.$offset : '';
2218 2218
 
2219 2219
         $query = <<<EOQ
2220 2220
 SELECT DISTINCT ?concept ?date ?label $fcl
Please login to merge, or discard this patch.