Add tags support for domains with filtering and bulk actions
Introduces a 'tags' field to the domains table and UI, allowing users to organize domains with custom tags. Adds tag input and display to create, edit, bulk-add, and view pages, as well as tag-based filtering and bulk tag management (add/remove) in the domain list. Updates backend validation, controller logic, and migrations to support tags, including a new migration and index for efficient tag searches.
This commit is contained in:
@@ -178,6 +178,17 @@ class Domain extends Model
|
||||
});
|
||||
}
|
||||
|
||||
// Apply tag filter
|
||||
if (!empty($filters['tag'])) {
|
||||
$domains = array_filter($domains, function($domain) use ($filters) {
|
||||
if (empty($domain['tags'])) {
|
||||
return false;
|
||||
}
|
||||
$domainTags = array_map('trim', explode(',', $domain['tags']));
|
||||
return in_array($filters['tag'], $domainTags);
|
||||
});
|
||||
}
|
||||
|
||||
// Get total count after filtering
|
||||
$totalDomains = count($domains);
|
||||
|
||||
@@ -210,5 +221,27 @@ class Domain extends Model
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all unique tags from all domains
|
||||
*/
|
||||
public function getAllTags(): array
|
||||
{
|
||||
$stmt = $this->db->query("SELECT DISTINCT tags FROM domains WHERE tags IS NOT NULL AND tags != ''");
|
||||
$results = $stmt->fetchAll();
|
||||
|
||||
$allTags = [];
|
||||
foreach ($results as $row) {
|
||||
if (!empty($row['tags'])) {
|
||||
$tags = array_map('trim', explode(',', $row['tags']));
|
||||
$allTags = array_merge($allTags, $tags);
|
||||
}
|
||||
}
|
||||
|
||||
// Return unique, sorted tags
|
||||
$allTags = array_unique($allTags);
|
||||
sort($allTags);
|
||||
return $allTags;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user