public function showUpvote($post_id) { $url = \Yii::$app->urlManager->createAbsoluteUrl('forum/upvote'); $post = BbiiPost::find($post_id); if ($post === null || $post->user_id == \Yii::$app->user->identity->id) { return ''; } $criteria = new CDbCriteria(); $criteria->condition = "member_id = :userid and post_id = {$post_id}"; $criteria->params = array(':userid' => \Yii::$app->user->identity->id); // @todo this should be moved to the VW - DJE : 2015-05-14 $assets = AppAsset::register($this); if (BbiiUpvoted::find()->exists($criteria)) { $html = Html::img($asset->baseUrl . '/images/down.gif', 'upvote', array('title' => Yii::t('BbiiModule.bbii', 'Remove your vote'), 'id' => 'upvote_' . $post_id, 'style' => 'cursor:pointer;', 'onclick' => 'upvotePost(' . $post_id . ',"' . $url . '")')); } else { $html = Html::img($asset->baseUrl . '/images/up.gif', 'upvote', array('title' => Yii::t('BbiiModule.bbii', 'Vote this post up'), 'id' => 'upvote_' . $post_id, 'style' => 'cursor:pointer;', 'onclick' => 'upvotePost(' . $post_id . ',"' . $url . '")')); } return $html; }
<?php /* @var $post_id integer */ $models = BbiiUpvoted::find()->findAllByAttributes(array('post_id' => $post_id)); $count = count($models); if ($count) { echo '<div class = "post-upvote-footer">' . PHP_EOL; echo Yii::t('BbiiModule.bbii', 'Post appreciated by: '); $users = array(); foreach ($models as $model) { $member = BbiiMember::find($model->member_id); if ($member !== null) { $users[] = Html::a(Html::encode($member->member_name), array("member/view", "id" => $member->id)); } } echo implode(', ', $users); echo '</div>' . PHP_EOL; }