Skip to content

Commit

Permalink
'bigtiger'
Browse files Browse the repository at this point in the history
  • Loading branch information
yidashi committed Mar 1, 2017
1 parent b021cab commit 1d0f9a4
Show file tree
Hide file tree
Showing 111 changed files with 8,225 additions and 519 deletions.
2 changes: 1 addition & 1 deletion backend/controllers/SuggestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function behaviors()
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' => Comment::find()->where(['type' => 'suggest']),
'query' => Comment::find()->where(['entity' => 'suggest']),
'sort' => [
'defaultOrder' => [
'id' => SORT_DESC
Expand Down
10 changes: 5 additions & 5 deletions backend/views/site/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="icon">
<i class="fa fa-book"></i>
</div>
<a href="<?= Url::to(['/article/index']) ?>" class="small-box-footer" target="_blank" title="文章列表">更多信息 <i class="fa fa-arrow-circle-right"></i></a>
<a href="<?= Url::to(['/article/index']) ?>" class="small-box-footer" target="_blank">更多信息 <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div><!-- ./col -->
<div class="col-md-3 col-xs-6">
Expand All @@ -32,7 +32,7 @@
<div class="icon">
<i class="fa fa-book"></i>
</div>
<a href="<?= Url::to(['/article/index']) ?>" class="small-box-footer" target="_blank" title="文章列表">更多信息 <i class="fa fa-arrow-circle-right"></i></a>
<a href="<?= Url::to(['/article/index']) ?>" class="small-box-footer" target="_blank">更多信息 <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div><!-- ./col -->
<div class="col-md-3 col-xs-6">
Expand All @@ -45,20 +45,20 @@
<div class="icon">
<i class="fa fa-user"></i>
</div>
<a href="<?= Url::to(['/user/admin/index']) ?>" class="small-box-footer" target="_blank" title="用户管理">更多信息 <i class="fa fa-arrow-circle-right"></i></a>
<a href="<?= Url::to(['/user/admin/index']) ?>" class="small-box-footer" target="_blank">更多信息 <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div><!-- ./col -->
<div class="col-md-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-purple">
<div class="inner">
<h3><?= \common\models\Comment::find()->where(['type' => 'suggest'])->count() ?></h3>
<h3><?= \common\models\Comment::find()->where(['entity' => 'suggest'])->count() ?></h3>
<p>留言</p>
</div>
<div class="icon">
<i class="fa fa-files-o"></i>
</div>
<a href="<?= Url::to(['/suggest/index']) ?>" class="small-box-footer" target="_blank" title="留言板">更多信息 <i class="fa fa-arrow-circle-right"></i></a>
<a href="<?= Url::to(['/suggest/index']) ?>" class="small-box-footer" target="_blank">更多信息 <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div><!-- ./col -->
</div><!-- /.row -->
Expand Down
51 changes: 51 additions & 0 deletions common/behaviors/BaseAttachAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace common\behaviors;

use yii\base\Behavior;

class BaseAttachAttribute extends Behavior
{

/**
*
* @var \yii\db\ActiveRecord
*/
public $owner;


/**
* @var string
*/
public $attribute;

/**
*
* @var mixed
*/
protected $value;


public function canGetProperty($name, $checkVars = true)
{
return parent::canGetProperty($name, $checkVars) || $this->attribute == $name;
}

// 根据特性返回这个值
public function __get($name)
{
if ($name != $this->attribute) {
return parent::__get($name);
}
if ($this->value == null) {
$this->value = $this->getValue();
}
return $this->value;
}

protected function getValue()
{

}

}
39 changes: 12 additions & 27 deletions common/behaviors/CommentBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

use common\models\Comment;
use common\models\CommentInfo;
use common\traits\EntityTrait;
use Yii;
use yii\base\Behavior;
use yii\db\ActiveRecord;
use yii\validators\Validator;

class CommentBehavior extends Behavior
{
use EntityTrait;
/**
* @var \yii\db\ActiveRecord
*/
public $owner;

public $type;

public $defaultStatus = 1;

public function events()
Expand Down Expand Up @@ -55,8 +55,8 @@ public function afterInsert()
return;
}
$model = new CommentInfo();
$model->type = $this->getType();
$model->type_id = $this->getTypeId();
$model->entity = $this->getEntity();
$model->entity_id = $this->getEntityId();
$model->status = $status;
$model->save();
}
Expand All @@ -74,8 +74,8 @@ public function afterUpdate()
return;
}
$model = new CommentInfo();
$model->type = $this->getType();
$model->type_id = $this->getTypeId();
$model->entity = $this->getEntity();
$model->entity_id = $this->getEntityId();
$model->status = $status;
$model->save();
} else {
Expand All @@ -87,32 +87,17 @@ public function afterUpdate()

public function afterDelete()
{
$type = $this->getType();
$type_id = $this->getTypeId();
CommentInfo::deleteAll(['type' => $type, 'type_id' => $type_id]);
Comment::deleteAll(['type' => $type, 'type_id' => $type_id]);
$entity = $this->getEntity();
$entityId = $this->getEntityId();
CommentInfo::deleteAll(['entity' => $entity, 'entity_id' => $entityId]);
Comment::deleteAll(['entity' => $entity, 'entity_id' => $entityId]);
}

public function getCommentInfo()
{
return $this->owner->hasOne(CommentInfo::className(), [
'type_id' => $this->owner->primaryKey()[0]
])->where(["type" => $this->getType()]);
}


public function getType()
{
if ($this->type == null) {
$this->type = $this->owner->className();
}

return ltrim($this->type,"\\");
}

public function getTypeId()
{
return $this->owner->getPrimaryKey();
'entity_id' => $this->owner->primaryKey()[0]
])->where(['entity' => $this->getEntity()]);
}

public function getCommentTotal()
Expand Down
22 changes: 7 additions & 15 deletions common/behaviors/MetaBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@


use common\models\Meta;
use common\traits\EntityTrait;
use Yii;
use yii\base\Behavior;
use yii\db\ActiveRecord;

class MetaBehavior extends Behavior
{
public $type;

use EntityTrait;
public function events()
{
return [
Expand Down Expand Up @@ -48,28 +49,19 @@ public function getMetaModel()
$model = $this->owner->meta;
if ($model == null) {
$model = new Meta([
'type' => $this->getType(),
'type_id' => $this->owner->getPrimaryKey()
'entity' => $this->getEntity(),
'entity_id' => $this->getEntityId()
]);
}
return $model;
}
public function getMeta()
{
return $this->owner->hasOne(Meta::className(), [
'type_id' => $this->owner->primaryKey()[0]
'entity_id' => $this->owner->primaryKey()[0]
])->where([
"type" => $this->getType()
"entity" => $this->getEntity()
]);
}

public function getType()
{
if ($this->type == null) {
$this->type = $this->owner->className();
}

return ltrim($this->type,"\\");
}

}
61 changes: 48 additions & 13 deletions common/behaviors/VoteBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@


use common\models\Vote;
use common\models\VoteInfo;
use common\traits\EntityTrait;
use Yii;
use yii\base\Behavior;
use yii\db\ActiveRecord;

class VoteBehavior extends Behavior
{
use EntityTrait;
/**
* @var \yii\db\ActiveRecord
*/
public $owner;

public $type;

public function events()
{
return [
ActiveRecord::EVENT_AFTER_INSERT => 'afterInsert',
ActiveRecord::EVENT_AFTER_UPDATE => 'afterUpdate',
ActiveRecord::EVENT_AFTER_DELETE => 'afterDelete',
];
}
Expand All @@ -43,7 +46,7 @@ public function getIsUp()
{
if (!Yii::$app->user->isGuest) {
$userId = Yii::$app->user->id;
$up = Vote::find()->where(['type' => $this->type, 'type_id' => $this->owner->id, 'user_id' => $userId, 'action' => Vote::ACTION_UP])->one();
$up = Vote::find()->where(['entity' => $this->entity, 'entity_id' => $this->owner->id, 'user_id' => $userId, 'action' => Vote::ACTION_UP])->one();
if ($up) {
return true;
}
Expand All @@ -59,32 +62,64 @@ public function getIsDown()
{
if (!Yii::$app->user->isGuest) {
$userId = Yii::$app->user->id;
$down = Vote::find()->where(['type' => $this->type, 'type_id' => $this->owner->id, 'user_id' => $userId, 'action' => Vote::ACTION_DOWN])->one();
$down = Vote::find()->where(['entity' => $this->entity, 'entity_id' => $this->owner->id, 'user_id' => $userId, 'action' => Vote::ACTION_DOWN])->one();
if ($down) {
return true;
}
}
return false;
}

public function getType()
public function getVoteInfo()
{
return $this->owner->hasOne(VoteInfo::className(), [
'entity_id' => $this->owner->primaryKey()[0]
])->where(['entity' => $this->getEntity()]);
}

public function getUpTotal()
{
if ($this->type == null) {
$this->type = $this->owner->className();
$model = $this->owner->voteInfo;
if ($model == null) {
return 0;
}
return $model->up;
}

return ltrim($this->type,"\\");
public function getDownTotal()
{
$model = $this->owner->voteInfo;
if ($model == null) {
return 0;
}
return $model->down;
}

public function getTypeId()
public function afterInsert()
{
return $this->owner->getPrimaryKey();
$model = new VoteInfo();
$model->entity = $this->getEntity();
$model->entity_id = $this->getEntityId();
$model->save();
}

public function afterUpdate()
{
/* @var $model \common\models\VoteInfo */
$model = $this->owner->VoteInfo;
if ($model == null) {
$model = new VoteInfo();
$model->entity = $this->getEntity();
$model->entity_id = $this->getEntityId();
$model->save();
}
}

public function afterDelete()
{
$type = $this->getType();
$type_id = $this->getTypeId();
Vote::deleteAll(['type' => $type, 'type_id' => $type_id]);
$entity = $this->getEntity();
$entityId = $this->getEntityId();
VoteInfo::deleteAll(['entity' => $entity, 'entity_id' => $entityId]);
Vote::deleteAll(['entity' => $entity, 'entity_id' => $entityId]);
}
}
30 changes: 30 additions & 0 deletions common/components/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* Author: ljt
* DateTime: 2016/11/9 9:46
* Description:
*/

namespace common\components;

use Yii;

class Controller extends \yii\web\Controller
{
public function renderJson($status = 1, $message = '', $data = [])
{
\Yii::$app->response->format = 'json';
return array_merge(['status' => $status, 'message' => $message], $data);
}

public function goReferrer()
{
return Yii::$app->controller->redirect(Yii::$app->request->getReferrer());
}

public function flash($key, $value)
{
Yii::$app->session->setFlash($key, $value);
}
}
Loading

0 comments on commit 1d0f9a4

Please sign in to comment.