Skip to content

CFM-514_AttributeCollector_Creates_Empty_Invisible_Role #391

Merged
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 @@ -140,7 +140,6 @@ public function hydrate(int $id, \App\Model\Entity\Petition $petition): bool
// Get the collection object
$attributesCollection = new Collection($attributes);


/*********** PERSON ROLE ***************/
// Filter the Person Role Attributes and keep the field name
$personRoleAttributes = (new Collection($supportedAttributes))->filter(function($attr, $key) {
Expand All @@ -157,9 +156,11 @@ public function hydrate(int $id, \App\Model\Entity\Petition $petition): bool
$cxn = $this->getConnection();
$cxn->begin();

// Save the Person Role
$personRoleObj = TableRegistry::getTableLocator()->get('PersonRoles');
$role = $personRoleObj->saveAttributeCollectorPetitionAttributes((int)$person->id, $fieldsForPersonRole);
// Save the Person Role only if we collected something meaningful for it,
if(!empty($fieldsForPersonRole)) {
$personRoleObj = TableRegistry::getTableLocator()->get('PersonRoles');
$role = $personRoleObj->saveAttributeCollectorPetitionAttributes((int)$person->id, $fieldsForPersonRole);
}

/********* MVEAS **************/
// Filter the MVEAS Attributes and keep the field name
Expand All @@ -179,14 +180,17 @@ public function hydrate(int $id, \App\Model\Entity\Petition $petition): bool
);

// MVEAs for Role
$this->handleMveaAttributes(
$person,
$role,
'PersonRole',
$mveaAttributes,
$attributes,
$cxn
);
// Save the MVEAs for the PersonRole only if we collected something meaningful for it, and the role was created
if(!empty($fieldsForPersonRole)) {
$this->handleMveaAttributes(
$person,
$role,
'PersonRole',
$mveaAttributes,
$attributes,
$cxn
);
}

/****** PERSON ******/
// Keep the person attributes
Expand Down