Skip to content
Code-Schnipsel Gruppen Projekte
Commit 13e48385 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

Merge branch 'dev' of https://dev.quiqqer.com/quiqqer/customer into dev

Übergeordnete 365d84cb 6c4b4282
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -49,18 +49,15 @@ function ($params) {
$sortOn = 'username';
$sortBy = 'ASC';
if (isset($params['sortOn'])) {
if (!empty($params['sortOn'])) {
$sortOn = $params['sortOn'];
}
if (isset($params['sortBy'])) {
if (!empty($params['sortBy'])) {
$sortBy = $params['sortBy'];
}
if (isset($params['sortOn'])) {
$Search->order($sortOn.' '.$sortBy);
}
$Search->order($sortOn, $sortBy);
// exec
return $Search->searchForGrid();
......
......@@ -19,7 +19,7 @@ class Search extends Singleton
/**
* @var string
*/
protected $order = 'id DESC';
protected $order = 'user_id DESC';
/**
* @var array
......@@ -84,6 +84,7 @@ public function getAllowedFields()
'active',
'deleted',
'su',
'customerId',
'regdate',
'lastvisit',
......@@ -185,7 +186,7 @@ protected function parseListForGrid($data)
$Address = null;
try {
$User = $Users->get((int)$entry['id']);
$User = $Users->get((int)$entry['user_id']);
$Address = $User->getStandardAddress();
} catch (QUI\Exception $Exception) {
}
......@@ -274,7 +275,7 @@ protected function getQueryCount()
protected function getQuery($count = false)
{
$table = $this->table();
$order = 'users.'.$this->order;
$order = $this->order;
// limit
$limit = '';
......@@ -537,7 +538,7 @@ protected function executeQueryParams($queryData = [])
return $Statement->fetchAll(\PDO::FETCH_ASSOC);
} catch (\Exception $Exception) {
QUI\System\Log::writeRecursive($Exception);
QUI\System\Log::writeException($Exception);
QUI\System\Log::writeRecursive($query);
QUI\System\Log::writeRecursive($binds);
throw new QUI\Exception('Something went wrong');
......@@ -547,25 +548,48 @@ protected function executeQueryParams($queryData = [])
/**
* Set the order
*
* @param $order
* @param string $col - Order columny
* @param string $direction (optional) - Order direction [default: ASC]
* @return void
*/
public function order($order)
public function order(string $col, string $direction = 'ASC')
{
$allowed = [];
foreach ($this->getAllowedFields() as $field) {
$allowed[] = $field;
$allowed[] = $field.' ASC';
$allowed[] = $field.' asc';
$allowed[] = $field.' DESC';
$allowed[] = $field.' desc';
if (!\in_array($col, $this->getAllowedFields())) {
return;
}
$order = \trim($order);
$allowed = \array_flip($allowed);
$direction = \mb_strtoupper($direction);
if ($direction !== 'ASC') {
$direction = 'DESC';
}
if (isset($allowed[$order])) {
$this->order = $order;
switch ($col) {
case 'id':
$this->order = 'user_id '.$direction;
break;
case 'email':
case 'username':
case 'usergroup':
case 'usertitle':
case 'lang':
case 'birthday':
case 'active':
case 'deleted':
case 'su':
case 'customerId':
$this->order = 'users.`'.$col.'` '.$direction;
break;
case 'firstname':
case 'lastname':
$this->order = 'users.`'.$col.'` '.$direction.', ad.`'.$col.'` '.$direction;
break;
case 'company':
$this->order = 'ad.`'.$col.'` '.$direction;
break;
}
}
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren