1 | <?php |
||
32 | class DataHelper { |
||
33 | /** @var \OCP\Activity\IManager */ |
||
34 | protected $activityManager; |
||
35 | |||
36 | /** @var \OCA\Activity\Parameter\Factory */ |
||
37 | protected $parameterFactory; |
||
38 | |||
39 | /** @var IFactory */ |
||
40 | protected $l10Nfactory; |
||
41 | |||
42 | /** @var IL10N */ |
||
43 | protected $l; |
||
44 | |||
45 | /** |
||
46 | * @param IManager $activityManager |
||
47 | * @param Factory $parameterFactory |
||
48 | * @param IFactory $l10Nfactory |
||
49 | * @param IL10N $l |
||
50 | */ |
||
51 | 35 | public function __construct(IManager $activityManager, Factory $parameterFactory, IFactory $l10Nfactory, IL10N $l) { |
|
57 | |||
58 | /** |
||
59 | * @param string $user |
||
60 | */ |
||
61 | 6 | public function setUser($user) { |
|
64 | |||
65 | /** |
||
66 | * @param IL10N $l |
||
67 | */ |
||
68 | 1 | public function setL10n(IL10N $l) { |
|
72 | |||
73 | /** |
||
74 | * @brief Translate an event string with the translations from the app where it was send from |
||
75 | * @param string $app The app where this event comes from |
||
76 | * @param string $text The text including placeholders |
||
77 | * @param IParameter[] $params The parameter for the placeholder |
||
78 | * @return string translated |
||
79 | */ |
||
80 | 10 | public function translation($app, $text, array $params) { |
|
81 | 10 | if (!$text) { |
|
82 | 5 | return ''; |
|
83 | } |
||
84 | |||
85 | 9 | $preparedParams = []; |
|
86 | 9 | foreach ($params as $parameter) { |
|
87 | 6 | $preparedParams[] = $parameter->format(); |
|
88 | 9 | } |
|
89 | |||
90 | // Allow apps to correctly translate their activities |
||
91 | 9 | $translation = $this->activityManager->translate( |
|
92 | 9 | $app, $text, $preparedParams, false, false, $this->l->getLanguageCode()); |
|
93 | |||
94 | 9 | if ($translation !== false) { |
|
95 | 6 | return $translation; |
|
96 | } |
||
97 | |||
98 | 3 | $l = $this->l10Nfactory->get($app, $this->l->getLanguageCode()); |
|
99 | 3 | return $l->t($text, $preparedParams); |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * List with special parameters for the message |
||
104 | * |
||
105 | * @param string $app |
||
106 | * @param string $text |
||
107 | * @return array |
||
108 | */ |
||
109 | 7 | protected function getSpecialParameterList($app, $text) { |
|
118 | |||
119 | /** |
||
120 | * Format strings for display |
||
121 | * |
||
122 | * @param array $activity |
||
123 | * @param string $message 'subject' or 'message' |
||
124 | * @return array Modified $activity |
||
125 | */ |
||
126 | 6 | public function formatStrings($activity, $message) { |
|
133 | |||
134 | /** |
||
135 | * Get the parameter array from the parameter string of the database table |
||
136 | * |
||
137 | * @param IEvent $event |
||
138 | * @param string $parsing What are we parsing `message` or `subject` |
||
139 | * @param string $parameterString can be a JSON string, serialize() or a simple string. |
||
140 | * @return array List of Parameters |
||
141 | */ |
||
142 | 8 | public function getParameters(IEvent $event, $parsing, $parameterString) { |
|
143 | 8 | $parameters = $this->parseParameters($parameterString); |
|
144 | 8 | $parameterTypes = $this->getSpecialParameterList( |
|
145 | 8 | $event->getApp(), |
|
146 | 8 | ($parsing === 'subject') ? $event->getSubject() : $event->getMessage() |
|
147 | 8 | ); |
|
148 | |||
149 | 8 | foreach ($parameters as $i => $parameter) { |
|
150 | 7 | $parameters[$i] = $this->parameterFactory->get( |
|
151 | 7 | $parameter, |
|
152 | 7 | $event, |
|
153 | 7 | isset($parameterTypes[$i]) ? $parameterTypes[$i] : 'base' |
|
154 | 7 | ); |
|
155 | 8 | } |
|
156 | |||
157 | 8 | return $parameters; |
|
158 | } |
||
159 | |||
160 | /** |
||
161 | * @return Collection |
||
162 | */ |
||
163 | 1 | public function createCollection() { |
|
166 | |||
167 | /** |
||
168 | * Get the parameter array from the parameter string of the database table |
||
169 | * |
||
170 | * @param string $parameterString can be a JSON string, serialize() or a simple string. |
||
171 | * @return array List of Parameters |
||
172 | */ |
||
173 | 11 | public function parseParameters($parameterString) { |
|
216 | } |
||
217 |