Skip to content

Commit

Permalink
Wedge plugin beforeSavePetitionAttributes hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ioigoume committed Oct 30, 2022
1 parent 5b5a0f5 commit c2cf6a4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -1256,8 +1256,10 @@
'er.prov.plugin' => 'Provisioning failed for %1$s: %2$s',
'er.pt.conf.exp' => 'Viewed expired confirmation',
'er.pt.dupe.cou' => 'The target CO Person already has a Role in the specified COU',
'er.pt.dupe.cou-a' => 'The target CO Person already has a Role in the "%1$s" COU',
'er.pt.duplicate' => 'The identifier "%1$s" is already attached to an identity enrolled in this CO. This petition has been flagged as a duplicate.',
'er.pt.mail' => 'No email address found for %1$s to use for confirmation',
'er.pt.interrupt' => 'Petition has been interrupted',
'er.pt.readonly' => 'Petition is now read only (status=%1$s)',
'er.pt.relink.org' => 'Could not automatically relink Org Identity due to another existing CO Person record',
'er.pt.relink.role.c' => 'Could not automatically relink CO Person Role due to another existing CO Person record',
Expand Down
52 changes: 51 additions & 1 deletion app/Model/CoPetition.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,53 @@ public function attributeOptionalAndEmpty($efAttrID, $data, $efAttrs) {

return true;
}

/**
* Petition Attributes Before Save Wedge Plugin Hook
*
* @param Integer $id CO Petition ID
* @param Integer $enrollmentFlowId Enrollment Flow ID
* @param Array $requestData Attributes from submitted Petition
* @param Integer $petitionerId CO Person ID of the petitioner
*
* @since COmanage Registry v4.1.0
* @return bool
* @throws RuntimeException
*/

protected function beforeSavePetitionAttributes($id, $enrollmentFlowId, &$requestData, $petitionerId) {
$args = array();
$args['conditions']['CoEnrollmentFlowWedge.co_enrollment_flow_id'] = $enrollmentFlowId;
$args['conditions']['CoEnrollmentFlowWedge.status'] = SuspendableStatusEnum::Active;
$args['order'] = array('ordr' => 'asc');

$wedges = $this->CoEnrollmentFlow->CoEnrollmentFlowWedge->find('all', $args);

foreach($wedges as $wedge) {
$pluginName = $wedge["CoEnrollmentFlowWedge"]["plugin"];
// We need to load the dependency for the next call
$this->CoEnrollmentFlow->CoEnrollmentFlowWedge->bindModel(
array('hasMany' => array(
$pluginName => array(
'className' => $pluginName . '.' . $pluginName
)))
);
if(method_exists($this->CoEnrollmentFlow->CoEnrollmentFlowWedge->$pluginName, 'beforeSaveAttributes')) {
try {
$response = $this->CoEnrollmentFlow
->CoEnrollmentFlowWedge
->$pluginName
->beforeSaveAttributes($id, $enrollmentFlowId, $requestData, $petitionerId);
if(!$response) {
throw new RuntimeException(_txt('er.pt.interrupt'));
}
} catch (Exception $e) {
throw new RuntimeException($e->getMessage());
}
}

}
}

/**
* Check the eligibility for a CO Petition.
Expand Down Expand Up @@ -1983,7 +2030,10 @@ public function saveAttributes($id, $enrollmentFlowId, $requestData, $petitioner
if(!$id) {
throw new InvalidArgumentException(_txt('er.notprov.id', array(_txt('ct.petitions.1'))));
}


// Execute any Enroller plugin hooks
$this->beforeSavePetitionAttributes($id, $enrollmentFlowId, $requestData, $petitionerId);

// Start a transaction
$dbc = $this->getDataSource();
$dbc->begin();
Expand Down

0 comments on commit c2cf6a4

Please sign in to comment.