This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Feature: User Activity for #15 #19
Open
euantorano
wants to merge
44
commits into
mybb:master
Choose a base branch
from
euantorano:feature-user-activity
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 29 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 532f9e7
Working on user activity. Added user activity controller.
euantorano 5136b6b
Fixed package naming in docblocks. Also added repository binding to s…
euantorano fa8ee4b
Starting work on User Activity for #15.
euantorano ab88192
Working on user activity. Added user activity controller.
euantorano e61b607
Fixed package naming in docblocks. Also added repository binding to s…
euantorano cdfc38d
Merge branch 'feature-user-activity' of github.com:euantorano/mybb2 i…
euantorano cc00a85
Update Post.php
euantorano 30386b6
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano 1112a42
Working on formatting user activity entries.
euantorano 21d40b7
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano 01ca97e
Slight code reformatting.
euantorano 673b3ed
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano 6d37209
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano 31d4fba
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano eabfe83
Tidying up model observing.
euantorano 6fac0c9
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano 9412ccf
Fixed syntax error.
euantorano fafb4e9
Cleaned up presenter for activity.
euantorano 33e6fdf
Cleaning up and refactoring code.
euantorano cce3a86
Added settings.
euantorano a9ef59f
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano e88043b
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano bcae5c7
Added activity for liking content.
euantorano a10328f
Added basic user activity list to profile.
euantorano 3a2cdd2
Refactoring code.
euantorano f0f1700
Fixing indents in templates.
euantorano 25ac9a1
Fixing profile template.
euantorano be0c29b
Reformatting seeds.
euantorano a72f406
Removed unused `$guard` and `$request`.
euantorano 6f5a673
Removed old imports.
euantorano 258c9c5
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano c9ca049
Auto-loading the likeable relation for the Likes model, saving 3 quer…
euantorano 2f9dea2
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano a94eb61
Add `is_topic_starter` to `posts` table.
euantorano 3b8dc21
Added activity for new topics.
euantorano 1a5b91f
Merge branch 'master' of github.com:mybb/mybb2 into feature-user-acti…
euantorano 1b9ebfa
Fixed copyright header years.
euantorano 2440360
Converting indents to tabs.
euantorano f6c2c78
Updating license headers, added registration activity.
euantorano baa739e
Added twig test to check if a variable is a user.
euantorano 3df880c
Added page to show all activity for a user.
euantorano 9b544d3
Starting reformatting code.
euantorano a8f35f3
Fixed code style issues.
euantorano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,72 +12,155 @@ | |
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\SoftDeletes; | ||
use McCool\LaravelAutoPresenter\HasPresenter; | ||
use MyBB\Core\Likes\Contracts\LikeableInterface; | ||
use MyBB\Core\UserActivity\Contracts\ActivityStoreableInterface; | ||
use MyBB\Core\UserActivity\Traits\UserActivityTrait; | ||
use MyBB\Core\Likes\Traits\LikeableTrait; | ||
|
||
class Post extends Model implements HasPresenter | ||
class Post extends Model implements HasPresenter, LikeableInterface, ActivityStoreableInterface | ||
{ | ||
use SoftDeletes; | ||
use SoftDeletes; | ||
use UserActivityTrait; | ||
use LikeableTrait; | ||
|
||
/** | ||
* Indicates if the model should be timestamped. | ||
* | ||
* @var bool | ||
*/ | ||
public $timestamps = true; | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @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. | ||
* | ||
* @var array | ||
*/ | ||
protected $guarded = array(); | ||
|
||
/** | ||
* The date attributes. | ||
* | ||
* @var array | ||
*/ | ||
protected $dates = ['deleted_at', 'created_at', 'updated_at']; | ||
|
||
/** | ||
* Get the presenter class. | ||
* | ||
* @return string | ||
*/ | ||
public function getPresenterClass() | ||
{ | ||
return 'MyBB\Core\Presenters\Post'; | ||
} | ||
|
||
/** | ||
* A post belongs to a thread. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
*/ | ||
public function topic() | ||
{ | ||
return $this->belongsTo('MyBB\\Core\\Database\\Models\\Topic')->withTrashed(); | ||
} | ||
|
||
/** | ||
* A post is created by (and belongs to) a user/author. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
*/ | ||
public function author() | ||
{ | ||
return $this->belongsTo('MyBB\\Core\\Database\\Models\\User', 'user_id'); | ||
} | ||
/** | ||
* Indicates if the model should be timestamped. | ||
* | ||
* @var bool | ||
*/ | ||
public $timestamps = true; | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @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. | ||
* | ||
* @var array | ||
*/ | ||
protected $guarded = array(); | ||
|
||
/** | ||
* The date attributes. | ||
* | ||
* @var array | ||
*/ | ||
protected $dates = ['deleted_at', 'created_at', 'updated_at']; | ||
|
||
/** | ||
* Get the presenter class. | ||
* | ||
* @return string | ||
*/ | ||
public function getPresenterClass() | ||
{ | ||
return 'MyBB\Core\Presenters\Post'; | ||
} | ||
|
||
/** | ||
* A post belongs to a thread. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
*/ | ||
public function topic() | ||
{ | ||
return $this->belongsTo('MyBB\\Core\\Database\\Models\\Topic')->withTrashed(); | ||
} | ||
|
||
/** | ||
* A post is created by (and belongs to) a user/author. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
*/ | ||
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, | ||
]; | ||
} | ||
|
||
/** | ||
* 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this return the author of the post and not of the topic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. Not sure what I was thinking there... |
||
{ | ||
if (!isset($this->topic) || !isset($this->topic->author)) { | ||
$this->load(['topic', 'topic.author']); | ||
} | ||
|
||
return $this->topic->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, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we prefer multiple lines or one (
use SoftDeletes, UserActivityTrait, LikeableTrait;
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer one on each line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer that too (especially since it makes it easier when we need to rename a function). Should probably be added to our contributing file and changed where we're using one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely prefer one on each line. I'll add it.