Add Einrichtung and Fachbereich as permission/filter types (knowledgecenter + tasks)

- 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>
This commit is contained in:
2026-06-22 11:03:53 +02:00
parent 8fa061afac
commit eb3aa75615
13 changed files with 477 additions and 82 deletions

View File

@@ -196,6 +196,8 @@ function task_cert_normalize_target_selection(array $targetRules, array $targetO
'mandant_ids' => [],
'department_ids' => [],
'role_ids' => [],
'einricht_ids' => [],
'fachbereich_ids' => [],
'override_include_contact_ids' => [],
'override_exclude_contact_ids' => [],
'override_include_reason' => '',
@@ -206,6 +208,8 @@ function task_cert_normalize_target_selection(array $targetRules, array $targetO
$mandantId = (int) ($rule['main_mandant_id'] ?? 0);
$departmentId = (int) ($rule['main_department_id'] ?? 0);
$roleId = (int) ($rule['main_role_id'] ?? 0);
$einrichtId = (int) ($rule['main_einricht_id'] ?? 0);
$fachbereichId = (int) ($rule['main_bereich_id'] ?? 0);
if ($mandantId > 0) {
$selection['mandant_ids'][] = $mandantId;
@@ -218,6 +222,14 @@ function task_cert_normalize_target_selection(array $targetRules, array $targetO
if ($roleId > 0) {
$selection['role_ids'][] = $roleId;
}
if ($einrichtId > 0) {
$selection['einricht_ids'][] = $einrichtId;
}
if ($fachbereichId > 0) {
$selection['fachbereich_ids'][] = $fachbereichId;
}
}
foreach ($targetOverrides as $override) {
@@ -246,6 +258,8 @@ function task_cert_normalize_target_selection(array $targetRules, array $targetO
'mandant_ids',
'department_ids',
'role_ids',
'einricht_ids',
'fachbereich_ids',
'override_include_contact_ids',
'override_exclude_contact_ids',
];

View File

@@ -212,10 +212,14 @@ $buildTargetRules = static function (): array {
$mandantIds = array_values(array_unique(TaskCertRequest::postIntArray('target_mandant_ids')));
$departmentIds = array_values(array_unique(TaskCertRequest::postIntArray('target_department_ids')));
$roleIds = array_values(array_unique(TaskCertRequest::postIntArray('target_role_ids')));
$einrichtIds = array_values(array_unique(TaskCertRequest::postIntArray('target_einricht_ids')));
$fachbereichIds = array_values(array_unique(TaskCertRequest::postIntArray('target_fachbereich_ids')));
$mandantValues = $mandantIds === [] ? [0] : $mandantIds;
$departmentValues = $departmentIds === [] ? [0] : $departmentIds;
$roleValues = $roleIds === [] ? [0] : $roleIds;
$einrichtValues = $einrichtIds === [] ? [0] : $einrichtIds;
$fachbereichValues = $fachbereichIds === [] ? [0] : $fachbereichIds;
$rules = [];
$count = 0;
@@ -224,20 +228,27 @@ $buildTargetRules = static function (): array {
foreach ($mandantValues as $mandantId) {
foreach ($departmentValues as $departmentId) {
foreach ($roleValues as $roleId) {
if ((int) $mandantId === 0 && (int) $departmentId === 0 && (int) $roleId === 0) {
continue;
}
foreach ($einrichtValues as $einrichtId) {
foreach ($fachbereichValues as $fachbereichId) {
if ((int) $mandantId === 0 && (int) $departmentId === 0 && (int) $roleId === 0
&& (int) $einrichtId === 0 && (int) $fachbereichId === 0) {
continue;
}
$rules[] = [
'main_mandant_id' => (int) $mandantId ?: null,
'main_department_id' => (int) $departmentId ?: null,
'main_role_id' => (int) $roleId ?: null,
'active' => 1,
];
$rules[] = [
'main_mandant_id' => (int) $mandantId ?: null,
'main_department_id' => (int) $departmentId ?: null,
'main_role_id' => (int) $roleId ?: null,
'main_einricht_id' => (int) $einrichtId ?: null,
'main_bereich_id' => (int) $fachbereichId ?: null,
'active' => 1,
];
$count++;
if ($count > $maxRules) {
throw new RuntimeException('Zu viele Regelkombinationen. Bitte Auswahl einschränken.');
$count++;
if ($count > $maxRules) {
throw new RuntimeException('Zu viele Regelkombinationen. Bitte Auswahl einschränken.');
}
}
}
}
}

View File

@@ -60,6 +60,8 @@ $targetSelection = array_merge([
'mandant_ids' => [],
'department_ids' => [],
'role_ids' => [],
'einricht_ids' => [],
'fachbereich_ids' => [],
'override_include_contact_ids' => [],
'override_exclude_contact_ids' => [],
'override_include_reason' => '',
@@ -103,6 +105,8 @@ if ($quizQuestions === []) {
$lookupMandants = is_array($lookup['mandants'] ?? null) ? $lookup['mandants'] : [];
$lookupDepartments = is_array($lookup['departments'] ?? null) ? $lookup['departments'] : [];
$lookupRoles = is_array($lookup['roles'] ?? null) ? $lookup['roles'] : [];
$lookupEinrichts = is_array($lookup['einrichts'] ?? null) ? $lookup['einrichts'] : [];
$lookupFachbereiche = is_array($lookup['fachbereiche'] ?? null) ? $lookup['fachbereiche'] : [];
$lookupContacts = is_array($lookup['contacts'] ?? null) ? $lookup['contacts'] : [];
$lookupKnowledgePosts = is_array($lookup['knowledge_posts'] ?? null) ? $lookup['knowledge_posts'] : [];
$lookupTaskCategories = is_array($lookup['task_categories'] ?? null) ? $lookup['task_categories'] : [];
@@ -174,6 +178,8 @@ $ensureLookupRows = static function (array $rows, array $selectedIds, string $la
$lookupMandants = $ensureLookupRows($lookupMandants, (array) ($targetSelection['mandant_ids'] ?? []), 'description', 'Mandant');
$lookupDepartments = $ensureLookupRows($lookupDepartments, (array) ($targetSelection['department_ids'] ?? []), 'description', 'Abteilung');
$lookupRoles = $ensureLookupRows($lookupRoles, (array) ($targetSelection['role_ids'] ?? []), 'description', 'Rolle');
$lookupEinrichts = $ensureLookupRows($lookupEinrichts, (array) ($targetSelection['einricht_ids'] ?? []), 'description', 'Einrichtung');
$lookupFachbereiche = $ensureLookupRows($lookupFachbereiche, (array) ($targetSelection['fachbereich_ids'] ?? []), 'description', 'Fachbereich');
$lookupKnowledgePosts = $ensureLookupRows($lookupKnowledgePosts, (array) ($methodConfig['knowledge_post_ids'] ?? []), 'title', 'Beitrag');
$lookupTaskCategories = $ensureLookupRows($lookupTaskCategories, [(int) ($task['task_category_id'] ?? 0)], 'name', 'Kategorie');
$lookupContacts = $ensureLookupRows(
@@ -801,6 +807,32 @@ $taskSyncRedirectUrl = $taskId > 0
<?php endforeach; ?>
</select>
</div>
<div>
<label for="target_einricht_ids">Einrichtungen</label>
<select id="target_einricht_ids" class="tc-multiselect" name="target_einricht_ids[]" multiple data-placeholder="Einrichtungen auswählen">
<?php foreach ($lookupEinrichts as $einricht): ?>
<?php $id = (int) ($einricht['id'] ?? 0); ?>
<?php if ($id <= 0) { continue; } ?>
<option value="<?php echo $id; ?>" <?php echo in_array($id, (array) $targetSelection['einricht_ids'], true) ? 'selected' : ''; ?>>
<?php echo TaskCertView::e((string) ($einricht['description'] ?? ('Einrichtung #' . $id))); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div>
<label for="target_fachbereich_ids">Fachbereiche</label>
<select id="target_fachbereich_ids" class="tc-multiselect" name="target_fachbereich_ids[]" multiple data-placeholder="Fachbereiche auswählen">
<?php foreach ($lookupFachbereiche as $fachbereich): ?>
<?php $id = (int) ($fachbereich['id'] ?? 0); ?>
<?php if ($id <= 0) { continue; } ?>
<option value="<?php echo $id; ?>" <?php echo in_array($id, (array) $targetSelection['fachbereich_ids'], true) ? 'selected' : ''; ?>>
<?php echo TaskCertView::e((string) ($fachbereich['description'] ?? ('Fachbereich #' . $id))); ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
</section>

View File

@@ -38,6 +38,20 @@ class TaskLookupRepository
);
}
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(

View File

@@ -641,6 +641,8 @@ class AssignmentResolverService
l.main_mandant_id,
l.main_department_id,
l.main_role_id,
l.main_einricht_id,
l.main_bereich_id,
l.active
FROM main_contact c
LEFT JOIN main_contact_department l ON l.main_contact_id = c.id
@@ -662,6 +664,8 @@ class AssignmentResolverService
'main_mandant_id' => (int) ($row['main_mandant_id'] ?: $row['master_mandant_id']),
'main_department_id' => (int) ($row['main_department_id'] ?? 0),
'main_role_id' => (int) ($row['main_role_id'] ?? 0),
'main_einricht_id' => (int) ($row['main_einricht_id'] ?? 0),
'main_bereich_id' => (int) ($row['main_bereich_id'] ?? 0),
];
}
@@ -674,13 +678,17 @@ class AssignmentResolverService
$ruleMandant = (int) ($rule['main_mandant_id'] ?? 0);
$ruleDepartment = (int) ($rule['main_department_id'] ?? 0);
$ruleRole = (int) ($rule['main_role_id'] ?? 0);
$ruleEinricht = (int) ($rule['main_einricht_id'] ?? 0);
$ruleFachbereich = (int) ($rule['main_bereich_id'] ?? 0);
foreach ($scopeRows as $scope) {
$mandantMatch = $ruleMandant === 0 || $ruleMandant === (int) $scope['main_mandant_id'];
$departmentMatch = $ruleDepartment === 0 || $ruleDepartment === (int) $scope['main_department_id'];
$roleMatch = $ruleRole === 0 || $ruleRole === (int) $scope['main_role_id'];
$einrichtMatch = $ruleEinricht === 0 || $ruleEinricht === (int) $scope['main_einricht_id'];
$fachbereichMatch = $ruleFachbereich === 0 || $ruleFachbereich === (int) $scope['main_bereich_id'];
if ($mandantMatch && $departmentMatch && $roleMatch) {
if ($mandantMatch && $departmentMatch && $roleMatch && $einrichtMatch && $fachbereichMatch) {
return true;
}
}

View File

@@ -19,6 +19,8 @@ class TaskLookupService
'mandants' => $this->safeFetch('mandants', fn(): array => $this->lookupRepo->listMandants()),
'departments' => $this->safeFetch('departments', fn(): array => $this->lookupRepo->listDepartments()),
'roles' => $this->safeFetch('roles', fn(): array => $this->lookupRepo->listRoles()),
'einrichts' => $this->safeFetch('einrichts', fn(): array => $this->lookupRepo->listEinrichts()),
'fachbereiche' => $this->safeFetch('fachbereiche', fn(): array => $this->lookupRepo->listFachbereiche()),
'contacts' => $this->safeFetch('contacts', fn(): array => $this->lookupRepo->listActiveContacts()),
'knowledge_posts' => $this->safeFetch('knowledge_posts', fn(): array => $this->lookupRepo->listKnowledgePosts($languageId)),
];