public function updateAnaestheticAgents($agent_ids)
{
$curr_by_id = array();
foreach ($this->anaesthetic_agent_assignments as $aa) {
$curr_by_id[$aa->anaesthetic_agent_id] = $aa;
}
if (!empty($agent_ids)) {
foreach ($agent_ids as $aa_id) {
if (!isset($curr_by_id[$aa_id])) {
$aa = new OphTrOperationnote_OperationAnaestheticAgent();
$aa->et_ophtroperationnote_anaesthetic_id = $this->id;
$aa->anaesthetic_agent_id = $aa_id;
if (!$aa->save()) {
throw new Exception('Unable to save anaesthetic agent assignment: ' . print_r($aa->getErrors(), true));
}
} else {
unset($curr_by_id[$aa_id]);
}
}
}
foreach ($curr_by_id as $aa) {
if (!$aa->delete()) {
throw new Exception('Unable to delete anaesthetic agent assignment: ' . print_r($aa->getErrors(), true));
}
}
}