public function actionUndo($type, $follow) { $userId = Yii::$app->user->id; $model = Follow::findOne(['user_id' => $userId, 'type' => $type, 'follow_id' => $follow]); if ($model !== null) { $model->delete(); } $next = Yii::$app->request->get('next'); if (isset($next)) { return $this->redirect($next); } else { $this->goHome(); } }
public function actionUndo($type, $follow) { $model = Follow::findOne(['user_id' => Yii::$app->user->id, 'type' => $type, 'follow_id' => $follow]); if ($model !== null) { if ($model->delete() && $type == 3) { $topic = Topic::findOne($follow); $topic->follow = $topic->follow - 1; $topic->save(); } } $next = Yii::$app->request->get('next'); if (isset($next)) { return $this->redirect($next); } else { $this->goHome(); } }
<section> <div class="block-header">我收藏的节点</div> <?php $follow = \common\models\Follow::findAll(['user_id' => Yii::$app->user->id, 'type' => 2]); ?> <?php foreach ($follow as $f) { ?> <article class="sidebar"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody><tr> <td width="24" valign="middle" align="center"> <a href="/node/<?php echo $f->node->enname; ?> "><img src="<?php echo $f->node->logo24; ?> " class="img-rounded"></a> </td> <td width="10"></td> <td width="auto" valign="middle"> <a href="/node/<?php echo $f->node->enname; ?> "><?php echo $f->node->name; ?> </a> </td> </tr>
?> " class="img-rounded"></td> <?php } ?> <td width="10"></td> <td width="auto" valign="right"> <?php if (Yii::$app->user->isGuest || Yii::$app->user->id != $model->id) { ?> <div class="pull-right text-right"> <?php if (!Yii::$app->user->isGuest) { ?> <?php if (\common\models\Follow::findOne(['user_id' => Yii::$app->user->id, 'follow_id' => $model->id, 'type' => 1]) === null) { ?> <button type="button" class="btn btn-success btn-xs" name="setting-button" onclick="location.href = '/follow/do/1/<?php echo $model->id; ?> ?next=/member/<?php echo $model->username; ?> ';">加入特别关注</button> <?php } else { ?> <button type="button" class="btn btn-default btn-xs" name="setting-button" onclick="location.href = '/follow/undo/1/<?php echo $model->id; ?> ?next=/member/<?php
</tbody> </table> </article> <div class="block-header"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <td width="33%" align="center"><a href="/account/node" class="small"><strong><?php echo \common\models\Follow::find()->where(['user_id' => Yii::$app->user->id, 'type' => 2])->count(); ?> </strong><div class="mt3"></div><small>节点收藏</small></a></td> <td width="34%" align="center"><a href="/account/topic" class="small"><strong><?php echo \common\models\Follow::find()->where(['user_id' => Yii::$app->user->id, 'type' => 3])->count(); ?> </strong><div class="mt3"></div><small>主题收藏</small></a></td> <td width="33%" align="center"><a href="/account/follow" class="small"><strong><?php echo \common\models\Follow::find()->where(['user_id' => Yii::$app->user->id, 'type' => 1])->count(); ?> </strong><div class="mt3"></div><small>关注的人</small></a></td> </tbody> </table> </div> <?php if (Yii::$app->user->identity->email_status == 1) { ?> <div class="block-content"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody><tr> <td width="15"></td> <td width="auto" valign="middle" align="left"><a href="/create"><i class="glyphicon glyphicon-pencil"></i> 创作新主题</a></td></tr> </tbody> </table>
public function actionTopic() { $this->title = '我关注的主题' . ' - ' . Yii::$app->name; $this->description = ''; if (Yii::$app->user->isGuest) { return $this->redirect('/account/login?next=/account/topic'); } $query = Topic::find()->where(['in', 'id', ArrayHelper::map(Follow::findAll(['user_id' => Yii::$app->user->id, 'type' => 3]), 'follow_id', 'follow_id')]); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]); $model = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('topic', ['model' => $model, 'pagination' => $pagination]); }
public function actionTopic() { $this->title = '关注的建议' . ' - ' . Yii::$app->name; $this->description = ''; if (Yii::$app->user->isGuest) { return $this->redirect('/account/login?next=/account/topic'); } $query = (new Query())->select('topic.*, node.enname, node.name, user.username, user.avatar')->from(Topic::tableName())->leftJoin(Node::tableName(), 'node.id = topic.node_id')->leftJoin(User::tableName(), 'user.id = topic.user_id')->where(['in', 'topic.id', Follow::Topic()]); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]); $model = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('topic', ['model' => $model, 'pagination' => $pagination]); }
<?php $follow = \common\models\Follow::Node(false); if (!empty($follow)) { ?> <section> <div class="block-header"><small>我收藏的节点</small></div> <?php $follow = \common\models\Follow::Node(false); ?> <?php foreach ($follow as $f) { ?> <article class="sidebar"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody><tr> <td width="24" valign="middle" align="center"> <a href="/node/<?php echo $f['enname']; ?> "><img src="<?php echo Yii::$app->params['nodeUrl'] . '/24/' . $f['logo']; ?> " class="img-rounded"></a> </td> <td width="10"></td> <td width="auto" valign="middle"> <a href="/node/<?php echo $f['enname']; ?> "><?php
/** * 获取我收藏的建议id * @return array|\yii\db\ActiveRecord[] */ static function Topic() { if (!($FollowTopic = Yii::$app->cache->get('FollowTopic' . Yii::$app->user->id))) { $FollowTopic = ArrayHelper::map(Follow::find()->select('follow_id')->where(['user_id' => Yii::$app->user->id, 'type' => 3])->asArray()->all(), 'follow_id', 'follow_id'); Yii::$app->cache->set('FollowTopic' . Yii::$app->user->id, $FollowTopic, 0); } return $FollowTopic; }
<?php $follow = \common\models\Follow::User(false); if (!empty($follow)) { ?> <section> <div class="block-header"><small>我关注的人</small></div> <?php foreach ($follow as $f) { ?> <article class="sidebar block-hot-topic"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody><tr> <td width="24" valign="middle" align="center"> <a href="/member/<?php echo $f['username']; ?> "><img src="<?php echo Yii::$app->params['avatarUrl'] . '/24/' . $f['avatar']; ?> " class="img-rounded"></a> </td> <td width="10"></td> <td width="auto" valign="middle"> <span class="hot_topic"> <a href="/member/<?php echo $f['username']; ?> "><?php echo $f['username']; ?>