@@ -30,36 +30,36 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | interface IEntry extends JsonSerializable { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @since 12.0 |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getFullName(): string; |
|
| 33 | + /** |
|
| 34 | + * @since 12.0 |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getFullName(): string; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @since 12.0 |
|
| 41 | - * @return string[] |
|
| 42 | - */ |
|
| 43 | - public function getEMailAddresses(): array; |
|
| 39 | + /** |
|
| 40 | + * @since 12.0 |
|
| 41 | + * @return string[] |
|
| 42 | + */ |
|
| 43 | + public function getEMailAddresses(): array; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @since 12.0 |
|
| 47 | - * @return string|null image URI |
|
| 48 | - */ |
|
| 49 | - public function getAvatar(): ?string; |
|
| 45 | + /** |
|
| 46 | + * @since 12.0 |
|
| 47 | + * @return string|null image URI |
|
| 48 | + */ |
|
| 49 | + public function getAvatar(): ?string; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @since 12.0 |
|
| 53 | - * @param IAction $action an action to show in the contacts menu |
|
| 54 | - */ |
|
| 55 | - public function addAction(IAction $action): void; |
|
| 51 | + /** |
|
| 52 | + * @since 12.0 |
|
| 53 | + * @param IAction $action an action to show in the contacts menu |
|
| 54 | + */ |
|
| 55 | + public function addAction(IAction $action): void; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Get an arbitrary property from the contact |
|
| 59 | - * |
|
| 60 | - * @since 12.0 |
|
| 61 | - * @param string $key |
|
| 62 | - * @return mixed the value of the property or null |
|
| 63 | - */ |
|
| 64 | - public function getProperty(string $key); |
|
| 57 | + /** |
|
| 58 | + * Get an arbitrary property from the contact |
|
| 59 | + * |
|
| 60 | + * @since 12.0 |
|
| 61 | + * @param string $key |
|
| 62 | + * @return mixed the value of the property or null |
|
| 63 | + */ |
|
| 64 | + public function getProperty(string $key); |
|
| 65 | 65 | } |
@@ -31,140 +31,140 @@ |
||
| 31 | 31 | |
| 32 | 32 | class Entry implements IEntry { |
| 33 | 33 | |
| 34 | - /** @var string|int|null */ |
|
| 35 | - private $id = null; |
|
| 36 | - |
|
| 37 | - /** @var string */ |
|
| 38 | - private $fullName = ''; |
|
| 39 | - |
|
| 40 | - /** @var string[] */ |
|
| 41 | - private $emailAddresses = []; |
|
| 42 | - |
|
| 43 | - /** @var string|null */ |
|
| 44 | - private $avatar; |
|
| 45 | - |
|
| 46 | - /** @var IAction[] */ |
|
| 47 | - private $actions = []; |
|
| 48 | - |
|
| 49 | - /** @var array */ |
|
| 50 | - private $properties = []; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param string $id |
|
| 54 | - */ |
|
| 55 | - public function setId(string $id): void { |
|
| 56 | - $this->id = $id; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param string $displayName |
|
| 61 | - */ |
|
| 62 | - public function setFullName(string $displayName): void { |
|
| 63 | - $this->fullName = $displayName; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function getFullName(): string { |
|
| 70 | - return $this->fullName; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param string $address |
|
| 75 | - */ |
|
| 76 | - public function addEMailAddress(string $address): void { |
|
| 77 | - $this->emailAddresses[] = $address; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @return string[] |
|
| 82 | - */ |
|
| 83 | - public function getEMailAddresses(): array { |
|
| 84 | - return $this->emailAddresses; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param string $avatar |
|
| 89 | - */ |
|
| 90 | - public function setAvatar(string $avatar): void { |
|
| 91 | - $this->avatar = $avatar; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function getAvatar(): ?string { |
|
| 98 | - return $this->avatar; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param IAction $action |
|
| 103 | - */ |
|
| 104 | - public function addAction(IAction $action): void { |
|
| 105 | - $this->actions[] = $action; |
|
| 106 | - $this->sortActions(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return IAction[] |
|
| 111 | - */ |
|
| 112 | - public function getActions(): array { |
|
| 113 | - return $this->actions; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * sort the actions by priority and name |
|
| 118 | - */ |
|
| 119 | - private function sortActions(): void { |
|
| 120 | - usort($this->actions, function (IAction $action1, IAction $action2) { |
|
| 121 | - $prio1 = $action1->getPriority(); |
|
| 122 | - $prio2 = $action2->getPriority(); |
|
| 123 | - |
|
| 124 | - if ($prio1 === $prio2) { |
|
| 125 | - // Ascending order for same priority |
|
| 126 | - return strcasecmp($action1->getName(), $action2->getName()); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // Descending order when priority differs |
|
| 130 | - return $prio2 - $prio1; |
|
| 131 | - }); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param array $contact key-value array containing additional properties |
|
| 136 | - */ |
|
| 137 | - public function setProperties(array $contact): void { |
|
| 138 | - $this->properties = $contact; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param string $key |
|
| 143 | - * @return mixed |
|
| 144 | - */ |
|
| 145 | - public function getProperty(string $key) { |
|
| 146 | - if (!isset($this->properties[$key])) { |
|
| 147 | - return null; |
|
| 148 | - } |
|
| 149 | - return $this->properties[$key]; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public function jsonSerialize(): array { |
|
| 156 | - $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
| 157 | - $otherActions = array_map(function (IAction $action) { |
|
| 158 | - return $action->jsonSerialize(); |
|
| 159 | - }, array_slice($this->actions, 1)); |
|
| 160 | - |
|
| 161 | - return [ |
|
| 162 | - 'id' => $this->id, |
|
| 163 | - 'fullName' => $this->fullName, |
|
| 164 | - 'avatar' => $this->getAvatar(), |
|
| 165 | - 'topAction' => $topAction, |
|
| 166 | - 'actions' => $otherActions, |
|
| 167 | - 'lastMessage' => '', |
|
| 168 | - ]; |
|
| 169 | - } |
|
| 34 | + /** @var string|int|null */ |
|
| 35 | + private $id = null; |
|
| 36 | + |
|
| 37 | + /** @var string */ |
|
| 38 | + private $fullName = ''; |
|
| 39 | + |
|
| 40 | + /** @var string[] */ |
|
| 41 | + private $emailAddresses = []; |
|
| 42 | + |
|
| 43 | + /** @var string|null */ |
|
| 44 | + private $avatar; |
|
| 45 | + |
|
| 46 | + /** @var IAction[] */ |
|
| 47 | + private $actions = []; |
|
| 48 | + |
|
| 49 | + /** @var array */ |
|
| 50 | + private $properties = []; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param string $id |
|
| 54 | + */ |
|
| 55 | + public function setId(string $id): void { |
|
| 56 | + $this->id = $id; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param string $displayName |
|
| 61 | + */ |
|
| 62 | + public function setFullName(string $displayName): void { |
|
| 63 | + $this->fullName = $displayName; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function getFullName(): string { |
|
| 70 | + return $this->fullName; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param string $address |
|
| 75 | + */ |
|
| 76 | + public function addEMailAddress(string $address): void { |
|
| 77 | + $this->emailAddresses[] = $address; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @return string[] |
|
| 82 | + */ |
|
| 83 | + public function getEMailAddresses(): array { |
|
| 84 | + return $this->emailAddresses; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param string $avatar |
|
| 89 | + */ |
|
| 90 | + public function setAvatar(string $avatar): void { |
|
| 91 | + $this->avatar = $avatar; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function getAvatar(): ?string { |
|
| 98 | + return $this->avatar; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param IAction $action |
|
| 103 | + */ |
|
| 104 | + public function addAction(IAction $action): void { |
|
| 105 | + $this->actions[] = $action; |
|
| 106 | + $this->sortActions(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return IAction[] |
|
| 111 | + */ |
|
| 112 | + public function getActions(): array { |
|
| 113 | + return $this->actions; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * sort the actions by priority and name |
|
| 118 | + */ |
|
| 119 | + private function sortActions(): void { |
|
| 120 | + usort($this->actions, function (IAction $action1, IAction $action2) { |
|
| 121 | + $prio1 = $action1->getPriority(); |
|
| 122 | + $prio2 = $action2->getPriority(); |
|
| 123 | + |
|
| 124 | + if ($prio1 === $prio2) { |
|
| 125 | + // Ascending order for same priority |
|
| 126 | + return strcasecmp($action1->getName(), $action2->getName()); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // Descending order when priority differs |
|
| 130 | + return $prio2 - $prio1; |
|
| 131 | + }); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param array $contact key-value array containing additional properties |
|
| 136 | + */ |
|
| 137 | + public function setProperties(array $contact): void { |
|
| 138 | + $this->properties = $contact; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param string $key |
|
| 143 | + * @return mixed |
|
| 144 | + */ |
|
| 145 | + public function getProperty(string $key) { |
|
| 146 | + if (!isset($this->properties[$key])) { |
|
| 147 | + return null; |
|
| 148 | + } |
|
| 149 | + return $this->properties[$key]; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public function jsonSerialize(): array { |
|
| 156 | + $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
| 157 | + $otherActions = array_map(function (IAction $action) { |
|
| 158 | + return $action->jsonSerialize(); |
|
| 159 | + }, array_slice($this->actions, 1)); |
|
| 160 | + |
|
| 161 | + return [ |
|
| 162 | + 'id' => $this->id, |
|
| 163 | + 'fullName' => $this->fullName, |
|
| 164 | + 'avatar' => $this->getAvatar(), |
|
| 165 | + 'topAction' => $topAction, |
|
| 166 | + 'actions' => $otherActions, |
|
| 167 | + 'lastMessage' => '', |
|
| 168 | + ]; |
|
| 169 | + } |
|
| 170 | 170 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * sort the actions by priority and name |
| 118 | 118 | */ |
| 119 | 119 | private function sortActions(): void { |
| 120 | - usort($this->actions, function (IAction $action1, IAction $action2) { |
|
| 120 | + usort($this->actions, function(IAction $action1, IAction $action2) { |
|
| 121 | 121 | $prio1 = $action1->getPriority(); |
| 122 | 122 | $prio2 = $action2->getPriority(); |
| 123 | 123 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public function jsonSerialize(): array { |
| 156 | 156 | $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
| 157 | - $otherActions = array_map(function (IAction $action) { |
|
| 157 | + $otherActions = array_map(function(IAction $action) { |
|
| 158 | 158 | return $action->jsonSerialize(); |
| 159 | 159 | }, array_slice($this->actions, 1)); |
| 160 | 160 | |