Skip to content

Commit

Permalink
Implemented direction of sorting.
Browse files Browse the repository at this point in the history
  • Loading branch information
arnemorken committed Feb 6, 2022
1 parent 8ab0fad commit a3e7e7e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
15 changes: 11 additions & 4 deletions data/anyTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
* - "idKeyMetaTable": The id key used in the meta table, "event_id" or "user_id".
* - "nameKey": The name key used by the client and in the table, e.g. "event_name" or "login_name".
* - "orderBy": The field to sort by. e.g. "event_date_start".
* - "orderDir": The direction of the sort, "ASC" or "DESC".
* - "metaId": The name of the id foeld in the meta table, e.g. "meta_id" or "umeta_id".
* - "fields": An array containing the field names of the table.
* - "fieldsMeta": An array containing the name of the meta keys of the meta table.
Expand Down Expand Up @@ -146,6 +147,7 @@ class anyTable extends dbTable
$mFilters = null,
$mPermission = null,
$mOrderBy = null,
$mOrderDir = "ASC",
$mSortFunction = null;

protected $mInsertSuccessMsg = "",
Expand Down Expand Up @@ -228,7 +230,8 @@ private function initProperties($defsOrType)
$this->mIdKeyTable = $defsOrType["idKeyTable"];
$this->mIdKeyMetaTable = $defsOrType["idKeyMetaTable"];
$this->mNameKey = $defsOrType["nameKey"];
$this->mOrderBy = $defsOrType["orderBy"];
$this->mOrderBy = isset($defsOrType["orderBy"]) ? $defsOrType["orderBy"] : null;
$this->mOrderDir = isset($defsOrType["orderDir"]) ? $defsOrType["orderDir"] : "ASC";
$this->mMetaId = $defsOrType["metaId"];

// Set table fields, meta table fields and user link table fields
Expand Down Expand Up @@ -795,8 +798,11 @@ protected function dbSearchList(&$data,$skipOwnId=false,$flat=false,$simple=fals
return true; // We do not have subusers (user table does not have parent_id field) TODO! Neccessary?
// Build and execute the full statement
if (Parameters::get("order"))
if (Parameters::get("order")) {
$this->mOrderBy = ltrim(Parameters::get("order"));
if (Parameters::get("dir"))
$this->mOrderDir = ltrim(Parameters::get("dir"));
}
$partial_stmt = $this->dbPrepareSearchListStmt($skipOwnId);
$limit = $this->findLimit();
$stmt = $partial_stmt.$limit;
Expand Down Expand Up @@ -999,11 +1005,12 @@ protected function findListWhere($skipOwnId=false)
return $where;
} // findListWhere

protected function findListOrderBy($sort="ASC")
protected function findListOrderBy()
{
if (!isset($this->mOrderBy))
return "";
$ob = "ORDER BY ".$this->getTableName().".".$this->mOrderBy." ".$sort." ";
$dir = $this->mOrderDir ? $this->mOrderDir : "";
$ob = "ORDER BY ".$this->getTableName().".".$this->mOrderBy." ".$dir." ";
return $ob;
} // findListOrderBy

Expand Down
2 changes: 1 addition & 1 deletion data/plugins/group/groupTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function initFilters($filters)
/////////////////////// Database query fragments ////////////////////////////
/////////////////////////////////////////////////////////////////////////////

protected function findListOrderBy($sort="ASC")
protected function findListOrderBy()
{
return "ORDER BY ".$this->getTableName().".group_sort_order,".
$this->getTableName().".group_type,".
Expand Down
3 changes: 2 additions & 1 deletion view/anyModel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 37 additions & 22 deletions view/anyView.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a3e7e7e

Please sign in to comment.