/** * Executes the widget. */ public function run() { $currentUserLiked = false; $likes = Like::GetLikes(get_class($this->object), $this->object->id); foreach ($likes as $like) { if ($like->getUser()->id == Yii::app()->user->id) { $currentUserLiked = true; } } $this->render('likeLink', array('likes' => $likes, 'currentUserLiked' => $currentUserLiked, 'id' => $this->object->getUniqueId())); }
/** * Returns an JSON with current like informations about a target */ public function actionShowLikes() { // Some Meta Infos $currentUserLiked = false; $likes = Like::GetLikes($this->contentModel, $this->contentId); foreach ($likes as $like) { if ($like->getUser()->id == Yii::app()->user->id) { $currentUserLiked = true; } } $json = array(); $json['currentUserLiked'] = $currentUserLiked; $json['likeCounter'] = count($likes); echo CJSON::encode($json); Yii::app()->end(); }