Skip to content

Commit

Permalink
Handle optional Enrollment Attributes that do not allow emtpy values. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis authored Apr 14, 2026
1 parent 7bd0bdd commit 9ffc7ca
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 9 deletions.
15 changes: 12 additions & 3 deletions app/src/Model/Table/AdHocAttributesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,19 @@ public function validationDefault(Validator $validator): Validator {
public function saveAttributeCollectorPetitionAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool
{
foreach ($fields as $idx => $field) {
// Check if this has already been saved
$tag = $field->enrollment_attribute->attribute_tag;
$value = $field->value;

if (
$field->enrollment_attribute->required !== true
&& ($tag === null || trim((string)$tag) === '')
) {
continue;
}

$adhoc = [
'tag' => $field->enrollment_attribute->attribute_tag,
'value' => $field->value
'tag' => $tag,
'value' => $value
];

if($parentModel === 'Person') {
Expand Down
13 changes: 11 additions & 2 deletions app/src/Model/Table/EmailAddressesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,19 @@ public function validationDefault(Validator $validator): Validator {
public function saveAttributeCollectorPetitionAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool
{
foreach ($fields as $idx => $field) {
// Check if this has already been saved
// Email Addresses can be optional, but if they are not provided we have to skip save since empty email values are not allowed.
$value = $field->value;

if (
$field->enrollment_attribute->required !== true
&& ($value === null || trim((string)$value) === '')
) {
continue;
}

$email = [
'person_id' => $personId,
'mail' => $field->value,
'mail' => $value,
'type_id' => $field->enrollment_attribute->attribute_type,
];

Expand Down
34 changes: 34 additions & 0 deletions app/src/Model/Table/IdentifiersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,38 @@ public function validationDefault(Validator $validator): Validator {

return $validator;
}

/**
* Save attributes for a given person and optionally their role.
*
* @since COmanage Registry v5.2.0
* @param int $personId Identifier for the person
* @param int|null $roleId Identifier for the role (nullable)
* @param string $parentModel Name of the parent model
* @param array $fields Array of attributes to save
* @return bool True on success, false otherwise
*/
public function saveAttributeCollectorPetitionAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool
{
foreach ($fields as $idx => $field) {
// Identifiers can be optional, but if they are not provided we have to skip save since empty strings are not allowed.
$value = $field->value;

if (
$field->enrollment_attribute->required !== true
&& ($value === null || trim((string)$value) === '')
) {
continue;
}

$identifier = [
'person_id' => $personId,
'identifier' => $value,
'type_id' => $field->enrollment_attribute->attribute_type,
];

$this->saveOrFail($this->newEntity($identifier));
}
return true;
}
}
13 changes: 11 additions & 2 deletions app/src/Model/Table/PronounsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,19 @@ public function validationDefault(Validator $validator): Validator {
public function saveAttributeCollectorPetitionAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool
{
foreach ($fields as $idx => $field) {
// Check if this has already been saved
// Pronouns can be optional, but if they are not provided we have to skip save since empty strings are not allowed.
$value = $field->value;

if (
$field->enrollment_attribute->required !== true
&& ($value === null || trim((string)$value) === '')
) {
continue;
}

$pronoun = [
'person_id' => $personId,
'pronouns' => $field->value,
'pronouns' => $value,
'language' => $field->enrollment_attribute->attribute_language,
'type_id' => $field->enrollment_attribute->attribute_type,
];
Expand Down
13 changes: 11 additions & 2 deletions app/src/Model/Table/UrlsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,19 @@ public function validationDefault(Validator $validator): Validator {
public function saveAttributeCollectorPetitionAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool
{
foreach ($fields as $idx => $field) {
// Check if this has already been saved
// URLs can be optional, but if they are not provided we have to skip save since empty URL strings are not allowed.
$value = $field->value;

if (
$field->enrollment_attribute->required !== true
&& ($value === null || trim((string)$value) === '')
) {
continue;
}

$url = [
'person_id' => $personId,
'url' => $field->value,
'url' => $value,
'type_id' => $field->enrollment_attribute->attribute_type,
];

Expand Down

0 comments on commit 9ffc7ca

Please sign in to comment.