diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index 72fcf486..29a954d8 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -219,7 +219,7 @@ public function finalize(int $id, \App\Model\Entity\Petition $petition): bool })->toArray(); $personAttributes = array_keys($personAttributes); - // Get all the fields/values required to build the PrersonRole + // Get all the fields/values required to build the PersonRole $fieldsForPerson = $attributesCollection->filter(function($attr, $key) use ($personAttributes) { return in_array($attr['enrollment_attribute']['attribute'], $personAttributes); })->toArray(); diff --git a/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php b/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php index 9fbb7dd8..97307f21 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php @@ -29,11 +29,8 @@ namespace CoreEnroller\Model\Table; -use Cake\ORM\Query; -use Cake\ORM\RulesChecker; +use Cake\Event\EventInterface; use Cake\ORM\Table; -use Cake\ORM\TableRegistry; -use Cake\Utility\Hash; use Cake\Validation\Validator; use \App\Lib\Enum\GroupTypeEnum; use \App\Lib\Enum\SuspendableStatusEnum; @@ -70,7 +67,7 @@ public function initialize(array $config): void { $this->belongsTo('AttributeTypes') ->setClassName('Types') ->setForeignKey('attribute_type') - ->setProperty('attribute_type'); + ->setProperty('type'); $this->hasMany('CoreEnroller.PetitionAttributes') diff --git a/app/src/Model/Table/AddressesTable.php b/app/src/Model/Table/AddressesTable.php index 2042a73c..056dfd25 100644 --- a/app/src/Model/Table/AddressesTable.php +++ b/app/src/Model/Table/AddressesTable.php @@ -29,8 +29,6 @@ namespace App\Model\Table; -use Cake\Collection\Collection; -use Cake\Utility\Hash; use \App\Lib\Enum\LanguageEnum; use \Cake\ORM\Table; use \Cake\ORM\TableRegistry; @@ -297,12 +295,7 @@ public function getPermittedFields(): array { */ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool { - $fieldType = Hash::extract($fields, '{n}.enrollment_attribute.attribute_type.id'); - $fieldTypeId = (new Collection($fieldType))->first(); - - $address = [ - 'type_id' => $fieldTypeId - ]; + $address = []; if($parentModel === 'Person') { if(empty($personId)) { @@ -318,6 +311,7 @@ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, foreach($fields as $fld) { $address[$fld->column_name] = $fld->value; + $address['type_id'] = $fld->enrollment_attribute->attribute_type; } $this->saveOrFail($this->newEntity($address)); diff --git a/app/src/Model/Table/EmailAddressesTable.php b/app/src/Model/Table/EmailAddressesTable.php index 8dd7c457..24013ad7 100644 --- a/app/src/Model/Table/EmailAddressesTable.php +++ b/app/src/Model/Table/EmailAddressesTable.php @@ -29,16 +29,13 @@ namespace App\Model\Table; -use Cake\Collection\Collection; use Cake\Datasource\EntityInterface; use Cake\Event\EventInterface; use Cake\ORM\Table; use Cake\ORM\TableRegistry; -use Cake\Utility\Hash; use Cake\Validation\Validator; use \App\Lib\Enum\ActionEnum; use \App\Lib\Enum\ProvisioningContextEnum; -use \App\Model\Entity\EmailAddress; class EmailAddressesTable extends Table { use \App\Lib\Traits\AutoViewVarsTrait; @@ -391,15 +388,12 @@ public function validationDefault(Validator $validator): Validator { */ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool { - $fieldType = Hash::extract($fields, '{n}.enrollment_attribute.attribute_type.id'); - $fieldTypeId = (new Collection($fieldType))->first(); - foreach ($fields as $idx => $field) { // Check if this has already been saved $email = [ 'person_id' => $personId, 'mail' => $field->value, - 'type_id' => $fieldTypeId + 'type_id' => $field->enrollment_attribute->attribute_type, ]; $this->saveOrFail($this->newEntity($email)); diff --git a/app/src/Model/Table/NamesTable.php b/app/src/Model/Table/NamesTable.php index 7f636c58..32659839 100644 --- a/app/src/Model/Table/NamesTable.php +++ b/app/src/Model/Table/NamesTable.php @@ -476,12 +476,8 @@ public function validationDefault(Validator $validator): Validator { */ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool { - $fieldType = Hash::extract($fields, '{n}.enrollment_attribute.attribute_type.id'); - $fieldTypeId = (new Collection($fieldType))->first(); - $name = [ 'person_id' => $personId, - 'type_id' => $fieldTypeId ]; // Save the primary name @@ -491,6 +487,8 @@ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, foreach($fields as $fld) { $name[$fld->column_name] = $fld->value; + $name['type_id'] = $fld->enrollment_attribute->attribute_type; + $name['language'] = $fld->enrollment_attribute->attribute_language; } $this->saveOrFail($this->newEntity($name)); diff --git a/app/src/Model/Table/PronounsTable.php b/app/src/Model/Table/PronounsTable.php index 8f8127b6..f9fa006b 100644 --- a/app/src/Model/Table/PronounsTable.php +++ b/app/src/Model/Table/PronounsTable.php @@ -29,9 +29,10 @@ namespace App\Model\Table; +use App\Lib\Enum\LanguageEnum; +use Cake\Datasource\EntityInterface; use Cake\ORM\Table; use Cake\Validation\Validator; -use App\Lib\Enum\LanguageEnum; class PronounsTable extends Table { use \App\Lib\Traits\AutoViewVarsTrait; @@ -188,6 +189,17 @@ public function validationDefault(Validator $validator): Validator { */ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool { + foreach ($fields as $idx => $field) { + // Check if this has already been saved + $pronoun = [ + 'person_id' => $personId, + 'pronouns' => $field->value, + 'language' => $field->enrollment_attribute->attribute_language, + 'type_id' => $field->enrollment_attribute->attribute_type, + ]; + + $this->saveOrFail($this->newEntity($pronoun)); + } return true; } } \ No newline at end of file diff --git a/app/src/Model/Table/TelephoneNumbersTable.php b/app/src/Model/Table/TelephoneNumbersTable.php index 00073179..0dd96503 100644 --- a/app/src/Model/Table/TelephoneNumbersTable.php +++ b/app/src/Model/Table/TelephoneNumbersTable.php @@ -235,12 +235,7 @@ public function validationDefault(Validator $validator): Validator { */ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool { - $fieldType = Hash::extract($fields, '{n}.enrollment_attribute.attribute_type.id'); - $fieldTypeId = (new Collection($fieldType))->first(); - - $telephone = [ - 'type_id' => $fieldTypeId - ]; + $telephone = []; if($parentModel === 'Person') { if(empty($personId)) { @@ -256,6 +251,7 @@ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, foreach($fields as $fld) { $telephone[$fld->column_name] = $fld->value; + $telephone['type_id'] = $fld->enrollment_attribute->attribute_type; } $this->saveOrFail($this->newEntity($telephone)); diff --git a/app/src/Model/Table/UrlsTable.php b/app/src/Model/Table/UrlsTable.php index f861c0be..24045f37 100644 --- a/app/src/Model/Table/UrlsTable.php +++ b/app/src/Model/Table/UrlsTable.php @@ -29,7 +29,10 @@ namespace App\Model\Table; +use Cake\Collection\Collection; +use Cake\Datasource\EntityInterface; use Cake\ORM\Table; +use Cake\Utility\Hash; use Cake\Validation\Validator; class UrlsTable extends Table { @@ -195,7 +198,7 @@ public function validationDefault(Validator $validator): Validator { /** * Save attributes for a given person and optionally their role. * - * @since COmanage Registry v5.0.0 + * @since COmanage Registry v5.1.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 @@ -204,6 +207,16 @@ public function validationDefault(Validator $validator): Validator { */ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, array $fields): bool { + foreach ($fields as $idx => $field) { + // Check if this has already been saved + $url = [ + 'person_id' => $personId, + 'url' => $field->value, + 'type_id' => $field->enrollment_attribute->attribute_type, + ]; + + $this->saveOrFail($this->newEntity($url)); + } return true; } } \ No newline at end of file