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 27 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
209 changes: 146 additions & 63 deletions app/Database/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

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;)?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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.


/**
* 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()
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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,
]);
}
}
126 changes: 64 additions & 62 deletions app/Database/Repositories/Eloquent/SearchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,73 @@

class SearchRepository implements SearchRepositoryInterface
{
/**
* @var Search $searchModel
* @access protected
*/
protected $searchModel;
/**
* @var Guard $guard ;
* @access protected
*/
protected $guard;
/**
* @var Search $searchModel
* @access protected
*/
protected $searchModel;
/**
* @var Guard $guard ;
* @access protected
*/
protected $guard;

/**
* @param Search $searchModel The model to use for search logs.
* @param Guard $guard Laravel guard instance, used to get user ID.
*/
public function __construct(
Search $searchModel,
Guard $guard
)
{
$this->searchModel = $searchModel;
$this->guard = $guard;
}
/**
* @param Search $searchModel The model to use for search logs.
* @param Guard $guard Laravel guard instance, used to get user ID.
*/
public function __construct(
Search $searchModel,
Guard $guard
) {
$this->searchModel = $searchModel;
$this->guard = $guard;
}

/**
* Find a single searchlog by ID.
*
* @param string $id The ID of the search to find.
*
* @return mixed
*/
public function find($id)
{
$userId = $this->guard->user()->id;
if($userId <= 0)
{
$userId = null;
}
return $this->searchModel->where('user_id', $userId)->find($id);
}
/**
* Find a single searchlog by ID.
*
* @param string $id The ID of the search to find.
*
* @return mixed
*/
public function find($id)
{
$userId = $this->guard->user()->id;
if ($userId <= 0) {
$userId = null;
}

/**
* Create a new searchlog
*
* @param array $details Details about the searchlog.
*
* @return mixed
*/
public function create(array $details = [])
{
$details = array_merge([
'id' => md5(uniqid(microtime(), true)),
'keywords' => '',
'as_topics' => true,
'user_id' => $this->guard->user()->id,
'topics' => '',
'posts' => ''
], $details);
return $this->searchModel->where('user_id', $userId)->find($id);
}

if($details['user_id'] < 0)
{
$details['user_id'] = null;
}
/**
* Create a new searchlog
*
* @param array $details Details about the searchlog.
*
* @return mixed
*/
public function create(array $details = [])
{
$details = array_merge(
[
'id' => md5(uniqid(microtime(), true)),
'keywords' => '',
'as_topics' => true,
'user_id' => $this->guard->user()->id,
'topics' => '',
'posts' => ''
],
$details
);

$searchlog = $this->searchModel->create($details);
return $searchlog;
}
if ($details['user_id'] < 0) {
$details['user_id'] = null;
}

$searchlog = $this->searchModel->create($details);

return $searchlog;
}
}
33 changes: 16 additions & 17 deletions app/Database/Repositories/SearchRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@
interface SearchRepositoryInterface
{

/**
* Find a single search log by ID.
*
* @param string $id The ID of the search log to find.
*
* @return mixed
*/
public function find($id);

/**
* Create a new searchlog
*
* @param array $details Details about the searchlog.
*
* @return mixed
*/
public function create(array $details = []);
/**
* Find a single search log by ID.
*
* @param string $id The ID of the search log to find.
*
* @return mixed
*/
public function find($id);

/**
* Create a new searchlog
*
* @param array $details Details about the searchlog.
*
* @return mixed
*/
public function create(array $details = []);
}