|
|
@@ -161,22 +161,27 @@ class Data_Source {
|
|
|
return $this->_fieldOwner;
|
|
|
}
|
|
|
|
|
|
- function _get_sql_cols() {
|
|
|
- $sql_cols = "t.*";
|
|
|
+ function _getSqlCols($colsList = null) {
|
|
|
+ $sqlCols = "t.*";
|
|
|
if (!empty($this->_cols)) {
|
|
|
- $sql_cols_arr = array();
|
|
|
- foreach ($this->_cols as $k_field => $v_field_label) {
|
|
|
- if ($this->isGeomField($k_field)) {
|
|
|
- $sqlFld = "AsWKT(t.`{$k_field}`) as {$k_field}";
|
|
|
+ $sqlColsList = array();
|
|
|
+ if (null === $colsList || empty($colsList)) {
|
|
|
+ $colsList = array_keys($this->_cols);
|
|
|
+ }
|
|
|
+ foreach ($colsList as $fieldName) {
|
|
|
+ if (!array_key_exists($fieldName, $this->_cols)) throw new Exception("Field not exists '{$fieldName}'!");
|
|
|
+
|
|
|
+ if ($this->isGeomField($fieldName)) {
|
|
|
+ $sqlFld = "AsWKT(t.`{$fieldName}`) as {$fieldName}";
|
|
|
} else {
|
|
|
- $sqlFld = "t.`{$k_field}`";
|
|
|
+ $sqlFld = "t.`{$fieldName}`";
|
|
|
}
|
|
|
- $sql_cols_arr[] = $sqlFld;
|
|
|
+ $sqlColsList[] = $sqlFld;
|
|
|
}
|
|
|
- $sql_cols = implode(", ", $sql_cols_arr);
|
|
|
+ $sqlCols = implode(", ", $sqlColsList);
|
|
|
}
|
|
|
-if(V::get('DBG_DS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql_cols (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql_cols);echo'</pre>'."\n\n";}
|
|
|
- return $sql_cols;
|
|
|
+ DBG::_('DBG_DS', '>0', "sqlCols", $sqlCols, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ return $sqlCols;
|
|
|
}
|
|
|
|
|
|
public function setAccessFltrAllowed($isAccessFltrAllowed) {
|
|
|
@@ -563,7 +568,7 @@ if(V::get('DBG_DS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
|
|
|
public function getItem($primaryKey) {
|
|
|
$primaryKeyField = $this->getPrimaryKeyField();
|
|
|
$ret = null;
|
|
|
- $sql_cols = $this->_get_sql_cols();
|
|
|
+ $sql_cols = $this->_getSqlCols();
|
|
|
$primaryKey = intval($primaryKey);// TODO: validate $primaryKey
|
|
|
$sql = "select {$sql_cols}
|
|
|
from `{$this->_tbl}` as t
|
|
|
@@ -585,10 +590,13 @@ if(V::get('DBG_DS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
|
|
|
$primaryKeyField = $this->getPrimaryKeyField();
|
|
|
$items = array();
|
|
|
$sql = new stdClass();
|
|
|
+ $sql->_cols = V::get('cols', null, $params);
|
|
|
+ if (!is_array($sql->_cols) || empty($sql->_cols)) {
|
|
|
+ $sql->_cols = null;
|
|
|
+ }
|
|
|
$sql->limit = V::get('limit', $this->_default_sql_limit, $params, 'int');
|
|
|
$sql->offset = V::get('limitstart', 0, $params, 'int');
|
|
|
$sql->orderBy = '';
|
|
|
- $sql->_orderBy = V::get('order_by', '', $params);
|
|
|
$sql->_sortBy = V::get('sortBy', '', $params);
|
|
|
if ($sql->_sortBy) {// ID A,COL_X D,COL_Y A,...
|
|
|
$sql->_sortByList = array();
|
|
|
@@ -629,8 +637,8 @@ if(V::get('DBG_DS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- $sql->cols = $this->_get_sql_cols();
|
|
|
$sql->where = $this->_parseSqlWhere($params);
|
|
|
+ $sql->cols = $this->_getSqlCols($sql->_cols);
|
|
|
$sql->query = "select {$sql->cols}
|
|
|
from `{$this->_tbl}` t
|
|
|
where {$sql->where}
|
|
|
@@ -652,7 +660,7 @@ if(V::get('DBG_DS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
|
|
|
public function getHistItems($id, $params = array()) {
|
|
|
$ret = array();
|
|
|
$sql_tbl = $this->_tbl . "_HIST";
|
|
|
- $sql_cols = $this->_get_sql_cols();
|
|
|
+ $sql_cols = $this->_getSqlCols();
|
|
|
$sql_where = "t.`ID_USERS2`='{$id}'";
|
|
|
|
|
|
$paramNotEmptyFlds = V::get('notEmptyFlds', '', $params);
|