/**
  * Set the section comments on the element.
  *
  * @param $data
  * @throws \CDbException
  * @throws \Exception
  */
 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));
         }
     }
 }
 public function getDisorderSectionComments($disorder_section_id, $element_id)
 {
     $criteria = new \CDbCriteria();
     $criteria->select = 'comments';
     $criteria->condition = "element_id=:element_id";
     $criteria->addCondition("ophcocvi_clinicinfo_disorder_section_id=:disorder_section_id");
     $criteria->params = array(':element_id' => $element_id, ':disorder_section_id' => $disorder_section_id);
     $item = Element_OphCoCvi_ClinicalInfo_Disorder_Section_Comments::model()->find($criteria);
     return $item['comments'] ? $item['comments'] : '';
 }