Skip to content

Commit

Permalink
#3149 - Sorting for adv search more - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Dec 29, 2021
1 parent 73b89e8 commit ad73a44
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
18 changes: 15 additions & 3 deletions inc/classes/BxDolFormQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,23 @@ static public function removeFormFields($sModule)
$oDb->query("DELETE FROM `sys_form_fields_ids` WHERE `module` = :module", $aBindings);
}

static public function getFormInputs($sObject)
static public function getFormInputs($sObject, $mDisplay = '')
{
$oDb = BxDolDb::getInstance();
$sQuery = $oDb->prepare("SELECT * FROM `sys_form_inputs` WHERE `object` = ?", $sObject);
return $oDb->getAll($sQuery);
if ($mDisplay == ''){
$sQuery = $oDb->prepare("SELECT * FROM `sys_form_inputs` WHERE `object` = ?", $sObject);
return $oDb->getAll($sQuery);
}
else{
if (!is_array($mDisplay))
$mDisplay = [$mDisplay];
$sQuery = $oDb->prepare("
SELECT DISTINCT `sys_form_inputs`.* FROM `sys_form_inputs`
INNER JOIN `sys_form_display_inputs` ON `sys_form_display_inputs`.`input_name` =`sys_form_inputs`.`name`
WHERE `sys_form_display_inputs`.`display_name` IN (" . $oDb->implode_escape($mDisplay) . ")
AND `sys_form_inputs`.`object` = ? AND `sys_form_display_inputs`.`active` = 1", $sObject);
return $oDb->getAll($sQuery);
}
}
}

Expand Down
19 changes: 16 additions & 3 deletions modules/base/general/classes/BxBaseModGeneralModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,20 @@ public function serviceGetSortableFieldsExtended($aInputsAdd = array())

$aSortableFields = [];

$aInputs = BxDolFormQuery::getFormInputs($CNF['OBJECT_FORM_ENTRY']);
$aDisplays = [];
if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
$aDisplays[] = $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'];
}
if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
$aDisplays[] = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
}

$aInputsAll = BxDolFormQuery::getFormInputs($CNF['OBJECT_FORM_ENTRY']);
foreach($aInputsAll as $aInput){
$aInputsAll[$aInput['name']] = $aInput;
}

$aInputs = BxDolFormQuery::getFormInputs($CNF['OBJECT_FORM_ENTRY'], $aDisplays);
foreach($aInputs as $aInput){
$aInputs[$aInput['name']] = $aInput;
if ($aInput['type'] == 'text'){
Expand All @@ -388,13 +401,13 @@ public function serviceGetSortableFieldsExtended($aInputsAdd = array())
foreach($aSortableFields as $sSortableField){
$aResult[$sSortableField . '_asc'] = [
'name' => $sSortableField,
'caption' => $aInputs[$sSortableField]['caption'],
'caption' => $aInputsAll[$sSortableField]['caption'],
'direction' => 'asc'
];

$aResult[$sSortableField . '_desc'] = [
'name' => $sSortableField,
'caption' => $aInputs[$sSortableField]['caption'],
'caption' => $aInputsAll[$sSortableField]['caption'],
'direction' => 'desc'
];
}
Expand Down

0 comments on commit ad73a44

Please sign in to comment.