Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- use Modules\Forum\Entities\ReplyWithThread;
- use Spatie\Activitylog\Models\Activity as BaseActivity;
- class Activity extends BaseActivity
- {
- private $morphRelationModels = [
- 'replies' => ReplyWithThread::class
- ];
- public function getSubjectTypeAttribute($value)
- {
- if (is_null($value)) return ($value);
- if (array_key_exists($value, $this->morphRelationModels)){
- return $this->morphRelationModels[$value];
- }
- return $value;
- }
- public function getSubjectDescriptionAttribute(): string
- {
- $subjectType = $this->subject_type;
- $relationModels = array_flip($this->morphRelationModels);
- if (array_key_exists($subjectType, $relationModels)){
- $subjectType = $relationModels[$subjectType];
- }
- switch ($subjectType){
- case 'replies':
- return __('Replied thread').$this->generateLink(
- route('forum.threads.show', ['slug' => $this->subject->thread->slug]),
- $this->subject->thread->title
- );
- break;
- case 'threads':
- return __('Created thread').$this->generateLink(
- $this->subject->slug,
- $this->subject->title
- );
- break;
- default:
- return '';
- }
- }
- private function generateLink(string $url, string $title): string
- {
- return sprintf(
- ' <a href="%s">%s</a>',
- $url,
- $title
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement