2015-08-16 18:59:23 +01:00
|
|
|
<?php
|
|
|
|
|
2018-09-25 12:30:50 +01:00
|
|
|
namespace BookStack\Actions;
|
|
|
|
|
|
|
|
use BookStack\Auth\User;
|
2019-09-19 18:03:17 +01:00
|
|
|
use BookStack\Entities\Entity;
|
2018-09-25 12:30:50 +01:00
|
|
|
use BookStack\Model;
|
2015-08-16 18:59:23 +01:00
|
|
|
|
|
|
|
/**
|
2019-09-19 18:03:17 +01:00
|
|
|
* @property string $key
|
|
|
|
* @property User $user
|
|
|
|
* @property Entity $entity
|
|
|
|
* @property string $extra
|
|
|
|
* @property string $entity_type
|
|
|
|
* @property int $entity_id
|
|
|
|
* @property int $user_id
|
|
|
|
* @property int $book_id
|
2015-08-16 18:59:23 +01:00
|
|
|
*/
|
|
|
|
class Activity extends Model
|
|
|
|
{
|
2015-08-30 11:47:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the entity for this activity.
|
|
|
|
*/
|
2015-08-16 18:59:23 +01:00
|
|
|
public function entity()
|
|
|
|
{
|
2018-01-28 16:58:52 +00:00
|
|
|
if ($this->entity_type === '') {
|
|
|
|
$this->entity_type = null;
|
|
|
|
}
|
2016-02-28 19:03:04 +00:00
|
|
|
return $this->morphTo('entity');
|
2015-08-16 18:59:23 +01:00
|
|
|
}
|
|
|
|
|
2015-08-30 11:47:58 +01:00
|
|
|
/**
|
|
|
|
* Get the user this activity relates to.
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2015-08-16 18:59:23 +01:00
|
|
|
public function user()
|
|
|
|
{
|
2016-05-01 21:20:50 +01:00
|
|
|
return $this->belongsTo(User::class);
|
2015-08-16 18:59:23 +01: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 11:47:58 +01:00
|
|
|
/**
|
|
|
|
* Checks if another Activity matches the general information of another.
|
|
|
|
*/
|
2020-04-10 20:55:33 +01:00
|
|
|
public function isSimilarTo(Activity $activityB): bool
|
2018-01-28 16:58:52 +00:00
|
|
|
{
|
2016-05-28 14:02:48 +01:00
|
|
|
return [$this->key, $this->entity_type, $this->entity_id] === [$activityB->key, $activityB->entity_type, $activityB->entity_id];
|
2015-08-30 11:47:58 +01:00
|
|
|
}
|
2015-08-16 18:59:23 +01:00
|
|
|
}
|