Exemple #1
0
function dislike($secret_id, $user_id)
{
    $l_ = new Like();
    $l = $l_->where("secret_id = {$secret_id} and user_id = {$user_id}");
    $l[0]->drop();
    return 1;
}
Exemple #2
0
 public function testGetListLikeSuccessNoLike()
 {
     $like = Like::destroy(1);
     $response = $this->call('GET', 'api/like');
     $like_infor = Like::where('user_id', $this->_user_id)->get();
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $like_infor->toArray()), json_decode($response->getContent(), true));
 }
Exemple #3
0
 public static function deleteLike($rating_id)
 {
     $error_code = ApiResponse::OK;
     $user_id = Session::get('user_id');
     if (Rating::where('id', $rating_id)->first()) {
         $like = Like::where('rating_id', $rating_id)->where('user_id', $user_id)->first();
         if ($like) {
             //update like_count on rating
             $like_rating = Rating::where('id', $like->rating_id)->first();
             if ($like_rating != null) {
                 $like_rating->like_count = $like_rating->like_count - 1;
                 $like_rating->save();
             }
             $like->delete();
             $data = 'Like deleted';
         } else {
             $error_code = ApiResponse::NOT_EXISTED_LIKE;
             $data = ApiResponse::getErrorContent(ApiResponse::NOT_EXISTED_LIKE);
         }
     } else {
         $error_code = ApiResponse::UNAVAILABLE_RATING;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
     }
     return array("code" => $error_code, "data" => $data);
 }
 public static function delete($entry_id)
 {
     $likes = Like::where('entry_id', $entry_id)->get();
     foreach ($likes as $like) {
         $like->delete();
     }
     return true;
 }
Exemple #5
0
 public function updateRank()
 {
     $likes = Like::where('comment_id', '=', $this->id)->get();
     $rank = 0;
     foreach ($likes as $like) {
         $rank += $like->value;
     }
     $this->rank = $rank;
     $this->save();
 }
 public function testGetTimelineSuccess()
 {
     $this->setUpRating();
     $this->setUpCountry();
     $this->setUpWineNote();
     $this->setUpProfile();
     $_params = $this->_params;
     $_params['user_id'] = "user_id";
     $response = $this->_getAuth($_params);
     $error_code = ApiResponse::OK;
     $user_timeline = array();
     $user_timeline[] = $this->_user_id;
     $user_follow = Follow::where('from_id', $this->_user_id)->orderBy('updated_at', 'asc')->get();
     if (isset($user_follow)) {
         foreach ($user_follow as $user) {
             $user_timeline[] = $user->to_id;
         }
     }
     $pagination = ApiResponse::pagination();
     $page = $pagination['page'];
     $limit = $pagination['limit'];
     $wine = Wine::with('winery')->forPage($page, $limit)->get();
     $ratings = Rating::whereIn('user_id', $user_timeline)->whereNotNull('wine_unique_id')->with('profile')->with('wine')->forPage($page, $limit)->get();
     foreach ($ratings as $rating) {
         $winery = Winery::where('id', $rating->wine->winery_id)->first();
         $rating->winery = $winery;
         $country = Country::where('id', $rating->winery->country_id)->first();
         $rating->winery->country_name = $country->country_name;
         $like = Like::where('user_id', $this->_user_id)->where('rating_id', $rating->id)->first();
         if ($like) {
             $rating->liked = true;
         } else {
             $rating->liked = false;
         }
         $wishlist = Wishlist::where('user_id', $this->_user_id)->where('wine_unique_id', $rating->wine_unique_id)->first();
         if ($wishlist) {
             $rating->wishlist = true;
         } else {
             $rating->wishlist = false;
         }
         if ($rating->wine->image_url != null) {
             $rating->wine->image_url = URL::asset($rating->wine->image_url);
         }
         if ($rating->wine->wine_flag != null) {
             $rating->wine->wine_flag = URL::asset($rating->wine->wine_flag);
         }
         if ($rating->profile->image != null) {
             $rating->profile->image = URL::asset($rating->profile->image);
         }
         $rating->winery = $rating->winery->toArray();
     }
     $data = $ratings;
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $ratings->toArray()), json_decode($response->getContent(), true));
 }
Exemple #7
0
 public function getLike($slug)
 {
     $json_data = array('liked' => false);
     $product = Product::where('slug', '=', $slug)->first();
     $user = Auth::user();
     $like = Like::where('product_id', '=', $product->id)->where('user_id', '=', $user->id)->first();
     if (empty($like)) {
         $new_like = new Like();
         $new_like->product_id = $product->id;
         $new_like->user_id = $user->id;
         $new_like->save();
         $json_data['liked'] = true;
     }
     if (Request::ajax()) {
         return Response::json($json_data);
     }
     return Redirect::back();
 }
Exemple #8
0
 public static function getActivity()
 {
     $user_id = Session::get('user_id');
     $error_code = ApiResponse::OK;
     $act = array();
     $ratings = Rating::where('user_id', $user_id)->get();
     foreach ($ratings as $rating) {
         $likes = Like::where('rating_id', $rating->id)->whereNotIn('user_id', [$user_id])->get();
         if ($likes) {
             $title = 'like';
             foreach ($likes as $like) {
                 $act[] = Rating::getProfile($like->user_id, $title, $like->id, $rating->id, $like->updated_at);
             }
         }
         $comments = Comment::where('rating_id', $rating->id)->whereNotIn('user_id', [$user_id])->get();
         if ($comments) {
             $title = 'comment';
             foreach ($comments as $comment) {
                 $act[] = Rating::getProfile($comment->user_id, $title, $comment->id, $rating->id, $comment->updated_at);
             }
         }
         $wishlists = Wishlist::where('wine_unique_id', $rating->wine_unique_id)->whereNotIn('user_id', [$user_id])->get();
         if ($wishlists) {
             $title = 'wishlist';
             foreach ($wishlists as $wishlist) {
                 $act[] = Rating::getProfile($wishlist->user_id, $title, $wishlist->id, $rating->id, $wishlist->updated_at);
             }
         }
     }
     $user_follow = Follow::where('to_id', $user_id)->get();
     if ($user_follow) {
         $title = 'follow';
         foreach ($user_follow as $user) {
             $act[] = Rating::getProfile($user->from_id, $title, $user->id, null, $user->updated_at);
         }
     }
     $data = Rating::orderBy($act, 'updated_at');
     return array("code" => $error_code, "data" => $data);
 }
 /**
  * Delete likes related to the current record
  * @param string $type
  */
 public function removeLikes($type = 'like')
 {
     Like::where('likeable_type', $this->morphClass)->where('likeable_id', $this->id)->where('type', $type)->delete();
     LikeCounter::where('likeable_type', $this->morphClass)->where('likeable_id', $this->id)->where('type', $type)->delete();
 }
 /**
  * Deletes the post with the supllied postid
  * @return json $returnObject object containing status and message
  */
 public function deletePost()
 {
     $inputJson = Input::all();
     $post = Post::find($inputJson['postid']);
     $returnObject = new stdClass();
     $returnObject->status = 'ok';
     $returnObject->mission_completed = 'false';
     $usertask = UserTask::where('user_id', $post->user_id)->where('task_id', $post->task_id)->where('group_id', $post->group_id)->get();
     if (isset($usertask[0])) {
         $userTaskRecord = UserTask::find($usertask[0]->id);
         $userTaskRecord->delete();
         $returnObject->mission_completed = 'true';
     }
     // remove likes associated with the post
     $affectedLikes = Like::where('post_id', $inputJson['postid'])->delete();
     // remove notifications associated with the post
     $affectedNotifications = Notification::where('type', 'newlike')->orWhere('type', 'newcomment')->where('source_id', $inputJson['postid'])->delete();
     $post->delete();
     $returnObject->message = "Post deleted successfully";
     return Response::json($returnObject);
 }
Exemple #11
0
 public function unlike($id)
 {
     $like = new Like();
     $user = Auth::user();
     $id = Input::only('proposal_id');
     $like->where('user_id', $user->id)->where('proposal_id', $id)->first()->delete();
     return Redirect::back();
 }
 /**
  *  Like song by id
  *
  * @return Response
  */
 public function like($id)
 {
     if (Auth::check()) {
         $song = Song::find($id);
         if ($song->exists()) {
             $like = Like::where('user', "=", Auth::user()->id)->where('song', '=', $id)->first();
             if ($like) {
                 $like->delete();
                 return Response::json(['like' => false]);
             } else {
                 $like = new Like();
                 $like->user = Auth::user()->id;
                 $like->song = $id;
                 $like->save();
                 return Response::json(['like' => true]);
             }
         } else {
             App::abort('404');
         }
     } else {
         return Response::json(['auth' => false]);
     }
 }
 public function cekLike()
 {
     if (Input::has('id')) {
         $like = Like::where('idkatalog', '=', Input::get('id'))->where('iduser', '=', Auth::user()->id)->get();
         echo json_encode(array('exists' => count($like)));
     }
 }
Exemple #14
0
 private function get($type, $id, $userId)
 {
     return Like::where('likeable_type', $type)->where('user_id', $userId)->where('likeable_id', $id)->first();
 }
Exemple #15
0
 public static function usersIDs($type, $id)
 {
     return Like::where('likeable_type', $type)->where('likeable_id', $id)->get()->map(function ($like) {
         return $like->user_id;
     });
 }