| 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 |
|