From bcc4cf9ac4641fe8e0e98bc4eb44cb73eae06c86 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 4 Feb 2025 18:29:13 +0200 Subject: [PATCH] Fix, partially, the AttributeCollectors finalize function. --- .../Model/Table/AttributeCollectorsTable.php | 34 +++++++++++++------ .../Table/BasicAttributeCollectorsTable.php | 2 +- .../element/mveas/fieldset-field.php | 2 ++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index bd5b1d27a..03ecee815 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -29,6 +29,7 @@ namespace CoreEnroller\Model\Table; +use App\Model\Entity\Petition; use Cake\Datasource\ConnectionManager; use Cake\ORM\Query; use Cake\ORM\RulesChecker; @@ -117,21 +118,32 @@ public function initialize(array $config): void { /** * Perform steps necessary to finalize the Petition. - * - * @since COmanage Registry v5.0.0 - * @param int $id Attribute Collector ID - * @param int $petitionId Petition ID + * + * @param int $id Attribute Collector ID + * @param Petition $petition * @return bool true on success + * @since COmanage Registry v5.1.0 */ - public function finalize(int $id, int $petitionId) { -// XXX convert Petition Attributes to operational Attributes -// keep in mind this can be called multiple times if the plugin is -// instantiated more than once in the Enrollment Flow ($id will be different) -// any errors should be logged or otherwise managed, returning false -// or throwing an error will NOT prevent the petition from finalizing + public function finalize(int $id, \App\Model\Entity\Petition $petition) { + $cfg = $this->get($id); + + if(empty($petition->enrollee_person_id)) { + throw new \InvalidArgumentException(__d('error', 'Petitions.enrollee.notfound', [$petition->id])); + } + + $People = TableRegistry::getTableLocator()->get('People'); + + $person = $People->get($petition->enrollee_person_id); + + $attributes = $this->EnrollmentAttributes + ->PetitionAttributes + ->find() + ->where(['petition_id' => $petition->id]) + ->firstOrFail(); -debug("in AttributeCollector finalize"); + // XXX Should i save the primary name? + // XXX Should i save the email? return true; } diff --git a/app/plugins/CoreEnroller/src/Model/Table/BasicAttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/BasicAttributeCollectorsTable.php index cd0ac0766..5fa748580 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/BasicAttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/BasicAttributeCollectorsTable.php @@ -147,7 +147,7 @@ public function finalize(int $id, \App\Model\Entity\Petition $petition) { // At this point there is a Person record allocated and stored in the Petition, // but it doesn't have any attributes on it, including a Primary Name. // We assume we're the only attribute collector, so we'll force a Primary Name - // based on the Basic Attribtues, and create a skeletal role. + // based on the Basic Attributes, and create a skeletal role. if(empty($petition->enrollee_person_id)) { throw new \InvalidArgumentException(__d('error', 'Petitions.enrollee.notfound', [$petition->id])); diff --git a/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php b/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php index 4a1624761..e8e7e53e6 100644 --- a/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php +++ b/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php @@ -52,6 +52,8 @@ // Each default value is mutually exclusive to the rest. We do not have to worry about a conflict. $options['default'] = match(true) { isset($attr->default_value) => $attr->default_value, + // XXX The $attr->default_value_env_name for the name attribute is tricky. Since the name has many values. + // Check the EnvSource plugin isset($attr->default_value_env_name) && getenv($attr->default_value_env_name) !== false => getenv($attr->default_value_env_name), isset($attr->default_value_datetime) => $attr->default_value_datetime,