public function actionAddComment($id)
{
$element = $this->getMessageElement();
if (count($element->comments)) {
throw new \CHttpException(409, 'Only one comment allowed per message.');
}
$comment = new OphCoMessaging_Message_Comment();
\OELog::log(print_r($_POST, true));
$comment->comment_text = @$_POST['OEModule_OphCoMessaging_models_OphCoMessaging_Message_Comment']['comment_text'];
$comment->element_id = $element->id;
if (!$comment->validate()) {
$this->show_comment_form = true;
$this->action = new \CInlineAction($this, 'view');
$errors = array('Comment' => array());
foreach ($comment->getErrors() as $err) {
$errors['Comment'] = array_values($err);
}
$this->render('view', array('errors' => $errors, 'comment' => $comment));
} else {
$transaction = \Yii::app()->db->beginTransaction();
try {
$element->marked_as_read = true;
$element->save();
$comment->save();
$transaction->commit();
\Yii::app()->user->setFlash('success', 'Comment added to record');
} catch (\Exception $e) {
$transaction->rollback();
throw $e;
}
$this->redirectAfterAction();
}
}