public function run() { if (empty($_POST)) { if ($this->element->{$this->field}) { if (preg_match('/^[0-9]+ [a-zA-Z]+ [0-9]+$/', $this->element->{$this->field})) { $this->value = $this->element->{$this->field}; } else { $this->value = date('j M Y', strtotime($this->element->{$this->field})); } } else { if (@$this->htmlOptions['null']) { $this->value = null; } else { $this->value = date('j M Y'); } } } else { if ($this->name) { $this->value = $this->getPOSTValue($this->name); } else { $this->value = $_POST[get_class($this->element)][$this->field]; } } parent::run(); }
public function run() { if ($this->element) { $this->class = CHTML::modelName($this->element); } else { $this->class = get_class($this); } if (empty($_POST) || !array_key_exists($this->class, $_POST)) { if (empty($this->element->event_id)) { if ($this->default) { // It's a new event so fetch the most recent element_diagnosis $firmId = Yii::app()->session['selected_firm_id']; $firm = Firm::model()->findByPk($firmId); if (isset(Yii::app()->getController()->patient)) { $patientId = Yii::app()->getController()->patient->id; $episode = Episode::getCurrentEpisodeByFirm($patientId, $firm, true); if ($episode && ($disorder = $episode->diagnosis)) { // There is a diagnosis for this episode $this->value = $disorder->id; $this->label = $disorder->term; } } } } else { if (isset($this->element->disorder)) { $this->value = $this->element->disorder->id; $this->label = $this->element->disorder->term; } } } elseif (array_key_exists($this->field, $_POST[$this->class])) { if (preg_match('/[^\\d]/', $_POST[$this->class][$this->field])) { if ($disorder = Disorder::model()->find('term=? and specialty_id is not null', array($_POST[$this->class][$this->field]))) { $this->value = $disorder->id; $this->label = $disorder->term; } } else { $this->value = $_POST[$this->class][$this->field]; if ($disorder = Disorder::model()->findByPk($this->value)) { $this->label = $disorder->term; } } } parent::run(); }