OEModule\OphCoCvi\models\Element_OphCoCvi_ClinicalInfo::updateDisorderSectionComments PHP Метод

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

Set the section comments on the element.
public updateDisorderSectionComments ( $data )
$data
    public function updateDisorderSectionComments($data)
    {
        $current = $this->getRelated('cvi_disorder_section_comments', true);
        while ($section_comment = array_shift($current)) {
            if (array_key_exists($section_comment->ophcocvi_clinicinfo_disorder_section_id, $data)) {
                $comment_data = $data[$section_comment->ophcocvi_clinicinfo_disorder_section_id];
                $section_comment->comments = isset($comment_data['comments']) ? $comment_data['comments'] : "";
                if (!$section_comment->save()) {
                    throw new \Exception('Unable to save CVI Disorder Section Comment: ' . print_r($section_comment->getErrors(), true));
                }
                unset($data[$section_comment->ophcocvi_clinicinfo_disorder_section_id]);
            } else {
                if (!$section_comment->delete()) {
                    throw new \Exception('Unable to delete CVI Disorder Section Comment: ' . print_r($section_comment->getErrors(), true));
                }
            }
        }
        foreach ($data as $section_id => $values) {
            $section_comment = new Element_OphCoCvi_ClinicalInfo_Disorder_Section_Comments();
            $section_comment->ophcocvi_clinicinfo_disorder_section_id = $section_id;
            $section_comment->comments = isset($values['comments']) ? $values['comments'] : "";
            $section_comment->element_id = $this->id;
            if (!$section_comment->save()) {
                throw new \Exception("Unable to save CVI Disorder Section Comment: " . print_r($section_comment->getErrors(), true));
            }
        }
    }