Element_OphTrOperationnote_Anaesthetic::updateComplications PHP Method

updateComplications() public method

Update the complications assigned to this element.
public updateComplications ( int[] $complication_ids )
$complication_ids int[]
    public function updateComplications($complication_ids)
    {
        $curr_by_id = array();
        foreach ($this->anaesthetic_complication_assignments as $ca) {
            $curr_by_id[$ca->anaesthetic_complication_id] = $ca;
        }
        if (!empty($complication_ids)) {
            foreach ($complication_ids as $c_id) {
                if (!isset($curr_by_id[$c_id])) {
                    $ca = new OphTrOperationnote_AnaestheticComplication();
                    $ca->et_ophtroperationnote_anaesthetic_id = $this->id;
                    $ca->anaesthetic_complication_id = $c_id;
                    if (!$ca->save()) {
                        throw new Exception('Unable to save complication assignment: ' . print_r($ca->getErrors(), true));
                    }
                } else {
                    unset($curr_by_id[$c_id]);
                }
            }
        }
        foreach ($curr_by_id as $ca) {
            if (!$ca->delete()) {
                throw new Exception('Unable to delete complication assignment: ' . print_r($ca->getErrors(), true));
            }
        }
    }

Usage Example

コード例 #1
0
 /**
  * Update the anaesthetic agents and complications.
  *
  * @param Element_OphTrOperationnote_Anaesthetic $element
  * @param $data
  * @param $index
  */
 protected function saveComplexAttributes_Element_OphTrOperationnote_Anaesthetic($element, $data, $index)
 {
     $element->updateAnaestheticAgents(isset($data['AnaestheticAgent']) ? $data['AnaestheticAgent'] : array());
     $element->updateComplications(isset($data['OphTrOperationnote_AnaestheticComplications']) ? $data['OphTrOperationnote_AnaestheticComplications'] : array());
 }