mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 14:36:13 +00:00
Feature: filter activities by user in docgen: use creator as user
This commit is contained in:
parent
03fe9210a9
commit
6d6aa689d0
@ -11,7 +11,6 @@ and this project adheres to
|
|||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
<!-- write down unreleased development here -->
|
<!-- write down unreleased development here -->
|
||||||
* [activity] Feature: In docgen, allow filtering activities and social works for acc course by logged user
|
|
||||||
* [person][export] Fixed: rename the alias for `accompanying_period` to `acp` in filter associated with person
|
* [person][export] Fixed: rename the alias for `accompanying_period` to `acp` in filter associated with person
|
||||||
* [activity][export] Feature: improve label for aliases in "Filter by activity type"
|
* [activity][export] Feature: improve label for aliases in "Filter by activity type"
|
||||||
* [activity][export] DX/Feature: use of an `ActivityTypeRepositoryInterface` instead of the old-style EntityRepository
|
* [activity][export] DX/Feature: use of an `ActivityTypeRepositoryInterface` instead of the old-style EntityRepository
|
||||||
|
@ -135,30 +135,29 @@ class ListActivitiesByAccompanyingPeriodContext implements
|
|||||||
return $normalized;
|
return $normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filterActivitiesByCurrentUser(array $activities): array
|
public function filterActivitiesByUser(array $activities, User $user): array
|
||||||
{
|
{
|
||||||
return array_filter(
|
return array_filter(
|
||||||
$activities,
|
$activities,
|
||||||
function ($activity) {
|
function ($activity) use ($user) {
|
||||||
$activityUsernames = array_map(static function ($user) {
|
$activityUsernames = array_map(static function ($user) {
|
||||||
return $user['username'];
|
return $user['username'];
|
||||||
}, $activity['users'] ?? []);
|
}, $activity['users'] ?? []);
|
||||||
|
return in_array($user->getUsername(), $activityUsernames, true);
|
||||||
return in_array($this->security->getUser()->getUsername(), $activityUsernames, true);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filterWorksByCurrentUser(array $works): array
|
public function filterWorksByUser(array $works, User $user): array
|
||||||
{
|
{
|
||||||
return array_filter(
|
return array_filter(
|
||||||
$works,
|
$works,
|
||||||
function ($work) {
|
function ($work) use ($user) {
|
||||||
$workUsernames = array_map(static function ($user) {
|
$workUsernames = array_map(static function ($user) {
|
||||||
return $user['username'];
|
return $user['username'];
|
||||||
}, $work['referrers'] ?? []);
|
}, $work['referrers'] ?? []);
|
||||||
|
|
||||||
return in_array($this->security->getUser()->getUsername(), $workUsernames, true);
|
return in_array($user->getUsername(), $workUsernames, true);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -168,11 +167,10 @@ class ListActivitiesByAccompanyingPeriodContext implements
|
|||||||
$data = $this->accompanyingPeriodContext->getData($template, $entity, $contextGenerationData);
|
$data = $this->accompanyingPeriodContext->getData($template, $entity, $contextGenerationData);
|
||||||
|
|
||||||
$activities = $this->getActivitiesSimplified($entity);
|
$activities = $this->getActivitiesSimplified($entity);
|
||||||
|
|
||||||
$myActivitiesOnly = $contextGenerationData['myActivitiesOnly'];
|
$myActivitiesOnly = $contextGenerationData['myActivitiesOnly'];
|
||||||
|
|
||||||
if ($myActivitiesOnly) {
|
if ($myActivitiesOnly) {
|
||||||
$activities = $this->filterActivitiesByCurrentUser($activities);
|
$activities = $this->filterActivitiesByUser($activities, $contextGenerationData['creator']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['activities'] = $activities;
|
$data['activities'] = $activities;
|
||||||
@ -180,9 +178,8 @@ class ListActivitiesByAccompanyingPeriodContext implements
|
|||||||
$myWorksOnly = $contextGenerationData['myWorksOnly'];
|
$myWorksOnly = $contextGenerationData['myWorksOnly'];
|
||||||
|
|
||||||
if ($myWorksOnly) {
|
if ($myWorksOnly) {
|
||||||
$data['course']['works'] = $this->filterWorksByCurrentUser($data['course']['works']);
|
$data['course']['works'] = $this->filterWorksByUser($data['course']['works'], $contextGenerationData['creator']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user