2015-08-17 01:59:23 +08:00
|
|
|
<?php
|
|
|
|
|
2015-09-11 02:31:09 +08:00
|
|
|
namespace BookStack;
|
2015-08-17 01:59:23 +08:00
|
|
|
|
|
|
|
/**
|
2015-08-30 18:47:58 +08:00
|
|
|
* @property string key
|
|
|
|
* @property \User user
|
2015-08-17 01:59:23 +08:00
|
|
|
* @property \Entity entity
|
2015-08-30 18:47:58 +08:00
|
|
|
* @property string extra
|
2015-08-17 01:59:23 +08:00
|
|
|
*/
|
|
|
|
class Activity extends Model
|
|
|
|
{
|
2015-08-30 18:47:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the entity for this activity.
|
|
|
|
*/
|
2015-08-17 01:59:23 +08:00
|
|
|
public function entity()
|
|
|
|
{
|
2016-03-05 20:09:09 +08:00
|
|
|
if ($this->entity_type === '') $this->entity_type = null;
|
2016-02-29 03:03:04 +08:00
|
|
|
return $this->morphTo('entity');
|
2015-08-17 01:59:23 +08:00
|
|
|
}
|
|
|
|
|
2015-08-30 18:47:58 +08:00
|
|
|
/**
|
|
|
|
* Get the user this activity relates to.
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2015-08-17 01:59:23 +08:00
|
|
|
public function user()
|
|
|
|
{
|
2016-05-02 04:20:50 +08:00
|
|
|
return $this->belongsTo(User::class);
|
2015-08-17 01:59:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns text from the language files, Looks up by using the
|
|
|
|
* activity key.
|
|
|
|
*/
|
|
|
|
public function getText()
|
|
|
|
{
|
|
|
|
return trans('activities.' . $this->key);
|
|
|
|
}
|
|
|
|
|
2015-08-30 18:47:58 +08:00
|
|
|
/**
|
|
|
|
* Checks if another Activity matches the general information of another.
|
|
|
|
* @param $activityB
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isSimilarTo($activityB) {
|
2016-05-28 21:02:48 +08:00
|
|
|
return [$this->key, $this->entity_type, $this->entity_id] === [$activityB->key, $activityB->entity_type, $activityB->entity_id];
|
2015-08-30 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2015-08-17 01:59:23 +08:00
|
|
|
}
|