Esempio n. 1
0
 /**
  * Executes the widget.
  */
 public function run()
 {
     $currentUserLiked = false;
     $likes = Like::GetLikes($this->object->className(), $this->object->id);
     foreach ($likes as $like) {
         if ($like->user->id == Yii::$app->user->id) {
             $currentUserLiked = true;
         }
     }
     return $this->render('likeLink', array('object' => $this->object, 'likes' => $likes, 'currentUserLiked' => $currentUserLiked, 'id' => $this->object->getUniqueId(), 'likeUrl' => Url::to(['/like/like/like', 'contentModel' => $this->object->className(), 'contentId' => $this->object->id]), 'unlikeUrl' => Url::to(['/like/like/unlike', 'contentModel' => $this->object->className(), 'contentId' => $this->object->id]), 'userListUrl' => Url::to(['/like/like/user-list', 'contentModel' => $this->object->className(), 'contentId' => $this->object->getPrimaryKey()]), 'title' => $this->generateLikeTitleText($currentUserLiked, $likes)));
 }
Esempio n. 2
0
 /**
  * Returns an JSON with current like informations about a target
  */
 public function actionShowLikes()
 {
     Yii::$app->response->format = 'json';
     // Some Meta Infos
     $currentUserLiked = false;
     $likes = Like::GetLikes($this->contentModel, $this->contentId);
     foreach ($likes as $like) {
         if ($like->user->id == Yii::$app->user->id) {
             $currentUserLiked = true;
         }
     }
     return ['currentUserLiked' => $currentUserLiked, 'likeCounter' => count($likes)];
 }