[go: up one dir, main page]

Skip to content

Commit

Permalink
remove feehi/assets directory replace config cdn resource with config…
Browse files Browse the repository at this point in the history
… file components section assetManager bundles and optimize sql query use lazy loading
  • Loading branch information
liufee committed Nov 29, 2017
1 parent 2b1d875 commit 1c549d0
Show file tree
Hide file tree
Showing 38 changed files with 143 additions and 411 deletions.
4 changes: 2 additions & 2 deletions backend/assets/AppAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function init()
];

public $depends = [
'feehi\assets\YiiAsset',
'feehi\assets\BootstrapAsset',
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
4 changes: 2 additions & 2 deletions backend/assets/IndexAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function init()
];

public $depends = [
'feehi\assets\YiiAsset',
'feehi\assets\BootstrapAsset',
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
2 changes: 1 addition & 1 deletion backend/grid/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use yii;
use yii\helpers\ArrayHelper;
use yii\widgets\LinkPager;
use feehi\assets\GridViewAsset;
use yii\grid\GridViewAsset;
use yii\helpers\Json;
use yii\widgets\BaseListView;

Expand Down
18 changes: 16 additions & 2 deletions backend/models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@

class Article extends \common\models\Article
{
/**
* @var string
*/
public $tag = '';

/**
* @var null|string
*/
public $content = null;

/**
* @inheritdoc
Expand Down Expand Up @@ -129,8 +138,13 @@ public function beforeDelete()
public function afterFind()
{
parent::afterFind();
$metaModel = new ArticleMetaTag();
$this->tag = $metaModel->getTagsByArticle($this->id, true);
$this->tag = call_user_func(function(){
$tags = '';
foreach ($this->articleTags as $tag) {
$tags .= $tag->value . ',';
}
return rtrim($tags, ',');
});
$this->content = ArticleContent::findOne(['aid' => $this->id])['content'];
}

Expand Down
3 changes: 2 additions & 1 deletion backend/models/search/ArticleSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace backend\models\search;

use common\models\Article as CommonArticle;
use backend\models\Article;
use common\models\Category;
use yii\data\ActiveDataProvider;
Expand Down Expand Up @@ -72,7 +73,7 @@ public function scenarios()
*/
public function search($params, $type = self::ARTICLE)
{
$query = Article::find()->select([])->where(['type' => $type]);
$query = CommonArticle::find()->select([])->where(['type' => $type])->with('category');
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
Expand Down
5 changes: 1 addition & 4 deletions backend/models/search/CommentSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function rules()
*/
public function search($params)
{
$query = self::find();
$query = self::find()->with('article');
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
Expand Down Expand Up @@ -111,9 +111,6 @@ public function search($params)
}
$query->andFilterWhere(['aid' => $aidArray]);
}
if( $this->aid ){
$this->article_title = Article::findOne($this->aid)['title'];
}
return $dataProvider;
}
}
2 changes: 1 addition & 1 deletion backend/views/article/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use common\libs\Constants;
use yii\helpers\Html;
use backend\widgets\Bar;
use common\widgets\Pjax;
use yii\widgets\Pjax;
use backend\grid\CheckboxColumn;
use backend\grid\ActionColumn;
use backend\grid\StatusColumn;
Expand Down
2 changes: 1 addition & 1 deletion backend/views/comment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
'attribute' => 'article_title',
'label' => yii::t('app', 'Article Title'),
'value' => function ($model) {
return Article::getArticleById($model->aid)['title'];
return $model->article->title;
}
],
[
Expand Down
2 changes: 1 addition & 1 deletion backend/views/site/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use yii\helpers\Html;
use backend\widgets\ActiveForm;
use yii\helpers\Url;
use feehi\components\Captcha;
use yii\captcha\Captcha;

AppAsset::register($this);
$this->title = yii::t('app', 'Login');
Expand Down
2 changes: 1 addition & 1 deletion backend/widgets/ActiveForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use yii\base\InvalidCallException;
use yii\helpers\Html;
use yii\helpers\Json;
use feehi\assets\ActiveFormAsset;
use yii\widgets\ActiveFormAsset;

class ActiveForm extends \yii\widgets\ActiveForm
{
Expand Down
31 changes: 28 additions & 3 deletions common/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,40 @@
'from' => ['admin@feehi.com' => 'Feehi CMS robot ']
],
],
'view' => [
'class' => feehi\components\View::className(),
],
'feehi' => [
'class' => feehi\components\Feehi::className(),
],
'authManager' => [
'class' => yii\rbac\DbManager::className(),
],
'assetManager' => [
'bundles' => [
yii\widgets\ActiveFormAsset::className() => [
'js' => ['yii.activeForm.js'],
],
yii\bootstrap\BootstrapAsset::className() => [
'css' => ['css/bootstrap.css'],
],
yii\captcha\CaptchaAsset::className() => [
'js' => ['yii.captcha.js'],
],
yii\grid\GridViewAsset::className() => [
'js' => ['yii.gridView.js'],
],
yii\web\JqueryAsset::className() => [
'js' => ['jquery.js'],
],
yii\widgets\PjaxAsset::className() => [
'js' => ['jquery.pjax.js'],
],
yii\web\YiiAsset::className() => [
'js' => ['yii.js'],
],
yii\validators\ValidationAsset::className() => [
'js' => ['yii.validation.js'],
],
],
],
],
];
$install = yii::getAlias('@common/config/conf/db.php');
Expand Down
28 changes: 20 additions & 8 deletions common/models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace common\models;

use common\models\meta\ArticleMetaLike;
use common\models\meta\ArticleMetaTag;
use Yii;
use common\libs\Constants;
use yii\behaviors\TimestampBehavior;
Expand Down Expand Up @@ -54,10 +56,6 @@ class Article extends \yii\db\ActiveRecord
const ARTICLE_PUBLISHED = 1;
const ARTICLE_DRAFT = 0;

public $tag = '';

public $content = null;

public function behaviors()
{
return [
Expand Down Expand Up @@ -232,12 +230,26 @@ public function getArticleContent()
}

/**
* @param $id
* @return static
* @return \yii\db\ActiveQuery
*/
public function getArticleLikes()
{
$tempModel = new ArticleMetaLike();
return $this->hasMany(ArticleMetaLike::className(), ['aid' => 'id'])->where(['key'=>$tempModel->keyName]);
}

public function getArticleTags()
{
$tempModel = new ArticleMetaTag();
return $this->hasMany(ArticleMetaLike::className(), ['aid' => 'id'])->where(['key'=>$tempModel->keyName]);
}

/**
* @return integer
*/
public static function getArticleById($id)
public function getArticleLikeCount()
{
return self::findOne(['id' => $id]);
return $this->getArticleLikes()->count('id');
}

public function afterFind()
Expand Down
1 change: 0 additions & 1 deletion common/models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public function getCommentByAid($id)
$v = $row->getAttributes();
if ($v['reply_to'] == 0) {
$v['sub'] = self::getCommentChildren($list, $v['id']);
$v['content'] = $v['content'];
$newList[] = $v;
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/models/meta/ArticleMetaTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ArticleMetaTag extends \common\models\ArticleMeta

public function getTagsByArticle($aid, $isString=false)
{
$result = $this->find()->where(['key'=>$this->keyName])->where(['aid'=>$aid])->asArray()->all();
$result = $this->find()->where(['key'=>$this->keyName])->andWhere(['aid'=>$aid])->asArray()->all();
if( $result === null ){
if( $isString ){
return '';
Expand Down
45 changes: 0 additions & 45 deletions common/widgets/Pjax.php

This file was deleted.

22 changes: 0 additions & 22 deletions feehi/assets/ActiveFormAsset.php

This file was deleted.

18 changes: 0 additions & 18 deletions feehi/assets/BootstrapAsset.php

This file was deleted.

22 changes: 0 additions & 22 deletions feehi/assets/CaptchaAsset.php

This file was deleted.

22 changes: 0 additions & 22 deletions feehi/assets/GridViewAsset.php

This file was deleted.

18 changes: 0 additions & 18 deletions feehi/assets/JqueryAsset.php

This file was deleted.

Loading

0 comments on commit 1c549d0

Please sign in to comment.