|
@@ -374,13 +374,23 @@ class AclQueryFeatures {
|
|
|
// TODO: 'in' operator? // $this->_query->where($pkField, 'in', "");
|
|
// TODO: 'in' operator? // $this->_query->where($pkField, 'in', "");
|
|
|
$sqlPk = $this->getAclSqlPrimaryKeyField();
|
|
$sqlPk = $this->getAclSqlPrimaryKeyField();
|
|
|
$sqlBackRefPk = DB::getPDO()->quote($backRef['primaryKey']);
|
|
$sqlBackRefPk = DB::getPDO()->quote($backRef['primaryKey']);
|
|
|
- $this->_query->where("
|
|
|
|
|
- t.{$sqlPk} in (
|
|
|
|
|
- select refTable.REMOTE_PRIMARY_KEY
|
|
|
|
|
- from `{$refTable}` refTable
|
|
|
|
|
- where refTable.PRIMARY_KEY = {$sqlBackRefPk}
|
|
|
|
|
- )
|
|
|
|
|
- ");
|
|
|
|
|
|
|
+ $limit = V::get('limit', 10, $this->_params, 'int');
|
|
|
|
|
+ $offset = V::get('limitstart', 0, $this->_params, 'int');
|
|
|
|
|
+ DBG::log(['limit' => $limit, 'offset' => $offset], 'array', "DBG: limit with __backRef \$this->_params");
|
|
|
|
|
+ $sqlLimit = "limit {$limit} offset {$offset}";
|
|
|
|
|
+ // $this->_query->where("
|
|
|
|
|
+ // t.{$sqlPk} in (
|
|
|
|
|
+ // select refTable.REMOTE_PRIMARY_KEY
|
|
|
|
|
+ // from `{$refTable}` refTable
|
|
|
|
|
+ // where refTable.PRIMARY_KEY = {$sqlBackRefPk}
|
|
|
|
|
+ // order by refTable.REMOTE_PRIMARY_KEY DESC -- TODO refTable.SORT_PRIO
|
|
|
|
|
+ // -- {$sqlLimit} -- BUG MariaDB not support limit in subquery
|
|
|
|
|
+ // )
|
|
|
|
|
+ // ");
|
|
|
|
|
+ // TODO: convert `where t.ID in ( ... )` into `join` and `order by`
|
|
|
|
|
+ // join `CRM__#REF_TABLE__120_VIEW` refTable on (refTable.REMOTE_PRIMARY_KEY = t.ID and refTable.PRIMARY_KEY = '37' )
|
|
|
|
|
+ $this->_query->join($refTable, 'refTable', [ 'rawJoin' => "t.{$sqlPk} = refTable.REMOTE_PRIMARY_KEY and refTable.PRIMARY_KEY = {$sqlBackRefPk}" ]);
|
|
|
|
|
+ // moved to getItems: $this->_query->orderBy("refTable.REMOTE_PRIMARY_KEY DESC"); // TODO: order by refTable.SORT_PRIO
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('__childRef', $this->_params)) {
|
|
if (array_key_exists('__childRef', $this->_params)) {
|
|
@@ -470,6 +480,9 @@ class AclQueryFeatures {
|
|
|
// 'order_dir' => 'desc',
|
|
// 'order_dir' => 'desc',
|
|
|
// TODO: sortBy from wfs query
|
|
// TODO: sortBy from wfs query
|
|
|
$sortBy = ($this->hasParam('sortBy')) ? $this->getParam('sortBy') : null;
|
|
$sortBy = ($this->hasParam('sortBy')) ? $this->getParam('sortBy') : null;
|
|
|
|
|
+ if (!$sortBy && array_key_exists('__backRef', $this->_params)) {
|
|
|
|
|
+ $sortBy = "refTable.REMOTE_PRIMARY_KEY DESC"; // TODO: order by refTable.SORT_PRIO
|
|
|
|
|
+ }
|
|
|
if (!$sortBy) {
|
|
if (!$sortBy) {
|
|
|
$sortBy = $this->hasParam('order_by')
|
|
$sortBy = $this->hasParam('order_by')
|
|
|
? ( $this->hasParam('order_dir')
|
|
? ( $this->hasParam('order_dir')
|
|
@@ -617,6 +630,7 @@ class AclQueryFeatures {
|
|
|
select r.REMOTE_PRIMARY_KEY
|
|
select r.REMOTE_PRIMARY_KEY
|
|
|
from `{$refTable}` r
|
|
from `{$refTable}` r
|
|
|
where r.PRIMARY_KEY = '{$primaryKey}'
|
|
where r.PRIMARY_KEY = '{$primaryKey}'
|
|
|
|
|
+ order by r.REMOTE_PRIMARY_KEY DESC -- TODO r.SORT_PRIO
|
|
|
limit {$refLimitPlus1}
|
|
limit {$refLimitPlus1}
|
|
|
");
|
|
");
|
|
|
DBG::log($xlinks, 'array', "add remote xlink's for '{$fieldName}' \$items[{$primaryKey}]");
|
|
DBG::log($xlinks, 'array', "add remote xlink's for '{$fieldName}' \$items[{$primaryKey}]");
|