Skip to content

Commit

Permalink
Addde ability to see activity
Browse files Browse the repository at this point in the history
  • Loading branch information
milanarandjelovic committed Feb 7, 2017
1 parent b6af7b9 commit c5380f0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/Http/Controllers/Forum/DiscussionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public function store(DiscussionRequest $request)

$channel = Channel::where('id', $discussion->channel_id)->first();

activity()->by($request->input('user_id'))
->performedOn($channel)
->withProperties([
'type' => 'discussion',
'title' => $discussion->title,
'link' => 'discuss/channels/' . $channel->channel_url . '/' . $discussion->slug,
])
->log('Create discussion');

return redirect('discuss/channels/' . $channel->channel_url . '/' . $discussion->slug);
}

Expand Down
7 changes: 6 additions & 1 deletion app/Http/Controllers/Forum/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Forum;

use Spatie\Activitylog\Models\Activity;
use Validator;
use App\Models\User;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -68,11 +69,15 @@ public function show($username)
)
->first();

$u = User::where('username', $username)->first();
$userActivities = Activity::all()->where('causer_id', $u->id);

$country = Countries::all()->where('id', $user->country_flag)->first();

return view('forum.users.show')
->with('user', $user)
->with('country', $country);
->with('country', $country)
->with('userActivities', $userActivities);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateActivityLogTable extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('activity_log', function (Blueprint $table) {
$table->increments('id');
$table->string('log_name')->nullable();
$table->string('description');
$table->integer('subject_id')->nullable();
$table->string('subject_type')->nullable();
$table->integer('causer_id')->nullable();
$table->string('causer_type')->nullable();
$table->text('properties')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down()
{
Schema::drop('activity_log');
}
}
14 changes: 14 additions & 0 deletions resources/views/forum/users/partials/activity.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@foreach($userActivities as $activity)
@if($activity->getExtraProperty('type') === 'discussion')
<div class="stream-small">
<span class="label label-success"> Discussion</span>
<span class="text-muted">{{ $activity->created_at->diffForHumans() }}</span>
/
<a href="{{ '/@' . $user->username }}">{{ $user->getNameOrUsername() }}</a>
<span class="text-muted">{{ $activity->description }}</span>
<a href="{{ $activity->getExtraProperty('link') }}">
<span class="">{{ $activity->getExtraProperty('title') }}</span>
</a>
</div>
@endif
@endforeach
2 changes: 1 addition & 1 deletion resources/views/forum/users/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class="btn btn-sm btn-default">
<h5>Activites</h5>
</div> {{-- /.ibox-title --}}
<div class="ibox-content">
<p>Add activates</p>
@include('forum.users.partials.activity')
</div> {{-- /.ibox-content --}}
</div> {{-- /.ibox --}}
</div> {{-- /.col-lg-8 --}}
Expand Down

0 comments on commit c5380f0

Please sign in to comment.