+ /**
+ * Returns the liker phrase based on a list of likers
+ *
+ * @param string $verb the activity verb
+ * @param array $likers a list of likers
+ *
+ * @return string the liker phrase
+ *
+ * @throws InternalServerErrorException in case either the verb is invalid or the list of likers is empty
+ */
+ private function getLikerPhrase(string $verb, array $likers): string
+ {
+ $total = count($likers);
+
+ if ($total === 0) {
+ throw new InternalServerErrorException(sprintf('There has to be at least one Liker for verb "%s"', $verb));
+ } else if ($total === 1) {
+ $likerString = $likers[0];
+ } else {
+ if ($total < $this->config->get('system', 'max_likers')) {
+ $likerString = implode(', ', array_slice($likers, 0, -1));
+ $likerString .= ' ' . $this->l10n->t('and') . ' ' . $likers[count($likers) - 1];
+ } else {
+ $likerString = implode(', ', array_slice($likers, 0, $this->config->get('system', 'max_likers') - 1));
+ $likerString .= ' ' . $this->l10n->t('and %d other people', $total - $this->config->get('system', 'max_likers'));
+ }
+ }
+
+ switch ($verb) {
+ case 'like':
+ return $this->l10n->tt('%2$s likes this.', '%2$s like this.', $total, $likerString);
+ case 'dislike':
+ return $this->l10n->tt('%2$s doesn\'t like this.', '%2$s don\'t like this.', $total, $likerString);
+ case 'attendyes':
+ return $this->l10n->tt('%2$s attends.', '%2$s attend.', $total, $likerString);
+ case 'attendno':
+ return $this->l10n->tt('%2$s doesn\'t attend.', '%2$s don\'t attend.', $total, $likerString);
+ case 'attendmaybe':
+ return $this->l10n->tt('%2$s attends maybe.', '%2$s attend maybe.', $total, $likerString);
+ case 'announce':
+ return $this->l10n->tt('%2$s reshared this.', '%2$s reshared this.', $total, $likerString);
+ default:
+ throw new InternalServerErrorException(sprintf('Unknown verb "%s"', $verb));
+ }
+ }
+