2021-06-26 11:23:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Actions;
|
2018-09-25 07:30:50 -04:00
|
|
|
|
2020-12-30 13:25:35 -05:00
|
|
|
use BookStack\Model;
|
|
|
|
use BookStack\Traits\HasCreatorAndUpdater;
|
2021-10-30 16:29:59 -04:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2020-12-30 13:25:35 -05:00
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
2017-01-13 11:15:48 -05:00
|
|
|
|
2020-05-01 18:24:11 -04:00
|
|
|
/**
|
2021-09-18 16:21:44 -04:00
|
|
|
* @property int $id
|
|
|
|
* @property string $text
|
|
|
|
* @property string $html
|
2021-09-17 19:33:03 -04:00
|
|
|
* @property int|null $parent_id
|
2021-09-18 16:21:44 -04:00
|
|
|
* @property int $local_id
|
2020-05-01 18:24:11 -04:00
|
|
|
*/
|
2020-12-30 13:25:35 -05:00
|
|
|
class Comment extends Model
|
2017-01-13 11:15:48 -05:00
|
|
|
{
|
2021-10-30 16:29:59 -04:00
|
|
|
use HasFactory;
|
2020-12-30 13:25:35 -05:00
|
|
|
use HasCreatorAndUpdater;
|
|
|
|
|
2020-05-01 18:24:11 -04:00
|
|
|
protected $fillable = ['text', 'parent_id'];
|
2017-09-03 11:37:51 -04:00
|
|
|
protected $appends = ['created', 'updated'];
|
|
|
|
|
2017-01-13 11:15:48 -05:00
|
|
|
/**
|
2021-06-26 11:23:15 -04:00
|
|
|
* Get the entity that this comment belongs to.
|
2017-01-13 11:15:48 -05:00
|
|
|
*/
|
2020-12-30 13:25:35 -05:00
|
|
|
public function entity(): MorphTo
|
2017-01-13 11:15:48 -05:00
|
|
|
{
|
|
|
|
return $this->morphTo('entity');
|
|
|
|
}
|
2017-05-15 15:10:14 -04:00
|
|
|
|
2017-01-13 11:15:48 -05:00
|
|
|
/**
|
2017-09-03 11:37:51 -04:00
|
|
|
* Check if a comment has been updated since creation.
|
2017-01-13 11:15:48 -05:00
|
|
|
*/
|
2020-12-30 13:25:35 -05:00
|
|
|
public function isUpdated(): bool
|
2017-01-13 11:15:48 -05:00
|
|
|
{
|
2017-09-03 11:37:51 -04:00
|
|
|
return $this->updated_at->timestamp > $this->created_at->timestamp;
|
2017-01-13 11:15:48 -05:00
|
|
|
}
|
2017-05-15 15:10:14 -04:00
|
|
|
|
2017-01-13 11:15:48 -05:00
|
|
|
/**
|
2017-09-03 11:37:51 -04:00
|
|
|
* Get created date as a relative diff.
|
2021-06-26 11:23:15 -04:00
|
|
|
*
|
2017-09-03 11:37:51 -04:00
|
|
|
* @return mixed
|
2017-01-13 11:15:48 -05:00
|
|
|
*/
|
2017-09-03 11:37:51 -04:00
|
|
|
public function getCreatedAttribute()
|
2017-01-13 11:15:48 -05:00
|
|
|
{
|
2017-09-03 11:37:51 -04:00
|
|
|
return $this->created_at->diffForHumans();
|
2017-01-13 11:15:48 -05:00
|
|
|
}
|
2017-05-15 15:10:14 -04:00
|
|
|
|
2017-09-03 11:37:51 -04:00
|
|
|
/**
|
|
|
|
* Get updated date as a relative diff.
|
2021-06-26 11:23:15 -04:00
|
|
|
*
|
2017-09-03 11:37:51 -04:00
|
|
|
* @return mixed
|
2017-06-05 16:16:59 -04:00
|
|
|
*/
|
2017-09-03 11:37:51 -04:00
|
|
|
public function getUpdatedAttribute()
|
|
|
|
{
|
|
|
|
return $this->updated_at->diffForHumans();
|
2017-05-29 23:32:47 -04:00
|
|
|
}
|
2017-01-13 11:15:48 -05:00
|
|
|
}
|