1
0
mirror of https://github.com/flarum/core.git synced 2025-08-01 22:20:21 +02:00

Add user activity system

This commit is contained in:
Toby Zerner
2015-03-17 17:06:12 +10:30
parent 5055377eb1
commit 3880ce70f0
27 changed files with 508 additions and 72 deletions

View File

@@ -1,36 +1,69 @@
<?php namespace Flarum\Core\Activity;
<?php namespace Flarum\Core\Models;
use Flarum\Core\Entity;
use Illuminate\Support\Str;
use Auth;
class Activity extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'activity';
class Activity extends Entity {
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['time'];
protected $table = 'activity';
/**
* Unserialize the data attribute.
*
* @param string $value
* @return string
*/
public function getDataAttribute($value)
{
return json_decode($value);
}
public function getDates()
{
return ['time'];
}
/**
* Serialize the data attribute.
*
* @param string $value
*/
public function setDataAttribute($value)
{
$this->attributes['data'] = json_encode($value);
}
public function fromUser()
{
return $this->belongsTo('Flarum\Core\Models\User', 'from_user_id');
}
/**
* Define the relationship with the activity's recipient.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo('Flarum\Core\Models\User', 'user_id');
}
public function permission($permission)
{
return User::current()->can($permission, 'activity', $this);
}
public function editable()
{
return $this->permission('edit');
}
public function deletable()
{
return $this->permission('delete');
}
/**
* Define the relationship with the activity's sender.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function sender()
{
return $this->belongsTo('Flarum\Core\Models\User', 'sender_id');
}
/**
* Define the relationship with the activity's sender.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function post()
{
return $this->belongsTo('Flarum\Core\Models\Post', 'post_id');
}
}