-
Notifications
You must be signed in to change notification settings - Fork 108
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
14 changed files
with
249 additions
and
59 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
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
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,65 @@ | ||
<?php | ||
|
||
namespace backend\models; | ||
|
||
use Yii; | ||
use yii\base\Model; | ||
use yii\data\ActiveDataProvider; | ||
|
||
/** | ||
* PostSearch represents the model behind the search form about `backend\models\Post`. | ||
*/ | ||
class PostSearch extends Post | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
[['id', 'created_at', 'user_id'], 'integer'], | ||
[['title', 'content', 'tags'], 'safe'], | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function scenarios() | ||
{ | ||
// bypass scenarios() implementation in the parent class | ||
return Model::scenarios(); | ||
} | ||
|
||
/** | ||
* Creates data provider instance with search query applied | ||
* | ||
* @param array $params | ||
* | ||
* @return ActiveDataProvider | ||
*/ | ||
public function search($params) | ||
{ | ||
$query = Post::find(); | ||
|
||
$dataProvider = new ActiveDataProvider([ | ||
'query' => $query, | ||
]); | ||
|
||
if (!($this->load($params) && $this->validate())) { | ||
return $dataProvider; | ||
} | ||
|
||
$query->andFilterWhere([ | ||
'id' => $this->id, | ||
'created_at' => $this->created_at, | ||
'user_id' => $this->user_id, | ||
]); | ||
|
||
$query->andFilterWhere(['like', 'title', $this->title]) | ||
->andFilterWhere(['like', 'content', $this->content]) | ||
->andFilterWhere(['like', 'tags', $this->tags]); | ||
|
||
return $dataProvider; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
return [ | ||
'Forum' => '论坛', | ||
'Board' => '版块', | ||
'Thread' => '帖子', | ||
'Post' => '评论', | ||
]; |
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,66 @@ | ||
<?php | ||
|
||
namespace backend\modules\forum\models; | ||
|
||
use Yii; | ||
use yii\base\Model; | ||
use yii\data\ActiveDataProvider; | ||
|
||
/** | ||
* BoardSearch represents the model behind the search form about `backend\modules\forum\models\Board`. | ||
*/ | ||
class BoardSearch extends Board | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
[['id', 'forum_id', 'parent_id', 'columns', 'user_id'], 'integer'], | ||
[['name', 'description'], 'safe'], | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function scenarios() | ||
{ | ||
// bypass scenarios() implementation in the parent class | ||
return Model::scenarios(); | ||
} | ||
|
||
/** | ||
* Creates data provider instance with search query applied | ||
* | ||
* @param array $params | ||
* | ||
* @return ActiveDataProvider | ||
*/ | ||
public function search($params) | ||
{ | ||
$query = Board::find(); | ||
|
||
$dataProvider = new ActiveDataProvider([ | ||
'query' => $query, | ||
]); | ||
|
||
if (!($this->load($params) && $this->validate())) { | ||
return $dataProvider; | ||
} | ||
|
||
$query->andFilterWhere([ | ||
'id' => $this->id, | ||
'user_id' => $this->user_id, | ||
'forum_id' => $this->forum_id, | ||
'columns' => $this->columns, | ||
'parent_id' => $this->parent_id | ||
]); | ||
|
||
$query->andFilterWhere(['like', 'name', $this->name]) | ||
->andFilterWhere(['like', 'description', $this->description]); | ||
|
||
return $dataProvider; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
use yii\helpers\Html; | ||
use yii\grid\GridView; | ||
|
||
/* @var $this yii\web\View */ | ||
|
||
$this->title = Yii::t('forum', 'Board'); | ||
?> | ||
<div class="board-index"> | ||
<h1><?= Html::encode($this->title) ?></h1> | ||
<div class="board-all"> | ||
<?= GridView::widget([ | ||
'dataProvider' => $dataProvider, | ||
'filterModel' => $searchModel, | ||
'columns' => [ | ||
['class' => 'yii\grid\SerialColumn'], | ||
|
||
'id', | ||
'name', | ||
'parent_id', | ||
'forum_id', | ||
'description:ntext', | ||
'user_id', | ||
|
||
['class' => 'yii\grid\ActionColumn'], | ||
], | ||
]); ?> | ||
</div> | ||
</div> |
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 |
---|---|---|
@@ -1,46 +1,36 @@ | ||
<?php | ||
|
||
use yii\helpers\Html; | ||
use yii\helpers\Url; | ||
use yii\helpers\HtmlPurifier; | ||
use shiyang\infinitescroll\InfiniteScrollPager; | ||
use yii\grid\GridView; | ||
|
||
/* @var $this yii\web\View */ | ||
/* @var $model backend\models\Post */ | ||
|
||
$this->title = Yii::t('app', 'Posts'); | ||
$this->params['breadcrumbs'][] = $this->title; | ||
$this->title = Yii::$app->setting->get('siteTitle'); | ||
?> | ||
<div class="post-index"> | ||
|
||
<h1><?= Html::encode($this->title) ?></h1> | ||
<ul class="timeline"> | ||
<li class="time-label"> | ||
<?= Html::a(Yii::t('app', 'Create a post'), ['/post/create', 'category' => 'post'], ['class' => 'btn btn-success']) ?> | ||
</li> | ||
<?php foreach($models as $post): ?> | ||
<li> | ||
<i class="glyphicon glyphicon-list-alt bg-blue"></i> | ||
<div class="timeline-item"> | ||
<span class="time"><?= Yii::$app->formatter->asRelativeTime($post['created_at']) ?></span> | ||
<h3 class="timeline-header"><span class="new-icon"></span> | ||
<a href="<?= Url::toRoute(['/post/view', 'id' => $post['id']]) ?>" title="?" target="_blank"><?= Html::encode($post['title']) ?></a> | ||
</h3> | ||
<div class="timeline-body"> | ||
<p><?= HtmlPurifier::process(mb_substr(strip_tags($post['content']), 0, 140, 'utf-8')) ?></p> | ||
</div> | ||
<div class="timeline-footer"> | ||
<a class="btn btn-primary btn-xs" href="<?= Url::toRoute(['/post/view', 'id' => $post['id']]) ?>" target="_blank"><?= Yii::t('app', 'Read more') ?></a> | ||
<a class="btn btn-danger btn-xs" href="<?= Url::toRoute(['/post/delete', 'id' => $post['id']]) ?>" data-confirm="<?= Yii::t('app', 'Are you sure to delete it?') ?>" data-method="post"> | ||
<span class="glyphicon glyphicon-trash"></span> <?= Yii::t('app', 'Delete') ?> | ||
</a> | ||
</div> | ||
</div> | ||
</li> | ||
<?php endforeach ?> | ||
<?= InfiniteScrollPager::widget([ | ||
'pagination' => $pages, | ||
'widgetId' => '.timeline', | ||
]);?> | ||
</ul> | ||
<p> | ||
<?= Html::a(Yii::t('app', 'Create Post'), ['create'], ['class' => 'btn btn-success']) ?> | ||
</p> | ||
<div class="post-all"> | ||
<?= GridView::widget([ | ||
'dataProvider' => $dataProvider, | ||
'filterModel' => $searchModel, | ||
'columns' => [ | ||
'id', | ||
'title:ntext', | ||
[ | ||
'attribute' => 'content', | ||
'value' => function ($model) { | ||
return mb_substr($model->content, 0, 200, 'utf-8'); | ||
} | ||
], | ||
'tags:ntext', | ||
'user_id', | ||
'created_at:time', | ||
['class' => 'yii\grid\ActionColumn'], | ||
], | ||
]); ?> | ||
</div> | ||
</div> |
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
Oops, something went wrong.