@@ -31,30 +31,30 @@ |
||
31 | 31 | */ |
32 | 32 | interface IEntry extends JsonSerializable { |
33 | 33 | |
34 | - /** |
|
35 | - * @since 12.0 |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getFullName(); |
|
39 | - |
|
40 | - /** |
|
41 | - * @since 12.0 |
|
42 | - * @return string[] |
|
43 | - */ |
|
44 | - public function getEMailAddresses(); |
|
45 | - |
|
46 | - /** |
|
47 | - * @since 12.0 |
|
48 | - * @param IAction $action an action to show in the contacts menu |
|
49 | - */ |
|
50 | - public function addAction(IAction $action); |
|
51 | - |
|
52 | - /** |
|
53 | - * Get an arbitrary property from the contact |
|
54 | - * |
|
55 | - * @since 12.0 |
|
56 | - * @param string $key |
|
57 | - * @return mixed the value of the property or null |
|
58 | - */ |
|
59 | - public function getProperty($key); |
|
34 | + /** |
|
35 | + * @since 12.0 |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getFullName(); |
|
39 | + |
|
40 | + /** |
|
41 | + * @since 12.0 |
|
42 | + * @return string[] |
|
43 | + */ |
|
44 | + public function getEMailAddresses(); |
|
45 | + |
|
46 | + /** |
|
47 | + * @since 12.0 |
|
48 | + * @param IAction $action an action to show in the contacts menu |
|
49 | + */ |
|
50 | + public function addAction(IAction $action); |
|
51 | + |
|
52 | + /** |
|
53 | + * Get an arbitrary property from the contact |
|
54 | + * |
|
55 | + * @since 12.0 |
|
56 | + * @param string $key |
|
57 | + * @return mixed the value of the property or null |
|
58 | + */ |
|
59 | + public function getProperty($key); |
|
60 | 60 | } |
@@ -33,33 +33,33 @@ |
||
33 | 33 | */ |
34 | 34 | interface IAction extends JsonSerializable { |
35 | 35 | |
36 | - /** |
|
37 | - * @param string $icon absolute URI to an icon |
|
38 | - * @since 12.0 |
|
39 | - */ |
|
40 | - public function setIcon($icon); |
|
36 | + /** |
|
37 | + * @param string $icon absolute URI to an icon |
|
38 | + * @since 12.0 |
|
39 | + */ |
|
40 | + public function setIcon($icon); |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return string localized action name, e.g. 'Call' |
|
44 | - * @since 12.0 |
|
45 | - */ |
|
46 | - public function getName(); |
|
42 | + /** |
|
43 | + * @return string localized action name, e.g. 'Call' |
|
44 | + * @since 12.0 |
|
45 | + */ |
|
46 | + public function getName(); |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $name localized action name, e.g. 'Call' |
|
50 | - * @since 12.0 |
|
51 | - */ |
|
52 | - public function setName($name); |
|
48 | + /** |
|
49 | + * @param string $name localized action name, e.g. 'Call' |
|
50 | + * @since 12.0 |
|
51 | + */ |
|
52 | + public function setName($name); |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param int $priority priorize actions, high order ones are shown on top |
|
56 | - * @since 12.0 |
|
57 | - */ |
|
58 | - public function setPriority($priority); |
|
54 | + /** |
|
55 | + * @param int $priority priorize actions, high order ones are shown on top |
|
56 | + * @since 12.0 |
|
57 | + */ |
|
58 | + public function setPriority($priority); |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return int priority to priorize actions, high order ones are shown on top |
|
62 | - * @since 12.0 |
|
63 | - */ |
|
64 | - public function getPriority(); |
|
60 | + /** |
|
61 | + * @return int priority to priorize actions, high order ones are shown on top |
|
62 | + * @since 12.0 |
|
63 | + */ |
|
64 | + public function getPriority(); |
|
65 | 65 | } |
@@ -28,27 +28,27 @@ |
||
28 | 28 | */ |
29 | 29 | interface IActionFactory { |
30 | 30 | |
31 | - /** |
|
32 | - * Construct and return a new link action for the contacts menu |
|
33 | - * |
|
34 | - * @since 12.0 |
|
35 | - * |
|
36 | - * @param string $icon full path to the action's icon |
|
37 | - * @param string $name localized name of the action |
|
38 | - * @param string $href target URL |
|
39 | - * @return ILinkAction |
|
40 | - */ |
|
41 | - public function newLinkAction($icon, $name, $href); |
|
31 | + /** |
|
32 | + * Construct and return a new link action for the contacts menu |
|
33 | + * |
|
34 | + * @since 12.0 |
|
35 | + * |
|
36 | + * @param string $icon full path to the action's icon |
|
37 | + * @param string $name localized name of the action |
|
38 | + * @param string $href target URL |
|
39 | + * @return ILinkAction |
|
40 | + */ |
|
41 | + public function newLinkAction($icon, $name, $href); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Construct and return a new email action for the contacts menu |
|
45 | - * |
|
46 | - * @since 12.0 |
|
47 | - * |
|
48 | - * @param string $icon full path to the action's icon |
|
49 | - * @param string $name localized name of the action |
|
50 | - * @param string $email target e-mail address |
|
51 | - * @return ILinkAction |
|
52 | - */ |
|
53 | - public function newEMailAction($icon, $name, $email); |
|
43 | + /** |
|
44 | + * Construct and return a new email action for the contacts menu |
|
45 | + * |
|
46 | + * @since 12.0 |
|
47 | + * |
|
48 | + * @param string $icon full path to the action's icon |
|
49 | + * @param string $name localized name of the action |
|
50 | + * @param string $email target e-mail address |
|
51 | + * @return ILinkAction |
|
52 | + */ |
|
53 | + public function newEMailAction($icon, $name, $email); |
|
54 | 54 | } |
@@ -29,15 +29,15 @@ |
||
29 | 29 | */ |
30 | 30 | interface ILinkAction extends IAction { |
31 | 31 | |
32 | - /** |
|
33 | - * @since 12.0 |
|
34 | - * @param string $href the target URL of the action |
|
35 | - */ |
|
36 | - public function setHref($href); |
|
32 | + /** |
|
33 | + * @since 12.0 |
|
34 | + * @param string $href the target URL of the action |
|
35 | + */ |
|
36 | + public function setHref($href); |
|
37 | 37 | |
38 | - /** |
|
39 | - * @since 12.0 |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function getHref(); |
|
38 | + /** |
|
39 | + * @since 12.0 |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function getHref(); |
|
43 | 43 | } |
@@ -29,9 +29,9 @@ |
||
29 | 29 | */ |
30 | 30 | interface IProvider { |
31 | 31 | |
32 | - /** |
|
33 | - * @since 12.0 |
|
34 | - * @param IEntry $entry |
|
35 | - */ |
|
36 | - public function process(IEntry $entry); |
|
32 | + /** |
|
33 | + * @since 12.0 |
|
34 | + * @param IEntry $entry |
|
35 | + */ |
|
36 | + public function process(IEntry $entry); |
|
37 | 37 | } |
@@ -30,69 +30,69 @@ |
||
30 | 30 | |
31 | 31 | class Manager { |
32 | 32 | |
33 | - /** @var ContactsStore */ |
|
34 | - private $store; |
|
33 | + /** @var ContactsStore */ |
|
34 | + private $store; |
|
35 | 35 | |
36 | - /** @var ActionProviderStore */ |
|
37 | - private $actionProviderStore; |
|
36 | + /** @var ActionProviderStore */ |
|
37 | + private $actionProviderStore; |
|
38 | 38 | |
39 | - /** @var IAppManager */ |
|
40 | - private $appManager; |
|
39 | + /** @var IAppManager */ |
|
40 | + private $appManager; |
|
41 | 41 | |
42 | - /** @var IURLGenerator */ |
|
43 | - private $urlGenerator; |
|
42 | + /** @var IURLGenerator */ |
|
43 | + private $urlGenerator; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param ContactsStore $store |
|
47 | - * @param ActionProviderStore $actionProviderStore |
|
48 | - * @param IAppManager $appManager |
|
49 | - */ |
|
50 | - public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager) { |
|
51 | - $this->store = $store; |
|
52 | - $this->actionProviderStore = $actionProviderStore; |
|
53 | - $this->appManager = $appManager; |
|
54 | - } |
|
45 | + /** |
|
46 | + * @param ContactsStore $store |
|
47 | + * @param ActionProviderStore $actionProviderStore |
|
48 | + * @param IAppManager $appManager |
|
49 | + */ |
|
50 | + public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager) { |
|
51 | + $this->store = $store; |
|
52 | + $this->actionProviderStore = $actionProviderStore; |
|
53 | + $this->appManager = $appManager; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param string $userId |
|
58 | - * @param string $filter |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - public function getEntries($userId, $filter) { |
|
62 | - $entries = $this->store->getContacts($filter); |
|
56 | + /** |
|
57 | + * @param string $userId |
|
58 | + * @param string $filter |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + public function getEntries($userId, $filter) { |
|
62 | + $entries = $this->store->getContacts($filter); |
|
63 | 63 | |
64 | - $sortedEntries = $this->sortEntries($entries); |
|
65 | - $topEntries = array_slice($sortedEntries, 0, 25); |
|
66 | - $this->processEntries($topEntries); |
|
64 | + $sortedEntries = $this->sortEntries($entries); |
|
65 | + $topEntries = array_slice($sortedEntries, 0, 25); |
|
66 | + $this->processEntries($topEntries); |
|
67 | 67 | |
68 | - $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $userId); |
|
69 | - return [ |
|
70 | - 'contacts' => $topEntries, |
|
71 | - 'contactsAppEnabled' => $contactsEnabled, |
|
72 | - ]; |
|
73 | - } |
|
68 | + $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $userId); |
|
69 | + return [ |
|
70 | + 'contacts' => $topEntries, |
|
71 | + 'contactsAppEnabled' => $contactsEnabled, |
|
72 | + ]; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param IEntry[] $entries |
|
77 | - * @return IEntry[] |
|
78 | - */ |
|
79 | - private function sortEntries(array $entries) { |
|
80 | - usort($entries, function(IEntry $entryA, IEntry $entryB) { |
|
81 | - return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
82 | - }); |
|
83 | - return $entries; |
|
84 | - } |
|
75 | + /** |
|
76 | + * @param IEntry[] $entries |
|
77 | + * @return IEntry[] |
|
78 | + */ |
|
79 | + private function sortEntries(array $entries) { |
|
80 | + usort($entries, function(IEntry $entryA, IEntry $entryB) { |
|
81 | + return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
82 | + }); |
|
83 | + return $entries; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @param IEntry[] $entries |
|
88 | - */ |
|
89 | - private function processEntries(array $entries) { |
|
90 | - $providers = $this->actionProviderStore->getProviders(); |
|
91 | - foreach ($entries as $entry) { |
|
92 | - foreach ($providers as $provider) { |
|
93 | - $provider->process($entry); |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
86 | + /** |
|
87 | + * @param IEntry[] $entries |
|
88 | + */ |
|
89 | + private function processEntries(array $entries) { |
|
90 | + $providers = $this->actionProviderStore->getProviders(); |
|
91 | + foreach ($entries as $entry) { |
|
92 | + foreach ($providers as $provider) { |
|
93 | + $provider->process($entry); |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | } |
@@ -34,38 +34,38 @@ |
||
34 | 34 | */ |
35 | 35 | class DetailsProvider implements IProvider { |
36 | 36 | |
37 | - /** @var IURLGenerator */ |
|
38 | - private $urlGenerator; |
|
37 | + /** @var IURLGenerator */ |
|
38 | + private $urlGenerator; |
|
39 | 39 | |
40 | - /** @var IActionFactory */ |
|
41 | - private $actionFactory; |
|
40 | + /** @var IActionFactory */ |
|
41 | + private $actionFactory; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param IURLGenerator $urlGenerator |
|
45 | - * @param IActionFactory $actionFactory |
|
46 | - */ |
|
47 | - public function __construct(IURLGenerator $urlGenerator, IActionFactory $actionFactory) { |
|
48 | - $this->actionFactory = $actionFactory; |
|
49 | - $this->urlGenerator = $urlGenerator; |
|
50 | - } |
|
43 | + /** |
|
44 | + * @param IURLGenerator $urlGenerator |
|
45 | + * @param IActionFactory $actionFactory |
|
46 | + */ |
|
47 | + public function __construct(IURLGenerator $urlGenerator, IActionFactory $actionFactory) { |
|
48 | + $this->actionFactory = $actionFactory; |
|
49 | + $this->urlGenerator = $urlGenerator; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param IEntry $entry |
|
54 | - */ |
|
55 | - public function process(IEntry $entry) { |
|
56 | - $uid = $entry->getProperty('UID'); |
|
52 | + /** |
|
53 | + * @param IEntry $entry |
|
54 | + */ |
|
55 | + public function process(IEntry $entry) { |
|
56 | + $uid = $entry->getProperty('UID'); |
|
57 | 57 | |
58 | - if (is_null($uid)) { |
|
59 | - // Nothing to do |
|
60 | - return; |
|
61 | - } |
|
58 | + if (is_null($uid)) { |
|
59 | + // Nothing to do |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - // TODO: unique contact URL to the contacts app |
|
64 | - // TODO: l10n |
|
65 | - $contactsUrl = $this->urlGenerator->getAbsoluteURL('/index.php/apps/contacts'); |
|
66 | - $action = $this->actionFactory->newLinkAction('icon-info', 'Details', $contactsUrl); |
|
67 | - $action->setPriority(0); |
|
68 | - $entry->addAction($action); |
|
69 | - } |
|
63 | + // TODO: unique contact URL to the contacts app |
|
64 | + // TODO: l10n |
|
65 | + $contactsUrl = $this->urlGenerator->getAbsoluteURL('/index.php/apps/contacts'); |
|
66 | + $action = $this->actionFactory->newLinkAction('icon-info', 'Details', $contactsUrl); |
|
67 | + $action->setPriority(0); |
|
68 | + $entry->addAction($action); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | } |