Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Modules\Forum\Entities\ReplyWithThread;
  6. use Spatie\Activitylog\Models\Activity as BaseActivity;
  7.  
  8. class Activity extends BaseActivity
  9. {
  10. private $morphRelationModels = [
  11. 'replies' => ReplyWithThread::class
  12. ];
  13.  
  14. public function getSubjectTypeAttribute($value)
  15. {
  16. if (is_null($value)) return ($value);
  17.  
  18. if (array_key_exists($value, $this->morphRelationModels)){
  19. return $this->morphRelationModels[$value];
  20. }
  21.  
  22. return $value;
  23. }
  24.  
  25. public function getSubjectDescriptionAttribute(): string
  26. {
  27. $subjectType = $this->subject_type;
  28. $relationModels = array_flip($this->morphRelationModels);
  29.  
  30. if (array_key_exists($subjectType, $relationModels)){
  31. $subjectType = $relationModels[$subjectType];
  32. }
  33.  
  34. switch ($subjectType){
  35. case 'replies':
  36. return __('Replied thread').$this->generateLink(
  37. route('forum.threads.show', ['slug' => $this->subject->thread->slug]),
  38. $this->subject->thread->title
  39. );
  40. break;
  41. case 'threads':
  42. return __('Created thread').$this->generateLink(
  43. $this->subject->slug,
  44. $this->subject->title
  45. );
  46. break;
  47. default:
  48. return '';
  49. }
  50. }
  51.  
  52. private function generateLink(string $url, string $title): string
  53. {
  54. return sprintf(
  55. ' <a href="%s">%s</a>',
  56. $url,
  57. $title
  58. );
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement