From 6b31898566b97568cbb232e5e611b61371588ff9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 12:22:48 +0200 Subject: [PATCH] NavigationController: Adjust how to load navigation items refs #10246 --- .../controllers/NavigationController.php | 59 ++++++++++++++++--- .../views/scripts/navigation/index.phtml | 12 ++-- .../views/scripts/navigation/shared.phtml | 10 ++-- 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index 577882f2d..c407b3e1a 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -63,18 +63,63 @@ class NavigationController extends Controller return $types; } + /** + * Return all shared navigation item configurations + * + * @param string $owner A username if only items shared by a specific user are desired + * + * @return array + */ + protected function fetchSharedNavigationItemConfigs($owner = null) + { + $configs = array(); + foreach ($this->itemTypeConfig as $type => $_) { + $config = Config::navigation($type); + $config->getConfigObject()->setKeyColumn('name'); + $query = $config->select(); + if ($owner !== null) { + $query->where('owner', $owner); + } + + foreach ($query as $itemConfig) { + $configs[] = $itemConfig; + } + } + + return $configs; + } + + /** + * Return all user navigation item configurations + * + * @param string $username + * + * @return array + */ + protected function fetchUserNavigationItemConfigs($username) + { + $configs = array(); + foreach ($this->itemTypeConfig as $type => $_) { + $config = Config::navigation($type, $username); + $config->getConfigObject()->setKeyColumn('name'); + foreach ($config->select() as $itemConfig) { + $configs[] = $itemConfig; + } + } + + return $configs; + } + /** * Show the current user a list of his/her navigation items */ public function indexAction() { $user = $this->Auth()->getUser(); - $ds = new ArrayDatasource(array_merge( - Config::app('navigation')->select()->where('owner', $user->getUsername())->fetchAll(), - iterator_to_array($user->loadNavigationConfig()) + $this->fetchSharedNavigationItemConfigs($user->getUsername()), + $this->fetchUserNavigationItemConfigs($user->getUsername()) )); - $ds->setKeyColumn('name'); $query = $ds->select(); $this->view->types = $this->listItemTypes(); @@ -104,9 +149,8 @@ class NavigationController extends Controller public function sharedAction() { $this->assertPermission('config/application/navigation'); - $config = Config::app('navigation'); - $config->getConfigObject()->setKeyColumn('name'); - $query = $config->select(); + $ds = new ArrayDatasource($this->fetchSharedNavigationItemConfigs()); + $query = $ds->select(); $removeForm = new Form(); $removeForm->setUidDisabled(); @@ -302,6 +346,7 @@ class NavigationController extends Controller $this->assertPermission('config/application/navigation'); $this->assertHttpMethod('POST'); + // TODO: I'd like these being form fields $itemType = $this->params->getRequired('type'); $itemOwner = $this->params->getRequired('owner'); diff --git a/application/views/scripts/navigation/index.phtml b/application/views/scripts/navigation/index.phtml index 1cf0374f9..2f77d0995 100644 --- a/application/views/scripts/navigation/index.phtml +++ b/application/views/scripts/navigation/index.phtml @@ -22,17 +22,17 @@ translate('Remove'); ?> - $item): ?> + qlink( - $name, + $item->name, 'navigation/edit', array( - 'name' => $name, + 'name' => $item->name, 'type' => $item->type ), array( - 'title' => sprintf($this->translate('Edit navigation item %s'), $name) + 'title' => sprintf($this->translate('Edit navigation item %s'), $item->name) ) ); ?> type && isset($types[$item->type]) @@ -43,12 +43,12 @@ '', 'navigation/remove', array( - 'name' => $name, + 'name' => $item->name, 'type' => $item->type ), array( 'icon' => 'trash', - 'title' => sprintf($this->translate('Remove navigation item %s'), $name) + 'title' => sprintf($this->translate('Remove navigation item %s'), $item->name) ) ); ?> diff --git a/application/views/scripts/navigation/shared.phtml b/application/views/scripts/navigation/shared.phtml index e35b01539..5d0a3107f 100644 --- a/application/views/scripts/navigation/shared.phtml +++ b/application/views/scripts/navigation/shared.phtml @@ -23,19 +23,19 @@ if (! $this->compact): ?> translate('Unshare'); ?> - $item): ?> + qlink( - $name, + $item->name, 'navigation/edit', array( - 'name' => $name, + 'name' => $item->name, 'type' => $item->type, 'owner' => $item->owner, 'referrer' => 'shared' ), array( - 'title' => sprintf($this->translate('Edit shared navigation item %s'), $name) + 'title' => sprintf($this->translate('Edit shared navigation item %s'), $item->name) ) ); ?> type && isset($types[$item->type]) @@ -55,7 +55,7 @@ if (! $this->compact): ?> ); ?> setDefault('name', $name) + ->setDefault('name', $item->name) ->setAction(Url::fromPath( 'navigation/unshare', array('type' => $item->type, 'owner' => $item->owner)