Exemplo n.º 1
0
 public function actionFavorite($id)
 {
     $this->layout = '//u';
     $user = User::findOne($id);
     \Yii::$app->view->params['model'] = $user;
     $dataProvider = new ActiveDataProvider(['query' => Collection::find()->where(['author_id' => $id])]);
     $totalCount = $dataProvider->getTotalCount();
     $pages = new Pagination(['totalCount' => $totalCount]);
     return $this->render('favorites', ['models' => $dataProvider->getModels(), 'pages' => $pages, 'author' => $user]);
 }
Exemplo n.º 2
0
 private function delFav()
 {
     $params = ['obj_type' => \Yii::$app->request->post('obj_type'), 'obj_id' => \Yii::$app->request->post('obj_id')];
     $result = Collection::delFav($params['obj_type'], $params['obj_id']);
     if ($result) {
         $arr = ['r' => 1, 'label' => '收藏', 'status' => 0];
     } else {
         $arr = ['r' => 0];
     }
     return json_encode($arr);
 }
Exemplo n.º 3
0
 public function init()
 {
     if (!\Yii::$app->user->isGuest) {
         if (Collection::isFav(['obj_type' => $this->object['obj_type'], 'obj_id' => $this->object['obj_id']])) {
             $this->status = 1;
             $this->label = "已收藏";
         }
     }
     $assets = \Yii::$app->assetManager->publish('@app/modules/favorite/exts/assets/', ['forceCopy' => true]);
     $this->getView()->registerJsFile($assets['1'] . '/favorite.js', ['depends' => [AppAsset::className()]]);
 }
Exemplo n.º 4
0
 public function actionAddFav()
 {
     $collections = Collection::find()->where(['author_id' => Yii::$app->user->id])->all();
     return $this->renderAjax('addFav', ['collections' => $collections]);
 }
Exemplo n.º 5
0
            <div class="mb10">
                <dl class="menu">
                    <dt>相关</dt>
                    <?php 
$parent = $model->parents()->all();
$children = $model->children(1)->all();
$tags = ArrayHelper::merge($parent, $children);
if (!empty($tags)) {
    foreach ($tags as $tag) {
        echo '<dd>' . Html::a($tag->name, $tag->url) . '</dd>';
    }
}
?>
                    <dd>

                    </dd>
                    <dd>

                    </dd>
                </dl>
            </div>
        </div>
    </div>
<?php 
$isFollow = Tag::isFollow($model->id, Yii::$app->user->id);
$js = "var isFollow = " . ($isFollow ? 1 : 0) . "; var tagId=" . $model->id . ";";
$this->registerJs($js, 1);
$this->registerJsFile('/js/angular.min.js');
$this->registerJsFile('/js/angular.tag.js');
echo FavModal::widget(['collections' => Collection::findAll(['author_id' => Yii::$app->user->id])]);