BaseEventTypeController::actionDelete PHP Method

actionDelete() public method

Delete the event given by $id. Performs the soft delete action if it's been confirmed by $_POST.
public actionDelete ( $id )
$id
    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);
    }

Usage Example

Esempio n. 1
0
 /**
  * Ensures that any attached operation booking status is updated after the op note is removed.
  *
  * @param $id
  *
  * @return bool|void
  */
 public function actionDelete($id)
 {
     $proclist = Element_OphTrOperationnote_ProcedureList::model()->find('event_id=?', array($id));
     $this->dont_redirect = true;
     if (parent::actionDelete($id)) {
         if ($proclist && $proclist->booking_event_id) {
             if ($api = Yii::app()->moduleAPI->get('OphTrOperationbooking')) {
                 $api->setOperationStatus($proclist->booking_event_id, 'Scheduled or Rescheduled');
             }
         }
         if (Event::model()->count('episode_id=?', array($this->event->episode_id)) == 0) {
             $this->redirect(array('/patient/episodes/' . $this->event->episode->patient->id));
         } else {
             $this->redirect(array('/patient/episode/' . $this->event->episode_id));
         }
     }
 }
BaseEventTypeController