2015-08-17 01:59:23 +08:00
|
|
|
<?php
|
|
|
|
|
2018-09-25 19:30:50 +08:00
|
|
|
namespace BookStack\Actions;
|
|
|
|
|
|
|
|
use BookStack\Auth\User;
|
2019-09-20 01:03:17 +08:00
|
|
|
use BookStack\Entities\Entity;
|
2018-09-25 19:30:50 +08:00
|
|
|
use BookStack\Model;
|
2020-11-08 08:03:19 +08:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2015-08-17 01:59:23 +08:00
|
|
|
|
|
|
|
/**
|
2020-11-08 08:03:19 +08:00
|
|
|
* @property string $type
|
2019-09-20 01:03:17 +08:00
|
|
|
* @property User $user
|
|
|
|
* @property Entity $entity
|
2020-11-08 08:03:19 +08:00
|
|
|
* @property string $detail
|
2019-09-20 01:03:17 +08:00
|
|
|
* @property string $entity_type
|
|
|
|
* @property int $entity_id
|
|
|
|
* @property int $user_id
|
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()
|
|
|
|
{
|
2018-01-29 00:58:52 +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.
|
|
|
|
*/
|
2020-11-08 08:03:19 +08:00
|
|
|
public function user(): BelongsTo
|
2015-08-17 01:59:23 +08:00
|
|
|
{
|
2016-05-02 04:20:50 +08:00
|
|
|
return $this->belongsTo(User::class);
|
2015-08-17 01:59:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-08 08:03:19 +08:00
|
|
|
* Returns text from the language files, Looks up by using the activity key.
|
2015-08-17 01:59:23 +08:00
|
|
|
*/
|
2020-11-08 08:03:19 +08:00
|
|
|
public function getText(): string
|
2015-08-17 01:59:23 +08:00
|
|
|
{
|
2020-11-08 08:03:19 +08:00
|
|
|
return trans('activities.' . $this->type);
|
2015-08-17 01:59:23 +08:00
|
|
|
}
|
|
|
|
|
2015-08-30 18:47:58 +08:00
|
|
|
/**
|
|
|
|
* Checks if another Activity matches the general information of another.
|
|
|
|
*/
|
2020-04-11 03:55:33 +08:00
|
|
|
public function isSimilarTo(Activity $activityB): bool
|
2018-01-29 00:58:52 +08:00
|
|
|
{
|
2020-11-08 08:03:19 +08:00
|
|
|
return [$this->type, $this->entity_type, $this->entity_id] === [$activityB->type, $activityB->entity_type, $activityB->entity_id];
|
2015-08-30 18:47:58 +08:00
|
|
|
}
|
2015-08-17 01:59:23 +08:00
|
|
|
}
|