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:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user