Skip to content

Commit

Permalink
refactor(formanswer): cleaner SQL request
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Sep 24, 2021
1 parent 6e6ee2b commit f8347be
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,24 @@ public static function getMyLastAnswersAsValidator($limit = 5) : DBMysqlIterator
$formTable = PluginFormcreatorForm::getTable();
$validatorTable = PluginFormcreatorForm_Validator::getTable();
$formFk = PluginFormcreatorForm::getForeignKeyField();
$where = [
'OR' => [
[
'AND' => [
"$validatorTable.itemtype" => User::class,
"$validatorTable.items_id" => $userId,
]
],
]
];
if (count($groupIdList) > 0) {
$where['OR'][] = [
'AND' => [
"$validatorTable.itemtype" => Group::class,
"$validatorTable.items_id" => $groupIdList,
]
];
}
$request = [
'SELECT' => [
$formTable => ['name'],
Expand All @@ -1467,26 +1485,7 @@ public static function getMyLastAnswersAsValidator($limit = 5) : DBMysqlIterator
]
]
],
'WHERE' => [
'OR' => [
[
'AND' => [
"$formTable.validation_required" => 1,
"$validatorTable.itemtype" => User::class,
"$validatorTable.items_id" => $userId,
"$formAnswerTable.users_id_validator" => $userId
]
],
[
'AND' => [
"$formTable.validation_required" => 2,
"$validatorTable.itemtype" => Group::class,
"$validatorTable.items_id" => $groupIdList + ['NULL', '0', ''],
"$formAnswerTable.groups_id_validator" => $groupIdList + ['NULL', '0', ''],
]
]
]
],
'WHERE' => $where,
'ORDER' => [
"$formAnswerTable.status ASC",
"$formAnswerTable.request_date DESC",
Expand Down

0 comments on commit f8347be

Please sign in to comment.