Merge pull request #12808 from owncloud/add-special-parameterlist-to-manager

Add special parameterlist to manager
This commit is contained in:
Joas Schilling 2014-12-12 13:03:26 +01:00
commit 4f92e4a233
5 changed files with 93 additions and 3 deletions

View File

@ -94,15 +94,46 @@ class Activity implements \OCP\Activity\IExtension {
case self::SUBJECT_REMOTE_SHARE_RECEIVED:
return $l->t('You received a new remote share from %s', $params)->__toString();
case self::SUBJECT_REMOTE_SHARE_ACCEPTED:
return $l->t('%1$s accepted remote share <strong>%2$s</strong>', $params)->__toString();
return $l->t('%1$s accepted remote share %2$s', $params)->__toString();
case self::SUBJECT_REMOTE_SHARE_DECLINED:
return $l->t('%1$s declined remote share <strong>%2$s</strong>', $params)->__toString();
return $l->t('%1$s declined remote share %2$s', $params)->__toString();
case self::SUBJECT_REMOTE_SHARE_UNSHARED:
return $l->t('%1$s unshared <strong>%2$s</strong>', $params)->__toString();
return $l->t('%1$s unshared %2$s', $params)->__toString();
}
}
}
/**
* The extension can define the type of parameters for translation
*
* Currently known types are:
* * file => will strip away the path of the file and add a tooltip with it
* * username => will add the avatar of the user
*
* @param string $app
* @param string $text
* @return array|false
*/
public function getSpecialParameterList($app, $text) {
if ($app === 'files_sharing') {
switch ($text) {
case self::SUBJECT_REMOTE_SHARE_RECEIVED:
return array(
0 => '',// We can not use 'username' since the user is in a different ownCloud
);
case self::SUBJECT_REMOTE_SHARE_ACCEPTED:
case self::SUBJECT_REMOTE_SHARE_DECLINED:
case self::SUBJECT_REMOTE_SHARE_UNSHARED:
return array(
0 => '',// We can not use 'username' since the user is in a different ownCloud
1 => 'file',
);
}
}
return false;
}
/**
* A string naming the css class for the icon to be used can be returned.
* If no icon is known for the given type false is to be returned.

View File

@ -167,6 +167,25 @@ class ActivityManager implements IManager {
return false;
}
/**
* @param string $app
* @param string $text
* @return array|false
*/
function getSpecialParameterList($app, $text) {
foreach($this->extensions as $extension) {
$c = $extension();
if ($c instanceof IExtension) {
$specialParameter = $c->getSpecialParameterList($app, $text);
if (is_array($specialParameter)) {
return $specialParameter;
}
}
}
return false;
}
/**
* @param string $type
* @return string

View File

@ -79,6 +79,19 @@ interface IExtension {
*/
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
/**
* The extension can define the type of parameters for translation
*
* Currently known types are:
* * file => will strip away the path of the file and add a tooltip with it
* * username => will add the avatar of the user
*
* @param string $app
* @param string $text
* @return array|false
*/
function getSpecialParameterList($app, $text);
/**
* A string naming the css class for the icon to be used can be returned.
* If no icon is known for the given type false is to be returned.

View File

@ -99,6 +99,13 @@ interface IManager {
*/
function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
/**
* @param string $app
* @param string $text
* @return array|false
*/
function getSpecialParameterList($app, $text);
/**
* @param string $type
* @return string

View File

@ -59,6 +59,14 @@ class Test_ActivityManager extends \Test\TestCase {
$this->assertFalse($result);
}
public function testGetSpecialParameterList() {
$result = $this->activityManager->getSpecialParameterList('APP0', '');
$this->assertEquals(array(0 => 'file', 1 => 'username'), $result);
$result = $this->activityManager->getSpecialParameterList('APP1', '');
$this->assertFalse($result);
}
public function testTypeIcon() {
$result = $this->activityManager->getTypeIcon('NT1');
$this->assertEquals('icon-nt-one', $result);
@ -132,6 +140,14 @@ class SimpleExtension implements \OCP\Activity\IExtension {
return false;
}
public function getSpecialParameterList($app, $text) {
if ($app === 'APP0') {
return array(0 => 'file', 1 => 'username');
}
return false;
}
public function getTypeIcon($type) {
if ($type === 'NT1') {
return 'icon-nt-one';
@ -185,6 +201,10 @@ class NoOpExtension implements \OCP\Activity\IExtension {
return false;
}
public function getSpecialParameterList($app, $text) {
return false;
}
public function getTypeIcon($type) {
return false;
}