1 | <?php |
||
13 | class NotifynderCollection extends Collection |
||
14 | { |
||
15 | /** |
||
16 | * @var NotifynderTranslator |
||
17 | */ |
||
18 | protected $notifynderTranslator; |
||
19 | |||
20 | /** |
||
21 | * @param array $models |
||
22 | */ |
||
23 | public function __construct($models) |
||
24 | { |
||
25 | parent::__construct($models); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Translator instance. |
||
30 | * |
||
31 | * @return NotifynderTranslator |
||
32 | */ |
||
33 | public function translator() |
||
34 | { |
||
35 | return app('notifynder.translator'); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * This method translate the body text from |
||
40 | * another language. It used by collection. |
||
41 | * |
||
42 | * @param $language (String) |
||
43 | * @return Collection |
||
44 | */ |
||
45 | public function translate($language) |
||
46 | { |
||
47 | // Loop through the notifications |
||
48 | foreach ($this->items as $key => $item) { |
||
49 | try { |
||
50 | $translation = $this->translator() |
||
51 | ->translate($language, $this->items[$key]['body']['name']); |
||
52 | |||
53 | $this->items[$key]['body']['text'] = $translation; |
||
54 | } catch (NotificationTranslationNotFoundException $e) { |
||
55 | $this->items[$key]['body']['text']; |
||
56 | } |
||
57 | } |
||
58 | |||
59 | $this->parse(); |
||
60 | |||
61 | return $this; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Parse the body of the notification. |
||
66 | * |
||
67 | * @return $this |
||
68 | */ |
||
69 | public function parse() |
||
80 | } |
||
81 |