Exemplo n.º 1
0
 public function getListByCategory($slug, $fields = [], $with = [], $page = false, $pageSize = false, $order = '')
 {
     $category = Category::getInstance()->getBySlug($slug);
     $model = self::$model->find()->select($fields)->where(['type' => Content::TYPE_ARTICLE, 'status' => Content::STATUS_ACTIVE, 'meta_id' => $category['id']])->join('RIGHT JOIN', Relationship::tableName() . ' relation', 'content_id=id');
     $countModel = clone $model;
     $pagination = new Pagination(['totalCount' => $countModel->count(), 'pageSize' => $pageSize]);
     if ($page) {
         $pagination->setPage($page, true);
     }
     switch (strtoupper($order)) {
         case 'VIEW':
             $model->orderBy('view_total DESC');
             break;
         case 'COMMENT':
             $model->orderBy('comment_total DESC');
             break;
         case 'CREATED':
             $model->orderBy('created_at DESC');
             break;
         case 'UPDATED':
             $model->orderBy('updated_at DESC');
             break;
     }
     return ['data' => $model->with($with)->limit($pagination->getLimit())->offset($pagination->getOffset())->all(), 'pagination' => $pagination];
 }
Exemplo n.º 2
0
 public function getPosts($isPublished = true)
 {
     $query = $this->hasMany(Post::className(), ['cid' => 'cid'])->with('categories')->with('tags')->with('author')->orderByCid();
     if ($isPublished) {
         $query = $query->published();
     }
     return $query->viaTable(Relationship::tableName(), ['mid' => 'mid']);
 }
Exemplo n.º 3
0
 public function afterDelete()
 {
     parent::afterDelete();
     //修改直接子类的父级id
     self::updateAll(['parent' => $this->parent], 'parent=:parent AND type=:type', [':parent' => $this->mid, ':type' => static::TYPE]);
     //删除和文章的关联
     Relationship::deleteAll(['mid' => $this->mid]);
 }
Exemplo n.º 4
0
 public function actionDeleteUser()
 {
     $selection = (array) Yii::$app->request->post('selection');
     foreach ($selection as $id) {
         if ($id != Yii::$app->params['adminId']) {
             User::deleteAll(['id' => $id]);
             Post::deleteAll(['user_id' => $id]);
             PostNotification::deleteAll(['action_id' => $id]);
             PostNotification::deleteAll(['receiver_id' => $id]);
             Comment::deleteAll(['user_id' => $id]);
             Like::deleteAll(['user_id' => $id]);
             Message::deleteAll(['sender_id' => $id]);
             Message::deleteAll(['receiver_id' => $id]);
             Relationship::deleteAll(['user_id_1' => $id]);
             Relationship::deleteAll(['user_id_2' => $id]);
             RelationshipNotification::deleteAll(['action_id' => $id]);
             RelationshipNotification::deleteAll(['receive_id' => $id]);
             Schedule::deleteAll(['own_id' => $id]);
             ScheduleNotification::deleteAll(['action_id' => $id]);
             ScheduleNotification::deleteAll(['receiver_id' => $id]);
         }
     }
     return $this->render('user-manage');
 }
Exemplo n.º 5
0
<?php

use yii\helpers\Html;
/* @var $this \yii\web\View */
/* @var $content string */
$model = \common\models\User::findOne(['id' => Yii::$app->user->getId()]);
$postCount = \common\models\Post::find()->where(['user_id' => $model['id']])->count();
$friendCount = \common\models\Relationship::find()->where(['user_id_1' => $model['id'], 'status' => 1])->count() + \common\models\Relationship::find()->where(['user_id_2' => $model['id'], 'status' => 1])->count();
$listNewRelNotify = \common\models\RelationshipNotification::find()->where(['receive_id' => Yii::$app->user->getId()])->orderBy('status')->limit(20)->asArray()->all();
$newRelNotifyCount = \common\models\RelationshipNotification::find()->where(['receive_id' => Yii::$app->user->getId(), 'status' => 0])->count();
$listNewMsgNotify = \common\models\Message::find()->where(['receiver_id' => Yii::$app->user->getId()])->orderBy('is_notified')->limit(20)->asArray()->all();
$newMsgNotifyCount = \common\models\Message::find()->where(['receiver_id' => Yii::$app->user->getId(), 'is_notified' => 0])->count();
?>

<header class="main-header">

    <?php 
echo Html::a('<span class="logo-mini">APP</span><span class="logo-lg">' . Yii::$app->name . '</span>', Yii::$app->homeUrl, ['class' => 'logo']);
?>

    <nav class="navbar navbar-static-top" role="navigation">

        <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
            <span class="sr-only">Toggle navigation</span>
        </a>

        <div class="navbar-custom-menu">

            <ul class="nav navbar-nav">

                <!-- Messages: style can be found in dropdown.less-->
Exemplo n.º 6
0
 public static function isInRelationship($user_id_1, $user_id_2)
 {
     $sql = 'SELECT * FROM relationship WHERE ((user_id_1=:user_id_1 AND user_id_2=:user_id_2)
               OR (user_id_1=:user_id_2 AND user_id_2=:user_id_1)) AND status=1';
     return Relationship::findBySql($sql, [':user_id_1' => $user_id_1, ':user_id_2' => $user_id_2])->count() > 0;
 }
Exemplo n.º 7
0
 public function insertTags($tags, $beforeCount = true, $afterCount = true)
 {
     if (!is_array($tags)) {
         return false;
     }
     $this->deleteTags($beforeCount);
     //先删除标签
     //插入新标签
     $tagIds = Tag::scanTags($tags);
     if ($tagIds) {
         foreach ($tagIds as $v) {
             $model = new Relationship();
             $model->cid = $this->cid;
             $model->mid = $v;
             $model->insert(false);
             if ($afterCount) {
                 //更新标签文章数
                 Tag::updateAllCounters(['count' => 1], ['mid' => $v]);
             }
         }
     }
     return true;
 }
Exemplo n.º 8
0
 * Created by PhpStorm.
 * User: Nguyen
 * Date: 10/10/2015
 * Time: 3:03 PM
 */
use common\models\Relationship;
use dosamigos\ckeditor\CKEditor;
use kartik\date\DatePicker;
use kartik\select2\Select2;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$this->title = 'Sửa bài';
$this->params['breadcrumbs'][] = $this->title;
$sql = 'SELECT * FROM relationship WHERE ((user_id_1=:user_id)
                  OR (user_id_2=:user_id)) AND status=1';
$arrRelationship = Relationship::findBySql($sql, [':user_id' => Yii::$app->user->getId()])->asArray()->all();
$arrUserName = array();
foreach ($arrRelationship as $rel) {
    if ($rel['user_id_1'] == Yii::$app->user->getId()) {
        $arrUserName[$rel['user_id_2']] = \common\models\User::findOne(['id' => $rel['user_id_2']])->username;
    } else {
        $arrUserName[$rel['user_id_1']] = \common\models\User::findOne(['id' => $rel['user_id_1']])->username;
    }
}
?>

<div class="post-edit-form">
    <div class="row">
        <div class="col-lg-10 col-lg-offset-1">
            <div class="box box-info">
                <div class="box-header">
Exemplo n.º 9
0
 /**
  * 保存或插入内容的标签
  * @param string|array $tags 标签
  * @return bool
  * @throws ErrorException
  * @throws \Exception
  */
 public function saveTags($tags)
 {
     if (is_string($tags)) {
         if (($tags = trim($tags)) === '') {
             $tags = [];
         } else {
             $tags = explode(',', $tags);
         }
     }
     //对标签去除空格并去重
     $tags = array_unique(array_map('trim', $tags));
     //如果标签为空并且是新增内容,则直接返回真
     if (empty($tags) && !$this->id) {
         return true;
     }
     $relationshipModel = new Relationship();
     $metaModel = new Meta(['scenario' => Meta::SCENARIO_TAG]);
     //取出Meta表已经有的同名标签
     $existTags = $metaModel->find()->where(['type' => Meta::TYPE_TAG])->andFilterWhere(['in', 'name', $tags])->select(['name'])->asArray()->column();
     //取出数据库没有的标签名称(要添加到Meta表的标签)
     $newTags = array_diff($tags, $existTags);
     if (!empty($newTags)) {
         //如果有新增的标签
         foreach ($newTags as $tag) {
             $model = clone $metaModel;
             $model->setAttributes(['name' => $tag]);
             if (!$model->insert()) {
                 throw new ErrorException(current($model->getFirstErrors()));
             }
         }
     }
     //如果标签不为空
     if (!empty($tags)) {
         //找出本内容的标签
         $contentTags = $metaModel->find()->where(['type' => Meta::TYPE_TAG, 'name' => $tags, 'status' => Meta::STATUS_ACTIVE])->select(['id', 'name'])->asArray()->all();
     } else {
         $contentTags = [];
     }
     //取出久的标签
     $oldTags = ArrayHelper::getColumn($this->tags, 'name');
     $updateCountersTagIds = [];
     if (!empty($contentTags)) {
         //准备插入的文章关联标签
         $relationshipInsertData = [];
         foreach ($contentTags as $tag) {
             //如果要加的标签之前就有则跳过
             if (in_array($tag['name'], $oldTags)) {
                 continue;
             }
             $relationshipInsertData[] = ['content_id' => $this->id, 'meta_id' => $tag['id']];
             $updateCountersTagIds[] = $tag['id'];
         }
         if (!empty($relationshipInsertData)) {
             if (!$relationshipModel->getDb()->createCommand()->batchInsert($relationshipModel->tableName(), ['content_id', 'meta_id'], $relationshipInsertData)->execute()) {
                 throw new \ErrorException('插入文章标签关联失败');
             }
         }
     }
     $deleteTagIds = [];
     foreach ($this->tags as $tag) {
         if (!in_array($tag->name, $tags)) {
             $deleteTagIds[] = $tag->id;
         }
     }
     //内容新增的标签的内容统计+1
     if (!empty($updateCountersTagIds)) {
         if (!$metaModel->updateAllCounters(['content_total' => 1], ['id' => $updateCountersTagIds])) {
             throw new ErrorException('更新标签内容统计失败');
         }
     }
     if (!empty($deleteTagIds)) {
         //内容之前的标签被删除则内容统计-1
         $metaModel->updateAllCounters(['content_total' => -1], ['id' => $deleteTagIds]);
         //然后删除内容里这些不要的标签
         $relationshipModel->deleteAll(['content_id' => $this->id, 'meta_id' => $deleteTagIds]);
     }
     return true;
 }
Exemplo n.º 10
0
 public function afterDelete()
 {
     parent::afterDelete();
     //删除和文章的关联
     Relationship::deleteAll(['mid' => $this->mid]);
 }
Exemplo n.º 11
0
                    </li>
                </ul>
                <a href="?r=message/compose-with-a-user&user_id=<?php 
echo $model['id'];
?>
" class="btn btn-block btn-warning btn-sm"><b>Gửi tin nhắn</b></a>
                <?php 
$user_id_1 = Yii::$app->user->getId();
$user_id_2 = $model['id'];
if ($user_id_1 > $user_id_2) {
    $tg = $user_id_1;
    $user_id_1 = $user_id_2;
    $user_id_2 = $tg;
}
$isFriend = \common\models\Relationship::findOne(['user_id_1' => $user_id_1, 'user_id_2' => $user_id_2, 'status' => 1]) != null;
$pendingRelationship = \common\models\Relationship::findOne(['user_id_1' => $user_id_1, 'user_id_2' => $user_id_2, 'status' => 0]);
$isFriendPending = $pendingRelationship != null;
if (!$isFriend) {
    if ($isFriendPending) {
        if (Yii::$app->user->getId() != $pendingRelationship['user_id_action']) {
            echo '<a id="accept_friend_btn" class="btn btn-block btn-success"><b>Chấp nhận yêu cầu</b></a>';
        } else {
            echo '<a class="btn btn-primary btn-block disabled"><b>Đã gửi yêu cầu</b></a>';
        }
    } else {
        echo '<a id="add_friend_btn" class="btn btn-primary btn-block"><b>Thêm vào mối quan hệ</b></a>';
    }
}
?>
                <div id="add_friend_group" class="row" style="margin-top: 10px; display: none">
                    <div class="col-lg-6">
Exemplo n.º 12
0
 public function actionShowListFriend($friend_type)
 {
     $user_id = Yii::$app->user->getId();
     $sql = 'SELECT * FROM relationship WHERE ((user_id_1=:user_id AND with_user_1_is=:friend_type)
               OR (user_id_2=:user_id AND with_user_2_is=:friend_type)) AND status=1';
     $arrRelationship = Relationship::findBySql($sql, [':user_id' => $user_id, ':friend_type' => $friend_type])->asArray()->all();
     $model = array();
     foreach ($arrRelationship as $relationship) {
         if ($relationship['user_id_1'] == $user_id) {
             array_push($model, User::findOne(['id' => $relationship['user_id_2']]));
         } else {
             array_push($model, User::findOne(['id' => $relationship['user_id_1']]));
         }
     }
     return $this->render('show-friend', ['model' => $model]);
 }