public function proposition(Request $request) { $results = array(); $propositionFactory = new PropositionFactory(); $userFactory = new UserFactory(); $id = $request->get('id'); $proposition = $propositionFactory->getProposition($id); if ($proposition == null) { return response()->json([404, "Not found"]); } if ($proposition->status() == Proposition::BLOCKED) { return response()->json([404, "Not found"]); } $proposer = $userFactory->getUser($proposition->proposerId()); $result = ['propositionId' => $proposition->propositionId(), 'proposer' => ['id' => $proposition->proposerId(), 'fullName' => $proposer->firstName() . " " . $proposer->lastName(), 'avatar' => $proposer->avatar()], 'propositionSort' => $proposition->propositionSort(), 'propositionLong' => $proposition->propositionLong(), 'date_created' => Carbon::createFromTimestamp(strtotime($proposition->date_created()))->diffForHumans(), 'deadline' => $proposition->deadline(), 'ending_in' => Carbon::now()->diffInDays(Carbon::createFromTimestamp(strtotime($proposition->deadline())), false), 'marker' => $propositionFactory->getMarker($proposition->propositionId()), 'votes' => ['upvotes' => $propositionFactory->getUpvotes($id), 'downvotes' => $propositionFactory->getDownvotes($id)]]; foreach ($propositionFactory->getComments($id) as $comment) { $commentUser = $userFactory->getUser($comment->commenterId()); $result['comments'][$comment->commentId()] = ['commentId' => $comment->commentId(), 'commentBody' => $comment->body(), 'commenter' => ['id' => $commentUser->userId(), 'fullName' => $commentUser->firstName() . " " . $commentUser->lastName(), 'avatar' => $commentUser->avatar()], 'date_created' => Carbon::createFromTimestamp(strtotime($comment->created_at()))->diffForHumans()]; } foreach (with(new TagsFactory())->getTagsByPropositionId($proposition->propositionId()) as $tag) { $result['tags'][$tag->id()] = $tag->content(); } return response()->json($result); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $propositionFactory = new PropositionFactory(); $userFactory = new UserFactory(); $proposition = $propositionFactory->getProposition($id); if ($proposition == null) { abort(404); } if ($proposition->status() !== Proposition::ACCEPTED) { abort(404); } $proposer = $userFactory->getUser($proposition->proposerId()); $viewProposition = ['propositionId' => $proposition->propositionId(), 'proposer' => ['id' => $proposition->proposerId(), 'fullName' => $proposer->firstName() . " " . $proposer->lastName(), 'avatar' => $proposer->avatar()], 'propositionSort' => $proposition->propositionSort(), 'propositionLong' => $proposition->propositionLong(), 'date_created' => Carbon::createFromTimestamp(strtotime($proposition->date_created()))->diffForHumans(), 'deadline' => $proposition->deadline(), 'ending_in' => Carbon::now()->diffInDays(Carbon::createFromTimestamp(strtotime($proposition->deadline())), false), 'marker' => $propositionFactory->getMarker($proposition->propositionId())]; $viewVotes = ['upvotes' => $propositionFactory->getUpvotes($id), 'downvotes' => $propositionFactory->getDownvotes($id)]; $viewShareLinks = ['facebook' => Share::load(route('proposition', [$viewProposition['propositionId']]), $viewProposition['propositionSort'])->facebook(), 'twitter' => Share::load(route('proposition', [$viewProposition['propositionId']]), $viewProposition['propositionSort'])->twitter(), 'plus' => Share::load(route('proposition', [$viewProposition['propositionId']]), $viewProposition['propositionSort'])->gplus(), 'pinterest' => Share::load(route('proposition', [$viewProposition['propositionId']]), $viewProposition['propositionSort'])->pinterest()]; $viewComments = array(); foreach ($propositionFactory->getComments($id) as $comment) { $commentUser = $userFactory->getUser($comment->commenterId()); $viewComments[$comment->commentId()] = ['commentId' => $comment->commentId(), 'commentBody' => $comment->body(), 'commenter' => ['id' => $commentUser->userId(), 'fullName' => $commentUser->firstName() . " " . $commentUser->lastName(), 'avatar' => $commentUser->avatar()], 'date_created' => Carbon::createFromTimestamp(strtotime($comment->created_at()))->diffForHumans()]; } $viewProposition['commentsCount'] = count($viewComments); $viewTags = array(); foreach (with(new TagsFactory())->getTagsByPropositionId($proposition->propositionId()) as $tag) { $viewTags[$tag->id()] = $tag->content(); } if (Auth::check()) { \App::setLocale(Auth::user()->language()); $user = Auth::user(); $viewUser = ['userId' => $user->userId(), 'fullName' => $user->firstName() . " " . $user->lastName(), 'firstName' => $user->firstName(), 'lastName' => $user->lastName(), 'contactEmail' => $user->contactEmail(), 'email' => $user->email(), 'avatar' => $user->avatar(), 'belongsToSchool' => $user->belongsToSchool(), 'schoolEmail' => $user->googleEmail(), 'role' => $user->role()]; $viewVotes = ['upvotes' => $propositionFactory->getUpvotes($id), 'downvotes' => $propositionFactory->getDownvotes($id), 'userHasVoted' => $propositionFactory->getUserVoteStatus($id, $user->userId())]; return view('proposition_new', ['fullName' => $user->firstName() . " " . $user->lastName(), 'user' => $viewUser, 'proposition' => $viewProposition, 'votes' => $viewVotes, 'comments' => $viewComments, 'shareLinks' => $viewShareLinks, 'tags' => $viewTags]); } else { return view('proposition_public', ['proposition' => $viewProposition, 'votes' => $viewVotes, 'comments' => $viewComments, 'shareLinks' => $viewShareLinks]); } }