Element_OphTrOperationnote_Cataract::updateComplications PHP Method

updateComplications() public method

Update the complications on the element.
public updateComplications ( $complication_ids )
$complication_ids
    public function updateComplications($complication_ids)
    {
        $curr_by_id = array();
        foreach ($this->complication_assignments as $ca) {
            $curr_by_id[$ca->complication_id] = $ca;
        }
        foreach ($complication_ids as $c_id) {
            if (!isset($curr_by_id[$c_id])) {
                $ca = new OphTrOperationnote_CataractComplication();
                $ca->cataract_id = $this->id;
                $ca->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

Ejemplo n.º 1
0
 /**
  * Update the complications and the operative devices.
  *
  * @param Element_OphTrOperationnote_Cataract $element
  * @param $data
  * @param $index
  */
 protected function saveComplexAttributes_Element_OphTrOperationnote_Cataract($element, $data, $index)
 {
     $element->updateComplications(isset($data['OphTrOperationnote_CataractComplications']) ? $data['OphTrOperationnote_CataractComplications'] : array());
     $element->updateOperativeDevices(isset($data['OphTrOperationnote_CataractOperativeDevices']) ? $data['OphTrOperationnote_CataractOperativeDevices'] : array());
 }