Element_OphTrOperationbooking_Operation::updateProcedures PHP Méthode

updateProcedures() public méthode

Stores procedures identified by the given procedure ids against this element.
public updateProcedures ( array $procedure_ids )
$procedure_ids array
    public function updateProcedures($procedure_ids)
    {
        $existing_ids = array();
        foreach (OphTrOperationbooking_Operation_Procedures::model()->findAll('element_id = :elementId', array(':elementId' => $this->id)) as $item) {
            $existing_ids[$item->proc_id] = $item->id;
        }
        foreach ($procedure_ids as $id) {
            if (in_array($id, $existing_ids)) {
                unset($existing_ids[$id]);
            } else {
                $item = new OphTrOperationbooking_Operation_Procedures();
                $item->element_id = $this->id;
                $item->proc_id = $id;
                if (!$item->save()) {
                    throw new Exception('Unable to save MultiSelect item: ' . print_r($item->getErrors(), true));
                }
            }
        }
        OphTrOperationbooking_Operation_Procedures::model()->deleteByPk(array_values($existing_ids));
    }