@@ -40,114 +40,114 @@ |
||
| 40 | 40 | |
| 41 | 41 | class SectionSearch implements IProvider { |
| 42 | 42 | |
| 43 | - /** @var IManager */ |
|
| 44 | - protected $settingsManager; |
|
| 45 | - |
|
| 46 | - /** @var IGroupManager */ |
|
| 47 | - protected $groupManager; |
|
| 48 | - |
|
| 49 | - /** @var IURLGenerator */ |
|
| 50 | - protected $urlGenerator; |
|
| 51 | - |
|
| 52 | - /** @var IL10N */ |
|
| 53 | - protected $l; |
|
| 54 | - |
|
| 55 | - public function __construct(IManager $settingsManager, |
|
| 56 | - IGroupManager $groupManager, |
|
| 57 | - IURLGenerator $urlGenerator, |
|
| 58 | - IL10N $l) { |
|
| 59 | - $this->settingsManager = $settingsManager; |
|
| 60 | - $this->groupManager = $groupManager; |
|
| 61 | - $this->urlGenerator = $urlGenerator; |
|
| 62 | - $this->l = $l; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @inheritDoc |
|
| 67 | - */ |
|
| 68 | - public function getId(): string { |
|
| 69 | - return 'settings'; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @inheritDoc |
|
| 74 | - */ |
|
| 75 | - public function getName(): string { |
|
| 76 | - return $this->l->t('Settings'); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @inheritDoc |
|
| 81 | - */ |
|
| 82 | - public function getOrder(string $route, array $routeParameters): int { |
|
| 83 | - if ($route === 'settings.PersonalSettings.index' || $route === 'settings.AdminSettings.index') { |
|
| 84 | - return -1; |
|
| 85 | - } |
|
| 86 | - // At the very bottom |
|
| 87 | - return 500; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @inheritDoc |
|
| 92 | - */ |
|
| 93 | - public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
| 94 | - $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 95 | - |
|
| 96 | - $result = $this->searchSections( |
|
| 97 | - $query, |
|
| 98 | - $this->settingsManager->getPersonalSections(), |
|
| 99 | - $isAdmin ? $this->l->t('Personal') : '', |
|
| 100 | - 'settings.PersonalSettings.index' |
|
| 101 | - ); |
|
| 102 | - |
|
| 103 | - if ($this->groupManager->isAdmin($user->getUID())) { |
|
| 104 | - $result = array_merge($result, $this->searchSections( |
|
| 105 | - $query, |
|
| 106 | - $this->settingsManager->getAdminSections(), |
|
| 107 | - $this->l->t('Administration'), |
|
| 108 | - 'settings.AdminSettings.index' |
|
| 109 | - )); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return SearchResult::complete( |
|
| 113 | - $this->l->t('Settings'), |
|
| 114 | - $result |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @param ISearchQuery $query |
|
| 120 | - * @param IIconSection[][] $sections |
|
| 121 | - * @param string $subline |
|
| 122 | - * @param string $routeName |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function searchSections(ISearchQuery $query, array $sections, string $subline, string $routeName): array { |
|
| 126 | - $result = []; |
|
| 127 | - foreach ($sections as $priority => $sectionsByPriority) { |
|
| 128 | - foreach ($sectionsByPriority as $section) { |
|
| 129 | - if ( |
|
| 130 | - stripos($section->getName(), $query->getTerm()) === false && |
|
| 131 | - stripos($section->getID(), $query->getTerm()) === false |
|
| 132 | - ) { |
|
| 133 | - continue; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * We can't use the icon URL at the moment as they don't invert correctly for dark theme |
|
| 138 | - * $iconUrl = $section->getIcon(); |
|
| 139 | - */ |
|
| 140 | - |
|
| 141 | - $result[] = new SearchResultEntry( |
|
| 142 | - '', |
|
| 143 | - $section->getName(), |
|
| 144 | - $subline, |
|
| 145 | - $this->urlGenerator->linkToRouteAbsolute($routeName, ['section' => $section->getID()]), |
|
| 146 | - 'icon-settings-dark' |
|
| 147 | - ); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $result; |
|
| 152 | - } |
|
| 43 | + /** @var IManager */ |
|
| 44 | + protected $settingsManager; |
|
| 45 | + |
|
| 46 | + /** @var IGroupManager */ |
|
| 47 | + protected $groupManager; |
|
| 48 | + |
|
| 49 | + /** @var IURLGenerator */ |
|
| 50 | + protected $urlGenerator; |
|
| 51 | + |
|
| 52 | + /** @var IL10N */ |
|
| 53 | + protected $l; |
|
| 54 | + |
|
| 55 | + public function __construct(IManager $settingsManager, |
|
| 56 | + IGroupManager $groupManager, |
|
| 57 | + IURLGenerator $urlGenerator, |
|
| 58 | + IL10N $l) { |
|
| 59 | + $this->settingsManager = $settingsManager; |
|
| 60 | + $this->groupManager = $groupManager; |
|
| 61 | + $this->urlGenerator = $urlGenerator; |
|
| 62 | + $this->l = $l; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @inheritDoc |
|
| 67 | + */ |
|
| 68 | + public function getId(): string { |
|
| 69 | + return 'settings'; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @inheritDoc |
|
| 74 | + */ |
|
| 75 | + public function getName(): string { |
|
| 76 | + return $this->l->t('Settings'); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @inheritDoc |
|
| 81 | + */ |
|
| 82 | + public function getOrder(string $route, array $routeParameters): int { |
|
| 83 | + if ($route === 'settings.PersonalSettings.index' || $route === 'settings.AdminSettings.index') { |
|
| 84 | + return -1; |
|
| 85 | + } |
|
| 86 | + // At the very bottom |
|
| 87 | + return 500; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @inheritDoc |
|
| 92 | + */ |
|
| 93 | + public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
| 94 | + $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 95 | + |
|
| 96 | + $result = $this->searchSections( |
|
| 97 | + $query, |
|
| 98 | + $this->settingsManager->getPersonalSections(), |
|
| 99 | + $isAdmin ? $this->l->t('Personal') : '', |
|
| 100 | + 'settings.PersonalSettings.index' |
|
| 101 | + ); |
|
| 102 | + |
|
| 103 | + if ($this->groupManager->isAdmin($user->getUID())) { |
|
| 104 | + $result = array_merge($result, $this->searchSections( |
|
| 105 | + $query, |
|
| 106 | + $this->settingsManager->getAdminSections(), |
|
| 107 | + $this->l->t('Administration'), |
|
| 108 | + 'settings.AdminSettings.index' |
|
| 109 | + )); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return SearchResult::complete( |
|
| 113 | + $this->l->t('Settings'), |
|
| 114 | + $result |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param ISearchQuery $query |
|
| 120 | + * @param IIconSection[][] $sections |
|
| 121 | + * @param string $subline |
|
| 122 | + * @param string $routeName |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function searchSections(ISearchQuery $query, array $sections, string $subline, string $routeName): array { |
|
| 126 | + $result = []; |
|
| 127 | + foreach ($sections as $priority => $sectionsByPriority) { |
|
| 128 | + foreach ($sectionsByPriority as $section) { |
|
| 129 | + if ( |
|
| 130 | + stripos($section->getName(), $query->getTerm()) === false && |
|
| 131 | + stripos($section->getID(), $query->getTerm()) === false |
|
| 132 | + ) { |
|
| 133 | + continue; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * We can't use the icon URL at the moment as they don't invert correctly for dark theme |
|
| 138 | + * $iconUrl = $section->getIcon(); |
|
| 139 | + */ |
|
| 140 | + |
|
| 141 | + $result[] = new SearchResultEntry( |
|
| 142 | + '', |
|
| 143 | + $section->getName(), |
|
| 144 | + $subline, |
|
| 145 | + $this->urlGenerator->linkToRouteAbsolute($routeName, ['section' => $section->getID()]), |
|
| 146 | + 'icon-settings-dark' |
|
| 147 | + ); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $result; |
|
| 152 | + } |
|
| 153 | 153 | } |