/** * @param $sender * @param $receiver * @param $object */ private static function createNewNotification($sender, $event) { $noti = new Notification(); $noti["sender_id"] = $sender; $noti["is_read"] = 0; $noti["objectType"] = POST; if ($event instanceof FollowEvent) { $noti["type"] = FOLLOW; $noti["receiver_id"] = $event["following_id"]; if ($event["follow_type"] == 2) { $noti["objectType"] = BOARD; } else { $noti["objectType"] = USER; } } else { $post = Post::getPostById($event["post_id"]); $noti["receiver_id"] = $post["user_id"]; if ($event instanceof LikeEvent) { $noti["type"] = LIKE; $noti["objectID"] = $event["post_id"]; } else { if ($event instanceof CommentEvent) { $noti["type"] = COMMENT; $noti["objectID"] = $event["post_id"]; } else { if ($event instanceof PinEvent) { $noti["type"] = PIN; $noti["objectID"] = $event["post_id"]; } } } } return $noti; }
/** * Delete post * * @param Request $request * @param int $id * @return \Illuminate\Http\RedirectResponse */ public function delete(Request $request, $id = 0) { if ($request->isMethod('post')) { foreach ($request->input('posts') as $post) { $post = Post::getPostById($post); if (!empty($post)) { if (!empty($post->image)) { if (Storage::exists('uploads/' . $post->image) && Storage::exists('uploads/fb-' . $post->image)) { Storage::delete('uploads/' . $post->image, 'uploads/fb-' . $post->image); } } $post->delete(); } } } else { $post = Post::getPostById($id); if (!empty($post)) { if (!empty($post->image)) { if (Storage::exists('uploads/' . $post->image) && Storage::exists('uploads/fb-' . $post->image)) { Storage::delete('uploads/' . $post->image, 'uploads/fb-' . $post->image); } } $post->delete(); } return redirect()->back(); } }
public function likePost($post_id) { if (!Auth::check()) { return response()->json('Please login'); } $current_id = Auth::user()->user_id; $avatar_link = Auth::user()->avatar_link; $name = Auth::user()->name; $post = LikeEvent::checkLiked($post_id, $current_id); $channel = Post::getPostById($post_id)["user_id"]; if (!$post) { $result = LikeEvent::createLikeEvent($post_id, $current_id); $pusher = App::make('pusher'); $pusher->trigger($channel, 'like', array('name' => $name, 'post_id' => $post_id, 'avatar_link' => $avatar_link)); } else { $result = LikeEvent::removeLikeEvent($post["like_event_id"]); } return response()->json(["result" => $result]); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($post_id) { // $post = $this->getPostDetail($post_id)[0]; $post_stat = $this->getPostDetail($post_id)[1]; if (Auth::check()) { $post["liked"] = LikeEvent::checkLiked($post["post_id"], Auth::user()->user_id); } $post["comments"] = Post::getCommentsByPostId($post_id); $post["likes"] = $post_stat["likes"]; $post["pins"] = $post_stat["pins"]; $post["boards"] = Board::getPostsInBoard($post["board_id"]); $post["places"] = Place::getPlaceById(Post::getPostById($post_id)['place_id']); $recommend = new RecommendController(); $post["recommend_posts"] = $recommend->getPost($post_id); return response()->json($post); }
/** * Disapprove post * * @param $id * @return \Illuminate\Http\RedirectResponse */ public function disapprove($id) { $post = Post::getPostById($id); if ($post) { $post->approve = 0; $post->save(); if ($post->author_id != Auth::user()->id) { $notification = new Notification(); $notification->from = Auth::user()->id; $notification->to = $post->author_id; $notification->type = 6; $notification->save(); } } return redirect()->route('admin_posts'); }
public function getPost($post_id) { $client = new Client(); $post = Post::getPostById($post_id); $index_name = Config::get('elasticsearch.index_name'); $post_type = Config::get('elasticsearch.post_type'); $params = ["index" => $index_name, "analyzer" => 'vi_analyzer', 'text' => $post["description"]]; $tokens = $client->indices()->analyze($params)["tokens"]; $search = new SearchController(); $results = []; foreach ($tokens as $token) { $query = ["description" => $token["token"]]; $results[] = $search->search($post_type, $query); } return $results; }