/** * Display the specified resource. * * @param int $id * @return Response */ public function show($topic_id) { $posts = \Nexus\Post::with('author')->where('topic_id', $topic_id)->orderBy('id', 'dsc'); $topic = \Nexus\Topic::findOrFail($topic_id); // is this topic readonly to the authenticated user? $readonly = true; if ($topic->readonly == false) { $readonly = false; } if ($topic->section->moderator->id === \Auth::user()->id) { $readonly = false; } if (\Auth::user()->administrator) { $readonly = false; } // is this topic secret to the authenticated user? $userCanSeeSecrets = false; if ($topic->section->moderator->id === \Auth::user()->id) { $userCanSeeSecrets = true; } if (\Auth::user()->administrator) { $userCanSeeSecrets = true; } // get the previously read progress so we can indicate this in the view $readProgress = \Nexus\Helpers\ViewHelper::getReadProgress(\Auth::user(), $topic); // get the subscription status $topicStatus = \Nexus\Helpers\ViewHelper::getTopicStatus(\Auth::user(), $topic); $unsubscribed = $topicStatus['unsubscribed']; \Nexus\Helpers\ViewHelper::updateReadProgress(\Auth::user(), $topic); \Nexus\Helpers\ActivityHelper::updateActivity(\Auth::user()->id, "Reading <em>{$topic->title}</em>", action('Nexus\\TopicController@show', ['id' => $topic->id])); $breadcrumbs = \Nexus\Helpers\BreadcrumbHelper::breadcrumbForTopic($topic); return view('topics.index', compact('topic', 'posts', 'readonly', 'userCanSeeSecrets', 'readProgress', 'breadcrumbs', 'unsubscribed')); }
<?php $status = \Nexus\Helpers\ViewHelper::getTopicStatus(Auth::user(), $topic); ?> <div class="well"> <h2> @if ($status['unsubscribed']) <?php $textClass = 'text-muted'; ?> <a href="{{ action('Nexus\TopicController@show', ['topic_id' => $topic->id])}}" class="{{$textClass}}"> <span class="glyphicon glyphicon-eye-close {{$textClass}}" aria-hidden="true"></span> @elseif ($status['new_posts']) <?php $textClass = 'text-danger'; ?> <a href="{{ action('Nexus\TopicController@show', ['topic_id' => $topic->id])}}" class="{{$textClass}}"> <span class="glyphicon glyphicon-fire {{$textClass}}" aria-hidden="true"></span> @elseif ($status['never_read']) <?php $textClass = 'text-warning'; ?> <a href="{{ action('Nexus\TopicController@show', ['topic_id' => $topic->id])}}" class="{{$textClass}}"> <span class="glyphicon glyphicon-asterisk {{$textClass}}" aria-hidden="true"></span> @else <?php $textClass = ''; ?>
public function test_getTopicStatus_returns_subscribed_when_a_user_resubscribes() { $faker = \Faker\Factory::create(); // GIVEN we have a user $user = factory(User::class, 1)->create(); // AND we add a topic $topic = factory(Topic::class, 1)->create(); // WHEN the user is unsubscribed from the topic \Nexus\Helpers\ViewHelper::unsubscribeFromTopic($user, $topic); // THEN the topic does not appear new to the user $topicStatus = \Nexus\Helpers\ViewHelper::getTopicStatus($user, $topic); $this->assertTrue($topicStatus['unsubscribed']); // WHEN the user is unsubscribed from the topic \Nexus\Helpers\ViewHelper::subscribeToTopic($user, $topic); // THEN the topic does not appear new to the user $topicStatus = \Nexus\Helpers\ViewHelper::getTopicStatus($user, $topic); $this->assertFalse($topicStatus['unsubscribed']); }