@@ -51,6 +51,9 @@ discard block |
||
| 51 | 51 | ]; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | + /** |
|
| 55 | + * @param string $type |
|
| 56 | + */ |
|
| 54 | 57 | protected function formatSections($sections, $currentSection, $type) { |
| 55 | 58 | $templateParameters = []; |
| 56 | 59 | /** @var \OCP\Settings\ISection[] $prioritizedSections */ |
@@ -81,6 +84,9 @@ discard block |
||
| 81 | 84 | return $templateParameters; |
| 82 | 85 | } |
| 83 | 86 | |
| 87 | + /** |
|
| 88 | + * @param string $currentSections |
|
| 89 | + */ |
|
| 84 | 90 | protected function formatPersonalSections($currentSections) { |
| 85 | 91 | $sections = $this->settingsManager->getPersonalSections(); |
| 86 | 92 | $templateParameters = $this->formatSections($sections, $currentSections, 'personal'); |
@@ -88,6 +94,9 @@ discard block |
||
| 88 | 94 | return $templateParameters; |
| 89 | 95 | } |
| 90 | 96 | |
| 97 | + /** |
|
| 98 | + * @param string $currentSections |
|
| 99 | + */ |
|
| 91 | 100 | protected function formatAdminSections($currentSections) { |
| 92 | 101 | $sections = $this->settingsManager->getAdminSections(); |
| 93 | 102 | $templateParameters = $this->formatSections($sections, $currentSections, 'admin'); |
@@ -111,6 +120,9 @@ discard block |
||
| 111 | 120 | return ['content' => $html]; |
| 112 | 121 | } |
| 113 | 122 | |
| 123 | + /** |
|
| 124 | + * @param string $section |
|
| 125 | + */ |
|
| 114 | 126 | private function getIndexResponse($section) { |
| 115 | 127 | $templateParams = []; |
| 116 | 128 | $templateParams = array_merge($templateParams, $this->getNavigationParameters($section)); |
@@ -29,95 +29,95 @@ |
||
| 29 | 29 | use OCP\Settings\ISettings; |
| 30 | 30 | |
| 31 | 31 | trait CommonSettingsTrait { |
| 32 | - /** @var ISettingsManager */ |
|
| 33 | - private $settingsManager; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @param string $currentSection |
|
| 37 | - * @return array |
|
| 38 | - */ |
|
| 39 | - private function getNavigationParameters($currentSection) { |
|
| 40 | - $templateParameters = [ |
|
| 41 | - 'personal' => $this->formatPersonalSections($currentSection), |
|
| 42 | - 'admin' => [] |
|
| 43 | - ]; |
|
| 44 | - |
|
| 45 | - if(\OC_User::isAdminUser(\OC_User::getUser())) { |
|
| 46 | - $templateParameters['admin'] = $this->formatAdminSections($currentSection); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - return [ |
|
| 50 | - 'forms' => $templateParameters |
|
| 51 | - ]; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - protected function formatSections($sections, $currentSection, $type) { |
|
| 55 | - $templateParameters = []; |
|
| 56 | - /** @var \OCP\Settings\ISection[] $prioritizedSections */ |
|
| 57 | - foreach($sections as $prioritizedSections) { |
|
| 58 | - foreach ($prioritizedSections as $section) { |
|
| 59 | - if($type === 'admin') { |
|
| 60 | - $settings = $this->settingsManager->getAdminSettings($section->getID()); |
|
| 61 | - } else if($type === 'personal') { |
|
| 62 | - $settings = $this->settingsManager->getPersonalSettings($section->getID()); |
|
| 63 | - } |
|
| 64 | - if (empty($settings)) { |
|
| 65 | - continue; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $icon = ''; |
|
| 69 | - if ($section instanceof IIconSection) { |
|
| 70 | - $icon = $section->getIcon(); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $templateParameters[] = [ |
|
| 74 | - 'anchor' => $section->getID(), |
|
| 75 | - 'section-name' => $section->getName(), |
|
| 76 | - 'active' => $section->getID() === $currentSection, |
|
| 77 | - 'icon' => $icon, |
|
| 78 | - ]; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - return $templateParameters; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - protected function formatPersonalSections($currentSections) { |
|
| 85 | - $sections = $this->settingsManager->getPersonalSections(); |
|
| 86 | - $templateParameters = $this->formatSections($sections, $currentSections, 'personal'); |
|
| 87 | - |
|
| 88 | - return $templateParameters; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - protected function formatAdminSections($currentSections) { |
|
| 92 | - $sections = $this->settingsManager->getAdminSections(); |
|
| 93 | - $templateParameters = $this->formatSections($sections, $currentSections, 'admin'); |
|
| 94 | - |
|
| 95 | - return $templateParameters; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @param ISettings[] $settings |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - private function formatSettings($settings) { |
|
| 103 | - $html = ''; |
|
| 104 | - foreach ($settings as $prioritizedSettings) { |
|
| 105 | - foreach ($prioritizedSettings as $setting) { |
|
| 106 | - /** @var \OCP\Settings\ISettings $setting */ |
|
| 107 | - $form = $setting->getForm(); |
|
| 108 | - $html .= $form->renderAs('')->render(); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - return ['content' => $html]; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - private function getIndexResponse($section) { |
|
| 115 | - $templateParams = []; |
|
| 116 | - $templateParams = array_merge($templateParams, $this->getNavigationParameters($section)); |
|
| 117 | - $templateParams = array_merge($templateParams, $this->getSettings($section)); |
|
| 118 | - |
|
| 119 | - return new TemplateResponse('settings', 'settings/frame', $templateParams); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - abstract public function getSettings($section); |
|
| 32 | + /** @var ISettingsManager */ |
|
| 33 | + private $settingsManager; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param string $currentSection |
|
| 37 | + * @return array |
|
| 38 | + */ |
|
| 39 | + private function getNavigationParameters($currentSection) { |
|
| 40 | + $templateParameters = [ |
|
| 41 | + 'personal' => $this->formatPersonalSections($currentSection), |
|
| 42 | + 'admin' => [] |
|
| 43 | + ]; |
|
| 44 | + |
|
| 45 | + if(\OC_User::isAdminUser(\OC_User::getUser())) { |
|
| 46 | + $templateParameters['admin'] = $this->formatAdminSections($currentSection); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + return [ |
|
| 50 | + 'forms' => $templateParameters |
|
| 51 | + ]; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + protected function formatSections($sections, $currentSection, $type) { |
|
| 55 | + $templateParameters = []; |
|
| 56 | + /** @var \OCP\Settings\ISection[] $prioritizedSections */ |
|
| 57 | + foreach($sections as $prioritizedSections) { |
|
| 58 | + foreach ($prioritizedSections as $section) { |
|
| 59 | + if($type === 'admin') { |
|
| 60 | + $settings = $this->settingsManager->getAdminSettings($section->getID()); |
|
| 61 | + } else if($type === 'personal') { |
|
| 62 | + $settings = $this->settingsManager->getPersonalSettings($section->getID()); |
|
| 63 | + } |
|
| 64 | + if (empty($settings)) { |
|
| 65 | + continue; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $icon = ''; |
|
| 69 | + if ($section instanceof IIconSection) { |
|
| 70 | + $icon = $section->getIcon(); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $templateParameters[] = [ |
|
| 74 | + 'anchor' => $section->getID(), |
|
| 75 | + 'section-name' => $section->getName(), |
|
| 76 | + 'active' => $section->getID() === $currentSection, |
|
| 77 | + 'icon' => $icon, |
|
| 78 | + ]; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + return $templateParameters; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + protected function formatPersonalSections($currentSections) { |
|
| 85 | + $sections = $this->settingsManager->getPersonalSections(); |
|
| 86 | + $templateParameters = $this->formatSections($sections, $currentSections, 'personal'); |
|
| 87 | + |
|
| 88 | + return $templateParameters; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + protected function formatAdminSections($currentSections) { |
|
| 92 | + $sections = $this->settingsManager->getAdminSections(); |
|
| 93 | + $templateParameters = $this->formatSections($sections, $currentSections, 'admin'); |
|
| 94 | + |
|
| 95 | + return $templateParameters; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @param ISettings[] $settings |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + private function formatSettings($settings) { |
|
| 103 | + $html = ''; |
|
| 104 | + foreach ($settings as $prioritizedSettings) { |
|
| 105 | + foreach ($prioritizedSettings as $setting) { |
|
| 106 | + /** @var \OCP\Settings\ISettings $setting */ |
|
| 107 | + $form = $setting->getForm(); |
|
| 108 | + $html .= $form->renderAs('')->render(); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + return ['content' => $html]; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + private function getIndexResponse($section) { |
|
| 115 | + $templateParams = []; |
|
| 116 | + $templateParams = array_merge($templateParams, $this->getNavigationParameters($section)); |
|
| 117 | + $templateParams = array_merge($templateParams, $this->getSettings($section)); |
|
| 118 | + |
|
| 119 | + return new TemplateResponse('settings', 'settings/frame', $templateParams); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + abstract public function getSettings($section); |
|
| 123 | 123 | } |
@@ -41,241 +41,241 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | 43 | class NavigationManager implements INavigationManager { |
| 44 | - protected $entries = []; |
|
| 45 | - protected $closureEntries = []; |
|
| 46 | - protected $activeEntry; |
|
| 47 | - /** @var bool */ |
|
| 48 | - protected $init = false; |
|
| 49 | - /** @var IAppManager|AppManager */ |
|
| 50 | - protected $appManager; |
|
| 51 | - /** @var IURLGenerator */ |
|
| 52 | - private $urlGenerator; |
|
| 53 | - /** @var IFactory */ |
|
| 54 | - private $l10nFac; |
|
| 55 | - /** @var IUserSession */ |
|
| 56 | - private $userSession; |
|
| 57 | - /** @var IGroupManager|Manager */ |
|
| 58 | - private $groupManager; |
|
| 59 | - /** @var IConfig */ |
|
| 60 | - private $config; |
|
| 44 | + protected $entries = []; |
|
| 45 | + protected $closureEntries = []; |
|
| 46 | + protected $activeEntry; |
|
| 47 | + /** @var bool */ |
|
| 48 | + protected $init = false; |
|
| 49 | + /** @var IAppManager|AppManager */ |
|
| 50 | + protected $appManager; |
|
| 51 | + /** @var IURLGenerator */ |
|
| 52 | + private $urlGenerator; |
|
| 53 | + /** @var IFactory */ |
|
| 54 | + private $l10nFac; |
|
| 55 | + /** @var IUserSession */ |
|
| 56 | + private $userSession; |
|
| 57 | + /** @var IGroupManager|Manager */ |
|
| 58 | + private $groupManager; |
|
| 59 | + /** @var IConfig */ |
|
| 60 | + private $config; |
|
| 61 | 61 | |
| 62 | - public function __construct(IAppManager $appManager, |
|
| 63 | - IURLGenerator $urlGenerator, |
|
| 64 | - IFactory $l10nFac, |
|
| 65 | - IUserSession $userSession, |
|
| 66 | - IGroupManager $groupManager, |
|
| 67 | - IConfig $config) { |
|
| 68 | - $this->appManager = $appManager; |
|
| 69 | - $this->urlGenerator = $urlGenerator; |
|
| 70 | - $this->l10nFac = $l10nFac; |
|
| 71 | - $this->userSession = $userSession; |
|
| 72 | - $this->groupManager = $groupManager; |
|
| 73 | - $this->config = $config; |
|
| 74 | - } |
|
| 62 | + public function __construct(IAppManager $appManager, |
|
| 63 | + IURLGenerator $urlGenerator, |
|
| 64 | + IFactory $l10nFac, |
|
| 65 | + IUserSession $userSession, |
|
| 66 | + IGroupManager $groupManager, |
|
| 67 | + IConfig $config) { |
|
| 68 | + $this->appManager = $appManager; |
|
| 69 | + $this->urlGenerator = $urlGenerator; |
|
| 70 | + $this->l10nFac = $l10nFac; |
|
| 71 | + $this->userSession = $userSession; |
|
| 72 | + $this->groupManager = $groupManager; |
|
| 73 | + $this->config = $config; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Creates a new navigation entry |
|
| 78 | - * |
|
| 79 | - * @param array|\Closure $entry Array containing: id, name, order, icon and href key |
|
| 80 | - * The use of a closure is preferred, because it will avoid |
|
| 81 | - * loading the routing of your app, unless required. |
|
| 82 | - * @return void |
|
| 83 | - */ |
|
| 84 | - public function add($entry) { |
|
| 85 | - if ($entry instanceof \Closure) { |
|
| 86 | - $this->closureEntries[] = $entry; |
|
| 87 | - return; |
|
| 88 | - } |
|
| 76 | + /** |
|
| 77 | + * Creates a new navigation entry |
|
| 78 | + * |
|
| 79 | + * @param array|\Closure $entry Array containing: id, name, order, icon and href key |
|
| 80 | + * The use of a closure is preferred, because it will avoid |
|
| 81 | + * loading the routing of your app, unless required. |
|
| 82 | + * @return void |
|
| 83 | + */ |
|
| 84 | + public function add($entry) { |
|
| 85 | + if ($entry instanceof \Closure) { |
|
| 86 | + $this->closureEntries[] = $entry; |
|
| 87 | + return; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $entry['active'] = false; |
|
| 91 | - if(!isset($entry['icon'])) { |
|
| 92 | - $entry['icon'] = ''; |
|
| 93 | - } |
|
| 94 | - if(!isset($entry['type'])) { |
|
| 95 | - $entry['type'] = 'link'; |
|
| 96 | - } |
|
| 97 | - $this->entries[] = $entry; |
|
| 98 | - } |
|
| 90 | + $entry['active'] = false; |
|
| 91 | + if(!isset($entry['icon'])) { |
|
| 92 | + $entry['icon'] = ''; |
|
| 93 | + } |
|
| 94 | + if(!isset($entry['type'])) { |
|
| 95 | + $entry['type'] = 'link'; |
|
| 96 | + } |
|
| 97 | + $this->entries[] = $entry; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * returns all the added Menu entries |
|
| 102 | - * @param string $type |
|
| 103 | - * @return array an array of the added entries |
|
| 104 | - */ |
|
| 105 | - public function getAll($type = 'link') { |
|
| 106 | - $this->init(); |
|
| 107 | - foreach ($this->closureEntries as $c) { |
|
| 108 | - $this->add($c()); |
|
| 109 | - } |
|
| 110 | - $this->closureEntries = array(); |
|
| 100 | + /** |
|
| 101 | + * returns all the added Menu entries |
|
| 102 | + * @param string $type |
|
| 103 | + * @return array an array of the added entries |
|
| 104 | + */ |
|
| 105 | + public function getAll($type = 'link') { |
|
| 106 | + $this->init(); |
|
| 107 | + foreach ($this->closureEntries as $c) { |
|
| 108 | + $this->add($c()); |
|
| 109 | + } |
|
| 110 | + $this->closureEntries = array(); |
|
| 111 | 111 | |
| 112 | - if ($type === 'all') { |
|
| 113 | - return $this->entries; |
|
| 114 | - } |
|
| 112 | + if ($type === 'all') { |
|
| 113 | + return $this->entries; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - return array_filter($this->entries, function($entry) use ($type) { |
|
| 117 | - return $entry['type'] === $type; |
|
| 118 | - }); |
|
| 119 | - } |
|
| 116 | + return array_filter($this->entries, function($entry) use ($type) { |
|
| 117 | + return $entry['type'] === $type; |
|
| 118 | + }); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * removes all the entries |
|
| 123 | - */ |
|
| 124 | - public function clear($loadDefaultLinks = true) { |
|
| 125 | - $this->entries = []; |
|
| 126 | - $this->closureEntries = []; |
|
| 127 | - $this->init = !$loadDefaultLinks; |
|
| 128 | - } |
|
| 121 | + /** |
|
| 122 | + * removes all the entries |
|
| 123 | + */ |
|
| 124 | + public function clear($loadDefaultLinks = true) { |
|
| 125 | + $this->entries = []; |
|
| 126 | + $this->closureEntries = []; |
|
| 127 | + $this->init = !$loadDefaultLinks; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Sets the current navigation entry of the currently running app |
|
| 132 | - * @param string $id of the app entry to activate (from added $entry) |
|
| 133 | - */ |
|
| 134 | - public function setActiveEntry($id) { |
|
| 135 | - $this->activeEntry = $id; |
|
| 136 | - } |
|
| 130 | + /** |
|
| 131 | + * Sets the current navigation entry of the currently running app |
|
| 132 | + * @param string $id of the app entry to activate (from added $entry) |
|
| 133 | + */ |
|
| 134 | + public function setActiveEntry($id) { |
|
| 135 | + $this->activeEntry = $id; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * gets the active Menu entry |
|
| 140 | - * @return string id or empty string |
|
| 141 | - * |
|
| 142 | - * This function returns the id of the active navigation entry (set by |
|
| 143 | - * setActiveEntry |
|
| 144 | - */ |
|
| 145 | - public function getActiveEntry() { |
|
| 146 | - return $this->activeEntry; |
|
| 147 | - } |
|
| 138 | + /** |
|
| 139 | + * gets the active Menu entry |
|
| 140 | + * @return string id or empty string |
|
| 141 | + * |
|
| 142 | + * This function returns the id of the active navigation entry (set by |
|
| 143 | + * setActiveEntry |
|
| 144 | + */ |
|
| 145 | + public function getActiveEntry() { |
|
| 146 | + return $this->activeEntry; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - private function init() { |
|
| 150 | - if ($this->init) { |
|
| 151 | - return; |
|
| 152 | - } |
|
| 153 | - $this->init = true; |
|
| 149 | + private function init() { |
|
| 150 | + if ($this->init) { |
|
| 151 | + return; |
|
| 152 | + } |
|
| 153 | + $this->init = true; |
|
| 154 | 154 | |
| 155 | - $l = $this->l10nFac->get('lib'); |
|
| 156 | - if ($this->config->getSystemValue('knowledgebaseenabled', true)) { |
|
| 157 | - $this->add([ |
|
| 158 | - 'type' => 'settings', |
|
| 159 | - 'id' => 'help', |
|
| 160 | - 'order' => 5, |
|
| 161 | - 'href' => $this->urlGenerator->linkToRoute('settings_help'), |
|
| 162 | - 'name' => $l->t('Help'), |
|
| 163 | - 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'), |
|
| 164 | - ]); |
|
| 165 | - } |
|
| 155 | + $l = $this->l10nFac->get('lib'); |
|
| 156 | + if ($this->config->getSystemValue('knowledgebaseenabled', true)) { |
|
| 157 | + $this->add([ |
|
| 158 | + 'type' => 'settings', |
|
| 159 | + 'id' => 'help', |
|
| 160 | + 'order' => 5, |
|
| 161 | + 'href' => $this->urlGenerator->linkToRoute('settings_help'), |
|
| 162 | + 'name' => $l->t('Help'), |
|
| 163 | + 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'), |
|
| 164 | + ]); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - if ($this->userSession->isLoggedIn()) { |
|
| 168 | - if ($this->isAdmin()) { |
|
| 169 | - // App management |
|
| 170 | - $this->add([ |
|
| 171 | - 'type' => 'settings', |
|
| 172 | - 'id' => 'core_apps', |
|
| 173 | - 'order' => 3, |
|
| 174 | - 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
|
| 175 | - 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
|
| 176 | - 'name' => $l->t('Apps'), |
|
| 177 | - ]); |
|
| 178 | - } |
|
| 167 | + if ($this->userSession->isLoggedIn()) { |
|
| 168 | + if ($this->isAdmin()) { |
|
| 169 | + // App management |
|
| 170 | + $this->add([ |
|
| 171 | + 'type' => 'settings', |
|
| 172 | + 'id' => 'core_apps', |
|
| 173 | + 'order' => 3, |
|
| 174 | + 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
|
| 175 | + 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
|
| 176 | + 'name' => $l->t('Apps'), |
|
| 177 | + ]); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - // Personal and (if applicable) admin settings |
|
| 181 | - $this->add([ |
|
| 182 | - 'type' => 'settings', |
|
| 183 | - 'id' => 'settings', |
|
| 184 | - 'order' => 1, |
|
| 185 | - 'href' => $this->urlGenerator->linkToRoute('settings_personal'), |
|
| 186 | - 'name' => $l->t('Settings'), |
|
| 187 | - 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
| 188 | - ]); |
|
| 180 | + // Personal and (if applicable) admin settings |
|
| 181 | + $this->add([ |
|
| 182 | + 'type' => 'settings', |
|
| 183 | + 'id' => 'settings', |
|
| 184 | + 'order' => 1, |
|
| 185 | + 'href' => $this->urlGenerator->linkToRoute('settings_personal'), |
|
| 186 | + 'name' => $l->t('Settings'), |
|
| 187 | + 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
| 188 | + ]); |
|
| 189 | 189 | |
| 190 | - // Logout |
|
| 191 | - $this->add([ |
|
| 192 | - 'type' => 'settings', |
|
| 193 | - 'id' => 'logout', |
|
| 194 | - 'order' => 99999, |
|
| 195 | - 'href' => $this->urlGenerator->linkToRouteAbsolute( |
|
| 196 | - 'core.login.logout', |
|
| 197 | - ['requesttoken' => \OCP\Util::callRegister()] |
|
| 198 | - ), |
|
| 199 | - 'name' => $l->t('Log out'), |
|
| 200 | - 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
|
| 201 | - ]); |
|
| 190 | + // Logout |
|
| 191 | + $this->add([ |
|
| 192 | + 'type' => 'settings', |
|
| 193 | + 'id' => 'logout', |
|
| 194 | + 'order' => 99999, |
|
| 195 | + 'href' => $this->urlGenerator->linkToRouteAbsolute( |
|
| 196 | + 'core.login.logout', |
|
| 197 | + ['requesttoken' => \OCP\Util::callRegister()] |
|
| 198 | + ), |
|
| 199 | + 'name' => $l->t('Log out'), |
|
| 200 | + 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
|
| 201 | + ]); |
|
| 202 | 202 | |
| 203 | - if ($this->isSubadmin()) { |
|
| 204 | - // User management |
|
| 205 | - $this->add([ |
|
| 206 | - 'type' => 'settings', |
|
| 207 | - 'id' => 'core_users', |
|
| 208 | - 'order' => 4, |
|
| 209 | - 'href' => $this->urlGenerator->linkToRoute('settings_users'), |
|
| 210 | - 'name' => $l->t('Users'), |
|
| 211 | - 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
|
| 212 | - ]); |
|
| 213 | - } |
|
| 214 | - } |
|
| 203 | + if ($this->isSubadmin()) { |
|
| 204 | + // User management |
|
| 205 | + $this->add([ |
|
| 206 | + 'type' => 'settings', |
|
| 207 | + 'id' => 'core_users', |
|
| 208 | + 'order' => 4, |
|
| 209 | + 'href' => $this->urlGenerator->linkToRoute('settings_users'), |
|
| 210 | + 'name' => $l->t('Users'), |
|
| 211 | + 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
|
| 212 | + ]); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - if ($this->appManager === 'null') { |
|
| 217 | - return; |
|
| 218 | - } |
|
| 219 | - foreach ($this->appManager->getInstalledApps() as $app) { |
|
| 220 | - // load plugins and collections from info.xml |
|
| 221 | - $info = $this->appManager->getAppInfo($app); |
|
| 222 | - if (empty($info['navigations'])) { |
|
| 223 | - continue; |
|
| 224 | - } |
|
| 225 | - foreach ($info['navigations'] as $nav) { |
|
| 226 | - if (!isset($nav['name'])) { |
|
| 227 | - continue; |
|
| 228 | - } |
|
| 229 | - if (!isset($nav['route'])) { |
|
| 230 | - continue; |
|
| 231 | - } |
|
| 232 | - $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
|
| 233 | - if ($role === 'admin' && !$this->isAdmin()) { |
|
| 234 | - continue; |
|
| 235 | - } |
|
| 236 | - $l = $this->l10nFac->get($app); |
|
| 237 | - $id = isset($nav['id']) ? $nav['id'] : $app; |
|
| 238 | - $order = isset($nav['order']) ? $nav['order'] : 100; |
|
| 239 | - $type = isset($nav['type']) ? $nav['type'] : 'link'; |
|
| 240 | - $route = $this->urlGenerator->linkToRoute($nav['route']); |
|
| 241 | - $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
|
| 242 | - foreach ([$icon, "$app.svg"] as $i) { |
|
| 243 | - try { |
|
| 244 | - $icon = $this->urlGenerator->imagePath($app, $i); |
|
| 245 | - break; |
|
| 246 | - } catch (\RuntimeException $ex) { |
|
| 247 | - // no icon? - ignore it then |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - if ($icon === null) { |
|
| 251 | - $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
|
| 252 | - } |
|
| 216 | + if ($this->appManager === 'null') { |
|
| 217 | + return; |
|
| 218 | + } |
|
| 219 | + foreach ($this->appManager->getInstalledApps() as $app) { |
|
| 220 | + // load plugins and collections from info.xml |
|
| 221 | + $info = $this->appManager->getAppInfo($app); |
|
| 222 | + if (empty($info['navigations'])) { |
|
| 223 | + continue; |
|
| 224 | + } |
|
| 225 | + foreach ($info['navigations'] as $nav) { |
|
| 226 | + if (!isset($nav['name'])) { |
|
| 227 | + continue; |
|
| 228 | + } |
|
| 229 | + if (!isset($nav['route'])) { |
|
| 230 | + continue; |
|
| 231 | + } |
|
| 232 | + $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
|
| 233 | + if ($role === 'admin' && !$this->isAdmin()) { |
|
| 234 | + continue; |
|
| 235 | + } |
|
| 236 | + $l = $this->l10nFac->get($app); |
|
| 237 | + $id = isset($nav['id']) ? $nav['id'] : $app; |
|
| 238 | + $order = isset($nav['order']) ? $nav['order'] : 100; |
|
| 239 | + $type = isset($nav['type']) ? $nav['type'] : 'link'; |
|
| 240 | + $route = $this->urlGenerator->linkToRoute($nav['route']); |
|
| 241 | + $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
|
| 242 | + foreach ([$icon, "$app.svg"] as $i) { |
|
| 243 | + try { |
|
| 244 | + $icon = $this->urlGenerator->imagePath($app, $i); |
|
| 245 | + break; |
|
| 246 | + } catch (\RuntimeException $ex) { |
|
| 247 | + // no icon? - ignore it then |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + if ($icon === null) { |
|
| 251 | + $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - $this->add([ |
|
| 255 | - 'id' => $id, |
|
| 256 | - 'order' => $order, |
|
| 257 | - 'href' => $route, |
|
| 258 | - 'icon' => $icon, |
|
| 259 | - 'type' => $type, |
|
| 260 | - 'name' => $l->t($nav['name']), |
|
| 261 | - ]); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 254 | + $this->add([ |
|
| 255 | + 'id' => $id, |
|
| 256 | + 'order' => $order, |
|
| 257 | + 'href' => $route, |
|
| 258 | + 'icon' => $icon, |
|
| 259 | + 'type' => $type, |
|
| 260 | + 'name' => $l->t($nav['name']), |
|
| 261 | + ]); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - private function isAdmin() { |
|
| 267 | - $user = $this->userSession->getUser(); |
|
| 268 | - if ($user !== null) { |
|
| 269 | - return $this->groupManager->isAdmin($user->getUID()); |
|
| 270 | - } |
|
| 271 | - return false; |
|
| 272 | - } |
|
| 266 | + private function isAdmin() { |
|
| 267 | + $user = $this->userSession->getUser(); |
|
| 268 | + if ($user !== null) { |
|
| 269 | + return $this->groupManager->isAdmin($user->getUID()); |
|
| 270 | + } |
|
| 271 | + return false; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - private function isSubadmin() { |
|
| 275 | - $user = $this->userSession->getUser(); |
|
| 276 | - if ($user !== null) { |
|
| 277 | - return $this->groupManager->getSubAdmin()->isSubAdmin($user); |
|
| 278 | - } |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 274 | + private function isSubadmin() { |
|
| 275 | + $user = $this->userSession->getUser(); |
|
| 276 | + if ($user !== null) { |
|
| 277 | + return $this->groupManager->getSubAdmin()->isSubAdmin($user); |
|
| 278 | + } |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | 281 | } |
@@ -27,89 +27,89 @@ |
||
| 27 | 27 | * @since 9.1 |
| 28 | 28 | */ |
| 29 | 29 | interface IManager { |
| 30 | - /** |
|
| 31 | - * @since 9.1.0 |
|
| 32 | - */ |
|
| 33 | - const KEY_ADMIN_SETTINGS = 'admin'; |
|
| 30 | + /** |
|
| 31 | + * @since 9.1.0 |
|
| 32 | + */ |
|
| 33 | + const KEY_ADMIN_SETTINGS = 'admin'; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @since 9.1.0 |
|
| 37 | - */ |
|
| 38 | - const KEY_ADMIN_SECTION = 'admin-section'; |
|
| 35 | + /** |
|
| 36 | + * @since 9.1.0 |
|
| 37 | + */ |
|
| 38 | + const KEY_ADMIN_SECTION = 'admin-section'; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * sets up settings according to data specified by an apps info.xml, within |
|
| 42 | - * the <settings> element. |
|
| 43 | - * |
|
| 44 | - * @param array $settings an associative array, allowed keys are as specified |
|
| 45 | - * by the KEY_ constant of this interface. The value |
|
| 46 | - * must always be a class name, implement either |
|
| 47 | - * IAdmin or ISection. I.e. only one section and admin |
|
| 48 | - * setting can be configured per app. |
|
| 49 | - * @since 9.1.0 |
|
| 50 | - */ |
|
| 51 | - public function setupSettings(array $settings); |
|
| 40 | + /** |
|
| 41 | + * sets up settings according to data specified by an apps info.xml, within |
|
| 42 | + * the <settings> element. |
|
| 43 | + * |
|
| 44 | + * @param array $settings an associative array, allowed keys are as specified |
|
| 45 | + * by the KEY_ constant of this interface. The value |
|
| 46 | + * must always be a class name, implement either |
|
| 47 | + * IAdmin or ISection. I.e. only one section and admin |
|
| 48 | + * setting can be configured per app. |
|
| 49 | + * @since 9.1.0 |
|
| 50 | + */ |
|
| 51 | + public function setupSettings(array $settings); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * attempts to remove an apps section and/or settings entry. A listener is |
|
| 55 | - * added centrally making sure that this method is called ones an app was |
|
| 56 | - * disabled. |
|
| 57 | - * |
|
| 58 | - * What this does not help with is when applications change their settings |
|
| 59 | - * or section classes during their life time. New entries will be added, |
|
| 60 | - * but inactive ones will still reside in the database. |
|
| 61 | - * |
|
| 62 | - * @param string $appId |
|
| 63 | - * @since 9.1.0 |
|
| 64 | - */ |
|
| 65 | - public function onAppDisabled($appId); |
|
| 53 | + /** |
|
| 54 | + * attempts to remove an apps section and/or settings entry. A listener is |
|
| 55 | + * added centrally making sure that this method is called ones an app was |
|
| 56 | + * disabled. |
|
| 57 | + * |
|
| 58 | + * What this does not help with is when applications change their settings |
|
| 59 | + * or section classes during their life time. New entries will be added, |
|
| 60 | + * but inactive ones will still reside in the database. |
|
| 61 | + * |
|
| 62 | + * @param string $appId |
|
| 63 | + * @since 9.1.0 |
|
| 64 | + */ |
|
| 65 | + public function onAppDisabled($appId); |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * The method should check all registered classes whether they are still |
|
| 69 | - * instantiable and remove them, if not. This method is called by a |
|
| 70 | - * background job once, after one or more apps were updated. |
|
| 71 | - * |
|
| 72 | - * An app`s info.xml can change during an update and make it unknown whether |
|
| 73 | - * a registered class name was changed or not. An old one would just stay |
|
| 74 | - * registered. Another case is if an admin takes a radical approach and |
|
| 75 | - * simply removes an app from the app folder. These unregular checks will |
|
| 76 | - * take care of such situations. |
|
| 77 | - * |
|
| 78 | - * @since 9.1.0 |
|
| 79 | - */ |
|
| 80 | - public function checkForOrphanedClassNames(); |
|
| 67 | + /** |
|
| 68 | + * The method should check all registered classes whether they are still |
|
| 69 | + * instantiable and remove them, if not. This method is called by a |
|
| 70 | + * background job once, after one or more apps were updated. |
|
| 71 | + * |
|
| 72 | + * An app`s info.xml can change during an update and make it unknown whether |
|
| 73 | + * a registered class name was changed or not. An old one would just stay |
|
| 74 | + * registered. Another case is if an admin takes a radical approach and |
|
| 75 | + * simply removes an app from the app folder. These unregular checks will |
|
| 76 | + * take care of such situations. |
|
| 77 | + * |
|
| 78 | + * @since 9.1.0 |
|
| 79 | + */ |
|
| 80 | + public function checkForOrphanedClassNames(); |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * returns a list of the admin sections |
|
| 84 | - * |
|
| 85 | - * @return array array of ISection[] where key is the priority |
|
| 86 | - * @since 9.1.0 |
|
| 87 | - */ |
|
| 88 | - public function getAdminSections(); |
|
| 82 | + /** |
|
| 83 | + * returns a list of the admin sections |
|
| 84 | + * |
|
| 85 | + * @return array array of ISection[] where key is the priority |
|
| 86 | + * @since 9.1.0 |
|
| 87 | + */ |
|
| 88 | + public function getAdminSections(); |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * returns a list of the personal sections |
|
| 92 | - * |
|
| 93 | - * @return array array of ISection[] where key is the priority |
|
| 94 | - * @since 12.0.0 |
|
| 95 | - */ |
|
| 96 | - public function getPersonalSections(); |
|
| 90 | + /** |
|
| 91 | + * returns a list of the personal sections |
|
| 92 | + * |
|
| 93 | + * @return array array of ISection[] where key is the priority |
|
| 94 | + * @since 12.0.0 |
|
| 95 | + */ |
|
| 96 | + public function getPersonalSections(); |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * returns a list of the admin settings |
|
| 100 | - * |
|
| 101 | - * @param string $section the section id for which to load the settings |
|
| 102 | - * @return array array of IAdmin[] where key is the priority |
|
| 103 | - * @since 9.1.0 |
|
| 104 | - */ |
|
| 105 | - public function getAdminSettings($section); |
|
| 98 | + /** |
|
| 99 | + * returns a list of the admin settings |
|
| 100 | + * |
|
| 101 | + * @param string $section the section id for which to load the settings |
|
| 102 | + * @return array array of IAdmin[] where key is the priority |
|
| 103 | + * @since 9.1.0 |
|
| 104 | + */ |
|
| 105 | + public function getAdminSettings($section); |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * returns a list of the personal settings |
|
| 109 | - * |
|
| 110 | - * @param string $section the section id for which to load the settings |
|
| 111 | - * @return array array of IPersonal[] where key is the priority |
|
| 112 | - * @since 12.0.0 |
|
| 113 | - */ |
|
| 114 | - public function getPersonalSettings($section); |
|
| 107 | + /** |
|
| 108 | + * returns a list of the personal settings |
|
| 109 | + * |
|
| 110 | + * @param string $section the section id for which to load the settings |
|
| 111 | + * @return array array of IPersonal[] where key is the priority |
|
| 112 | + * @since 12.0.0 |
|
| 113 | + */ |
|
| 114 | + public function getPersonalSettings($section); |
|
| 115 | 115 | } |
@@ -35,84 +35,84 @@ |
||
| 35 | 35 | * @package OC\Settings\Controller |
| 36 | 36 | */ |
| 37 | 37 | class AdminSettingsController extends Controller { |
| 38 | - use CommonSettingsTrait; |
|
| 38 | + use CommonSettingsTrait; |
|
| 39 | 39 | |
| 40 | - /** @var INavigationManager */ |
|
| 41 | - private $navigationManager; |
|
| 42 | - /** @var ISettingsManager */ |
|
| 43 | - private $settingsManager; |
|
| 40 | + /** @var INavigationManager */ |
|
| 41 | + private $navigationManager; |
|
| 42 | + /** @var ISettingsManager */ |
|
| 43 | + private $settingsManager; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param string $appName |
|
| 47 | - * @param IRequest $request |
|
| 48 | - * @param INavigationManager $navigationManager |
|
| 49 | - * @param ISettingsManager $settingsManager |
|
| 50 | - */ |
|
| 51 | - public function __construct( |
|
| 52 | - $appName, |
|
| 53 | - IRequest $request, |
|
| 54 | - INavigationManager $navigationManager, |
|
| 55 | - ISettingsManager $settingsManager |
|
| 56 | - ) { |
|
| 57 | - parent::__construct($appName, $request); |
|
| 58 | - $this->navigationManager = $navigationManager; |
|
| 59 | - $this->settingsManager = $settingsManager; |
|
| 60 | - } |
|
| 45 | + /** |
|
| 46 | + * @param string $appName |
|
| 47 | + * @param IRequest $request |
|
| 48 | + * @param INavigationManager $navigationManager |
|
| 49 | + * @param ISettingsManager $settingsManager |
|
| 50 | + */ |
|
| 51 | + public function __construct( |
|
| 52 | + $appName, |
|
| 53 | + IRequest $request, |
|
| 54 | + INavigationManager $navigationManager, |
|
| 55 | + ISettingsManager $settingsManager |
|
| 56 | + ) { |
|
| 57 | + parent::__construct($appName, $request); |
|
| 58 | + $this->navigationManager = $navigationManager; |
|
| 59 | + $this->settingsManager = $settingsManager; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param string $section |
|
| 64 | - * @return TemplateResponse |
|
| 65 | - * |
|
| 66 | - * @NoCSRFRequired |
|
| 67 | - */ |
|
| 68 | - public function index($section) { |
|
| 69 | - $this->navigationManager->setActiveEntry('admin'); |
|
| 70 | - return $this->getIndexResponse($section); |
|
| 71 | - } |
|
| 62 | + /** |
|
| 63 | + * @param string $section |
|
| 64 | + * @return TemplateResponse |
|
| 65 | + * |
|
| 66 | + * @NoCSRFRequired |
|
| 67 | + */ |
|
| 68 | + public function index($section) { |
|
| 69 | + $this->navigationManager->setActiveEntry('admin'); |
|
| 70 | + return $this->getIndexResponse($section); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @param string $section |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 77 | - private function getSettings($section) { |
|
| 78 | - // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
|
| 79 | - $settings = $this->settingsManager->getAdminSettings($section); |
|
| 80 | - $formatted = $this->formatSettings($settings); |
|
| 81 | - if($section === 'additional') { |
|
| 82 | - $formatted['content'] .= $this->getLegacyForms(); |
|
| 83 | - } |
|
| 84 | - return $formatted; |
|
| 85 | - } |
|
| 73 | + /** |
|
| 74 | + * @param string $section |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | + private function getSettings($section) { |
|
| 78 | + // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
|
| 79 | + $settings = $this->settingsManager->getAdminSettings($section); |
|
| 80 | + $formatted = $this->formatSettings($settings); |
|
| 81 | + if($section === 'additional') { |
|
| 82 | + $formatted['content'] .= $this->getLegacyForms(); |
|
| 83 | + } |
|
| 84 | + return $formatted; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @return bool|string |
|
| 89 | - */ |
|
| 90 | - private function getLegacyForms() { |
|
| 91 | - $forms = \OC_App::getForms('admin'); |
|
| 87 | + /** |
|
| 88 | + * @return bool|string |
|
| 89 | + */ |
|
| 90 | + private function getLegacyForms() { |
|
| 91 | + $forms = \OC_App::getForms('admin'); |
|
| 92 | 92 | |
| 93 | - $forms = array_map(function ($form) { |
|
| 94 | - if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
| 95 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
| 96 | - $sectionName = str_replace('</h2>', '', $sectionName); |
|
| 97 | - $anchor = strtolower($sectionName); |
|
| 98 | - $anchor = str_replace(' ', '-', $anchor); |
|
| 93 | + $forms = array_map(function ($form) { |
|
| 94 | + if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
| 95 | + $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
| 96 | + $sectionName = str_replace('</h2>', '', $sectionName); |
|
| 97 | + $anchor = strtolower($sectionName); |
|
| 98 | + $anchor = str_replace(' ', '-', $anchor); |
|
| 99 | 99 | |
| 100 | - return array( |
|
| 101 | - 'anchor' => $anchor, |
|
| 102 | - 'section-name' => $sectionName, |
|
| 103 | - 'form' => $form |
|
| 104 | - ); |
|
| 105 | - } |
|
| 106 | - return array( |
|
| 107 | - 'form' => $form |
|
| 108 | - ); |
|
| 109 | - }, $forms); |
|
| 100 | + return array( |
|
| 101 | + 'anchor' => $anchor, |
|
| 102 | + 'section-name' => $sectionName, |
|
| 103 | + 'form' => $form |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | + return array( |
|
| 107 | + 'form' => $form |
|
| 108 | + ); |
|
| 109 | + }, $forms); |
|
| 110 | 110 | |
| 111 | - $out = new Template('settings', 'admin/additional'); |
|
| 112 | - $out->assign('forms', $forms); |
|
| 111 | + $out = new Template('settings', 'admin/additional'); |
|
| 112 | + $out->assign('forms', $forms); |
|
| 113 | 113 | |
| 114 | - return $out->fetchPage(); |
|
| 115 | - } |
|
| 114 | + return $out->fetchPage(); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | } |
@@ -30,44 +30,44 @@ |
||
| 30 | 30 | use OCP\Settings\IManager as ISettingsManager; |
| 31 | 31 | |
| 32 | 32 | class PersonalSettingsController extends Controller { |
| 33 | - use CommonSettingsTrait { |
|
| 34 | - getSettings as private; |
|
| 35 | - } |
|
| 33 | + use CommonSettingsTrait { |
|
| 34 | + getSettings as private; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** @var INavigationManager */ |
|
| 38 | - private $navigationManager; |
|
| 37 | + /** @var INavigationManager */ |
|
| 38 | + private $navigationManager; |
|
| 39 | 39 | |
| 40 | - public function __construct( |
|
| 41 | - $appName, |
|
| 42 | - IRequest $request, |
|
| 43 | - INavigationManager $navigationManager, |
|
| 44 | - ISettingsManager $settingsManager |
|
| 45 | - ) { |
|
| 46 | - parent::__construct($appName, $request); |
|
| 47 | - $this->navigationManager = $navigationManager; |
|
| 48 | - $this->settingsManager = $settingsManager; |
|
| 49 | - } |
|
| 40 | + public function __construct( |
|
| 41 | + $appName, |
|
| 42 | + IRequest $request, |
|
| 43 | + INavigationManager $navigationManager, |
|
| 44 | + ISettingsManager $settingsManager |
|
| 45 | + ) { |
|
| 46 | + parent::__construct($appName, $request); |
|
| 47 | + $this->navigationManager = $navigationManager; |
|
| 48 | + $this->settingsManager = $settingsManager; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param string $section |
|
| 53 | - * @return TemplateResponse |
|
| 54 | - * |
|
| 55 | - * @NoCSRFRequired |
|
| 56 | - * @NoAdminRequired |
|
| 57 | - * @NoSubadminRequired |
|
| 58 | - */ |
|
| 59 | - public function index($section) { |
|
| 60 | - $this->navigationManager->setActiveEntry('personal'); |
|
| 61 | - return $this->getIndexResponse($section); |
|
| 62 | - } |
|
| 51 | + /** |
|
| 52 | + * @param string $section |
|
| 53 | + * @return TemplateResponse |
|
| 54 | + * |
|
| 55 | + * @NoCSRFRequired |
|
| 56 | + * @NoAdminRequired |
|
| 57 | + * @NoSubadminRequired |
|
| 58 | + */ |
|
| 59 | + public function index($section) { |
|
| 60 | + $this->navigationManager->setActiveEntry('personal'); |
|
| 61 | + return $this->getIndexResponse($section); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param string $section |
|
| 66 | - * @return array |
|
| 67 | - */ |
|
| 68 | - private function getSettings($section) { |
|
| 69 | - // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
|
| 70 | - $settings = $this->settingsManager->getPersonalSettings($section); |
|
| 71 | - return $this->formatSettings($settings); |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * @param string $section |
|
| 66 | + * @return array |
|
| 67 | + */ |
|
| 68 | + private function getSettings($section) { |
|
| 69 | + // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
|
| 70 | + $settings = $this->settingsManager->getPersonalSettings($section); |
|
| 71 | + return $this->formatSettings($settings); |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | <ul> |
| 33 | 33 | <li class="settings-caption">Personal</li> |
| 34 | 34 | <?php |
| 35 | - foreach($_['forms']['personal'] as $form) { |
|
| 36 | - if (isset($form['anchor'])) { |
|
| 37 | - $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.PersonalSettings.index', ['section' => $form['anchor']]); |
|
| 38 | - $class = 'nav-icon-' . $form['anchor']; |
|
| 39 | - $sectionName = $form['section-name']; |
|
| 40 | - $active = $form['active'] ? ' class="active"' : ''; |
|
| 41 | - ?> |
|
| 35 | + foreach($_['forms']['personal'] as $form) { |
|
| 36 | + if (isset($form['anchor'])) { |
|
| 37 | + $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.PersonalSettings.index', ['section' => $form['anchor']]); |
|
| 38 | + $class = 'nav-icon-' . $form['anchor']; |
|
| 39 | + $sectionName = $form['section-name']; |
|
| 40 | + $active = $form['active'] ? ' class="active"' : ''; |
|
| 41 | + ?> |
|
| 42 | 42 | <li <?php print_unescaped($form['active'] ? ' class="active"' : ''); ?>> |
| 43 | 43 | <a href="<?php p($anchor); ?>"> |
| 44 | 44 | <?php if (!empty($form['icon'])) { ?> |
@@ -50,24 +50,24 @@ discard block |
||
| 50 | 50 | </a> |
| 51 | 51 | </li> |
| 52 | 52 | <?php |
| 53 | - } |
|
| 54 | - } |
|
| 55 | - ?> |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + ?> |
|
| 56 | 56 | |
| 57 | 57 | <?php |
| 58 | - if(!empty($_['forms']['admin'])) { |
|
| 59 | - ?> |
|
| 58 | + if(!empty($_['forms']['admin'])) { |
|
| 59 | + ?> |
|
| 60 | 60 | <li class="settings-caption">Administration</li> |
| 61 | 61 | <?php |
| 62 | - } |
|
| 63 | - foreach($_['forms']['admin'] as $form) { |
|
| 64 | - if (isset($form['anchor'])) { |
|
| 62 | + } |
|
| 63 | + foreach($_['forms']['admin'] as $form) { |
|
| 64 | + if (isset($form['anchor'])) { |
|
| 65 | 65 | |
| 66 | - $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]); |
|
| 67 | - $class = 'nav-icon-' . $form['anchor']; |
|
| 68 | - $sectionName = $form['section-name']; |
|
| 69 | - $active = $form['active'] ? ' class="active"' : ''; |
|
| 70 | - ?> |
|
| 66 | + $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]); |
|
| 67 | + $class = 'nav-icon-' . $form['anchor']; |
|
| 68 | + $sectionName = $form['section-name']; |
|
| 69 | + $active = $form['active'] ? ' class="active"' : ''; |
|
| 70 | + ?> |
|
| 71 | 71 | <li <?php print_unescaped($form['active'] ? ' class="active"' : ''); ?>> |
| 72 | 72 | <a href="<?php p($anchor); ?>"> |
| 73 | 73 | <?php if (!empty($form['icon'])) { ?> |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | </a> |
| 80 | 80 | </li> |
| 81 | 81 | <?php |
| 82 | - } |
|
| 83 | - } |
|
| 84 | - ?> |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + ?> |
|
| 85 | 85 | </ul> |
| 86 | 86 | </div> |
| 87 | 87 | |
@@ -41,379 +41,379 @@ |
||
| 41 | 41 | use OCP\Settings\ISection; |
| 42 | 42 | |
| 43 | 43 | class Manager implements IManager { |
| 44 | - const TABLE_ADMIN_SETTINGS = 'admin_settings'; |
|
| 45 | - const TABLE_ADMIN_SECTIONS = 'admin_sections'; |
|
| 46 | - |
|
| 47 | - /** @var ILogger */ |
|
| 48 | - private $log; |
|
| 49 | - /** @var IDBConnection */ |
|
| 50 | - private $dbc; |
|
| 51 | - /** @var Mapper */ |
|
| 52 | - private $mapper; |
|
| 53 | - /** @var IL10N */ |
|
| 54 | - private $l; |
|
| 55 | - /** @var IConfig */ |
|
| 56 | - private $config; |
|
| 57 | - /** @var EncryptionManager */ |
|
| 58 | - private $encryptionManager; |
|
| 59 | - /** @var IUserManager */ |
|
| 60 | - private $userManager; |
|
| 61 | - /** @var ILockingProvider */ |
|
| 62 | - private $lockingProvider; |
|
| 63 | - /** @var IRequest */ |
|
| 64 | - private $request; |
|
| 65 | - /** @var IURLGenerator */ |
|
| 66 | - private $url; |
|
| 67 | - /** @var AccountManager */ |
|
| 68 | - private $accountManager; |
|
| 69 | - /** @var IGroupManager */ |
|
| 70 | - private $groupManager; |
|
| 71 | - /** @var IFactory */ |
|
| 72 | - private $l10nFactory; |
|
| 73 | - /** @var \OC_Defaults */ |
|
| 74 | - private $defaults; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param ILogger $log |
|
| 78 | - * @param IDBConnection $dbc |
|
| 79 | - * @param IL10N $l |
|
| 80 | - * @param IConfig $config |
|
| 81 | - * @param EncryptionManager $encryptionManager |
|
| 82 | - * @param IUserManager $userManager |
|
| 83 | - * @param ILockingProvider $lockingProvider |
|
| 84 | - * @param IRequest $request |
|
| 85 | - * @param Mapper $mapper |
|
| 86 | - * @param IURLGenerator $url |
|
| 87 | - * @param AccountManager $accountManager |
|
| 88 | - * @param IGroupManager $groupManager |
|
| 89 | - * @param IFactory $l10nFactory |
|
| 90 | - */ |
|
| 91 | - public function __construct( |
|
| 92 | - ILogger $log, |
|
| 93 | - IDBConnection $dbc, |
|
| 94 | - IL10N $l, |
|
| 95 | - IConfig $config, |
|
| 96 | - EncryptionManager $encryptionManager, |
|
| 97 | - IUserManager $userManager, |
|
| 98 | - ILockingProvider $lockingProvider, |
|
| 99 | - IRequest $request, |
|
| 100 | - Mapper $mapper, |
|
| 101 | - IURLGenerator $url, |
|
| 102 | - AccountManager $accountManager, |
|
| 103 | - IGroupManager $groupManager, |
|
| 104 | - IFactory $l10nFactory, |
|
| 105 | - \OC_Defaults $defaults |
|
| 106 | - ) { |
|
| 107 | - $this->log = $log; |
|
| 108 | - $this->dbc = $dbc; |
|
| 109 | - $this->mapper = $mapper; |
|
| 110 | - $this->l = $l; |
|
| 111 | - $this->config = $config; |
|
| 112 | - $this->encryptionManager = $encryptionManager; |
|
| 113 | - $this->userManager = $userManager; |
|
| 114 | - $this->lockingProvider = $lockingProvider; |
|
| 115 | - $this->request = $request; |
|
| 116 | - $this->url = $url; |
|
| 117 | - $this->accountManager = $accountManager; |
|
| 118 | - $this->groupManager = $groupManager; |
|
| 119 | - $this->l10nFactory = $l10nFactory; |
|
| 120 | - $this->defaults = $defaults; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @inheritdoc |
|
| 125 | - */ |
|
| 126 | - public function setupSettings(array $settings) { |
|
| 127 | - if (isset($settings[IManager::KEY_ADMIN_SECTION])) { |
|
| 128 | - $this->setupAdminSection($settings[IManager::KEY_ADMIN_SECTION]); |
|
| 129 | - } |
|
| 130 | - if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) { |
|
| 131 | - $this->setupAdminSettings($settings[IManager::KEY_ADMIN_SETTINGS]); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * attempts to remove an apps section and/or settings entry. A listener is |
|
| 137 | - * added centrally making sure that this method is called ones an app was |
|
| 138 | - * disabled. |
|
| 139 | - * |
|
| 140 | - * @param string $appId |
|
| 141 | - * @since 9.1.0 |
|
| 142 | - */ |
|
| 143 | - public function onAppDisabled($appId) { |
|
| 144 | - $appInfo = \OC_App::getAppInfo($appId); // hello static legacy |
|
| 145 | - |
|
| 146 | - if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) { |
|
| 147 | - $this->mapper->remove(self::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\')); |
|
| 148 | - } |
|
| 149 | - if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) { |
|
| 150 | - $this->mapper->remove(self::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\')); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - public function checkForOrphanedClassNames() { |
|
| 155 | - $tables = [self::TABLE_ADMIN_SECTIONS, self::TABLE_ADMIN_SETTINGS]; |
|
| 156 | - foreach ($tables as $table) { |
|
| 157 | - $classes = $this->mapper->getClasses($table); |
|
| 158 | - foreach ($classes as $className) { |
|
| 159 | - try { |
|
| 160 | - \OC::$server->query($className); |
|
| 161 | - } catch (QueryException $e) { |
|
| 162 | - $this->mapper->remove($table, $className); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @param string $sectionClassName |
|
| 170 | - */ |
|
| 171 | - private function setupAdminSection($sectionClassName) { |
|
| 172 | - if (!class_exists($sectionClassName)) { |
|
| 173 | - $this->log->debug('Could not find admin section class ' . $sectionClassName); |
|
| 174 | - return; |
|
| 175 | - } |
|
| 176 | - try { |
|
| 177 | - $section = $this->query($sectionClassName); |
|
| 178 | - } catch (QueryException $e) { |
|
| 179 | - // cancel |
|
| 180 | - return; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - if (!$section instanceof ISection) { |
|
| 184 | - $this->log->error( |
|
| 185 | - 'Admin section instance must implement \OCP\ISection. Invalid class: {class}', |
|
| 186 | - ['class' => $sectionClassName] |
|
| 187 | - ); |
|
| 188 | - return; |
|
| 189 | - } |
|
| 190 | - if (!$this->hasAdminSection(get_class($section))) { |
|
| 191 | - $this->addAdminSection($section); |
|
| 192 | - } else { |
|
| 193 | - $this->updateAdminSection($section); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - private function addAdminSection(ISection $section) { |
|
| 198 | - $this->mapper->add(self::TABLE_ADMIN_SECTIONS, [ |
|
| 199 | - 'id' => $section->getID(), |
|
| 200 | - 'class' => get_class($section), |
|
| 201 | - 'priority' => $section->getPriority(), |
|
| 202 | - ]); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - private function addAdminSettings(ISettings $settings) { |
|
| 206 | - $this->mapper->add(self::TABLE_ADMIN_SETTINGS, [ |
|
| 207 | - 'class' => get_class($settings), |
|
| 208 | - 'section' => $settings->getSection(), |
|
| 209 | - 'priority' => $settings->getPriority(), |
|
| 210 | - ]); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - private function updateAdminSettings(ISettings $settings) { |
|
| 214 | - $this->mapper->update( |
|
| 215 | - self::TABLE_ADMIN_SETTINGS, |
|
| 216 | - 'class', |
|
| 217 | - get_class($settings), |
|
| 218 | - [ |
|
| 219 | - 'section' => $settings->getSection(), |
|
| 220 | - 'priority' => $settings->getPriority(), |
|
| 221 | - ] |
|
| 222 | - ); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - private function updateAdminSection(ISection $section) { |
|
| 226 | - $this->mapper->update( |
|
| 227 | - self::TABLE_ADMIN_SECTIONS, |
|
| 228 | - 'class', |
|
| 229 | - get_class($section), |
|
| 230 | - [ |
|
| 231 | - 'id' => $section->getID(), |
|
| 232 | - 'priority' => $section->getPriority(), |
|
| 233 | - ] |
|
| 234 | - ); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * @param string $className |
|
| 239 | - * @return bool |
|
| 240 | - */ |
|
| 241 | - private function hasAdminSection($className) { |
|
| 242 | - return $this->mapper->has(self::TABLE_ADMIN_SECTIONS, $className); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @param string $className |
|
| 247 | - * @return bool |
|
| 248 | - */ |
|
| 249 | - private function hasAdminSettings($className) { |
|
| 250 | - return $this->mapper->has(self::TABLE_ADMIN_SETTINGS, $className); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - private function setupAdminSettings($settingsClassName) { |
|
| 254 | - if (!class_exists($settingsClassName)) { |
|
| 255 | - $this->log->debug('Could not find admin section class ' . $settingsClassName); |
|
| 256 | - return; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - try { |
|
| 260 | - /** @var ISettings $settings */ |
|
| 261 | - $settings = $this->query($settingsClassName); |
|
| 262 | - } catch (QueryException $e) { |
|
| 263 | - // cancel |
|
| 264 | - return; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - if (!$settings instanceof ISettings) { |
|
| 268 | - $this->log->error( |
|
| 269 | - 'Admin section instance must implement \OCP\Settings\ISection. Invalid class: {class}', |
|
| 270 | - ['class' => $settingsClassName] |
|
| 271 | - ); |
|
| 272 | - return; |
|
| 273 | - } |
|
| 274 | - if (!$this->hasAdminSettings(get_class($settings))) { |
|
| 275 | - $this->addAdminSettings($settings); |
|
| 276 | - } else { |
|
| 277 | - $this->updateAdminSettings($settings); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - private function query($className) { |
|
| 282 | - try { |
|
| 283 | - return \OC::$server->query($className); |
|
| 284 | - } catch (QueryException $e) { |
|
| 285 | - $this->log->logException($e); |
|
| 286 | - throw $e; |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * @inheritdoc |
|
| 292 | - */ |
|
| 293 | - public function getAdminSections() { |
|
| 294 | - // built-in sections |
|
| 295 | - $sections = [ |
|
| 296 | - 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
| 297 | - 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
| 298 | - 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 299 | - 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 300 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 301 | - 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
| 302 | - ]; |
|
| 303 | - |
|
| 304 | - $rows = $this->mapper->getAdminSectionsFromDB(); |
|
| 305 | - |
|
| 306 | - foreach ($rows as $row) { |
|
| 307 | - if (!isset($sections[$row['priority']])) { |
|
| 308 | - $sections[$row['priority']] = []; |
|
| 309 | - } |
|
| 310 | - try { |
|
| 311 | - $sections[$row['priority']][] = $this->query($row['class']); |
|
| 312 | - } catch (QueryException $e) { |
|
| 313 | - // skip |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - ksort($sections); |
|
| 318 | - |
|
| 319 | - return $sections; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * @param string $section |
|
| 324 | - * @return ISection[] |
|
| 325 | - */ |
|
| 326 | - private function getBuiltInAdminSettings($section) { |
|
| 327 | - $forms = []; |
|
| 328 | - try { |
|
| 329 | - if ($section === 'server') { |
|
| 330 | - /** @var ISettings $form */ |
|
| 331 | - $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
| 332 | - $forms[$form->getPriority()] = [$form]; |
|
| 333 | - $form = new Admin\ServerDevNotice(); |
|
| 334 | - $forms[$form->getPriority()] = [$form]; |
|
| 335 | - } |
|
| 336 | - if ($section === 'encryption') { |
|
| 337 | - /** @var ISettings $form */ |
|
| 338 | - $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
| 339 | - $forms[$form->getPriority()] = [$form]; |
|
| 340 | - } |
|
| 341 | - if ($section === 'sharing') { |
|
| 342 | - /** @var ISettings $form */ |
|
| 343 | - $form = new Admin\Sharing($this->config); |
|
| 344 | - $forms[$form->getPriority()] = [$form]; |
|
| 345 | - } |
|
| 346 | - if ($section === 'additional') { |
|
| 347 | - /** @var ISettings $form */ |
|
| 348 | - $form = new Admin\Additional($this->config); |
|
| 349 | - $forms[$form->getPriority()] = [$form]; |
|
| 350 | - } |
|
| 351 | - if ($section === 'tips-tricks') { |
|
| 352 | - /** @var ISettings $form */ |
|
| 353 | - $form = new Admin\TipsTricks($this->config); |
|
| 354 | - $forms[$form->getPriority()] = [$form]; |
|
| 355 | - } |
|
| 356 | - } catch (QueryException $e) { |
|
| 357 | - // skip |
|
| 358 | - } |
|
| 359 | - return $forms; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * @param string $section |
|
| 364 | - * @return ISection[] |
|
| 365 | - */ |
|
| 366 | - private function getBuiltInPersonalSettings($section) { |
|
| 367 | - $forms = []; |
|
| 368 | - try { |
|
| 369 | - if ($section === 'personal-info') { |
|
| 370 | - /** @var ISettings $form */ |
|
| 371 | - $form = new Personal\PersonalInfo($this->config, $this->userManager, $this->groupManager, $this->accountManager, $this->l10nFactory, $this->defaults); |
|
| 372 | - $forms[$form->getPriority()] = [$form]; |
|
| 373 | - } |
|
| 374 | - } catch (QueryException $e) { |
|
| 375 | - // skip |
|
| 376 | - } |
|
| 377 | - return $forms; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * @inheritdoc |
|
| 382 | - */ |
|
| 383 | - public function getAdminSettings($section) { |
|
| 384 | - $settings = $this->getBuiltInAdminSettings($section); |
|
| 385 | - $dbRows = $this->mapper->getAdminSettingsFromDB($section); |
|
| 386 | - |
|
| 387 | - foreach ($dbRows as $row) { |
|
| 388 | - if (!isset($settings[$row['priority']])) { |
|
| 389 | - $settings[$row['priority']] = []; |
|
| 390 | - } |
|
| 391 | - try { |
|
| 392 | - $settings[$row['priority']][] = $this->query($row['class']); |
|
| 393 | - } catch (QueryException $e) { |
|
| 394 | - // skip |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - ksort($settings); |
|
| 399 | - return $settings; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * @inheritdoc |
|
| 404 | - */ |
|
| 405 | - public function getPersonalSections() { |
|
| 406 | - $sections = [ |
|
| 407 | - 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
| 408 | - ]; |
|
| 409 | - return $sections; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * @inheritdoc |
|
| 414 | - */ |
|
| 415 | - public function getPersonalSettings($section) { |
|
| 416 | - $settings = $this->getBuiltInPersonalSettings($section); |
|
| 417 | - return $settings; |
|
| 418 | - } |
|
| 44 | + const TABLE_ADMIN_SETTINGS = 'admin_settings'; |
|
| 45 | + const TABLE_ADMIN_SECTIONS = 'admin_sections'; |
|
| 46 | + |
|
| 47 | + /** @var ILogger */ |
|
| 48 | + private $log; |
|
| 49 | + /** @var IDBConnection */ |
|
| 50 | + private $dbc; |
|
| 51 | + /** @var Mapper */ |
|
| 52 | + private $mapper; |
|
| 53 | + /** @var IL10N */ |
|
| 54 | + private $l; |
|
| 55 | + /** @var IConfig */ |
|
| 56 | + private $config; |
|
| 57 | + /** @var EncryptionManager */ |
|
| 58 | + private $encryptionManager; |
|
| 59 | + /** @var IUserManager */ |
|
| 60 | + private $userManager; |
|
| 61 | + /** @var ILockingProvider */ |
|
| 62 | + private $lockingProvider; |
|
| 63 | + /** @var IRequest */ |
|
| 64 | + private $request; |
|
| 65 | + /** @var IURLGenerator */ |
|
| 66 | + private $url; |
|
| 67 | + /** @var AccountManager */ |
|
| 68 | + private $accountManager; |
|
| 69 | + /** @var IGroupManager */ |
|
| 70 | + private $groupManager; |
|
| 71 | + /** @var IFactory */ |
|
| 72 | + private $l10nFactory; |
|
| 73 | + /** @var \OC_Defaults */ |
|
| 74 | + private $defaults; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param ILogger $log |
|
| 78 | + * @param IDBConnection $dbc |
|
| 79 | + * @param IL10N $l |
|
| 80 | + * @param IConfig $config |
|
| 81 | + * @param EncryptionManager $encryptionManager |
|
| 82 | + * @param IUserManager $userManager |
|
| 83 | + * @param ILockingProvider $lockingProvider |
|
| 84 | + * @param IRequest $request |
|
| 85 | + * @param Mapper $mapper |
|
| 86 | + * @param IURLGenerator $url |
|
| 87 | + * @param AccountManager $accountManager |
|
| 88 | + * @param IGroupManager $groupManager |
|
| 89 | + * @param IFactory $l10nFactory |
|
| 90 | + */ |
|
| 91 | + public function __construct( |
|
| 92 | + ILogger $log, |
|
| 93 | + IDBConnection $dbc, |
|
| 94 | + IL10N $l, |
|
| 95 | + IConfig $config, |
|
| 96 | + EncryptionManager $encryptionManager, |
|
| 97 | + IUserManager $userManager, |
|
| 98 | + ILockingProvider $lockingProvider, |
|
| 99 | + IRequest $request, |
|
| 100 | + Mapper $mapper, |
|
| 101 | + IURLGenerator $url, |
|
| 102 | + AccountManager $accountManager, |
|
| 103 | + IGroupManager $groupManager, |
|
| 104 | + IFactory $l10nFactory, |
|
| 105 | + \OC_Defaults $defaults |
|
| 106 | + ) { |
|
| 107 | + $this->log = $log; |
|
| 108 | + $this->dbc = $dbc; |
|
| 109 | + $this->mapper = $mapper; |
|
| 110 | + $this->l = $l; |
|
| 111 | + $this->config = $config; |
|
| 112 | + $this->encryptionManager = $encryptionManager; |
|
| 113 | + $this->userManager = $userManager; |
|
| 114 | + $this->lockingProvider = $lockingProvider; |
|
| 115 | + $this->request = $request; |
|
| 116 | + $this->url = $url; |
|
| 117 | + $this->accountManager = $accountManager; |
|
| 118 | + $this->groupManager = $groupManager; |
|
| 119 | + $this->l10nFactory = $l10nFactory; |
|
| 120 | + $this->defaults = $defaults; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @inheritdoc |
|
| 125 | + */ |
|
| 126 | + public function setupSettings(array $settings) { |
|
| 127 | + if (isset($settings[IManager::KEY_ADMIN_SECTION])) { |
|
| 128 | + $this->setupAdminSection($settings[IManager::KEY_ADMIN_SECTION]); |
|
| 129 | + } |
|
| 130 | + if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) { |
|
| 131 | + $this->setupAdminSettings($settings[IManager::KEY_ADMIN_SETTINGS]); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * attempts to remove an apps section and/or settings entry. A listener is |
|
| 137 | + * added centrally making sure that this method is called ones an app was |
|
| 138 | + * disabled. |
|
| 139 | + * |
|
| 140 | + * @param string $appId |
|
| 141 | + * @since 9.1.0 |
|
| 142 | + */ |
|
| 143 | + public function onAppDisabled($appId) { |
|
| 144 | + $appInfo = \OC_App::getAppInfo($appId); // hello static legacy |
|
| 145 | + |
|
| 146 | + if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) { |
|
| 147 | + $this->mapper->remove(self::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\')); |
|
| 148 | + } |
|
| 149 | + if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) { |
|
| 150 | + $this->mapper->remove(self::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\')); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + public function checkForOrphanedClassNames() { |
|
| 155 | + $tables = [self::TABLE_ADMIN_SECTIONS, self::TABLE_ADMIN_SETTINGS]; |
|
| 156 | + foreach ($tables as $table) { |
|
| 157 | + $classes = $this->mapper->getClasses($table); |
|
| 158 | + foreach ($classes as $className) { |
|
| 159 | + try { |
|
| 160 | + \OC::$server->query($className); |
|
| 161 | + } catch (QueryException $e) { |
|
| 162 | + $this->mapper->remove($table, $className); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @param string $sectionClassName |
|
| 170 | + */ |
|
| 171 | + private function setupAdminSection($sectionClassName) { |
|
| 172 | + if (!class_exists($sectionClassName)) { |
|
| 173 | + $this->log->debug('Could not find admin section class ' . $sectionClassName); |
|
| 174 | + return; |
|
| 175 | + } |
|
| 176 | + try { |
|
| 177 | + $section = $this->query($sectionClassName); |
|
| 178 | + } catch (QueryException $e) { |
|
| 179 | + // cancel |
|
| 180 | + return; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + if (!$section instanceof ISection) { |
|
| 184 | + $this->log->error( |
|
| 185 | + 'Admin section instance must implement \OCP\ISection. Invalid class: {class}', |
|
| 186 | + ['class' => $sectionClassName] |
|
| 187 | + ); |
|
| 188 | + return; |
|
| 189 | + } |
|
| 190 | + if (!$this->hasAdminSection(get_class($section))) { |
|
| 191 | + $this->addAdminSection($section); |
|
| 192 | + } else { |
|
| 193 | + $this->updateAdminSection($section); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + private function addAdminSection(ISection $section) { |
|
| 198 | + $this->mapper->add(self::TABLE_ADMIN_SECTIONS, [ |
|
| 199 | + 'id' => $section->getID(), |
|
| 200 | + 'class' => get_class($section), |
|
| 201 | + 'priority' => $section->getPriority(), |
|
| 202 | + ]); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + private function addAdminSettings(ISettings $settings) { |
|
| 206 | + $this->mapper->add(self::TABLE_ADMIN_SETTINGS, [ |
|
| 207 | + 'class' => get_class($settings), |
|
| 208 | + 'section' => $settings->getSection(), |
|
| 209 | + 'priority' => $settings->getPriority(), |
|
| 210 | + ]); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + private function updateAdminSettings(ISettings $settings) { |
|
| 214 | + $this->mapper->update( |
|
| 215 | + self::TABLE_ADMIN_SETTINGS, |
|
| 216 | + 'class', |
|
| 217 | + get_class($settings), |
|
| 218 | + [ |
|
| 219 | + 'section' => $settings->getSection(), |
|
| 220 | + 'priority' => $settings->getPriority(), |
|
| 221 | + ] |
|
| 222 | + ); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + private function updateAdminSection(ISection $section) { |
|
| 226 | + $this->mapper->update( |
|
| 227 | + self::TABLE_ADMIN_SECTIONS, |
|
| 228 | + 'class', |
|
| 229 | + get_class($section), |
|
| 230 | + [ |
|
| 231 | + 'id' => $section->getID(), |
|
| 232 | + 'priority' => $section->getPriority(), |
|
| 233 | + ] |
|
| 234 | + ); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * @param string $className |
|
| 239 | + * @return bool |
|
| 240 | + */ |
|
| 241 | + private function hasAdminSection($className) { |
|
| 242 | + return $this->mapper->has(self::TABLE_ADMIN_SECTIONS, $className); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @param string $className |
|
| 247 | + * @return bool |
|
| 248 | + */ |
|
| 249 | + private function hasAdminSettings($className) { |
|
| 250 | + return $this->mapper->has(self::TABLE_ADMIN_SETTINGS, $className); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + private function setupAdminSettings($settingsClassName) { |
|
| 254 | + if (!class_exists($settingsClassName)) { |
|
| 255 | + $this->log->debug('Could not find admin section class ' . $settingsClassName); |
|
| 256 | + return; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + try { |
|
| 260 | + /** @var ISettings $settings */ |
|
| 261 | + $settings = $this->query($settingsClassName); |
|
| 262 | + } catch (QueryException $e) { |
|
| 263 | + // cancel |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + if (!$settings instanceof ISettings) { |
|
| 268 | + $this->log->error( |
|
| 269 | + 'Admin section instance must implement \OCP\Settings\ISection. Invalid class: {class}', |
|
| 270 | + ['class' => $settingsClassName] |
|
| 271 | + ); |
|
| 272 | + return; |
|
| 273 | + } |
|
| 274 | + if (!$this->hasAdminSettings(get_class($settings))) { |
|
| 275 | + $this->addAdminSettings($settings); |
|
| 276 | + } else { |
|
| 277 | + $this->updateAdminSettings($settings); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + private function query($className) { |
|
| 282 | + try { |
|
| 283 | + return \OC::$server->query($className); |
|
| 284 | + } catch (QueryException $e) { |
|
| 285 | + $this->log->logException($e); |
|
| 286 | + throw $e; |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * @inheritdoc |
|
| 292 | + */ |
|
| 293 | + public function getAdminSections() { |
|
| 294 | + // built-in sections |
|
| 295 | + $sections = [ |
|
| 296 | + 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
| 297 | + 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
| 298 | + 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 299 | + 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 300 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 301 | + 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
| 302 | + ]; |
|
| 303 | + |
|
| 304 | + $rows = $this->mapper->getAdminSectionsFromDB(); |
|
| 305 | + |
|
| 306 | + foreach ($rows as $row) { |
|
| 307 | + if (!isset($sections[$row['priority']])) { |
|
| 308 | + $sections[$row['priority']] = []; |
|
| 309 | + } |
|
| 310 | + try { |
|
| 311 | + $sections[$row['priority']][] = $this->query($row['class']); |
|
| 312 | + } catch (QueryException $e) { |
|
| 313 | + // skip |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + ksort($sections); |
|
| 318 | + |
|
| 319 | + return $sections; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * @param string $section |
|
| 324 | + * @return ISection[] |
|
| 325 | + */ |
|
| 326 | + private function getBuiltInAdminSettings($section) { |
|
| 327 | + $forms = []; |
|
| 328 | + try { |
|
| 329 | + if ($section === 'server') { |
|
| 330 | + /** @var ISettings $form */ |
|
| 331 | + $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
| 332 | + $forms[$form->getPriority()] = [$form]; |
|
| 333 | + $form = new Admin\ServerDevNotice(); |
|
| 334 | + $forms[$form->getPriority()] = [$form]; |
|
| 335 | + } |
|
| 336 | + if ($section === 'encryption') { |
|
| 337 | + /** @var ISettings $form */ |
|
| 338 | + $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
| 339 | + $forms[$form->getPriority()] = [$form]; |
|
| 340 | + } |
|
| 341 | + if ($section === 'sharing') { |
|
| 342 | + /** @var ISettings $form */ |
|
| 343 | + $form = new Admin\Sharing($this->config); |
|
| 344 | + $forms[$form->getPriority()] = [$form]; |
|
| 345 | + } |
|
| 346 | + if ($section === 'additional') { |
|
| 347 | + /** @var ISettings $form */ |
|
| 348 | + $form = new Admin\Additional($this->config); |
|
| 349 | + $forms[$form->getPriority()] = [$form]; |
|
| 350 | + } |
|
| 351 | + if ($section === 'tips-tricks') { |
|
| 352 | + /** @var ISettings $form */ |
|
| 353 | + $form = new Admin\TipsTricks($this->config); |
|
| 354 | + $forms[$form->getPriority()] = [$form]; |
|
| 355 | + } |
|
| 356 | + } catch (QueryException $e) { |
|
| 357 | + // skip |
|
| 358 | + } |
|
| 359 | + return $forms; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * @param string $section |
|
| 364 | + * @return ISection[] |
|
| 365 | + */ |
|
| 366 | + private function getBuiltInPersonalSettings($section) { |
|
| 367 | + $forms = []; |
|
| 368 | + try { |
|
| 369 | + if ($section === 'personal-info') { |
|
| 370 | + /** @var ISettings $form */ |
|
| 371 | + $form = new Personal\PersonalInfo($this->config, $this->userManager, $this->groupManager, $this->accountManager, $this->l10nFactory, $this->defaults); |
|
| 372 | + $forms[$form->getPriority()] = [$form]; |
|
| 373 | + } |
|
| 374 | + } catch (QueryException $e) { |
|
| 375 | + // skip |
|
| 376 | + } |
|
| 377 | + return $forms; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * @inheritdoc |
|
| 382 | + */ |
|
| 383 | + public function getAdminSettings($section) { |
|
| 384 | + $settings = $this->getBuiltInAdminSettings($section); |
|
| 385 | + $dbRows = $this->mapper->getAdminSettingsFromDB($section); |
|
| 386 | + |
|
| 387 | + foreach ($dbRows as $row) { |
|
| 388 | + if (!isset($settings[$row['priority']])) { |
|
| 389 | + $settings[$row['priority']] = []; |
|
| 390 | + } |
|
| 391 | + try { |
|
| 392 | + $settings[$row['priority']][] = $this->query($row['class']); |
|
| 393 | + } catch (QueryException $e) { |
|
| 394 | + // skip |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + ksort($settings); |
|
| 399 | + return $settings; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * @inheritdoc |
|
| 404 | + */ |
|
| 405 | + public function getPersonalSections() { |
|
| 406 | + $sections = [ |
|
| 407 | + 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
| 408 | + ]; |
|
| 409 | + return $sections; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * @inheritdoc |
|
| 414 | + */ |
|
| 415 | + public function getPersonalSettings($section) { |
|
| 416 | + $settings = $this->getBuiltInPersonalSettings($section); |
|
| 417 | + return $settings; |
|
| 418 | + } |
|
| 419 | 419 | } |
@@ -34,173 +34,173 @@ |
||
| 34 | 34 | use OCP\Settings\ISettings; |
| 35 | 35 | |
| 36 | 36 | class PersonalInfo implements ISettings { |
| 37 | - /** @var IConfig */ |
|
| 38 | - private $config; |
|
| 39 | - /** @var IUserManager */ |
|
| 40 | - private $userManager; |
|
| 41 | - /** @var AccountManager */ |
|
| 42 | - private $accountManager; |
|
| 43 | - /** @var IGroupManager */ |
|
| 44 | - private $groupManager; |
|
| 45 | - /** @var IFactory */ |
|
| 46 | - private $l10nFactory; |
|
| 47 | - |
|
| 48 | - const COMMON_LANGUAGE_CODES = [ |
|
| 49 | - 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', |
|
| 50 | - 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko' |
|
| 51 | - ]; |
|
| 52 | - /** @var \OC_Defaults */ |
|
| 53 | - private $defaults; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param IConfig $config |
|
| 57 | - * @param IUserManager $userManager |
|
| 58 | - * @param IGroupManager $groupManager |
|
| 59 | - * @param AccountManager $accountManager |
|
| 60 | - * @param IFactory $l10nFactory |
|
| 61 | - */ |
|
| 62 | - public function __construct( |
|
| 63 | - IConfig $config, |
|
| 64 | - IUserManager $userManager, |
|
| 65 | - IGroupManager $groupManager, |
|
| 66 | - AccountManager $accountManager, |
|
| 67 | - IFactory $l10nFactory, |
|
| 68 | - \OC_Defaults $defaults |
|
| 69 | - ) { |
|
| 70 | - $this->config = $config; |
|
| 71 | - $this->userManager = $userManager; |
|
| 72 | - $this->accountManager = $accountManager; |
|
| 73 | - $this->groupManager = $groupManager; |
|
| 74 | - $this->l10nFactory = $l10nFactory; |
|
| 75 | - $this->defaults = $defaults; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 80 | - * @since 9.1 |
|
| 81 | - */ |
|
| 82 | - public function getForm() { |
|
| 83 | - $lookupServerUploadEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
| 84 | - $lookupServerUploadEnabled = $lookupServerUploadEnabled === 'yes'; |
|
| 85 | - |
|
| 86 | - $uid = \OC_User::getUser(); |
|
| 87 | - $user = $this->userManager->get($uid); |
|
| 88 | - |
|
| 89 | - $userData = $this->accountManager->getUser($user); |
|
| 90 | - list($activeLanguage, $commonLanguages, $languages) = $this->getLanguages($user); |
|
| 91 | - |
|
| 92 | - //links to clients |
|
| 93 | - $clients = [ |
|
| 94 | - 'desktop' => $this->config->getSystemValue('customclient_desktop', $this->defaults->getSyncClientUrl()), |
|
| 95 | - 'android' => $this->config->getSystemValue('customclient_android', $this->defaults->getAndroidClientUrl()), |
|
| 96 | - 'ios' => $this->config->getSystemValue('customclient_ios', $this->defaults->getiOSClientUrl()) |
|
| 97 | - ]; |
|
| 98 | - |
|
| 99 | - $parameters = [ |
|
| 100 | - 'avatarChangeSupported' => \OC_User::canUserChangeAvatar($uid), |
|
| 101 | - 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
| 102 | - 'avatar_scope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
|
| 103 | - 'displayNameChangeSupported' => \OC_User::canUserChangeDisplayName($uid), |
|
| 104 | - 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
| 105 | - 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
|
| 106 | - 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
|
| 107 | - 'emailMesage' => '', |
|
| 108 | - 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
|
| 109 | - 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
|
| 110 | - 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
|
| 111 | - 'address', $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
|
| 112 | - 'addressScope', $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
| 113 | - 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
|
| 114 | - 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
| 115 | - 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
|
| 116 | - 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
|
| 117 | - 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
|
| 118 | - 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
|
| 119 | - 'groups' => $this->groupManager->getUserGroups($user), |
|
| 120 | - 'passwordChangeSupported' => \OC_User::canUserChangePassword($uid), |
|
| 121 | - 'activelanguage' => $activeLanguage, |
|
| 122 | - 'commonlanguages' => $commonLanguages, |
|
| 123 | - 'languages' => $languages, |
|
| 124 | - 'clients' => $clients, |
|
| 125 | - ]; |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return string the section ID, e.g. 'sharing' |
|
| 133 | - * @since 9.1 |
|
| 134 | - */ |
|
| 135 | - public function getSection() { |
|
| 136 | - return 'personal-info'; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return int whether the form should be rather on the top or bottom of |
|
| 141 | - * the admin section. The forms are arranged in ascending order of the |
|
| 142 | - * priority values. It is required to return a value between 0 and 100. |
|
| 143 | - * |
|
| 144 | - * E.g.: 70 |
|
| 145 | - * @since 9.1 |
|
| 146 | - */ |
|
| 147 | - public function getPriority() { |
|
| 148 | - return 10; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - private function getLanguages(IUser $user) { |
|
| 152 | - $uid = $user->getUID(); |
|
| 153 | - |
|
| 154 | - $commonLanguages = []; |
|
| 155 | - $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
| 156 | - $languageCodes = $this->l10nFactory->findAvailableLanguages(); |
|
| 157 | - foreach($languageCodes as $lang) { |
|
| 158 | - $l = \OC::$server->getL10N('settings', $lang); |
|
| 159 | - // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version |
|
| 160 | - $potentialName = (string) $l->t('__language_name__'); |
|
| 161 | - if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file |
|
| 162 | - $ln = array('code' => $lang, 'name' => $potentialName); |
|
| 163 | - } elseif ($lang === 'en') { |
|
| 164 | - $ln = ['code' => $lang, 'name' => 'English (US)']; |
|
| 165 | - }else{//fallback to language code |
|
| 166 | - $ln=array('code'=>$lang, 'name'=>$lang); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // put appropriate languages into appropriate arrays, to print them sorted |
|
| 170 | - // used language -> common languages -> divider -> other languages |
|
| 171 | - if ($lang === $userLang) { |
|
| 172 | - $userLang = $ln; |
|
| 173 | - } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) { |
|
| 174 | - $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln; |
|
| 175 | - } else { |
|
| 176 | - $languages[]=$ln; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // if user language is not available but set somehow: show the actual code as name |
|
| 181 | - if (!is_array($userLang)) { |
|
| 182 | - $userLang = [ |
|
| 183 | - 'code' => $userLang, |
|
| 184 | - 'name' => $userLang, |
|
| 185 | - ]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - ksort($commonLanguages); |
|
| 189 | - |
|
| 190 | - // sort now by displayed language not the iso-code |
|
| 191 | - usort( $languages, function ($a, $b) { |
|
| 192 | - if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) { |
|
| 193 | - // If a doesn't have a name, but b does, list b before a |
|
| 194 | - return 1; |
|
| 195 | - } |
|
| 196 | - if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) { |
|
| 197 | - // If a does have a name, but b doesn't, list a before b |
|
| 198 | - return -1; |
|
| 199 | - } |
|
| 200 | - // Otherwise compare the names |
|
| 201 | - return strcmp($a['name'], $b['name']); |
|
| 202 | - }); |
|
| 203 | - |
|
| 204 | - return [$userLang, $commonLanguages, $languages]; |
|
| 205 | - } |
|
| 37 | + /** @var IConfig */ |
|
| 38 | + private $config; |
|
| 39 | + /** @var IUserManager */ |
|
| 40 | + private $userManager; |
|
| 41 | + /** @var AccountManager */ |
|
| 42 | + private $accountManager; |
|
| 43 | + /** @var IGroupManager */ |
|
| 44 | + private $groupManager; |
|
| 45 | + /** @var IFactory */ |
|
| 46 | + private $l10nFactory; |
|
| 47 | + |
|
| 48 | + const COMMON_LANGUAGE_CODES = [ |
|
| 49 | + 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', |
|
| 50 | + 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko' |
|
| 51 | + ]; |
|
| 52 | + /** @var \OC_Defaults */ |
|
| 53 | + private $defaults; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param IConfig $config |
|
| 57 | + * @param IUserManager $userManager |
|
| 58 | + * @param IGroupManager $groupManager |
|
| 59 | + * @param AccountManager $accountManager |
|
| 60 | + * @param IFactory $l10nFactory |
|
| 61 | + */ |
|
| 62 | + public function __construct( |
|
| 63 | + IConfig $config, |
|
| 64 | + IUserManager $userManager, |
|
| 65 | + IGroupManager $groupManager, |
|
| 66 | + AccountManager $accountManager, |
|
| 67 | + IFactory $l10nFactory, |
|
| 68 | + \OC_Defaults $defaults |
|
| 69 | + ) { |
|
| 70 | + $this->config = $config; |
|
| 71 | + $this->userManager = $userManager; |
|
| 72 | + $this->accountManager = $accountManager; |
|
| 73 | + $this->groupManager = $groupManager; |
|
| 74 | + $this->l10nFactory = $l10nFactory; |
|
| 75 | + $this->defaults = $defaults; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 80 | + * @since 9.1 |
|
| 81 | + */ |
|
| 82 | + public function getForm() { |
|
| 83 | + $lookupServerUploadEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
| 84 | + $lookupServerUploadEnabled = $lookupServerUploadEnabled === 'yes'; |
|
| 85 | + |
|
| 86 | + $uid = \OC_User::getUser(); |
|
| 87 | + $user = $this->userManager->get($uid); |
|
| 88 | + |
|
| 89 | + $userData = $this->accountManager->getUser($user); |
|
| 90 | + list($activeLanguage, $commonLanguages, $languages) = $this->getLanguages($user); |
|
| 91 | + |
|
| 92 | + //links to clients |
|
| 93 | + $clients = [ |
|
| 94 | + 'desktop' => $this->config->getSystemValue('customclient_desktop', $this->defaults->getSyncClientUrl()), |
|
| 95 | + 'android' => $this->config->getSystemValue('customclient_android', $this->defaults->getAndroidClientUrl()), |
|
| 96 | + 'ios' => $this->config->getSystemValue('customclient_ios', $this->defaults->getiOSClientUrl()) |
|
| 97 | + ]; |
|
| 98 | + |
|
| 99 | + $parameters = [ |
|
| 100 | + 'avatarChangeSupported' => \OC_User::canUserChangeAvatar($uid), |
|
| 101 | + 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
| 102 | + 'avatar_scope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
|
| 103 | + 'displayNameChangeSupported' => \OC_User::canUserChangeDisplayName($uid), |
|
| 104 | + 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
| 105 | + 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
|
| 106 | + 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
|
| 107 | + 'emailMesage' => '', |
|
| 108 | + 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
|
| 109 | + 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
|
| 110 | + 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
|
| 111 | + 'address', $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
|
| 112 | + 'addressScope', $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
| 113 | + 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
|
| 114 | + 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
| 115 | + 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
|
| 116 | + 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
|
| 117 | + 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
|
| 118 | + 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
|
| 119 | + 'groups' => $this->groupManager->getUserGroups($user), |
|
| 120 | + 'passwordChangeSupported' => \OC_User::canUserChangePassword($uid), |
|
| 121 | + 'activelanguage' => $activeLanguage, |
|
| 122 | + 'commonlanguages' => $commonLanguages, |
|
| 123 | + 'languages' => $languages, |
|
| 124 | + 'clients' => $clients, |
|
| 125 | + ]; |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return string the section ID, e.g. 'sharing' |
|
| 133 | + * @since 9.1 |
|
| 134 | + */ |
|
| 135 | + public function getSection() { |
|
| 136 | + return 'personal-info'; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return int whether the form should be rather on the top or bottom of |
|
| 141 | + * the admin section. The forms are arranged in ascending order of the |
|
| 142 | + * priority values. It is required to return a value between 0 and 100. |
|
| 143 | + * |
|
| 144 | + * E.g.: 70 |
|
| 145 | + * @since 9.1 |
|
| 146 | + */ |
|
| 147 | + public function getPriority() { |
|
| 148 | + return 10; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + private function getLanguages(IUser $user) { |
|
| 152 | + $uid = $user->getUID(); |
|
| 153 | + |
|
| 154 | + $commonLanguages = []; |
|
| 155 | + $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
| 156 | + $languageCodes = $this->l10nFactory->findAvailableLanguages(); |
|
| 157 | + foreach($languageCodes as $lang) { |
|
| 158 | + $l = \OC::$server->getL10N('settings', $lang); |
|
| 159 | + // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version |
|
| 160 | + $potentialName = (string) $l->t('__language_name__'); |
|
| 161 | + if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file |
|
| 162 | + $ln = array('code' => $lang, 'name' => $potentialName); |
|
| 163 | + } elseif ($lang === 'en') { |
|
| 164 | + $ln = ['code' => $lang, 'name' => 'English (US)']; |
|
| 165 | + }else{//fallback to language code |
|
| 166 | + $ln=array('code'=>$lang, 'name'=>$lang); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // put appropriate languages into appropriate arrays, to print them sorted |
|
| 170 | + // used language -> common languages -> divider -> other languages |
|
| 171 | + if ($lang === $userLang) { |
|
| 172 | + $userLang = $ln; |
|
| 173 | + } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) { |
|
| 174 | + $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln; |
|
| 175 | + } else { |
|
| 176 | + $languages[]=$ln; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // if user language is not available but set somehow: show the actual code as name |
|
| 181 | + if (!is_array($userLang)) { |
|
| 182 | + $userLang = [ |
|
| 183 | + 'code' => $userLang, |
|
| 184 | + 'name' => $userLang, |
|
| 185 | + ]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + ksort($commonLanguages); |
|
| 189 | + |
|
| 190 | + // sort now by displayed language not the iso-code |
|
| 191 | + usort( $languages, function ($a, $b) { |
|
| 192 | + if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) { |
|
| 193 | + // If a doesn't have a name, but b does, list b before a |
|
| 194 | + return 1; |
|
| 195 | + } |
|
| 196 | + if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) { |
|
| 197 | + // If a does have a name, but b doesn't, list a before b |
|
| 198 | + return -1; |
|
| 199 | + } |
|
| 200 | + // Otherwise compare the names |
|
| 201 | + return strcmp($a['name'], $b['name']); |
|
| 202 | + }); |
|
| 203 | + |
|
| 204 | + return [$userLang, $commonLanguages, $languages]; |
|
| 205 | + } |
|
| 206 | 206 | } |
@@ -26,138 +26,138 @@ |
||
| 26 | 26 | use OCP\IDBConnection; |
| 27 | 27 | |
| 28 | 28 | class Mapper { |
| 29 | - const TABLE_ADMIN_SETTINGS = 'admin_settings'; |
|
| 30 | - const TABLE_ADMIN_SECTIONS = 'admin_sections'; |
|
| 31 | - |
|
| 32 | - /** @var IDBConnection */ |
|
| 33 | - private $dbc; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @param IDBConnection $dbc |
|
| 37 | - */ |
|
| 38 | - public function __construct(IDBConnection $dbc) { |
|
| 39 | - $this->dbc = $dbc; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Get the configured admin settings from the database for the provided section |
|
| 44 | - * |
|
| 45 | - * @param string $section |
|
| 46 | - * @return array[] [['class' => string, 'priority' => int], ...] |
|
| 47 | - */ |
|
| 48 | - public function getAdminSettingsFromDB($section) { |
|
| 49 | - $query = $this->dbc->getQueryBuilder(); |
|
| 50 | - $query->select(['class', 'priority']) |
|
| 51 | - ->from(self::TABLE_ADMIN_SETTINGS) |
|
| 52 | - ->where($query->expr()->eq('section', $this->dbc->getQueryBuilder()->createParameter('section'))) |
|
| 53 | - ->setParameter('section', $section); |
|
| 54 | - |
|
| 55 | - $result = $query->execute(); |
|
| 56 | - return $result->fetchAll(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Get the configured admin sections from the database |
|
| 61 | - * |
|
| 62 | - * @return array[] [['class' => string, 'priority' => int], ...] |
|
| 63 | - */ |
|
| 64 | - public function getAdminSectionsFromDB() { |
|
| 65 | - $query = $this->dbc->getQueryBuilder(); |
|
| 66 | - $query->selectDistinct('s.class') |
|
| 67 | - ->addSelect('s.priority') |
|
| 68 | - ->from(self::TABLE_ADMIN_SECTIONS, 's') |
|
| 69 | - ->from(self::TABLE_ADMIN_SETTINGS, 'f') |
|
| 70 | - ->where($query->expr()->eq('s.id', 'f.section')); |
|
| 71 | - $result = $query->execute(); |
|
| 72 | - return array_map(function ($row) { |
|
| 73 | - $row['priority'] = (int)$row['priority']; |
|
| 74 | - return $row; |
|
| 75 | - }, $result->fetchAll()); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param string $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS |
|
| 80 | - * @param array $values |
|
| 81 | - */ |
|
| 82 | - public function add($table, array $values) { |
|
| 83 | - $query = $this->dbc->getQueryBuilder(); |
|
| 84 | - $values = array_map(function ($value) use ($query) { |
|
| 85 | - return $query->createNamedParameter($value); |
|
| 86 | - }, $values); |
|
| 87 | - $query->insert($table)->values($values); |
|
| 88 | - $query->execute(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * returns the registered classes in the given table |
|
| 93 | - * |
|
| 94 | - * @param $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS |
|
| 95 | - * @return string[] |
|
| 96 | - */ |
|
| 97 | - public function getClasses($table) { |
|
| 98 | - $q = $this->dbc->getQueryBuilder(); |
|
| 99 | - $resultStatement = $q->select('class') |
|
| 100 | - ->from($table) |
|
| 101 | - ->execute(); |
|
| 102 | - $data = $resultStatement->fetchAll(); |
|
| 103 | - $resultStatement->closeCursor(); |
|
| 104 | - |
|
| 105 | - return array_map(function ($row) { |
|
| 106 | - return $row['class']; |
|
| 107 | - }, $data); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Check if a class is configured in the database |
|
| 112 | - * |
|
| 113 | - * @param string $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS |
|
| 114 | - * @param string $className |
|
| 115 | - * @return bool |
|
| 116 | - */ |
|
| 117 | - public function has($table, $className) { |
|
| 118 | - $query = $this->dbc->getQueryBuilder(); |
|
| 119 | - $query->select('class') |
|
| 120 | - ->from($table) |
|
| 121 | - ->where($query->expr()->eq('class', $query->createNamedParameter($className))) |
|
| 122 | - ->setMaxResults(1); |
|
| 123 | - |
|
| 124 | - $result = $query->execute(); |
|
| 125 | - $row = $result->fetch(); |
|
| 126 | - $result->closeCursor(); |
|
| 127 | - |
|
| 128 | - return (bool)$row; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * deletes an settings or admin entry from the given table |
|
| 133 | - * |
|
| 134 | - * @param $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS |
|
| 135 | - * @param $className |
|
| 136 | - */ |
|
| 137 | - public function remove($table, $className) { |
|
| 138 | - $query = $this->dbc->getQueryBuilder(); |
|
| 139 | - $query->delete($table) |
|
| 140 | - ->where($query->expr()->eq('class', $query->createNamedParameter($className))); |
|
| 141 | - |
|
| 142 | - $query->execute(); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @param string $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS |
|
| 147 | - * @param string $idCol |
|
| 148 | - * @param string $id |
|
| 149 | - * @param array $values |
|
| 150 | - */ |
|
| 151 | - public function update($table, $idCol, $id, $values) { |
|
| 152 | - $query = $this->dbc->getQueryBuilder(); |
|
| 153 | - $query->update($table); |
|
| 154 | - foreach ($values as $key => $value) { |
|
| 155 | - $query->set($key, $query->createNamedParameter($value)); |
|
| 156 | - } |
|
| 157 | - $query |
|
| 158 | - ->where($query->expr()->eq($idCol, $query->createParameter($idCol))) |
|
| 159 | - ->setParameter($idCol, $id) |
|
| 160 | - ->execute(); |
|
| 161 | - } |
|
| 29 | + const TABLE_ADMIN_SETTINGS = 'admin_settings'; |
|
| 30 | + const TABLE_ADMIN_SECTIONS = 'admin_sections'; |
|
| 31 | + |
|
| 32 | + /** @var IDBConnection */ |
|
| 33 | + private $dbc; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param IDBConnection $dbc |
|
| 37 | + */ |
|
| 38 | + public function __construct(IDBConnection $dbc) { |
|
| 39 | + $this->dbc = $dbc; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Get the configured admin settings from the database for the provided section |
|
| 44 | + * |
|
| 45 | + * @param string $section |
|
| 46 | + * @return array[] [['class' => string, 'priority' => int], ...] |
|
| 47 | + */ |
|
| 48 | + public function getAdminSettingsFromDB($section) { |
|
| 49 | + $query = $this->dbc->getQueryBuilder(); |
|
| 50 | + $query->select(['class', 'priority']) |
|
| 51 | + ->from(self::TABLE_ADMIN_SETTINGS) |
|
| 52 | + ->where($query->expr()->eq('section', $this->dbc->getQueryBuilder()->createParameter('section'))) |
|
| 53 | + ->setParameter('section', $section); |
|
| 54 | + |
|
| 55 | + $result = $query->execute(); |
|
| 56 | + return $result->fetchAll(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Get the configured admin sections from the database |
|
| 61 | + * |
|
| 62 | + * @return array[] [['class' => string, 'priority' => int], ...] |
|
| 63 | + */ |
|
| 64 | + public function getAdminSectionsFromDB() { |
|
| 65 | + $query = $this->dbc->getQueryBuilder(); |
|
| 66 | + $query->selectDistinct('s.class') |
|
| 67 | + ->addSelect('s.priority') |
|
| 68 | + ->from(self::TABLE_ADMIN_SECTIONS, 's') |
|
| 69 | + ->from(self::TABLE_ADMIN_SETTINGS, 'f') |
|
| 70 | + ->where($query->expr()->eq('s.id', 'f.section')); |
|
| 71 | + $result = $query->execute(); |
|
| 72 | + return array_map(function ($row) { |
|
| 73 | + $row['priority'] = (int)$row['priority']; |
|
| 74 | + return $row; |
|
| 75 | + }, $result->fetchAll()); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param string $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS |
|
| 80 | + * @param array $values |
|
| 81 | + */ |
|
| 82 | + public function add($table, array $values) { |
|
| 83 | + $query = $this->dbc->getQueryBuilder(); |
|
| 84 | + $values = array_map(function ($value) use ($query) { |
|
| 85 | + return $query->createNamedParameter($value); |
|
| 86 | + }, $values); |
|
| 87 | + $query->insert($table)->values($values); |
|
| 88 | + $query->execute(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * returns the registered classes in the given table |
|
| 93 | + * |
|
| 94 | + * @param $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS |
|
| 95 | + * @return string[] |
|
| 96 | + */ |
|
| 97 | + public function getClasses($table) { |
|
| 98 | + $q = $this->dbc->getQueryBuilder(); |
|
| 99 | + $resultStatement = $q->select('class') |
|
| 100 | + ->from($table) |
|
| 101 | + ->execute(); |
|
| 102 | + $data = $resultStatement->fetchAll(); |
|
| 103 | + $resultStatement->closeCursor(); |
|
| 104 | + |
|
| 105 | + return array_map(function ($row) { |
|
| 106 | + return $row['class']; |
|
| 107 | + }, $data); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Check if a class is configured in the database |
|
| 112 | + * |
|
| 113 | + * @param string $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS |
|
| 114 | + * @param string $className |
|
| 115 | + * @return bool |
|
| 116 | + */ |
|
| 117 | + public function has($table, $className) { |
|
| 118 | + $query = $this->dbc->getQueryBuilder(); |
|
| 119 | + $query->select('class') |
|
| 120 | + ->from($table) |
|
| 121 | + ->where($query->expr()->eq('class', $query->createNamedParameter($className))) |
|
| 122 | + ->setMaxResults(1); |
|
| 123 | + |
|
| 124 | + $result = $query->execute(); |
|
| 125 | + $row = $result->fetch(); |
|
| 126 | + $result->closeCursor(); |
|
| 127 | + |
|
| 128 | + return (bool)$row; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * deletes an settings or admin entry from the given table |
|
| 133 | + * |
|
| 134 | + * @param $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS |
|
| 135 | + * @param $className |
|
| 136 | + */ |
|
| 137 | + public function remove($table, $className) { |
|
| 138 | + $query = $this->dbc->getQueryBuilder(); |
|
| 139 | + $query->delete($table) |
|
| 140 | + ->where($query->expr()->eq('class', $query->createNamedParameter($className))); |
|
| 141 | + |
|
| 142 | + $query->execute(); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @param string $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS |
|
| 147 | + * @param string $idCol |
|
| 148 | + * @param string $id |
|
| 149 | + * @param array $values |
|
| 150 | + */ |
|
| 151 | + public function update($table, $idCol, $id, $values) { |
|
| 152 | + $query = $this->dbc->getQueryBuilder(); |
|
| 153 | + $query->update($table); |
|
| 154 | + foreach ($values as $key => $value) { |
|
| 155 | + $query->set($key, $query->createNamedParameter($value)); |
|
| 156 | + } |
|
| 157 | + $query |
|
| 158 | + ->where($query->expr()->eq($idCol, $query->createParameter($idCol))) |
|
| 159 | + ->setParameter($idCol, $id) |
|
| 160 | + ->execute(); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | } |