PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.01
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.01
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / app / Models / Activity.php

Activity.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.10.01, at app/Models/Activity.php

114 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Models;
4
5 use FluentCommunity\App\Models\XProfile;
6
7 /**
8 * Meta Model - DB Model for Notifications table
9 *
10 * Database Model
11 *
12 * @package FluentCommunity\App\Models
13 *
14 * @version 1.0.0
15 *
16 * @property int $id
17 * @property int|null $user_id
18 * @property int|null $feed_id
19 * @property int|null $space_id
20 * @property int|null $related_id
21 * @property string|null $message
22 * @property int|null $is_public
23 * @property string|null $action_name
24 * @property string|null $created_at
25 * @property string|null $updated_at
26 * @property-read Feed|null $feed
27 * @property-read BaseSpace|null $space
28 * @property-read User|null $user
29 * @property-read XProfile|null $xprofile
30 */
31 class Activity extends Model
32 {
33 protected $table = 'fcom_user_activities';
34
35 protected $primaryKey = 'id';
36
37 protected $guarded = [ 'id' ];
38
39 protected $fillable = [
40 'user_id',
41 'feed_id',
42 'space_id',
43 'related_id',
44 'message',
45 'is_public',
46 'action_name',
47 ];
48
49 public static function boot()
50 {
51 parent::boot();
52 }
53
54 public function scopeByActions($query, $actions = [])
55 {
56 if (!empty($actions)) {
57 $query->whereIn('action_name', $actions);
58 }
59
60 return $query;
61 }
62
63 public function scopeBySpace($query, $spaceId)
64 {
65 if ($spaceId) {
66 return $query->where('space_id', $spaceId);
67 }
68
69 return $query;
70 }
71
72 public function feed()
73 {
74 return $this->belongsTo(Feed::class, 'feed_id');
75 }
76
77 public function space()
78 {
79 return $this->belongsTo(BaseSpace::class, 'space_id');
80 }
81
82 public function user()
83 {
84 return $this->belongsTo(User::class, 'user_id');
85 }
86
87 public function xprofile()
88 {
89 return $this->belongsTo(XProfile::class, 'user_id', 'user_id');
90 }
91
92 public function getFormattedMessage()
93 {
94 if (!$this->xprofile || !$this->feed) {
95 return '';
96 }
97
98 $message = '';
99
100 switch ($this->action_name) {
101 case 'feed_published':
102 /* translators: %1$s is the person name and %2$s is the feed excerpt */
103 $message = sprintf(__('%1$s published a new status %2$s', 'fluent-community'), '<span class="fcom_user_name">' . esc_html($this->xprofile->display_name) . '</span>', '<span class="fcom_feed_excerpt">' . esc_html($this->feed->getHumanExcerpt()) . '</span>');
104 break;
105 case 'comment_added':
106 /* translators: %1$s is the person name and %2$s is the feed excerpt */
107 $message = sprintf(__('%1$s added a comment on %2$s', 'fluent-community'), '<span class="fcom_user_name">' . esc_html($this->xprofile->display_name) . '</span>', '<span class="fcom_feed_excerpt">' . esc_html($this->feed->getHumanExcerpt()) . '</span>');
108 break;
109 }
110
111 return $message;
112 }
113 }
114