Skip to content

Commit

Permalink
NavigationController: Adjust how to load navigation items
Browse files Browse the repository at this point in the history
refs #10246
  • Loading branch information
Johannes Meyer committed Sep 30, 2015
1 parent 6a61d4a commit 6b31898
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
59 changes: 52 additions & 7 deletions application/controllers/NavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,63 @@ protected function listItemTypes()
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();
Expand Down Expand Up @@ -104,9 +149,8 @@ public function indexAction()
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();
Expand Down Expand Up @@ -302,6 +346,7 @@ public function unshareAction()
$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');

Expand Down
12 changes: 6 additions & 6 deletions application/views/scripts/navigation/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
<th style="width: 5em"><?= $this->translate('Remove'); ?></th>
</thead>
<tbody>
<?php foreach ($items as $name => $item): ?>
<?php foreach ($items as $item): ?>
<tr>
<td><?= $this->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)
)
); ?></td>
<td><?= $item->type && isset($types[$item->type])
Expand All @@ -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)
)
); ?></td>
</tr>
Expand Down
10 changes: 5 additions & 5 deletions application/views/scripts/navigation/shared.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ if (! $this->compact): ?>
<th style="width: 5em"><?= $this->translate('Unshare'); ?></th>
</thead>
<tbody>
<?php foreach ($items as $name => $item): ?>
<?php foreach ($items as $item): ?>
<tr>
<td><?= $this->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)
)
); ?></td>
<td><?= $item->type && isset($types[$item->type])
Expand All @@ -55,7 +55,7 @@ if (! $this->compact): ?>
); ?></td>
<?php else: ?>
<td data-base-target="_self"><?= $removeForm
->setDefault('name', $name)
->setDefault('name', $item->name)
->setAction(Url::fromPath(
'navigation/unshare',
array('type' => $item->type, 'owner' => $item->owner)
Expand Down

0 comments on commit 6b31898

Please sign in to comment.