Skip to content

Commit

Permalink
Attribute Collection code adjustments (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis authored Feb 14, 2025
1 parent ee254e8 commit 47eade9
Showing 1 changed file with 17 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function initialize(array $config): void {
* @since COmanage Registry v5.1.0
*/

public function finalize(int $id, \App\Model\Entity\Petition $petition): bool
public function hydrate(int $id, \App\Model\Entity\Petition $petition): bool
{
$cfg = $this->get($id);

Expand Down Expand Up @@ -176,14 +176,8 @@ public function finalize(int $id, \App\Model\Entity\Petition $petition): bool
$cxn->begin();

// Save the Person Role
try {
$personRoleObj = TableRegistry::getTableLocator()->get('PersonRoles');
$role = $personRoleObj->saveAttributes((int)$person->id, $fieldsForPersonRole);
} catch (\Exception $e) {
$cxn->rollback();
$this->llog('error', __d('error', 'save', [$e->getMessage()]));
throw new \RuntimeException(__d('error', 'save', ['PersonRole']));
}
$personRoleObj = TableRegistry::getTableLocator()->get('PersonRoles');
$role = $personRoleObj->saveAttributes((int)$person->id, $fieldsForPersonRole);

/********* MVEAS **************/
// Filter the MVEAS Attributes and keep the field name
Expand Down Expand Up @@ -224,15 +218,7 @@ public function finalize(int $id, \App\Model\Entity\Petition $petition): bool
return in_array($attr['enrollment_attribute']['attribute'], $personAttributes);
})->toArray();


try {
$People->saveAttributes($person->id, $fieldsForPerson);
} catch (\Exception $e) {
$this->llog('error', __d('error', 'save', [$e->getMessage()]));
$cxn->rollback();
throw new \RuntimeException(__d('error', 'save', ['Person']));
}

$People->saveAttributes($person->id, $fieldsForPerson);

/****** GROUP ******/
// Filter the MVEAS Attributes and keep the field name
Expand All @@ -246,15 +232,8 @@ public function finalize(int $id, \App\Model\Entity\Petition $petition): bool
return in_array($attr['enrollment_attribute']['attribute'], $groupAttributes);
})->toArray();


try {
$groupMemberObj = TableRegistry::getTableLocator()->get('GroupMembers');
$groupMemberObj->saveAttributes($person->id, $fieldsForGroup);
} catch (\Exception $e) {
$this->llog('error', __d('error', 'save', [$e->getMessage()]));
$cxn->rollback();
throw new \RuntimeException(__d('error', 'save', ['GroupMembers']));
}
$groupMemberObj = TableRegistry::getTableLocator()->get('GroupMembers');
$groupMemberObj->saveAttributes($person->id, $fieldsForGroup);

// Save the Date Of Birth. This is the only one that is single valued
// and goes under the Person
Expand Down Expand Up @@ -313,14 +292,8 @@ protected function handleMveaAttributes(
$supportedAttributes = $this->EnrollmentAttributes->supportedAttributes();
$mveaModel = $supportedAttributes[$attribute]['mveaModel'];

try {
$modelObj = TableRegistry::getTableLocator()->get($mveaModel);
$modelObj->saveAttributes((int)$person->id, $role?->id, $mveaParent, $fieldsForAttribute);
} catch (\Exception $e) {
$cxn->rollback();
$this->llog('error', __d('error', 'save', [$e->getMessage()]));
throw new \RuntimeException(__d('error', 'save', [$mveaModel]));
}
$modelObj = TableRegistry::getTableLocator()->get($mveaModel);
$modelObj->saveAttributes((int)$person->id, $role?->id, $mveaParent, $fieldsForAttribute);
}
}

Expand Down Expand Up @@ -477,14 +450,17 @@ public function verifiableEmailAddresses(

$set = $this->EnrollmentAttributes
->PetitionAttributes
->find('list',
[
'keyField' => 'id',
'valueField' => 'value'
])->where(['petition_id' => $petitionId])
->find()
->where(['petition_id' => $petitionId])
->where(fn(QueryExpression $exp, Query $q) => $exp->in('enrollment_attribute_id', array_keys($vv_enrollment_attributes)))
->toArray();

return !empty($set) ? $set : [];
$verifiableEmailAddressesArray = [];
if (!empty($set)) {
$emalAddresses = Hash::extract($set, '{n}.value');
$verifiableEmailAddressesArray = array_fill_keys($emalAddresses, false);
}

return $verifiableEmailAddressesArray;
}
}

0 comments on commit 47eade9

Please sign in to comment.