Element_OphTrOperationnote_Cataract::updateOperativeDevices PHP Метод

updateOperativeDevices() публичный Метод

Update the operative devices on the element.
public updateOperativeDevices ( $operative_device_ids )
$operative_device_ids
    public function updateOperativeDevices($operative_device_ids)
    {
        $curr_by_id = array();
        foreach ($this->operative_device_assignments as $oda) {
            $curr_by_id[$oda->operative_device_id] = $oda;
        }
        foreach ($operative_device_ids as $od_id) {
            if (!isset($curr_by_id[$od_id])) {
                $oda = new OphTrOperationnote_CataractOperativeDevice();
                $oda->cataract_id = $this->id;
                $oda->operative_device_id = $od_id;
                if (!$oda->save()) {
                    throw new Exception('Unable to save complication assignment: ' . print_r($oda->getErrors(), true));
                }
            } else {
                unset($curr_by_id[$od_id]);
            }
        }
        foreach ($curr_by_id as $oda) {
            if (!$oda->delete()) {
                throw new Exception('Unable to delete complication assignment: ' . print_r($oda->getErrors(), true));
            }
        }
    }

Usage Example

Пример #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());
 }