|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Apps\Model\Front\Profile; |
|
4
|
|
|
|
|
5
|
|
|
use Apps\ActiveRecord\UserNotification; |
|
6
|
|
|
use Ffcms\Core\App; |
|
7
|
|
|
use Ffcms\Core\Arch\Model; |
|
8
|
|
|
use Ffcms\Core\Helper\Date; |
|
9
|
|
|
use Ffcms\Core\Helper\Type\Any; |
|
10
|
|
|
use Ffcms\Templex\Url\Url; |
|
11
|
|
|
use Illuminate\Support\Collection; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class EntityNotificationsList. Build notification messages from active record object |
|
15
|
|
|
* @package Apps\Model\Front\Profile |
|
16
|
|
|
*/ |
|
17
|
|
|
class EntityNotificationsList extends Model |
|
18
|
|
|
{ |
|
19
|
|
|
public $items; |
|
20
|
|
|
|
|
21
|
|
|
/** @var UserNotification[]|Collection */ |
|
22
|
|
|
private $_records; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* EntityNotificationsList constructor. Pass records object inside. |
|
26
|
|
|
* @param Collection|UserNotification[] $records |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct($records) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->_records = $records; |
|
31
|
|
|
parent::__construct(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Build notification list as array |
|
36
|
|
|
*/ |
|
37
|
|
|
public function make() |
|
38
|
|
|
{ |
|
39
|
|
|
// check if records is not empty |
|
40
|
|
|
if ($this->_records === null) { |
|
41
|
|
|
return; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// list records and build response |
|
45
|
|
|
foreach ($this->_records as $record) { |
|
46
|
|
|
/** @var UserNotification $record */ |
|
47
|
|
|
$vars = null; |
|
48
|
|
|
if (!Any::isEmpty($record->vars)) { |
|
49
|
|
|
$vars = $record->vars; |
|
50
|
|
|
} |
|
51
|
|
|
if (isset($vars['snippet'])) { |
|
52
|
|
|
$vars['snippet'] = Url::a([App::$Alias->baseUrl . $record->uri], $vars['snippet']); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$text = App::$Translate->get('Profile', $record->msg, $vars); |
|
56
|
|
|
|
|
57
|
|
|
$this->items[] = [ |
|
58
|
|
|
'text' => $text, |
|
59
|
|
|
'date' => Date::humanize($record->created_at), |
|
60
|
|
|
'new' => !(bool)$record->readed |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|