public function showTopic($id) { $topic = Topic::findOrFail($id); $replys = Reply::where('topic_id', $id)->paginate(20); if (!\Auth::guest() && \Auth::user()->isAdmin() || !\Auth::guest() && \Auth::user()->isMod()) { if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } else { if ($topic->forumSection->forumHead['forOrg'] == 0 && $topic->forumSection->forumHead['forBiz'] == 0) { if (\Auth::guest()) { return view('forum.showTopic', compact('topic', 'replys')); } if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } else { if (!\Auth::guest() && $topic->forumSection->forumHead['forOrg'] == \Auth::user()->queryLeaderHeads()) { if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } elseif (!\Auth::guest() && $topic->forumSection->forumHead['forOrg'] == \Auth::user()->queryMemberHeads()) { if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } elseif (!\Auth::guest() && $topic->forumSection->forumHead['forBiz'] == \Auth::user()->queryBmemberHeads()) { if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } elseif (!\Auth::guest() && $topic->forumSection->forumHead['forBiz'] == \Auth::user()->queryBleaderHeads()) { if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } else { flash()->error('Nie masz dostępu do tego tematu!'); return redirect('/forum'); } } } }
/** * Displays a given thread. * * @param $id int The thread to display * @return Response */ public function displayThread($id) { // We only care about the ID before the first hyphen $id = strtok($id, '-'); // Retrieve the first post of the thread $thread = Thread::where('threads.id', $id)->join('users', 'users.id', '=', 'threads.author')->select('threads.*', 'users.username')->first(); $replies = Reply::where('replies.thread', $id)->join('users', 'users.id', '=', 'replies.author')->select('replies.*', 'users.username')->paginate(20); return view('thread', compact('thread', 'replies')); }
/** * Run the database seeds. * * @return void */ public function run() { $comments = \App\Comment::all(); $fake_replies = file_get_contents("http://jsonplaceholder.typicode.com/comments"); $fake_replies = json_decode($fake_replies, true); foreach ($comments as $comment) { if (mt_rand(0, 1)) { $replies = \App\Reply::where('reply_to_id', $comment->id)->get(); if (count($replies) > 0) { continue; } else { $reply = new \App\Reply(); $reply->reply_to_id = $comment->id; $one_reply = $fake_replies[mt_rand(0, count($fake_replies) - 1)]; $reply->reply_text = $one_reply['body']; $reply->save(); } } } }
$images = get_all_images_from_property_id($property->id); /* Raw SQL query to find the average rating on a property */ $num_stars = DB::select("SELECT AVG(comments.rating) AS 'avg' FROM comments JOIN properties ON properties.id = comments.property_id WHERE comments.property_id = " . $property->id); if (count($num_stars > 0)) { $num_stars = $num_stars[0]->avg; $num_stars = floor($num_stars * 2) / 2; } else { $num_stars = null; } $property->num_stars = $num_stars; /* Get all the comments on this property */ $comments = Comment::where('property_id', $property->id)->get(); foreach ($comments as $comment) { $comment->author_pic = get_thumbnail_from_user_id($comment->user_id); $comment->author = User::find($comment->user_id); $reply = \App\Reply::where('reply_to_id', $comment->id)->get(); $comment->reply = $reply; } /* Get all the comments for this user */ $all_owner_properties = Property::where('owner_id', $owner->id)->get(); $all_owner_comments = array(); foreach ($all_owner_properties as $owner_property) { $property_comments = Comment::where('property_id', $owner_property->id)->get(); foreach ($property_comments as $owner_property_comment) { array_push($all_owner_comments, $owner_property_comment); } } $owner->number_of_reviews = count($all_owner_comments); /* Get this district */ $district = District::find($property->district_id); /* Get the POIs for this district */