Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Feature: User Activity for #15 #19

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
150fc23
Starting work on User Activity for #15.
euantorano Mar 20, 2015
532f9e7
Working on user activity. Added user activity controller.
euantorano Mar 20, 2015
5136b6b
Fixed package naming in docblocks. Also added repository binding to s…
euantorano Mar 21, 2015
fa8ee4b
Starting work on User Activity for #15.
euantorano Mar 20, 2015
ab88192
Working on user activity. Added user activity controller.
euantorano Mar 20, 2015
e61b607
Fixed package naming in docblocks. Also added repository binding to s…
euantorano Mar 21, 2015
cdfc38d
Merge branch 'feature-user-activity' of github.com:euantorano/mybb2 i…
euantorano Mar 21, 2015
cc00a85
Update Post.php
euantorano Mar 21, 2015
30386b6
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano Mar 23, 2015
1112a42
Working on formatting user activity entries.
euantorano Mar 23, 2015
21d40b7
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano Mar 23, 2015
01ca97e
Slight code reformatting.
euantorano Mar 23, 2015
673b3ed
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano Mar 29, 2015
6d37209
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano Apr 7, 2015
31d4fba
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano Apr 9, 2015
eabfe83
Tidying up model observing.
euantorano Apr 9, 2015
6fac0c9
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano Apr 9, 2015
9412ccf
Fixed syntax error.
euantorano Apr 9, 2015
fafb4e9
Cleaned up presenter for activity.
euantorano Apr 9, 2015
33e6fdf
Cleaning up and refactoring code.
euantorano Apr 9, 2015
cce3a86
Added settings.
euantorano Apr 9, 2015
a9ef59f
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano Apr 19, 2015
e88043b
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano Apr 19, 2015
bcae5c7
Added activity for liking content.
euantorano Apr 19, 2015
a10328f
Added basic user activity list to profile.
euantorano Apr 19, 2015
3a2cdd2
Refactoring code.
euantorano Apr 19, 2015
f0f1700
Fixing indents in templates.
euantorano Apr 19, 2015
25ac9a1
Fixing profile template.
euantorano Apr 19, 2015
be0c29b
Reformatting seeds.
euantorano Apr 19, 2015
a72f406
Removed unused `$guard` and `$request`.
euantorano Apr 19, 2015
6f5a673
Removed old imports.
euantorano Apr 19, 2015
258c9c5
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano Apr 19, 2015
c9ca049
Auto-loading the likeable relation for the Likes model, saving 3 quer…
euantorano Apr 19, 2015
2f9dea2
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano Apr 24, 2015
a94eb61
Add `is_topic_starter` to `posts` table.
euantorano Apr 24, 2015
3b8dc21
Added activity for new topics.
euantorano Apr 24, 2015
1a5b91f
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano May 19, 2015
1b9ebfa
Fixed copyright header years.
euantorano May 19, 2015
2440360
Converting indents to tabs.
euantorano May 19, 2015
f6c2c78
Updating license headers, added registration activity.
euantorano May 19, 2015
baa739e
Added twig test to check if a variable is a user.
euantorano May 19, 2015
3df880c
Added page to show all activity for a user.
euantorano May 19, 2015
9b544d3
Starting reformatting code.
euantorano May 19, 2015
a8f35f3
Fixed code style issues.
euantorano May 19, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 96 additions & 2 deletions app/Database/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use McCool\LaravelAutoPresenter\HasPresenter;
use MyBB\Core\Likes\Contracts\LikeableInterface;
use MyBB\Core\Likes\Traits\LikeableTrait;
use MyBB\Core\UserActivity\Contracts\ActivityStoreableInterface;
use MyBB\Core\UserActivity\Traits\UserActivityTrait;

class Post extends Model implements HasPresenter
class Post extends Model implements HasPresenter, LikeableInterface, ActivityStoreableInterface
{
use SoftDeletes;
use UserActivityTrait;
use LikeableTrait;

// @codingStandardsIgnoreStart

/**
* Indicates if the model should be timestamped.
*
* @var boolean
* @var bool
*/
public $timestamps = true;

Expand All @@ -37,12 +41,14 @@ class Post extends Model implements HasPresenter
* @var string
*/
protected $table = 'posts';

/**
* The relations to eager load on every query.
*
* @var array
*/
protected $with = array();

/**
* The attributes that aren't mass assignable.
*
Expand Down Expand Up @@ -86,4 +92,92 @@ public function author()
{
return $this->belongsTo('MyBB\\Core\\Database\\Models\\User', 'user_id');
}

/**
* Get the ID of the model.
*
* @return int
*/
public function getContentId()
{
return $this->id;
}

/**
* Get extra details about a model.
*
* @return array The extra details to store.
*/
public function getExtraDetails()
{
return [
'topic_id' => $this->topic_id,
'topic_slug' => $this->topic->slug,
'topic_title' => $this->topic->title,
'content' => $this->content_parsed,
];
}

/**
* Check whether this activity entry should be saved.
*
* @return bool
*/
public function checkStoreable()
{
return (!$this->is_topic_starter);
}

/**
* Get the title of the content being liked.
*
* @return string
*/
public function getContentTitle()
{
if (!isset($this->topic)) {
$this->load(['topic', 'topic.author']);
}

return $this->topic->title;
}

/**
* Get the author of the content being liked.
*
* @return \MyBB\Core\Database\Models\User
*/
public function getContentAuthor()
{
return $this->author;
}

/**
* Get the short name of the content being liked.
*
* For example: "post".
*
* @return string
*/
public function getContentTypeShortName()
{
return "post";
}

/**
* Get the URL to view this content.
*
* @return string
*/
public function getViewUrl()
{
return route(
'topics.showPost',
[
'slug' => $this->topic->slug,
'id' => $this->topic_id,
'postId' => $this->id,
]
);
}
}
38 changes: 37 additions & 1 deletion app/Database/Models/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use McCool\LaravelAutoPresenter\HasPresenter;
use MyBB\Core\UserActivity\Contracts\ActivityStoreableInterface;
use MyBB\Core\UserActivity\Traits\UserActivityTrait;

class Topic extends Model implements HasPresenter
class Topic extends Model implements HasPresenter, ActivityStoreableInterface
{
use SoftDeletes;
use UserActivityTrait;

// @codingStandardsIgnoreStart

Expand Down Expand Up @@ -137,4 +140,37 @@ public function lastPost()
{
return $this->hasOne('MyBB\\Core\\Database\\Models\\Post', 'id', 'last_post_id');
}

/**
* Check whether this activity entry should be saved.
*
* @return bool
*/
public function checkStoreable()
{
return true;
}

/**
* Get the ID of the model.
*
* @return int
*/
public function getContentId()
{
return $this->id;
}

/**
* Get extra details about a model.
*
* @return array The extra details to store.
*/
public function getExtraDetails()
{
return [
'topic_slug' => $this->slug,
'topic_title' => $this->title,
];
}
}
1 change: 1 addition & 0 deletions app/Database/Repositories/Eloquent/TopicRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public function create(array $details = [])
$firstPost = $this->postRepository->addPostToTopic($topic, [
'content' => $details['content'],
'username' => $details['username'],
'is_topic_starter' => true,
]);

$topic->update([
Expand Down
41 changes: 35 additions & 6 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
namespace MyBB\Core\Http\Controllers;

use DaveJamesMiller\Breadcrumbs\Manager as Breadcrumbs;
use MyBB\Core\Database\Repositories\UserRepositoryInterface;
use MyBB\Core\Database\Repositories\ProfileFieldGroupRepositoryInterface;
use MyBB\Core\Database\Repositories\UserProfileFieldRepositoryInterface;
use MyBB\Core\Database\Repositories\UserRepositoryInterface;
use MyBB\Core\UserActivity\Database\Repositories\UserActivityRepositoryInterface;
use MyBB\Settings\Store;
use MyBB\Core\Exceptions\UserNotFoundException;

class UserController extends AbstractController
Expand All @@ -26,16 +28,32 @@ class UserController extends AbstractController
*/
protected $userProfileFields;

/**
* @var UserActivityRepositoryInterface $activityRepository
*/
protected $activityRepository;

/**
* @var Store $settings
*/
protected $settings;

/**
* @param UserRepositoryInterface $users
* @param UserProfileFieldRepositoryInterface $userProfileFields
* @param UserActivityRepositoryInterface $activityRepository
* @param Store $settings
*/
public function __construct(
UserRepositoryInterface $users,
UserProfileFieldRepositoryInterface $userProfileFields
UserProfileFieldRepositoryInterface $userProfileFields,
UserActivityRepositoryInterface $activityRepository,
Store $settings
) {
$this->users = $users;
$this->userProfileFields = $userProfileFields;
$this->activityRepository = $activityRepository;
$this->settings = $settings;
}

/**
Expand All @@ -59,12 +77,23 @@ public function profile(
}

$groups = $profileFieldGroups->getAll();
$activity = $this->activityRepository->paginateForUser(
$user,
$this->settings->get(
'user_profile.activity_per_page',
20
)
);

$breadcrumbs->setCurrentRoute('user.profile', $user);

return view('user.profile', [
'user' => $user,
'profile_field_groups' => $groups
]);
return view(
'user.profile',
[
'user' => $user,
'profile_field_groups' => $groups,
'activity' => $activity,
]
);
}
}
Loading