public actionCreate ( ) : boolean | string | ||
return | boolean | string |
public function actionCreate()
{
if (!empty($_POST)) {
// form has been submitted
if (isset($_POST['cancel'])) {
$this->redirectToPatientEpisodes();
}
// set and validate
$errors = $this->setAndValidateElementsFromData($_POST);
// creation
if (empty($errors)) {
$transaction = Yii::app()->db->beginTransaction();
try {
$success = $this->saveEvent($_POST);
if ($success) {
//TODO: should this be in the save event as pass through?
if ($this->eventIssueCreate) {
$this->event->addIssue($this->eventIssueCreate);
}
//TODO: should not be passing event?
$this->afterCreateElements($this->event);
$this->logActivity('created event.');
$this->event->audit('event', 'create');
Yii::app()->user->setFlash('success', "{$this->event_type->name} created.");
$transaction->commit();
$this->redirect(array($this->successUri . $this->event->id));
} else {
throw new Exception('could not save event');
}
} catch (Exception $e) {
$transaction->rollback();
throw $e;
}
}
} else {
$this->setOpenElementsFromCurrentEvent('create');
}
$this->editable = false;
$this->event_tabs = array(array('label' => 'Create', 'active' => true));
$cancel_url = $this->episode ? '/patient/episode/' . $this->episode->id : '/patient/episodes/' . $this->patient->id;
$this->event_actions = array(EventAction::link('Cancel', Yii::app()->createUrl($cancel_url), array('level' => 'cancel')));
$this->render('create', array('errors' => @$errors));
}
/** * Create Form with check for the cvi existing events count * @throws \Exception */ public function actionCreate() { $create_new_cvi = $this->request->getParam('createnewcvi', null); if ($create_new_cvi !== null) { $cancel_url = $this->episode ? '/patient/episode/' . $this->episode->id : '/patient/episodes/' . $this->patient->id; if ($create_new_cvi == 1) { if (!$this->getManager()->canCreateEventForPatient($this->patient)) { $this->getApp()->user->setFlash('warning.cvi_create', 'You cannot create another CVI whilst one exists that has not been issued.'); $this->redirect(array($cancel_url)); } else { parent::actionCreate(); } } else { $this->redirect(array($cancel_url)); } } else { $cvi_events = $this->getApp()->moduleAPI->get('OphCoCvi'); $current_cvis = $cvi_events->getEvents($this->patient); if (count($current_cvis) >= $this->cvi_limit) { $this->render('select_event', array('current_cvis' => $current_cvis, 'can_create' => $this->getManager()->canCreateEventForPatient($this->patient)), false); } else { parent::actionCreate(); } } }