Fix error on listEvaluation

- force default calcDate
- Export / UserHelper: handle case when a single user is given, when we expect more than one user
This commit is contained in:
Julien Fastré 2023-11-29 22:17:20 +01:00
parent a344f36592
commit fffc4a9c33
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 14 additions and 3 deletions

View File

@ -0,0 +1,5 @@
kind: Fixed
body: Fix error in ListEvaluation when "handling agents" are alone
time: 2023-11-29T22:15:01.627103072+01:00
custom:
Issue: ""

View File

@ -92,6 +92,11 @@ class UserHelper
} }
$asStrings = []; $asStrings = [];
if (array_key_exists('uid', $decoded) || is_numeric($decoded)) {
// this is a single value. We have to wrap it into an array
$decoded = [$decoded];
}
foreach ($decoded as $userId) { foreach ($decoded as $userId) {
if (is_array($userId)) { if (is_array($userId)) {
$uid = $userId['uid']; $uid = $userId['uid'];

View File

@ -193,6 +193,7 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{ {
$centers = array_map(static fn ($el) => $el['center'], $acl); $centers = array_map(static fn ($el) => $el['center'], $acl);
$calcDate = $data['calc_date'] ?? new RollingDate(RollingDate::T_TODAY);
$qb = $this->entityManager->createQueryBuilder(); $qb = $this->entityManager->createQueryBuilder();
@ -208,7 +209,7 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL')
// get participants at the given date // get participants at the given date
->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)') ->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)')
->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date'])); ->setParameter('calc_date', $this->rollingDateConverter->convert($calcDate));
if ($this->filterStatsByCenters) { if ($this->filterStatsByCenters) {
$qb $qb
@ -224,7 +225,7 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
$this->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date'])); $this->addSelectClauses($qb, $this->rollingDateConverter->convert($calcDate));
return $qb; return $qb;
} }
@ -278,7 +279,7 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
// referrers => at date XXXX // referrers => at date XXXX
$qb $qb
->addSelect('(SELECT JSON_BUILD_OBJECT(\'uid\', IDENTITY(history.user), \'d\', history.startDate) FROM '.UserHistory::class.' history '. ->addSelect('(SELECT JSON_BUILD_OBJECT(\'uid\', IDENTITY(history.user), \'d\', history.startDate) FROM '.UserHistory::class.' history '.
'WHERE history.accompanyingPeriod = acp AND history.startDate <= :calc_date AND (history.endDate IS NULL OR history.endDate > :calc_date)) AS referrers'); 'WHERE history.accompanyingPeriod = acp AND history.startDate <= :calc_date AND (history.endDate IS NULL OR history.endDate > :calc_date)) AS acpw_referrers');
// persons // persons
$qb $qb