mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-09-14 06:19:44 -04:00
refactor(helpers): add optional parameter to itemSortColumns for dynamic attribute handling
- Introduced `$definitionIds` parameter in `itemSortColumns` to allow pre-resolved attribute handling. - Updated `Items` controller to utilize the new parameter, improving code clarity and performance. - Simplified dynamic column management and minimized unnecessary queries. Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
This commit is contained in:
1 parent
926982b116
commit
e336fc245a
2 files changed
+11
-6
No files matched your search
@@ -111,13 +111,14 @@ class Items extends Secure_Controller
|
||||
$search = $this->request->getGet('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT);
|
||||
$offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT);
|
||||
$sort = $this->sanitizeSortColumn(itemSortColumns(), $this->request->getGet('sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 'items.item_id');
|
||||
$order = $this->request->getGet('order', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
$this->item_lib->set_item_location($this->request->getGet('stock_location'));
|
||||
|
||||
$definitionNames = $this->attribute->getDefinitionsByFlags(Attribute::SHOW_IN_ITEMS);
|
||||
$definitionNamesWithTypes = $this->attribute->getDefinitionsByFlags(Attribute::SHOW_IN_ITEMS, true);
|
||||
$definitionIds = array_keys($definitionNamesWithTypes);
|
||||
|
||||
$sort = $this->sanitizeSortColumn(itemSortColumns($definitionIds), $this->request->getGet('sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 'items.item_id');
|
||||
|
||||
$filters = [
|
||||
'start_date' => $this->request->getGet('start_date'),
|
||||
@@ -130,7 +131,7 @@ class Items extends Secure_Controller
|
||||
'search_custom' => false,
|
||||
'is_deleted' => false,
|
||||
'temporary' => false,
|
||||
'definition_ids' => array_keys($definitionNames)
|
||||
'definition_ids' => $definitionIds
|
||||
];
|
||||
|
||||
// Check if any filter is set in the multiselect dropdown
|
||||
|
||||
@@ -403,12 +403,16 @@ function item_headers(): array
|
||||
/**
|
||||
* Get all sortable column keys for items table, including dynamic attribute columns.
|
||||
*
|
||||
* @param array|null $definitionIds Attribute definition IDs to append as sortable columns.
|
||||
* If null, resolved via a query against SHOW_IN_ITEMS.
|
||||
* @return array Array of column headers in the format sanitizeSortColumn() expects
|
||||
*/
|
||||
function itemSortColumns(): array
|
||||
function itemSortColumns(?array $definitionIds = null): array
|
||||
{
|
||||
$attribute = model(Attribute::class);
|
||||
$definitionIds = array_keys($attribute->getDefinitionsByFlags($attribute::SHOW_IN_ITEMS));
|
||||
if ($definitionIds === null) {
|
||||
$attribute = model(Attribute::class);
|
||||
$definitionIds = array_keys($attribute->getDefinitionsByFlags($attribute::SHOW_IN_ITEMS));
|
||||
}
|
||||
|
||||
$headers = item_headers();
|
||||
|
||||
|
||||
Reference in new issue
Block a user