Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CO-2545_Add_petitionAttributes_beforeSave_hook_for_Wedge_plugins #433

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
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