-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
364 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* @link http://www.tintsoft.com/ | ||
* @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd. | ||
* @license http://www.tintsoft.com/license/ | ||
*/ | ||
namespace yuncms\question\frontend\models; | ||
|
||
use Yii; | ||
use yii\base\Model; | ||
use yuncms\question\models\QuestionComment; | ||
|
||
/** | ||
* Class CommentForm | ||
* @package yuncms\comment\frontend\models | ||
*/ | ||
class CommentForm extends Model | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
public $model_id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $content; | ||
|
||
private $_user; | ||
|
||
/** | ||
* @return \yii\web\IdentityInterface | ||
*/ | ||
public function getUser() | ||
{ | ||
if ($this->_user == null) { | ||
$this->_user = Yii::$app->user->identity; | ||
} | ||
return $this->_user; | ||
} | ||
|
||
/** | ||
* 保存评论 | ||
*/ | ||
public function save() | ||
{ | ||
if ($this->validate()) { | ||
$model = new QuestionComment([ | ||
'model_id' => $this->model_id, | ||
'user_id' => Yii::$app->user->id, | ||
'content' => $this->content, | ||
]); | ||
return $model->save(); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/** | ||
* @link http://www.tintsoft.com/ | ||
* @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd. | ||
* @license http://www.tintsoft.com/license/ | ||
*/ | ||
namespace yuncms\question\frontend\widgets; | ||
|
||
use Yii; | ||
use yii\base\Widget; | ||
use yii\helpers\Url; | ||
use yii\base\InvalidConfigException; | ||
use yuncms\question\frontend\models\CommentForm; | ||
|
||
/** | ||
* Class Comment | ||
* @package yuncms\question\widgets | ||
*/ | ||
class Comment extends Widget | ||
{ | ||
|
||
/** | ||
* @var int 关系ID | ||
*/ | ||
public $model_id; | ||
|
||
/** | ||
* @var bool 隐藏取消 | ||
*/ | ||
public $hide_cancel = false; | ||
|
||
/** @var bool */ | ||
public $validate = true; | ||
|
||
/** @inheritdoc */ | ||
public function init() | ||
{ | ||
parent::init(); | ||
$this->registerTranslations(); | ||
if (empty ($this->model_class)) { | ||
throw new InvalidConfigException ('The "model_class" property must be set.'); | ||
} | ||
if (empty ($this->model_id)) { | ||
throw new InvalidConfigException ('The "model_id" property must be set.'); | ||
} | ||
Url::remember('', 'actions-redirect'); | ||
} | ||
|
||
/** | ||
* 注册翻译 | ||
*/ | ||
public function registerTranslations() | ||
{ | ||
if (!isset(Yii::$app->i18n->translations['widgets/comment/*'])) { | ||
Yii::$app->i18n->translations['widgets/comment/*'] = [ | ||
'class' => 'yii\i18n\PhpMessageSource', | ||
'sourceLanguage' => 'en-US', | ||
'basePath' => __DIR__ . '/messages', | ||
'fileMap' => [ | ||
'widgets/comment/comment' => 'comment.php', | ||
], | ||
]; | ||
} | ||
} | ||
|
||
/** | ||
* 显示语言包 | ||
* @param string $category | ||
* @param string $message | ||
* @param array $params | ||
* @param null $language | ||
* @return string | ||
*/ | ||
public static function t($category, $message, $params = [], $language = null) | ||
{ | ||
return Yii::t('widgets/comment/' . $category, $message, $params, $language); | ||
} | ||
|
||
/** @inheritdoc */ | ||
public function run() | ||
{ | ||
$model = new CommentForm([ | ||
'model_id' => $this->model_id | ||
]); | ||
return $this->render('comment', [ | ||
'model' => $model, | ||
'model_id' => $this->model_id, | ||
'hide_cancel' => $this->hide_cancel, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* @link http://www.yiiframework.com/ | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @license http://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace yuncms\article; | ||
|
||
use yii\web\AssetBundle; | ||
|
||
/** | ||
* Asset bundle for the Twitter bootstrap javascript files. | ||
* | ||
* @author Qiang Xue <[email protected]> | ||
* @since 2.0 | ||
*/ | ||
class BootstrapPluginAsset extends AssetBundle | ||
{ | ||
public $sourcePath = '@bower/bootstrap/dist'; | ||
public $js = [ | ||
'js/bootstrap.js', | ||
]; | ||
public $depends = [ | ||
'yii\web\JqueryAsset', | ||
'yii\bootstrap\BootstrapAsset', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* @link http://www.tintsoft.com/ | ||
* @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd. | ||
* @license http://www.tintsoft.com/license/ | ||
*/ | ||
namespace yuncms\comment\frontend\widgets\assets; | ||
|
||
use yii\web\AssetBundle; | ||
|
||
/** | ||
* Class CommentAsset | ||
* @package yuncms\comment | ||
*/ | ||
class CommentAsset extends AssetBundle | ||
{ | ||
public $sourcePath = '@yuncms/comment/frontend/widgets/views/assets'; | ||
|
||
public $js = [ | ||
'js/comment.js', | ||
]; | ||
public $depends = [ | ||
'yii\web\JqueryAsset', | ||
'yii\bootstrap\BootstrapAsset' | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Configuration file for 'yii message/extract' command. | ||
* | ||
* This file is automatically generated by 'yii message/config' command. | ||
* It contains parameters for source code messages extraction. | ||
* You may modify this file to suit your needs. | ||
* | ||
* You can use 'yii message/config-template' command to create | ||
* template configuration file with detaild description for each parameter. | ||
*/ | ||
return [ | ||
'color' => null, | ||
'interactive' => true, | ||
// string, required, root directory of all source files | ||
'sourcePath' => __DIR__ . '/..', | ||
// string, required, root directory containing message translations. | ||
'messagePath' => __DIR__, | ||
'languages' => ['zh-CN'], | ||
'translator' => 'Comment::t', | ||
'sort' => false, | ||
'overwrite' => true, | ||
'removeUnused' => false, | ||
'markUnused' => true, | ||
'except' => [ | ||
'.svn', | ||
'.git', | ||
'.gitignore', | ||
'.gitkeep', | ||
'.hgignore', | ||
'.hgkeep', | ||
'/messages', | ||
'/BaseYii.php', | ||
], | ||
'only' => [ | ||
'*.php', | ||
], | ||
'format' => 'php', | ||
'db' => 'db', | ||
'sourceMessageTable' => '{{%source_message}}', | ||
'messageTable' => '{{%message}}', | ||
'catalog' => 'messages', | ||
'ignoreCategories' => ['yii', 'app'], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* Message translations. | ||
* | ||
* This file is automatically generated by 'yii message/extract' command. | ||
* It contains the localizable messages extracted from source code. | ||
* You may modify this file by translating the extracted messages. | ||
* | ||
* Each array element represents the translation (value) of a message (key). | ||
* If the value is empty, the message is considered as not translated. | ||
* Messages that no longer need translation will have their translations | ||
* enclosed between a pair of '@@' marks. | ||
* | ||
* Message string can be used with plural forms format. Check i18n section | ||
* of the guide for details. | ||
* | ||
* NOTE: this file must be saved in UTF-8 encoding. | ||
*/ | ||
return [ | ||
'Clean' => '取消', | ||
'Submit Comment' => '提交评论', | ||
'Write your comment' => '写下你的评论', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* 发布评论 | ||
* @param model_class | ||
* @param model_id | ||
* @param content | ||
* @param to_user_id | ||
*/ | ||
function add_comment(model_class, model_id, content, to_user_id) { | ||
var postData = {model_id: model_id, model_class: model_class, content: content}; | ||
if (to_user_id > 0) { | ||
postData.to_user_id = to_user_id; | ||
} | ||
jQuery.post('/comment/default/store', postData, function (html) { | ||
jQuery("#comments-" + model_class + "-" + model_id + " .widget-comment-list").append(html); | ||
jQuery("#comment-" + model_class + "-content-" + model_id).val(''); | ||
}); | ||
} | ||
|
||
/** | ||
* 加载评论 | ||
* @param model_class | ||
* @param model_id | ||
*/ | ||
function load_comments(model_class, model_id) { | ||
jQuery.get('/comment/default/list', { | ||
model_id: model_id, model_class: model_class | ||
}, function (html) { | ||
jQuery("#comments-" + model_class + "-" + model_id + " .widget-comment-list").append(html); | ||
}); | ||
} | ||
|
||
/** | ||
* 清除评论 | ||
* @param model_class | ||
* @param model_id | ||
*/ | ||
function clear_comments(model_class, model_id) { | ||
jQuery("#comments-" + model_class + "-" + model_id + " .widget-comment-list").empty(); | ||
} | ||
|
||
/*评论提交*/ | ||
jQuery(".comment-btn").click(function () { | ||
var model_id = jQuery(this).data('model_id'); | ||
var model_class = jQuery(this).data('model_class'); | ||
var to_user_id = jQuery(this).data('to_user_id'); | ||
var content = jQuery("#comment-" + model_class + "-content-" + model_id).val(); | ||
add_comment(model_class, model_id, content, to_user_id); | ||
jQuery("#comment-content-" + model_id + "").val(''); | ||
}); |
Oops, something went wrong.