Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public function dispatch(string $id) {
attributes: array_diff_key($this->request->getData(), ['petition_id' => true, 'token' => true])
);

$this->persistPetitionCouIdFromCollectedAttributes((int)$petition->id);

// On success, indicate the step is completed and generate a redirect
// to the next step

Expand Down Expand Up @@ -100,4 +102,51 @@ public function dispatch(string $id) {

$this->render('/Standard/dispatch');
}

/**
* If the Attribute Collector collected a COU for later context (eg approvals),
* persist Petition.cou_id during dispatch (not during finalization).
*
* @since COmanage Registry v5.2.0
* @param int $petitionId
* @return void
*/
protected function persistPetitionCouIdFromCollectedAttributes(int $petitionId): void {
$petitionAttributesTable = $this->AttributeCollectors
->EnrollmentAttributes
->PetitionAttributes;

// Fetch all petition attributes + enrollment attribute data
$attrs = $petitionAttributesTable
->find()
->where(['PetitionAttributes.petition_id' => $petitionId])
->contain(['EnrollmentAttributes'])
->toArray();

// Find the first "cou_id" with a non-empty value
// NOTE: Attribute Collector configuration can include multiple COU attributes/values, but the
// Petition record has only a single `cou_id` column. By convention/assumption we therefore
// select the first non-empty collected `cou_id` and ignore any additional values.
Comment on lines +127 to +129
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should reconcile this. The current (draft) of the documentation asserts that we only collect a single Person Role in a given Enrollment Flow. This is consistent with the Petition having a single COU ID, and consistent with the current configuration of the Attribute Collector, in that, as far as I can tell, there is no way to group together collections of Person Role Attributes. In other words, if I collect two COUs and two Titles, which Title goes with which COU?

We can either (1) decide that Attribute Collector only collects one set of Person Role attributes (at least for the immediate future) or (2) decide to properly support multiple Person Roles. If we choose (1), then Attribute Collector should not allow multiple single valued attributes (COU, title, organization, sponsor, valid from, etc) to be configured. If we choose (2), then we need a way to associate attributes to Roles and we need to decide what it means for the Petition metadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benno Since an Enrollment Flow can have multiple steps—and we can instantiate the Attribute Collector in more than one step—we could use the Enrollment Flow Step as the grouping key for Person Role attributes. In other words, for each step where an Attribute Collector is present, we would allow one COU, one title, etc., and treat that set of attributes as a single Person Role. That would let a petition represent multiple roles (one per step) rather than forcing everything into a single COU/title set. The Petition could then expose a helper that returns an array of role-attribute groups (one per step), instead of assuming/forcing a single COU per petition.

$couAttr = null;
foreach ($attrs as $pa) {
if (
!empty($pa->enrollment_attribute)
&& ($pa->enrollment_attribute->attribute ?? null) === 'cou_id'
&& ($pa->value ?? null) !== null
&& ($pa->value ?? null) !== ''
) {
$couAttr = $pa;
break;
}
}

if(!$couAttr) {
return;
}

$petitionsTable = $this->fetchTable('Petitions');
$petition = $petitionsTable->get($petitionId);
$petition->cou_id = (int)$couAttr->value;
$petitionsTable->saveOrFail($petition);
}
}