parent
6a61d4aa25
commit
6b31898566
|
@ -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');
|
||||
|
||||
|
|
|
@ -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])
|
||||
|
@ -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>
|
||||
|
|
|
@ -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])
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue