Skip to content

Attribute Collection code adjustments #298

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}