added categories to assetmanagement
This commit is contained in:
@@ -8,6 +8,7 @@ class AssetManagementController extends TTCrud
|
||||
// Simplified columns for better layout, details are in the 'assetDetails' slot
|
||||
protected array $columns = [
|
||||
['key' => 'assetDetails', 'text' => 'Gerät', 'modal' => false, 'table' => ['filter' => 'search', 'sortable' => true]],
|
||||
['key' => 'category', 'text' => 'Kategorie', 'modal' => false, 'table' => ['filter' => 'select', 'filterOptions' => []]],
|
||||
['key' => 'currentUser', 'text' => 'Status', 'modal' => false, 'table' => ['sortable' => false, 'filter' => false]],
|
||||
['key' => 'location', 'text' => 'Lagerort', 'required' => true, 'modal' => ['type' => 'text'], 'table' => ['filter' => 'search']],
|
||||
['key' => 'serviceDueDate', 'text' => 'Service fällig', 'required' => false, 'modal' => ['type' => 'date'], 'table' => ['filter' => 'date']],
|
||||
@@ -22,6 +23,15 @@ class AssetManagementController extends TTCrud
|
||||
$this->additionalJSVariables['ASSET_ADMIN'] = '0';
|
||||
$this->columns = array_filter($this->columns, fn($col) => $col['key'] !== 'actions');
|
||||
}
|
||||
|
||||
$categories = AssetManagementModel::getDistinctCategories();
|
||||
$categoryOptions = array_map(fn($cat) => ['value' => $cat, 'text' => $cat], $categories);
|
||||
foreach ($this->columns as &$column) {
|
||||
if ($column['key'] === 'category') {
|
||||
$column['table']['filterOptions'] = $categoryOptions;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,6 +292,18 @@ class AssetManagementController extends TTCrud
|
||||
self::returnJson(['success' => true, 'message' => 'Reservierung gelöscht.']);
|
||||
}
|
||||
|
||||
protected function getCategoriesAction()
|
||||
{
|
||||
$searchTerm = $this->request->q ?? '';
|
||||
$categories = AssetManagementModel::getDistinctCategories($searchTerm);
|
||||
|
||||
$result = array_map(function($category) {
|
||||
return ['value' => $category, 'text' => $category];
|
||||
}, $categories);
|
||||
|
||||
self::returnJson($result);
|
||||
}
|
||||
|
||||
protected function printLabelAction() {
|
||||
if (!$this->user->can('AssetAdmin')) {
|
||||
self::sendError("Permission denied", 403);
|
||||
|
||||
@@ -4,6 +4,7 @@ class AssetManagementModel extends TTCrudBaseModel {
|
||||
public int $id;
|
||||
public string $name;
|
||||
public ?string $description;
|
||||
public ?string $category;
|
||||
public ?int $mainImageId; // Renamed from imageId
|
||||
public ?string $imageIds; // Changed to JSON (will be a string in PHP)
|
||||
public string $assetNumber;
|
||||
@@ -35,8 +36,7 @@ class AssetManagementModel extends TTCrudBaseModel {
|
||||
foreach ($searchTerms as $term) {
|
||||
if (empty(trim($term))) continue;
|
||||
$escapedTerm = $db->real_escape_string($term);
|
||||
// For each term, search in name, assetNumber, and description.
|
||||
$searchConditions[] = "(`name` LIKE '%$escapedTerm%' OR `assetNumber` LIKE '%$escapedTerm%' OR `description` LIKE '%$escapedTerm%')";
|
||||
$searchConditions[] = "(`name` LIKE '%$escapedTerm%' OR `assetNumber` LIKE '%$escapedTerm%' OR `description` LIKE '%$escapedTerm%' OR `category` LIKE '%$escapedTerm%')";
|
||||
}
|
||||
|
||||
if (!empty($searchConditions)) {
|
||||
@@ -99,8 +99,8 @@ class AssetManagementModel extends TTCrudBaseModel {
|
||||
foreach ($searchTerms as $term) {
|
||||
if (empty(trim($term))) continue;
|
||||
$escapedTerm = $db->real_escape_string($term);
|
||||
// For each term, search in name, assetNumber, and description.
|
||||
$searchConditions[] = "(`name` LIKE '%$escapedTerm%' OR `assetNumber` LIKE '%$escapedTerm%' OR `description` LIKE '%$escapedTerm%')";
|
||||
// For each term, search in name, assetNumber, description, and category.
|
||||
$searchConditions[] = "(`name` LIKE '%$escapedTerm%' OR `assetNumber` LIKE '%$escapedTerm%' OR `description` LIKE '%$escapedTerm%' OR `category` LIKE '%$escapedTerm%')";
|
||||
}
|
||||
|
||||
if (!empty($searchConditions)) {
|
||||
@@ -128,4 +128,26 @@ class AssetManagementModel extends TTCrudBaseModel {
|
||||
|
||||
return $result->fetch_assoc()['count'];
|
||||
}
|
||||
|
||||
public static function getDistinctCategories(string $searchTerm = ''): array {
|
||||
$db = self::getDB();
|
||||
$table = self::getFullyQualifiedTable();
|
||||
|
||||
$sql = "SELECT DISTINCT `category` FROM $table WHERE `category` IS NOT NULL AND `category` != ''";
|
||||
|
||||
if (!empty($searchTerm)) {
|
||||
$escapedTerm = $db->real_escape_string($searchTerm);
|
||||
$sql .= " AND `category` LIKE '%$escapedTerm%'";
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY `category` ASC LIMIT 20";
|
||||
|
||||
$result = $db->query($sql);
|
||||
$categories = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$categories[] = $row['category'];
|
||||
}
|
||||
|
||||
return $categories;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user