<?php /* @var $post_id integer */ use app\modules\yboard\YBoard; use app\modules\yboard\models\YBoardUpvoted; use app\modules\yboard\models\YBoardMember; use yii\helpers\Html; $models = YBoardUpvoted::find()->where(['post_id' => $post_id])->all(); $count = count($models); if ($count) { echo '<div class="post-upvote-footer">' . PHP_EOL; echo YBoard::t('yboard', 'This post is appreciated by {no} member{plural}', ['no' => $count, 'plural' => $count > 1 ? 's' : '']) . ' '; $users = []; foreach ($models as $model) { $member = YBoardMember::findOne($model->member_id); if ($member !== null) { $users[] = Html::a(Html::encode($member->profile->username), ["member/view", "id" => $member->id], ['target' => '_blank']); } } $members = '<b>' . implode(', ', $users) . '</b>'; echo Html::a(YBoard::t('yboard', '[view]'), '#', ['onclick' => 'showAppreciation(\'' . $members . '\'); return false;']); echo '</div>' . PHP_EOL; }
/** * Number of Total Upvotes in All your posts */ public function getAppreciations() { return YBoardUpvoted::find()->where(['author' => $this->id])->count(); }
public function showUpvote($post_id) { $url = Yii::$app->urlManager->createAbsoluteUrl($this->module->id . '/forum/upvote'); $post = YBoardPost::findOne($post_id); if ($post === null || $post->user_id == Yii::$app->user->id) { return ''; } $upvoted = YBoardUpvoted::find()->where(['member_id' => Yii::$app->user->identity->id])->andWhere(['post_id' => $post_id])->count(); if ($upvoted > 0) { $html = Html::button(YBoard::t('yboard', 'Downvote') . ' <span class="glyphicon glyphicon-chevron-down"></span>', ['class' => 'btn btn-sm btn-default', 'title' => YBoard::t('yboard', 'Remove your appreciation'), 'id' => 'upvote_' . $post_id, 'style' => 'cursor:pointer;', 'onclick' => 'upvotePost(' . $post_id . ',' . $post->user_id . ',"' . $url . '")']); } else { $html = Html::button(YBoard::t('yboard', 'Upvote') . ' <span class="glyphicon glyphicon-chevron-up"></span>', ['class' => 'btn btn-sm btn-default', 'title' => YBoard::t('yboard', 'Appreciate this post'), 'id' => 'upvote_' . $post_id, 'style' => 'cursor:pointer;', 'onclick' => 'upvotePost(' . $post_id . ',' . $post->user_id . ',"' . $url . '")']); } return $html; }