From fad497d54ad3e941a42382304ae4333bcefe7fec Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 21 Apr 2026 11:56:35 +0300 Subject: [PATCH 1/2] CoreEnroller.AttributeCollector:enable enrolleeName interface --- .../Model/Table/AttributeCollectorsTable.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index 0ce5c1849..ad96cc05a 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -104,6 +104,94 @@ public function initialize(array $config): void { ]); } + /** + * Obtain a name (as a string) for the Enrollee associated with the specified Petition. + * + * Not all Petitions will have Enrollee Names, and some Petitions could have more than one + * Name. This function will try to find a suitable Name, but no guarantees can be made as + * to the result; different values can be returned across subsequent calls, especially if + * the Petition state changes. + * + * @since COmanage Registry v5.2.0 + * @param EntityInterface $config Configuration entity for this plugin + * @param int $petitionId Petition ID + * @return string|null Name, or null if there is no name data + */ + public function enrolleeName( + EntityInterface $config, + int $petitionId + ): ?string { + // Identify active "name" EnrollmentAttributes for this collector (in configured order) + $nameEnrollmentAttributeIds = $this->EnrollmentAttributes + ->find() + ->select(['id']) + ->where([ + 'attribute_collector_id' => $config->id, + 'attribute' => 'name', + 'status' => StatusEnum::Active, + ]) + ->orderBy(['ordr' => 'ASC']) + ->all() + ->extract('id') + ->toList(); + + if (empty($nameEnrollmentAttributeIds)) { + return null; + } + + // Pull all PetitionAttributes rows for those EnrollmentAttributes + $rows = $this->EnrollmentAttributes + ->PetitionAttributes + ->find() + ->where(['petition_id' => $petitionId]) + ->where(fn(QueryExpression $exp, Query $q) => $exp->in('enrollment_attribute_id', $nameEnrollmentAttributeIds)) + ->orderBy(['enrollment_attribute_id' => 'ASC', 'id' => 'ASC']) + ->toArray(); + + if (empty($rows)) { + return null; + } + + // Choose the first EnrollmentAttribute (by ordr) that has any stored rows + $rowsByEnrollmentAttributeId = []; + foreach ($rows as $r) { + $rowsByEnrollmentAttributeId[$r->enrollment_attribute_id][] = $r; + } + + $chosenEnrollmentAttributeId = null; + foreach ($nameEnrollmentAttributeIds as $eaId) { + if (!empty($rowsByEnrollmentAttributeId[$eaId])) { + $chosenEnrollmentAttributeId = $eaId; + break; + } + } + + if ($chosenEnrollmentAttributeId === null) { + return null; + } + + // Map PetitionAttributes.column_name => PetitionAttributes.value into Name fields + $allowedColumns = ['honorific', 'given', 'middle', 'family', 'suffix']; + $nameData = []; + + foreach ($rowsByEnrollmentAttributeId[$chosenEnrollmentAttributeId] as $r) { + $column = $r->column_name ?? ''; + if ($column !== '' && in_array($column, $allowedColumns, true) && !empty($r->value)) { + $nameData[$column] = $r->value; + } + } + + if (empty($nameData)) { + return null; + } + + // Construct a throw-away Name entity so we can use its full_name virtual field + $Names = TableRegistry::getTableLocator()->get('Names'); + $name = $Names->newEntity($nameData); + + return !empty($name->full_name) ? $name->full_name : null; + } + /** * Perform steps necessary to hydrate the Person record as part of Petition finalization. * From 50b271ed05524b88b9ffe58699bccda4a6a32430 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 21 Apr 2026 16:24:57 +0300 Subject: [PATCH 2/2] Change People Picker Enable description msg --- .../CoreEnroller/resources/locales/en_US/core_enroller.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po b/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po index 61bb47110..a1d2aa8d6 100644 --- a/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po +++ b/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po @@ -164,7 +164,7 @@ msgid "field.AttributeCollectors.valid_through.default.after.desc" msgstr "Days After Finalization" msgid "field.AttributeCollectors.enable_person_find" -msgstr "Enable People Picker for Self Service" +msgstr "Enable People Picker for Unauthenticated Enrollments" msgid "field.AttributeCollectors.enable_person_find.desc" msgstr "Enable people picker for self-service enrollments, see Attribute Collector documentation for privacy considerations"