function getColumnsForExtGridAndStore($createKeyFrom = NULL) { $fieldconfArr = (array) json_decode($this->getGeometryColumns($this->table, "fieldconf")); foreach ($fieldconfArr as $key => $value) { if ($value->properties == "*") { $table = new \app\models\Table($this->table); $distinctValues = $table->getGroupByAsArray($key); $fieldconfArr[$key]->properties = json_encode($distinctValues["data"], JSON_NUMERIC_CHECK); } } if ($this->geomType == "POLYGON" || $this->geomType == "MULTIPOLYGON") { $type = "Polygon"; } elseif ($this->geomType == "POINT" || $this->geomType == "MULTIPOINT") { $type = "Point"; } elseif ($this->geomType == "LINESTRING" || $this->geomType == "MULTILINESTRING" || $this->geomType == "LINE") { $type = "Path"; } if (substr($this->geomType, 0, 5) == "MULTI") { $multi = true; } else { $multi = false; } foreach ($this->metaData as $key => $value) { if ($value['type'] != "geometry" && $key != $this->primeryKey['attname']) { $fieldsForStore[] = array("name" => $key, "type" => $value['type']); $columnsForGrid[] = array("header" => $key, "dataIndex" => $key, "type" => $value['type'], "typeObj" => $value['typeObj'], "properties" => $fieldconfArr[$key]->properties ?: null); } } if ($createKeyFrom) { $fieldsForStore[] = array("name" => "_key_", "type" => "string"); $fieldsForStore[] = array("name" => "pkey", "type" => "string"); } $response["forStore"] = $fieldsForStore; $response["forGrid"] = $columnsForGrid; $response["type"] = $type; $response["multi"] = $multi; return $response; }
public function getAll($schema = false, $layer = false, $auth, $includeExtent = false, $parse = false, $es = false) { // TODO use the function settings.getColumns() instead $where = $auth ? "(authentication<>'foo' OR authentication is NULL)" : "(authentication='Write' OR authentication='None')"; $case = "CASE WHEN ((layergroup = '' OR layergroup IS NULL) AND baselayer != true) THEN 9999999 else sort_id END"; if ($schema) { $ids = explode(",", $schema); $qMarks = str_repeat('?,', count($ids) - 1) . '?'; $sql = "SELECT *, ({$case}) as sort FROM settings.geometry_columns_view WHERE {$where} AND f_table_schema in ({$qMarks}) ORDER BY sort"; } elseif ($layer) { $sql = "SELECT *, ({$case}) as sort FROM settings.geometry_columns_view WHERE {$where} AND f_table_schema = :sSchema AND f_table_name = :sName ORDER BY sort"; } else { $sql = "SELECT *, ({$case}) as sort FROM settings.geometry_columns_view WHERE {$where} ORDER BY sort"; } $sql .= \app\conf\App::$param["reverseLayerOrder"] ? " DESC" : " ASC"; $res = $this->prepare($sql); try { if ($schema) { $res->execute($ids); } elseif ($layer) { $split = explode(".", $layer); $res->execute(array("sSchema" => $split[0], "sName" => $split[1])); } else { $res->execute(); } } catch (\PDOException $e) { $response['success'] = false; $response['message'] = $e->getMessage(); $response['code'] = 401; return $response; } while ($row = $this->fetchRow($res, "assoc")) { $arr = array(); $primeryKey = $this->getPrimeryKey("{$row['f_table_schema']}.{$row['f_table_name']}"); $resVersioning = $this->doesColumnExist("{$row['f_table_schema']}.{$row['f_table_name']}", "gc2_version_gid"); $versioning = $resVersioning["exists"]; if ($row['type'] != "RASTER" && $includeExtent == true) { $srsTmp = "900913"; $sql = "SELECT ST_Xmin(ST_Extent(public.ST_Transform(\"" . $row['f_geometry_column'] . "\",{$srsTmp}))) AS xmin,ST_Xmax(ST_Extent(public.ST_Transform(\"" . $row['f_geometry_column'] . "\",{$srsTmp}))) AS xmax, ST_Ymin(ST_Extent(public.ST_Transform(\"" . $row['f_geometry_column'] . "\",{$srsTmp}))) AS ymin,ST_Ymax(ST_Extent(public.ST_Transform(\"" . $row['f_geometry_column'] . "\",{$srsTmp}))) AS ymax FROM {$row['f_table_schema']}.{$row['f_table_name']}"; $resExtent = $this->prepare($sql); try { $resExtent->execute(); } catch (\PDOException $e) { //print_r($e); } $extent = $this->fetchRow($resExtent, "assoc"); } foreach ($row as $key => $value) { if ($key == "type" && $value == "GEOMETRY") { $def = json_decode($row['def']); if (isset($def->geotype) && $def->geotype != "Default") { $value = "MULTI" . $def->geotype; } } if ($key == "layergroup" && !$value) { $value = "<font color='red'>[Ungrouped]</font>"; } if ($key == "fieldconf" && $value) { $obj = json_decode($value, true); if (is_array($obj)) { foreach ($obj as $k => $val) { if ($obj[$k]["properties"] == "*") { $table = new \app\models\Table($row['f_table_schema'] . "." . $row['f_table_name']); $distinctValues = $table->getGroupByAsArray($k); $obj[$k]["properties"] = json_encode($distinctValues["data"], JSON_NUMERIC_CHECK); } } $value = json_encode($obj); } else { $value = null; } } if ($parse) { if (($key == "fieldconf" || $key == "def" || $key == "class" || $key == "classwizard") && $value) { $value = json_decode($value); } } $arr = $this->array_push_assoc($arr, $key, $value); } $arr = $this->array_push_assoc($arr, "pkey", $primeryKey['attname']); $arr = $this->array_push_assoc($arr, "versioning", $versioning); if ($includeExtent == true) { $arr = $this->array_push_assoc($arr, "extent", $extent); } // Is indexed? if ($es) { $type = $row['f_table_name']; if (mb_substr($type, 0, 1, 'utf-8') == "_") { $type = "a" . $type; } $url = (App::$param['esHost'] ?: "http://127.0.0.1") . ":9200/{$this->postgisdb}_{$row['f_table_schema']}/{$type}/"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, true); // we want headers curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpcode == "200") { $arr = $this->array_push_assoc($arr, "indexed_in_es", true); } else { $arr = $this->array_push_assoc($arr, "indexed_in_es", false); } } // Session is sub-user we always check privileges if (isset($_SESSION) && $_SESSION['subuser']) { $privileges = (array) json_decode($row["privileges"]); if ($_SESSION['subuser'] == false || $_SESSION['subuser'] != false && $privileges[$_SESSION['usergroup'] ?: $_SESSION['subuser']] != "none" && $privileges[$_SESSION['usergroup'] ?: $_SESSION['subuser']] != false) { $response['data'][] = $arr; } elseif ($schema != false && $_SESSION['subuser'] == $schema) { $response['data'][] = $arr; } } else { $response['data'][] = $arr; } } $response['data'] = isset($response['data']) ? $response['data'] : array(); if (!isset($this->PDOerror)) { $response['auth'] = $auth ?: false; $response['success'] = true; $response['message'] = "geometry_columns_view fetched"; } else { $response['success'] = false; $response['message'] = $this->PDOerror[0]; $response['code'] = 401; } return $response; }