- Create knowledgecenter_category_einricht, _fachbereich, knowledgecenter_post_einricht, knowledgecenter_post_fachbereich tables; extend task_target_rule with main_einricht_id and main_bereich_id columns - Middleware: load main_einricht_id/main_bereich_id from main_contact_department, expose $allowedEinrichts/$allowedFachbereiche globals (same pattern as existing 3 types) - Ajax: add update_category/post_einrichts/fachbereiche functions, extend update_category_links() and search filter query - Views: add einricht/fachbereich LEFT JOINs and WHERE filters in all 5 query sites (categories_posts_listform, category_posts_widget, post_announcement_listform, post_cardform userHasAccessForPost, Ajax search) - post_cardform_settings: add Einrichtungen/Fachbereiche tagify pickers with save/load - Tasks: add listEinrichts/listFachbereiche to repo+service, add UI selects in task_form, extend target-rule normalization and upsert builder, extend AssignmentResolverService scope loading and matchesAnyRule to include einricht/fachbereich matching Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
175 lines
5.0 KiB
PHP
175 lines
5.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
class TaskLookupRepository
|
|
{
|
|
public function listTaskCategories(bool $includeInactive = false): array
|
|
{
|
|
$sql = 'SELECT id, name, slug, sort_order, active
|
|
FROM task_category';
|
|
if (!$includeInactive) {
|
|
$sql .= ' WHERE active = 1';
|
|
}
|
|
$sql .= ' ORDER BY sort_order ASC, name ASC';
|
|
|
|
return TaskCertDb::fetchAll(
|
|
$sql
|
|
);
|
|
}
|
|
|
|
public function listMandants(): array
|
|
{
|
|
return TaskCertDb::fetchAll(
|
|
'SELECT id, description FROM main_mandant ORDER BY description ASC'
|
|
);
|
|
}
|
|
|
|
public function listDepartments(): array
|
|
{
|
|
return TaskCertDb::fetchAll(
|
|
'SELECT id, description FROM main_department ORDER BY description ASC'
|
|
);
|
|
}
|
|
|
|
public function listRoles(): array
|
|
{
|
|
return TaskCertDb::fetchAll(
|
|
'SELECT id, description FROM main_role ORDER BY description ASC'
|
|
);
|
|
}
|
|
|
|
public function listEinrichts(): array
|
|
{
|
|
return TaskCertDb::fetchAll(
|
|
'SELECT id, description FROM organigramm_einricht ORDER BY description ASC'
|
|
);
|
|
}
|
|
|
|
public function listFachbereiche(): array
|
|
{
|
|
return TaskCertDb::fetchAll(
|
|
'SELECT id, description FROM organogramm_space ORDER BY description ASC'
|
|
);
|
|
}
|
|
|
|
public function listActiveContacts(): array
|
|
{
|
|
return TaskCertDb::fetchAll(
|
|
'SELECT id, name, email FROM main_contact WHERE active = 1 ORDER BY name ASC'
|
|
);
|
|
}
|
|
|
|
public function searchContacts(string $term, int $limit = 15): array
|
|
{
|
|
$term = trim($term);
|
|
if ($term === '' || mb_strlen($term) < 2) {
|
|
return [];
|
|
}
|
|
|
|
$limit = max(1, min(50, $limit));
|
|
$likeTerm = '%' . $term . '%';
|
|
|
|
return TaskCertDb::fetchAll(
|
|
'SELECT id, name, email
|
|
FROM main_contact
|
|
WHERE active = 1
|
|
AND (name LIKE ? OR email LIKE ?)
|
|
ORDER BY name ASC
|
|
LIMIT ' . $limit,
|
|
'ss',
|
|
[$likeTerm, $likeTerm]
|
|
);
|
|
}
|
|
|
|
public function getContactById(int $contactId): ?array
|
|
{
|
|
if ($contactId <= 0) {
|
|
return null;
|
|
}
|
|
|
|
$rows = TaskCertDb::fetchAll(
|
|
'SELECT id, name, email FROM main_contact WHERE id = ? AND active = 1',
|
|
'i',
|
|
[$contactId]
|
|
);
|
|
|
|
return $rows[0] ?? null;
|
|
}
|
|
|
|
public function listKnowledgePosts(int $languageId, int $limit = 500): array
|
|
{
|
|
$languageId = $languageId > 0 ? $languageId : 1;
|
|
$limit = max(1, min(1000, $limit));
|
|
|
|
return TaskCertDb::fetchAll(
|
|
'SELECT
|
|
p.id,
|
|
COALESCE(NULLIF(v.title, ""), CONCAT("Beitrag #", p.id)) AS title
|
|
FROM knowledgecenter_posts p
|
|
LEFT JOIN knowledgecenter_post_versions v
|
|
ON v.post_id = p.id
|
|
AND v.language_id = ?
|
|
AND v.version_number = (
|
|
SELECT MAX(v2.version_number)
|
|
FROM knowledgecenter_post_versions v2
|
|
WHERE v2.post_id = p.id
|
|
AND v2.language_id = ?
|
|
)
|
|
ORDER BY p.id DESC
|
|
LIMIT ' . $limit,
|
|
'ii',
|
|
[$languageId, $languageId]
|
|
);
|
|
}
|
|
|
|
public function mapKnowledgePostTitlesByIds(int $languageId, array $postIds): array
|
|
{
|
|
$languageId = $languageId > 0 ? $languageId : 1;
|
|
$ids = array_values(array_unique(array_filter(array_map('intval', $postIds), static fn(int $id): bool => $id > 0)));
|
|
if ($ids === []) {
|
|
return [];
|
|
}
|
|
|
|
$placeholders = implode(',', array_fill(0, count($ids), '?'));
|
|
$types = 'ii' . str_repeat('i', count($ids));
|
|
$params = array_merge([$languageId, $languageId], $ids);
|
|
|
|
$rows = TaskCertDb::fetchAll(
|
|
'SELECT
|
|
p.id,
|
|
COALESCE(NULLIF(v.title, ""), CONCAT("Beitrag #", p.id)) AS title
|
|
FROM knowledgecenter_posts p
|
|
LEFT JOIN knowledgecenter_post_versions v
|
|
ON v.post_id = p.id
|
|
AND v.language_id = ?
|
|
AND v.version_number = (
|
|
SELECT MAX(v2.version_number)
|
|
FROM knowledgecenter_post_versions v2
|
|
WHERE v2.post_id = p.id
|
|
AND v2.language_id = ?
|
|
)
|
|
WHERE p.id IN (' . $placeholders . ')',
|
|
$types,
|
|
$params
|
|
);
|
|
|
|
$map = [];
|
|
foreach ($rows as $row) {
|
|
$id = (int) ($row['id'] ?? 0);
|
|
if ($id <= 0) {
|
|
continue;
|
|
}
|
|
|
|
$map[$id] = trim((string) ($row['title'] ?? ('Beitrag #' . $id)));
|
|
}
|
|
|
|
foreach ($ids as $id) {
|
|
if (!isset($map[$id])) {
|
|
$map[$id] = 'Beitrag #' . $id;
|
|
}
|
|
}
|
|
|
|
return $map;
|
|
}
|
|
}
|