| 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 |
class Activity extends Model |
| 17 |
{ |
| 18 |
protected $table = 'fcom_user_activities'; |
| 19 |
|
| 20 |
protected $primaryKey = 'id'; |
| 21 |
|
| 22 |
protected $guarded = ['id']; |
| 23 |
|
| 24 |
protected $fillable = [ |
| 25 |
'user_id', |
| 26 |
'feed_id', |
| 27 |
'space_id', |
| 28 |
'related_id', |
| 29 |
'message', |
| 30 |
'is_public', |
| 31 |
'action_name' |
| 32 |
]; |
| 33 |
|
| 34 |
public static function boot() |
| 35 |
{ |
| 36 |
parent::boot(); |
| 37 |
} |
| 38 |
|
| 39 |
public function scopeByActions($query, $actions = []) |
| 40 |
{ |
| 41 |
if (!empty($actions)) { |
| 42 |
$query->whereIn('action_name', $actions); |
| 43 |
} |
| 44 |
|
| 45 |
return $query; |
| 46 |
} |
| 47 |
|
| 48 |
public function scopeBySpace($query, $spaceId) |
| 49 |
{ |
| 50 |
if ($spaceId) { |
| 51 |
return $query->where('space_id', $spaceId); |
| 52 |
} |
| 53 |
|
| 54 |
return $query->where('space_id', $spaceId); |
| 55 |
} |
| 56 |
|
| 57 |
public function feed() |
| 58 |
{ |
| 59 |
return $this->belongsTo(Feed::class, 'feed_id'); |
| 60 |
} |
| 61 |
|
| 62 |
public function space() |
| 63 |
{ |
| 64 |
return $this->belongsTo(BaseSpace::class, 'space_id'); |
| 65 |
} |
| 66 |
|
| 67 |
public function user() |
| 68 |
{ |
| 69 |
return $this->belongsTo(User::class, 'user_id'); |
| 70 |
} |
| 71 |
|
| 72 |
public function xprofile() |
| 73 |
{ |
| 74 |
return $this->belongsTo(XProfile::class, 'user_id', 'user_id'); |
| 75 |
} |
| 76 |
|
| 77 |
public function getFormattedMessage() |
| 78 |
{ |
| 79 |
if (!$this->xprofile || !$this->feed) { |
| 80 |
return ''; |
| 81 |
} |
| 82 |
|
| 83 |
$message = ''; |
| 84 |
|
| 85 |
switch ($this->action_name) { |
| 86 |
case 'feed_published': |
| 87 |
/* translators: %1$s is the person name and %2$s is the feed excerpt */ |
| 88 |
$message = sprintf(__('%1$s published a new status %2$s', 'fluent-community'), '<span class="fcom_user_name">' . $this->xprofile->display_name . '</span>', '<span class="fcom_feed_excerpt">' . $this->feed->getHumanExcerpt() . '</span>'); |
| 89 |
break; |
| 90 |
case 'comment_added': |
| 91 |
/* translators: %1$s is the person name and %2$s is the feed excerpt */ |
| 92 |
$message = sprintf(__('%1$s added a comment on %2$s', 'fluent-community'), '<span class="fcom_user_name">' . $this->xprofile->display_name . '</span>', '<span class="fcom_feed_excerpt">' . $this->feed->getHumanExcerpt() . '</span>'); |
| 93 |
break; |
| 94 |
} |
| 95 |
|
| 96 |
return $message; |
| 97 |
} |
| 98 |
} |
| 99 |
|