/** * Creates a new comment * TODO: Figure out how to fix the email issues * @param int $id The Comment id * @return array */ private function createComment() { $model = new Comments(); $model->attributes = $_POST; $model->approved = Cii::getConfig('autoApproveComments', 0); if ($model->save()) { return $model->getApiAttributes(); } return $this->returnError(400, NULL, $model->getErrors()); }
protected function beforeAction($action) { if (isset($_REQUEST['Comments'])) { $comment = $_REQUEST['Comments']; //Yii::app()->notify->add("Добавлен комментарий"); if (isset($comment)) { if (isset($comment['id']) and isset($comment['model'])) { } $entry = new Comments(); $entry->entryid = $comment['id']; $entry->comment = $comment['comment']; $entry->model = "Solutions"; $entry->student = Yii::app()->my->id; if ($entry->save()) { Yii::app()->notify->add("Добавлен комментарий "); } else { Yii::app()->notify->addErrors($entry->getErrors()); } } } return true; }
public function actionReply($id) { $reply = Comments::model()->findByPk($id); $comment = new Comments(); if (isset($_POST['Comments'])) { $comment->attributes = $_POST['Comments']; $comment->model = $reply->model; $comment->object_id = $reply->object_id; $comment->user_id = !Yii::app()->user->isGuest ? Yii::app()->user->id : 0; if ($comment->validate()) { $comment->appendTo($reply); Yii::app()->session['caf'] = CMS::time(); $data = array('code' => 'success', 'flash_message' => Yii::t('CommentsModule.default', 'COMM_SUCCESS_REPLY')); } else { $data = array('code' => 'fail', 'response' => $comment->getErrors()); } echo CJSON::encode($data); } else { $reply->unsetAttributes(array('text')); Yii::app()->clientScript->scriptMap = array('jquery.js' => false); $this->render('_reply_form', array('model' => $reply), false, true); } }
public function addComment($params = array()) { extract($params); if (isset($dynamic_id) && isset($user_id) && $user_id && $dynamic_id) { $comment = array('dynamic_id' => $dynamic_id, 'user_id' => $user_id); if (isset($content) && $content) { $comment['content'] = $content; } if (isset($image) && $image) { if (!is_null(json_decode($image))) { $images = json_decode($image); $comment['images'] = implode(',', $images); } else { $comment['images'] = $image; } } if (isset($content) && $content || isset($image) && $image) { $model = new Comments(); $model->attributes = $comment; if ($model->validate() && $model->save()) { $ret = $this->notice('OK', 0, '成功', []); } else { $ret = $this->notice('ERR', 307, '操作数据错误', $model->getErrors()); } } else { $ret = $this->notice('ERR', 303, '没有评论内容', []); } } else { $ret = $this->notice('ERR', 301, '缺少关键参数', []); } return $ret; }
public function actionAfterPost($st_id, $c_id, $j_id, $pr_id) { $model = new Comments(); // uncomment the following code to enable ajax-based validation /* if(isset($_POST['ajax']) && $_POST['ajax']==='job-profile-_form-form') { echo CActiveForm::validate($model); Yii::app()->end(); } */ if (isset($_POST['Comments'])) { $model->txt = $_POST['Comments']['txt']; $model->st_id = $st_id; $model->c_id = $c_id; $model->j_id = $j_id; $model->pr_id = Yii::App()->user->id; if ($model->validate()) { // form inputs are valid, do something here $model->save(); Yii::app()->user->setFlash('success', 'Comment Posted Successfully '); $this->redirect(array('index')); return; } else { var_dump($model->getErrors()); echo 'validation problem'; } } }