public function actionDelete($id)
{
if (isset($_POST['et_canceldelete'])) {
return $this->redirect(array('/' . $this->event_type->class_name . '/default/view/' . $id));
}
if (!empty($_POST)) {
$transaction = Yii::app()->db->beginTransaction();
try {
$this->event->softDelete();
$this->event->audit('event', 'delete', false);
if (Event::model()->count('episode_id=?', array($this->event->episode_id)) == 0) {
$this->event->episode->deleted = 1;
if (!$this->event->episode->save()) {
throw new Exception('Unable to save episode: ' . print_r($this->event->episode->getErrors(), true));
}
$this->event->episode->audit('episode', 'delete', false);
$transaction->commit();
if (!$this->dont_redirect) {
$this->redirect(array('/patient/episodes/' . $this->event->episode->patient->id));
} else {
return true;
}
}
Yii::app()->user->setFlash('success', 'An event was deleted, please ensure the episode status is still correct.');
$transaction->commit();
if (!$this->dont_redirect) {
$this->redirect(array('/patient/episode/' . $this->event->episode_id));
}
return true;
} catch (Exception $e) {
$transaction->rollback();
throw $e;
}
}
$this->title = 'Delete ' . $this->event_type->name;
$this->event_tabs = array(array('label' => 'View', 'active' => true));
if ($this->editable) {
$this->event_tabs[] = array('label' => 'Edit', 'href' => Yii::app()->createUrl($this->event->eventType->class_name . '/default/update/' . $this->event->id));
}
$this->processJsVars();
$episodes = $this->getEpisodes();
$viewData = array_merge(array('eventId' => $id), $episodes);
$this->render('delete', $viewData);
}