public function test_restoreTopicToSection_restores_a_topic_and_views()
 {
     // GIVEN I have a topic with posts in a section
     $section = factory(Section::class, 1)->create();
     $topic = factory(Topic::class, 1)->create(['section_id' => $section->id]);
     factory(Post::class, 20)->create(['topic_id' => $topic->id]);
     $topic_id = $topic->id;
     // and a user reads that topic
     $user = factory(User::class, 1)->create();
     \Nexus\Helpers\ViewHelper::updateReadProgress($user, $topic);
     $viewsCount = $topic->views->count();
     $this->assertNotEquals($viewsCount, 0);
     // and then that topic is deleted
     $topic->delete();
     // check topic deleted
     $this->assertTrue($topic->trashed());
     // and that we have no views - need to use trashed here
     $this->assertEquals(Topic::withTrashed()->find($topic_id)->views->count(), 0);
     // WHEN the topic is restored to the section
     \Nexus\Helpers\RestoreHelper::restoreTopicToSection($topic, $section);
     // check posts and views are restored
     $this->assertEquals($topic->views->count(), $viewsCount);
     // THEN the topic is restored
     $this->assertFalse($topic->trashed());
 }
Exemplo n.º 2
0
 /**
  * reports on the status of a given topic for a user
  *
  * @param  \Nexus\User $user - the user
  * @param  \Nexus\Topic $topic - a topic
  * @return array - of status values
  */
 public static function getTopicStatus(\Nexus\User $user, \Nexus\Topic $topic)
 {
     $status = ['new_posts' => false, 'never_read' => false, 'unsubscribed' => false];
     $mostRecentlyReadPostDate = \Nexus\Helpers\ViewHelper::getReadProgress($user, $topic);
     $mostRecentPostDate = $topic->most_recent_post_time;
     $view = \Nexus\View::where('topic_id', $topic->id)->where('user_id', $user->id)->first();
     if ($view !== null) {
         if ($view->unsubscribed != 0) {
             $status['unsubscribed'] = true;
         }
         if ($mostRecentPostDate !== false && $mostRecentlyReadPostDate !== false) {
             if ($mostRecentPostDate->gt($mostRecentlyReadPostDate)) {
                 $status['new_posts'] = true;
             }
         }
     } else {
         $status['never_read'] = true;
     }
     return $status;
 }
Exemplo n.º 3
0
<?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 = '';
?>
Exemplo n.º 4
0
 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']);
 }
Exemplo n.º 5
0
 public function markAllSubscribedTopicsAsRead()
 {
     \Nexus\Helpers\ViewHelper::catchUpCatchUp(\Auth::user());
     $message = '**Success!** all subscribed topics are now marked as read';
     \Nexus\Helpers\FlashHelper::showAlert($message, 'success');
     return redirect('/');
 }