public function actionUpdate($id)
{
if (!empty($_POST)) {
// somethings been submitted
if (isset($_POST['cancel'])) {
// Cancel button pressed, so just bounce to view
$this->redirect(array('default/view/' . $this->event->id));
}
$errors = $this->setAndValidateElementsFromData($_POST);
// update the event
if (empty($errors)) {
$transaction = Yii::app()->db->beginTransaction();
try {
//TODO: should all the auditing be moved into the saving of the event
$success = $this->saveEvent($_POST);
if ($success) {
//TODO: should not be pasing event?
$this->afterUpdateElements($this->event);
$this->logActivity('updated event');
$this->event->audit('event', 'update');
$this->event->user = Yii::app()->user->id;
if (!$this->event->save()) {
throw new SystemException('Unable to update event: ' . print_r($this->event->getErrors(), true));
}
OELog::log("Updated event {$this->event->id}");
$transaction->commit();
$this->redirect(array('default/view/' . $this->event->id));
} else {
throw new Exception('Unable to save edits to event');
}
} catch (Exception $e) {
$transaction->rollback();
throw $e;
}
}
} else {
// get the elements
$this->setOpenElementsFromCurrentEvent('update');
}
$this->editing = true;
$this->event_tabs = array(array('label' => 'View', 'href' => Yii::app()->createUrl($this->event->eventType->class_name . '/default/view/' . $this->event->id)), array('label' => 'Edit', 'active' => true));
$this->event_actions = array(EventAction::link('Cancel', Yii::app()->createUrl($this->event->eventType->class_name . '/default/view/' . $this->event->id), array('level' => 'cancel')));
$this->render($this->action->id, array('errors' => @$errors));
}