chg: [Aligntments] setAlignment function moved to its appropriate model

pull/38/head
iglocska 2021-01-13 14:20:53 +01:00
parent 539ce4b99a
commit 1a6505bf61
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 19 additions and 0 deletions

View File

@ -22,5 +22,24 @@ class AlignmentsTable extends AppTable
->notEmptyString('organisation_id')
->requirePresence(['individual_id', 'organisation_id'], 'create');
return $validator;
}
public function setAlignment($organisation_id, $individual_id, $type): void
{
$query = $this->find();
$query->where([
'organisation_id' => $organisation_id,
'individual_id' => $individual_id
]);
$existingAlignment = $query->first();
if (empty($existingAlignment)) {
$alignment = $this->newEmptyEntity();
$data = [
'organisation_id' => $organisation_id,
'individual_id' => $individual_id,
'type' => $type
];
$this->patchEntity($alignment, $data);
}
}
}