diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-07-03 13:48:15 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-07-08 09:04:37 +0200 |
commit | 8363f3c6355e5bd2bb54875d11e326747df265c8 (patch) | |
tree | ae305243f92442d662744a459e26a6a30551ef82 /lib/private | |
parent | 20fc4b8b533407c7282bf1634e90f3a52e5619f0 (diff) | |
download | nextcloud-server-8363f3c6355e5bd2bb54875d11e326747df265c8.tar.gz nextcloud-server-8363f3c6355e5bd2bb54875d11e326747df265c8.zip |
Adding new interface \OCP\Activity\IExtentsion
Adding method getNotificationTypes()
Adding method filterNotificationTypes()
Adding method getDefaultTypes()
Adding method translate() and getTypeIcon()
Adding method getGroupParameter()
Adding method getNavigation()
Adding method getNavigation()
Adding method isFilterValid() and getQueryForFilter()
Adding unit tests for \OC\ActivityManager
Diffstat (limited to 'lib/private')
-rwxr-xr-x | lib/private/activitymanager.php | 194 | ||||
-rw-r--r-- | lib/private/l10n.php | 3 |
2 files changed, 196 insertions, 1 deletions
diff --git a/lib/private/activitymanager.php b/lib/private/activitymanager.php index 66aa039eb18..f31b121c8e8 100755 --- a/lib/private/activitymanager.php +++ b/lib/private/activitymanager.php @@ -10,13 +10,22 @@ namespace OC; use OCP\Activity\IConsumer; +use OCP\Activity\IExtension; use OCP\Activity\IManager; class ActivityManager implements IManager { + /** + * @var \Closure[] + */ private $consumers = array(); /** + * @var \Closure[] + */ + private $extensions = array(); + + /** * @param $app * @param $subject * @param $subjectParams @@ -65,4 +74,189 @@ class ActivityManager implements IManager { array_push($this->consumers, $callable); } + /** + * In order to improve lazy loading a closure can be registered which will be called in case + * activity consumers are actually requested + * + * $callable has to return an instance of OCA\Activity\IConsumer + * + * @param \Closure $callable + * @return void + */ + function registerExtension(\Closure $callable) { + array_push($this->extensions, $callable); + } + + /** + * Will return additional notification types as specified by other apps + * + * @param string $languageCode + * @return array + */ + function getNotificationTypes($languageCode) { + $notificationTypes = array(); + foreach($this->extensions as $extension) { + $c = $extension(); + if ($c instanceof IExtension) { + $result = $c->getNotificationTypes($languageCode); + if (is_array($result)) { + $notificationTypes = array_merge($notificationTypes, $result); + } + } + } + + return $notificationTypes; + } + + /** + * @param array $types + * @param string $filter + * @return array + */ + function filterNotificationTypes($types, $filter) { + foreach($this->extensions as $extension) { + $c = $extension(); + if ($c instanceof IExtension) { + $result = $c->filterNotificationTypes($types, $filter); + if (is_array($result)) { + $types = $result; + } + } + } + return $types; + } + + /** + * @param string $method + * @return array + */ + function getDefaultTypes($method) { + $defaultTypes = array(); + foreach($this->extensions as $extension) { + $c = $extension(); + if ($c instanceof IExtension) { + $types = $c->getDefaultTypes($method); + if (is_array($types)) { + $defaultTypes = array_merge($types, $defaultTypes); + } + } + } + return $defaultTypes; + } + + /** + * @param string $app + * @param string $text + * @param array $params + * @param boolean $stripPath + * @param boolean $highlightParams + * @param string $languageCode + * @return string|false + */ + function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { + foreach($this->extensions as $extension) { + $c = $extension(); + if ($c instanceof IExtension) { + $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); + if (is_string($translation)) { + return $translation; + } + } + } + + return false; + } + + /** + * @param string $type + * @return string + */ + function getTypeIcon($type) { + foreach($this->extensions as $extension) { + $c = $extension(); + if ($c instanceof IExtension) { + $icon = $c->getTypeIcon($type); + if (is_string($icon)) { + return $icon; + } + } + } + + return ''; + } + + /** + * @param array $activity + * @return integer|false + */ + function getGroupParameter($activity) { + foreach($this->extensions as $extension) { + $c = $extension(); + if ($c instanceof IExtension) { + $parameter = $c->getGroupParameter($activity); + if ($parameter !== false) { + return $parameter; + } + } + } + + return false; + } + + /** + * @return array + */ + function getNavigation() { + $entries = array( + 'apps' => array(), + 'top' => array(), + ); + foreach($this->extensions as $extension) { + $c = $extension(); + if ($c instanceof IExtension) { + $additionalEntries = $c->getNavigation(); + if (is_array($additionalEntries)) { + $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); + $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); + } + } + } + + return $entries; + } + + /** + * @param string $filterValue + * @return boolean + */ + function isFilterValid($filterValue) { + foreach($this->extensions as $extension) { + $c = $extension(); + if ($c instanceof IExtension) { + if ($c->isFilterValid($filterValue) === true) { + return true; + } + } + } + + return false; + } + + /** + * @param string $filter + * @return array + */ + function getQueryForFilter($filter) { + foreach($this->extensions as $extension) { + $c = $extension(); + if ($c instanceof IExtension) { + $result = $c->getQueryForFilter($filter); + if (is_array($result)) { + return $result; + } + } + } + + return array(null, null); + } } diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 3e44be88150..28b35e92a2f 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -404,14 +404,15 @@ class OC_L10N implements \OCP\IL10N { /** * find the best language + * * @param array|string $app details below - * string language * * If $app is an array, ownCloud assumes that these are the available * languages. Otherwise ownCloud tries to find the files in the l10n * folder. * * If nothing works it returns 'en' + * @return string language */ public function getLanguageCode($app=null) { return self::findLanguage($app); |