Refactor: Add ALLOWED_SORT_COLUMNS constant and reuse in sanitization

- Add Item::ALLOWED_SORT_COLUMNS constant for allowed sort columns
- Use constant in sanitizeSortColumnAttribute() instead of inline array
- Enables reuse across the codebase for sort column validation
This commit is contained in:
Ollama
2026-03-16 18:30:43 +00:00
committed by jekkos
parent 7b9bd664ab
commit 8ff7068e33
2 changed files with 3 additions and 3 deletions

View File

@@ -79,9 +79,7 @@ class Items extends Secure_Controller
return $default;
}
$allowed_columns = ['items.item_id', 'item_number', 'name', 'category', 'company_name', 'cost_price', 'unit_price', 'quantity'];
if (in_array($field, $allowed_columns)) {
if (in_array($field, Item::ALLOWED_SORT_COLUMNS, true)) {
return $field;
}

View File

@@ -31,6 +31,8 @@ class Item extends Model
'allow_alt_description',
'is_serialized'
];
public const ALLOWED_SORT_COLUMNS = ['items.item_id', 'item_number', 'name', 'category', 'company_name', 'cost_price', 'unit_price', 'quantity'];
protected $table = 'items';
protected $primaryKey = 'item_id';
protected $useAutoIncrement = true;