Completed
Pull Request — master (#1098)
by
unknown
01:47
created
model/sparql/GenericSparql.php 1 patch
Spacing   +51 added lines, -51 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);
@@ -667,9 +667,9 @@  discard block
 block discarded – undo
667 667
                 $conceptscheme['title'] = $row->title->getValue();
668 668
             }
669 669
             // add dct:subject and their labels in the result
670
-            if(isset($row->domain) && isset($row->domainLabel)){
671
-                $conceptscheme['subject']['uri']=$row->domain->getURI();
672
-                $conceptscheme['subject']['prefLabel']=$row->domainLabel->getValue();
670
+            if (isset($row->domain) && isset($row->domainLabel)) {
671
+                $conceptscheme['subject']['uri'] = $row->domain->getURI();
672
+                $conceptscheme['subject']['prefLabel'] = $row->domainLabel->getValue();
673 673
             }
674 674
 
675 675
             $ret[$row->cs->getURI()] = $conceptscheme;
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
           $values[] = "<$graph>";
737 737
         }
738 738
         if (count($values)) {
739
-          return "FILTER (?graph IN (" . implode(',', $values) . "))";
739
+          return "FILTER (?graph IN (".implode(',', $values)."))";
740 740
         }
741 741
     }
742 742
 
@@ -747,16 +747,16 @@  discard block
 block discarded – undo
747 747
      * @return string sparql query clauses
748 748
      */
749 749
     protected function formatLimitAndOffset($limit, $offset) {
750
-        $limit = ($limit) ? 'LIMIT ' . $limit : '';
751
-        $offset = ($offset) ? 'OFFSET ' . $offset : '';
750
+        $limit = ($limit) ? 'LIMIT '.$limit : '';
751
+        $offset = ($offset) ? 'OFFSET '.$offset : '';
752 752
         // eliminating whitespace and line changes when the conditions aren't needed.
753 753
         $limitandoffset = '';
754 754
         if ($limit && $offset) {
755
-            $limitandoffset = "\n" . $limit . "\n" . $offset;
755
+            $limitandoffset = "\n".$limit."\n".$offset;
756 756
         } elseif ($limit) {
757
-            $limitandoffset = "\n" . $limit;
757
+            $limitandoffset = "\n".$limit;
758 758
         } elseif ($offset) {
759
-            $limitandoffset = "\n" . $offset;
759
+            $limitandoffset = "\n".$offset;
760 760
         }
761 761
 
762 762
         return $limitandoffset;
@@ -908,14 +908,14 @@  discard block
 block discarded – undo
908 908
         // if search language and UI/display language differ, must also consider case where there is no prefLabel in
909 909
         // the display language; in that case, should use the label with the same language as the matched label
910 910
         $labelcondFallback = ($searchLang != $lang) ?
911
-          "OPTIONAL { # in case previous OPTIONAL block gives no labels\n" .
911
+          "OPTIONAL { # in case previous OPTIONAL block gives no labels\n".
912 912
           "?s skos:prefLabel ?label . FILTER (LANGMATCHES(LANG(?label), LANG(?match))) }" : "";
913 913
 
914 914
         //  Including the labels if there is no query term given.
915 915
         if ($rawterm === '') {
916 916
           $labelClause = "?s skos:prefLabel ?label .";
917
-          $labelClause = ($lang) ? $labelClause . " FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause . "";
918
-          return $labelClause . " BIND(?label AS ?match)";
917
+          $labelClause = ($lang) ? $labelClause." FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause."";
918
+          return $labelClause." BIND(?label AS ?match)";
919 919
         }
920 920
 
921 921
         /*
@@ -987,20 +987,20 @@  discard block
 block discarded – undo
987 987
         $schemecond = '';
988 988
         if (!empty($schemes)) {
989 989
             $conditions = array();
990
-            foreach($schemes as $scheme) {
990
+            foreach ($schemes as $scheme) {
991 991
                 $conditions[] = "{?s skos:inScheme <$scheme>}";
992 992
             }
993
-            $schemecond = '{'.implode(" UNION ",$conditions).'}';
993
+            $schemecond = '{'.implode(" UNION ", $conditions).'}';
994 994
         }
995
-        $filterDeprecated="";
995
+        $filterDeprecated = "";
996 996
         //show or hide deprecated concepts
997
-        if(!$showDeprecated){
998
-            $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }";
997
+        if (!$showDeprecated) {
998
+            $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }";
999 999
         }
1000 1000
         // extra conditions for parent and group, if specified
1001
-        $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <" . $params->getParentLimit() . "> ." : "";
1002
-        $groupcond = ($params->getGroupLimit()) ? "<" . $params->getGroupLimit() . "> skos:member ?s ." : "";
1003
-        $pgcond = $parentcond . $groupcond;
1001
+        $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <".$params->getParentLimit()."> ." : "";
1002
+        $groupcond = ($params->getGroupLimit()) ? "<".$params->getGroupLimit()."> skos:member ?s ." : "";
1003
+        $pgcond = $parentcond.$groupcond;
1004 1004
 
1005 1005
         $orderextra = $this->isDefaultEndpoint() ? $this->graph : '';
1006 1006
 
@@ -1086,9 +1086,9 @@  discard block
 block discarded – undo
1086 1086
             $hit['type'][] = $this->shortenUri($typeuri);
1087 1087
         }
1088 1088
 
1089
-        if(!empty($fields)) {
1089
+        if (!empty($fields)) {
1090 1090
             foreach ($fields as $prop) {
1091
-                $propname = $prop . 's';
1091
+                $propname = $prop.'s';
1092 1092
                 if (isset($row->$propname)) {
1093 1093
                     foreach (explode("\n", $row->$propname->getValue()) as $line) {
1094 1094
                         $rdata = str_getcsv($line, ',', '"', '"');
@@ -1103,7 +1103,7 @@  discard block
 block discarded – undo
1103 1103
                             $propvals = $rdata[2];
1104 1104
                         }
1105 1105
 
1106
-                        $hit['skos:' . $prop][] = $propvals;
1106
+                        $hit['skos:'.$prop][] = $propvals;
1107 1107
                     }
1108 1108
                 }
1109 1109
             }
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
      * @return array query result object
1180 1180
      */
1181 1181
     public function queryConcepts($vocabs, $fields = null, $unique = false, $params, $showDeprecated = false) {
1182
-        $query = $this->generateConceptSearchQuery($fields, $unique, $params,$showDeprecated);
1182
+        $query = $this->generateConceptSearchQuery($fields, $unique, $params, $showDeprecated);
1183 1183
         $results = $this->query($query);
1184 1184
         return $this->transformConceptSearchResults($results, $vocabs, $fields);
1185 1185
     }
@@ -1234,10 +1234,10 @@  discard block
 block discarded – undo
1234 1234
         $conditions = $this->formatFilterConditions($letter, $lang);
1235 1235
         $filtercondLabel = $conditions['filterpref'];
1236 1236
         $filtercondALabel = $conditions['filteralt'];
1237
-        $qualifierClause = $qualifier ? "OPTIONAL { ?s <" . $qualifier->getURI() . "> ?qualifier }" : "";
1238
-        $filterDeprecated="";
1239
-        if(!$showDeprecated){
1240
-            $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }";
1237
+        $qualifierClause = $qualifier ? "OPTIONAL { ?s <".$qualifier->getURI()."> ?qualifier }" : "";
1238
+        $filterDeprecated = "";
1239
+        if (!$showDeprecated) {
1240
+            $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }";
1241 1241
         }
1242 1242
         $query = <<<EOQ
1243 1243
 SELECT DISTINCT ?s ?label ?alabel ?qualifier
@@ -1711,7 +1711,7 @@  discard block
 block discarded – undo
1711 1711
                 if (!isset($row->label) || $row->label->getLang() === $lang) {
1712 1712
                     $ret[$row->object->getUri()] = $val;
1713 1713
                 } elseif ($row->label->getLang() === $fallbacklang) {
1714
-                    $val['label'] .= ' (' . $row->label->getLang() . ')';
1714
+                    $val['label'] .= ' ('.$row->label->getLang().')';
1715 1715
                     $ret[$row->object->getUri()] = $val;
1716 1716
                 }
1717 1717
             }
@@ -1807,10 +1807,10 @@  discard block
 block discarded – undo
1807 1807
 
1808 1808
             $label = null;
1809 1809
             if (isset($row->label)) {
1810
-                if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) {
1810
+                if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) {
1811 1811
                     $label = $row->label->getValue();
1812 1812
                 } else {
1813
-                    $label = $row->label->getValue() . " (" . $row->label->getLang() . ")";
1813
+                    $label = $row->label->getValue()." (".$row->label->getLang().")";
1814 1814
                 }
1815 1815
 
1816 1816
             }
@@ -1886,8 +1886,8 @@  discard block
 block discarded – undo
1886 1886
         foreach ($result as $row) {
1887 1887
             if (isset($row->top) && isset($row->label)) {
1888 1888
                 $label = $row->label->getValue();
1889
-                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) {
1890
-                    $label .= ' (' . $row->label->getLang() . ')';
1889
+                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) {
1890
+                    $label .= ' ('.$row->label->getLang().')';
1891 1891
                 }
1892 1892
                 $top = array('uri' => $row->top->getUri(), 'topConceptOf' => $row->topuri->getUri(), 'label' => $label, 'hasChildren' => filter_var($row->children->getValue(), FILTER_VALIDATE_BOOLEAN));
1893 1893
                 if (isset($row->notation)) {
@@ -1980,7 +1980,7 @@  discard block
 block discarded – undo
1980 1980
                 $ret[$uri]['exact'] = $row->exact->getUri();
1981 1981
             }
1982 1982
             if (isset($row->tops)) {
1983
-               $topConceptsList=explode(" ", $row->tops->getValue());
1983
+               $topConceptsList = explode(" ", $row->tops->getValue());
1984 1984
                // sort to garantee an alphabetical ordering of the URI
1985 1985
                sort($topConceptsList);
1986 1986
                $ret[$uri]['tops'] = $topConceptsList;
@@ -1993,8 +1993,8 @@  discard block
 block discarded – undo
1993 1993
                 $label = null;
1994 1994
                 if (isset($row->childlabel)) {
1995 1995
                     $label = $row->childlabel->getValue();
1996
-                    if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang . "-") !== 0) {
1997
-                        $label .= " (" . $row->childlabel->getLang() . ")";
1996
+                    if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang."-") !== 0) {
1997
+                        $label .= " (".$row->childlabel->getLang().")";
1998 1998
                     }
1999 1999
 
2000 2000
                 }
@@ -2015,8 +2015,8 @@  discard block
 block discarded – undo
2015 2015
             }
2016 2016
             if (isset($row->label)) {
2017 2017
                 $preflabel = $row->label->getValue();
2018
-                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) {
2019
-                    $preflabel .= ' (' . $row->label->getLang() . ')';
2018
+                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) {
2019
+                    $preflabel .= ' ('.$row->label->getLang().')';
2020 2020
                 }
2021 2021
 
2022 2022
                 $ret[$uri]['prefLabel'] = $preflabel;
@@ -2137,9 +2137,9 @@  discard block
 block discarded – undo
2137 2137
      */
2138 2138
     private function generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated = false) {
2139 2139
         $fcl = $this->generateFromClause();
2140
-        $filterDeprecated="";
2141
-        if(!$showDeprecated){
2142
-            $filterDeprecated="  FILTER NOT EXISTS { ?conc owl:deprecated true }";
2140
+        $filterDeprecated = "";
2141
+        if (!$showDeprecated) {
2142
+            $filterDeprecated = "  FILTER NOT EXISTS { ?conc owl:deprecated true }";
2143 2143
         }
2144 2144
         $query = <<<EOQ
2145 2145
 SELECT ?conc ?super ?label ?members ?type ?notation $fcl
@@ -2178,10 +2178,10 @@  discard block
 block discarded – undo
2178 2178
                     'type' => array($row->type->shorten()),
2179 2179
                 );
2180 2180
                 if (isset($row->label)) {
2181
-                    if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) {
2181
+                    if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) {
2182 2182
                         $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue();
2183 2183
                     } else {
2184
-                        $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue() . " (" . $row->label->getLang() . ")";
2184
+                        $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue()." (".$row->label->getLang().")";
2185 2185
                     }
2186 2186
 
2187 2187
                 }
@@ -2209,8 +2209,8 @@  discard block
 block discarded – undo
2209 2209
      * @param boolean $showDeprecated whether to include deprecated concepts in search results
2210 2210
      * @return array Result array with concept URI as key and concept label as value
2211 2211
      */
2212
-    public function listConceptGroupContents($groupClass, $group, $lang,$showDeprecated = false) {
2213
-        $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang,$showDeprecated);
2212
+    public function listConceptGroupContents($groupClass, $group, $lang, $showDeprecated = false) {
2213
+        $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated);
2214 2214
         $result = $this->query($query);
2215 2215
         return $this->transformConceptGroupContentsResults($result, $lang);
2216 2216
     }
@@ -2223,9 +2223,9 @@  discard block
 block discarded – undo
2223 2223
      * @param int $limit maximum number of results to return
2224 2224
      * @return string sparql query
2225 2225
      */
2226
-    private function generateChangeListQuery($prop, $lang, $offset, $limit=200) {
2226
+    private function generateChangeListQuery($prop, $lang, $offset, $limit = 200) {
2227 2227
         $fcl = $this->generateFromClause();
2228
-        $offset = ($offset) ? 'OFFSET ' . $offset : '';
2228
+        $offset = ($offset) ? 'OFFSET '.$offset : '';
2229 2229
 
2230 2230
         $query = <<<EOQ
2231 2231
 SELECT DISTINCT ?concept ?date ?label $fcl
Please login to merge, or discard this patch.