diff --git a/backend/controllers/CommentController.php b/backend/controllers/CommentController.php
new file mode 100644
index 0000000..f001043
--- /dev/null
+++ b/backend/controllers/CommentController.php
@@ -0,0 +1,121 @@
+ [
+ 'class' => VerbFilter::className(),
+ 'actions' => [
+ 'delete' => ['post'],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * Lists all Comment models.
+ * @return mixed
+ */
+ public function actionIndex()
+ {
+ $dataProvider = new ActiveDataProvider([
+ 'query' => Comment::find(),
+ ]);
+
+ return $this->render('index', [
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+
+ /**
+ * Displays a single Comment model.
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionView($id)
+ {
+ return $this->render('view', [
+ 'model' => $this->findModel($id),
+ ]);
+ }
+
+ /**
+ * Creates a new Comment model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ * @return mixed
+ */
+ public function actionCreate()
+ {
+ $model = new Comment();
+
+ if ($model->load(Yii::$app->request->post()) && $model->save()) {
+ return $this->redirect(['view', 'id' => $model->comment_id]);
+ } else {
+ return $this->render('create', [
+ 'model' => $model,
+ ]);
+ }
+ }
+
+ /**
+ * Updates an existing Comment model.
+ * If update is successful, the browser will be redirected to the 'view' page.
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionUpdate($id)
+ {
+ $model = $this->findModel($id);
+
+ if ($model->load(Yii::$app->request->post()) && $model->save()) {
+ return $this->redirect(['view', 'id' => $model->comment_id]);
+ } else {
+ return $this->render('update', [
+ 'model' => $model,
+ ]);
+ }
+ }
+
+ /**
+ * Deletes an existing Comment model.
+ * If deletion is successful, the browser will be redirected to the 'index' page.
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionDelete($id)
+ {
+ $this->findModel($id)->delete();
+
+ return $this->redirect(['index']);
+ }
+
+ /**
+ * Finds the Comment model based on its primary key value.
+ * If the model is not found, a 404 HTTP exception will be thrown.
+ * @param integer $id
+ * @return Comment the loaded model
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ protected function findModel($id)
+ {
+ if (($model = Comment::findOne($id)) !== null) {
+ return $model;
+ } else {
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+ }
+}
diff --git a/backend/views/comment/_form.php b/backend/views/comment/_form.php
new file mode 100644
index 0000000..b8b2c16
--- /dev/null
+++ b/backend/views/comment/_form.php
@@ -0,0 +1,31 @@
+
+
+
diff --git a/backend/views/comment/create.php b/backend/views/comment/create.php
new file mode 100644
index 0000000..b3ab4a8
--- /dev/null
+++ b/backend/views/comment/create.php
@@ -0,0 +1,21 @@
+title = 'Create Comment';
+$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
diff --git a/backend/views/comment/index.php b/backend/views/comment/index.php
new file mode 100644
index 0000000..01f578c
--- /dev/null
+++ b/backend/views/comment/index.php
@@ -0,0 +1,36 @@
+title = 'Comments';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
diff --git a/backend/views/comment/update.php b/backend/views/comment/update.php
new file mode 100644
index 0000000..1ea8244
--- /dev/null
+++ b/backend/views/comment/update.php
@@ -0,0 +1,21 @@
+title = 'Update Comment: ' . ' ' . $model->comment_id;
+$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->comment_id, 'url' => ['view', 'id' => $model->comment_id]];
+$this->params['breadcrumbs'][] = 'Update';
+?>
+
diff --git a/backend/views/comment/view.php b/backend/views/comment/view.php
new file mode 100644
index 0000000..59aa83a
--- /dev/null
+++ b/backend/views/comment/view.php
@@ -0,0 +1,40 @@
+title = $model->comment_id;
+$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
diff --git a/common/models/Comment.php b/common/models/Comment.php
new file mode 100644
index 0000000..f6664c9
--- /dev/null
+++ b/common/models/Comment.php
@@ -0,0 +1,58 @@
+ 'Comment ID',
+ 'comment_pid' => 'Comment Pid',
+ 'content' => 'Content',
+ 'created_at' => 'Created At',
+ 'entity_id' => 'Entity ID',
+ 'user_id' => 'User ID',
+ ];
+ }
+
+ public function getUser()
+ {
+ return $this->hasOne(User::className(), ['id' => 'user_id']);
+ }
+}
diff --git a/common/widgets/CommentWidget.php b/common/widgets/CommentWidget.php
new file mode 100644
index 0000000..317dcff
--- /dev/null
+++ b/common/widgets/CommentWidget.php
@@ -0,0 +1,87 @@
+
+
+
+
+
' . $d['content'] . '
+
+
+
+ ';
+ }
+
+ private function display(array $comments, $level = 0)
+ {
+ foreach ($comments as $info)
+ {
+ echo '';
+
+ $this->html($info, $level + 1);
+
+ if (!empty($info['childs']))
+ {
+ $this->display($info['childs'], $level + 1);
+ }
+
+ echo '
';
+ }
+
+ if (isset($this->reload) && $this->reload == false)
+ {
+
+ }
+
+ }
+
+ private function field()
+ {
+ echo '';
+ }
+
+ public function init()
+ {
+
+ }
+ public function run()
+ {
+ echo '';
+ $this->field();
+ }
+}
diff --git a/frontend/controllers/CommentController.php b/frontend/controllers/CommentController.php
new file mode 100644
index 0000000..fd3a190
--- /dev/null
+++ b/frontend/controllers/CommentController.php
@@ -0,0 +1,69 @@
+with('user')->orderBy('created_at ASC')->all();
+
+ $comments = array();
+
+ foreach($post as $p)
+ {
+ $comments[$p['comment_id']] = array(
+ 'id' => $p['comment_id'],
+ 'parent' => $p['comment_pid'],
+ 'content' => $p['content'],
+ 'username' => $p->user->username,
+ 'created_at' => $p['created_at'],
+ 'childs' => array()
+ );
+ }
+
+ foreach ($comments as $key => &$val)
+ {
+ if ($val['parent'] != 0)
+ {
+ $comments[$val['parent']]['childs'][] =& $val;
+ }
+ }
+ unset($val);
+
+ foreach ($comments as $key => $val)
+ {
+ if ($val['parent'] != 0)
+ {
+ unset($comments[$key]);
+ }
+ }
+
+ if (Yii::$app->request->get('action') == 'reload')
+ {
+ return $this->renderAjax('index', array('data' => $comments));
+ }
+ else
+ {
+ return $this->render('index', array('data' => $comments, 'reload' => false));
+ }
+ }
+
+ public function actionCreate()
+ {
+ $comment = new Comment;
+
+ $comment->user_id = Yii::$app->user->identity->id;
+ $comment->content = Yii::$app->request->post('content');
+ $comment->entity_id = 3;//Yii::$app->request->post('entity_id');
+ $comment->comment_pid = Yii::$app->request->post('parent_id');
+ $comment->created_at = date('Y-m-d H:i:s', time());
+
+ $comment->save();
+
+ }
+
+}
diff --git a/frontend/views/comment/index.php b/frontend/views/comment/index.php
new file mode 100644
index 0000000..2c6e7d4
--- /dev/null
+++ b/frontend/views/comment/index.php
@@ -0,0 +1,10 @@
+registerJsFile(Yii::$app->request->baseUrl . '/js/comments.js', ['yii\web\JqueryAsset']);
+
+?>
+
+
+
+= CommentWidget::widget(['comments' => $data, 'reload' => $reload]) ?>
diff --git a/frontend/web/js/comments.js b/frontend/web/js/comments.js
new file mode 100644
index 0000000..0878021
--- /dev/null
+++ b/frontend/web/js/comments.js
@@ -0,0 +1,92 @@
+$(document).ready(function(){
+
+ applyScript();
+
+ /*var pubnub = PUBNUB({
+ subscribe_key: 'demo',
+ publish_key: 'demo'
+ });
+
+ pubnub.subscribe({
+ channel: 'comment',
+ message: function(m){console.log(m)},
+ error: function (error) {
+ // Handle error here
+ console.log(JSON.stringify(error));
+ }
+ }); */
+});
+
+function applyScript()
+{
+
+ var parent_id = 0;
+
+ var textarea = $(".new_comment").find("textarea");
+ var replyName;
+
+ $(".comment_reply").each(function()
+ {
+ $(this).hide();
+ });
+
+ $(".btn-reply").each(function()
+ {
+ $(this).on("click", function()
+ {
+ replyName = $(this).siblings().find(".comment_username").text();
+ parent_id = $(this).parents(".comment_body").attr("comment_id");
+
+ textarea.val(replyName + ', ');
+
+ });
+
+ });
+
+ $(".btn-send").on('click', function()
+ {
+ var content = textarea.val();
+
+ if (content.indexOf(replyName) > -1 == false)
+ {
+ parent_id = 0;
+ }
+ createComment(content, parent_id);
+ });
+
+ function reload_comments()
+ {
+ var path = window.location.protocol + "//" + window.location.host + "/";
+ $.ajax({
+ type: 'GET',
+ url : path + 'comment',
+ data : {
+ 'action' : 'reload'
+ },
+ success: function(res)
+ {
+ $("#comment_wrapper").html(res);
+ console.log('reloaded');
+
+ applyScript();
+ }
+ });
+ }
+ function createComment(content, parent_id)
+ {
+ $.ajax({
+ type: 'POST',
+ url : '/comment/create',
+ data: {
+ 'content' : content,
+ 'parent_id' : parent_id
+ },
+ success: function(res)
+ {
+ //reload_comments();
+ alert('Comment sent');
+ }
+ });
+ }
+
+}
--
libgit2 0.21.4