Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 1b940a9

Browse files
zachmullenyuzhengZ
authored andcommitted
BUG: refs #0384. Fix Folder::getItemsFiltered() to display shared items
If an item was shared in two different folders that were both being queried in the same ajax call (such as two top level folders in the same tree), the item would only be returned for one of the parent folders, not all of them.
1 parent 9c02085 commit 1b940a9

File tree

2 files changed

+51
-61
lines changed

2 files changed

+51
-61
lines changed

core/controllers/BrowseController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ public function selectfolderAction()
253253
/** get getfolders content (ajax function for the treetable) */
254254
public function getfolderscontentAction()
255255
{
256-
$this->requireAjaxRequest();
257256
$this->_helper->layout->disableLayout();
258257
$this->_helper->viewRenderer->setNoRender();
259258
$folderIds = $this->_getParam('folders');

core/models/pdo/FolderModel.php

Lines changed: 51 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -601,50 +601,49 @@ function getItemsFiltered($folder, $userDao = null, $policy = 0)
601601
}
602602
}
603603

604-
$subqueryUser = $this->database->select()
605-
->setIntegrityCheck(false)
606-
->from(array('f' => 'item'))
607-
->join(array('p' => 'itempolicyuser'),
608-
'f.item_id = p.item_id',
609-
array('p.policy'))
610-
->join(array('i' => 'item2folder'),
611-
$this->database->getDB()->quoteInto('i.folder_id IN (?)', $folderIds).'
612-
AND i.item_id = p.item_id', array('i.folder_id'))
613-
->where('policy >= ?', $policy)
614-
->where('user_id = ? ', $userId);
615-
616-
$subqueryGroup = $this->database->select()
617-
->setIntegrityCheck(false)
618-
->from(array('f' => 'item'))
619-
->join(array('p' => 'itempolicygroup'),
620-
'f.item_id = p.item_id',
621-
array('p.policy'))
622-
->join(array('i' => 'item2folder'),
623-
$this->database->getDB()->quoteInto('i.folder_id IN (?)', $folderIds).'
624-
AND i.item_id = p.item_id', array('i.folder_id'))
625-
->where('policy >= ?', $policy)
626-
->where('( '.$this->database->getDB()->quoteInto('p.group_id = ? ', MIDAS_GROUP_ANONYMOUS_KEY).' OR
627-
p.group_id IN (' .new Zend_Db_Expr(
628-
$this->database->select()
629-
->setIntegrityCheck(false)
630-
->from(array('u2g' => 'user2group'),
631-
array('group_id'))
632-
->where('u2g.user_id = ?', $userId)
633-
.'))' ));
634-
635-
636-
637-
$sql = $this->database->select()
638-
->union(array($subqueryUser, $subqueryGroup));
639-
640604
if($isAdmin)
641605
{
642606
$sql = $this->database->select()
643-
->setIntegrityCheck(false)
644-
->from(array('f' => 'item'))
645-
->join(array('i' => 'item2folder'),
646-
$this->database->getDB()->quoteInto('i.folder_id IN (?)', $folderIds).'
647-
AND i.item_id = f.item_id', array('i.folder_id'));
607+
->setIntegrityCheck(false)
608+
->from(array('f' => 'item'))
609+
->join(array('i' => 'item2folder'),
610+
$this->database->getDB()->quoteInto('i.folder_id IN (?)', $folderIds).'
611+
AND i.item_id = f.item_id', array('i.folder_id'));
612+
}
613+
else
614+
{
615+
$subqueryUser = $this->database->select()
616+
->setIntegrityCheck(false)
617+
->from(array('f' => 'item'))
618+
->join(array('p' => 'itempolicyuser'),
619+
'f.item_id = p.item_id',
620+
array('p.policy'))
621+
->join(array('i' => 'item2folder'),
622+
$this->database->getDB()->quoteInto('i.folder_id IN (?)', $folderIds).'
623+
AND i.item_id = p.item_id', array('i.folder_id'))
624+
->where('policy >= ?', $policy)
625+
->where('user_id = ? ', $userId);
626+
627+
$subqueryGroup = $this->database->select()
628+
->setIntegrityCheck(false)
629+
->from(array('f' => 'item'))
630+
->join(array('p' => 'itempolicygroup'),
631+
'f.item_id = p.item_id',
632+
array('p.policy'))
633+
->join(array('i' => 'item2folder'),
634+
$this->database->getDB()->quoteInto('i.folder_id IN (?)', $folderIds).'
635+
AND i.item_id = p.item_id', array('i.folder_id'))
636+
->where('policy >= ?', $policy)
637+
->where('( '.$this->database->getDB()->quoteInto('p.group_id = ? ', MIDAS_GROUP_ANONYMOUS_KEY).' OR
638+
p.group_id IN (' .new Zend_Db_Expr(
639+
$this->database->select()
640+
->setIntegrityCheck(false)
641+
->from(array('u2g' => 'user2group'),
642+
array('group_id'))
643+
->where('u2g.user_id = ?', $userId)
644+
.'))' ));
645+
646+
$sql = $this->database->select()->union(array($subqueryUser, $subqueryGroup));
648647
}
649648

650649
$rowset = $this->database->fetchAll($sql);
@@ -668,30 +667,22 @@ function getItemsFiltered($folder, $userDao = null, $policy = 0)
668667
{
669668
if(isset($policyArray[$row['item_id']]))
670669
{
671-
$tmpDao = $this->initDao('Item', $row);
672-
$tmpDao->policy = $policyArray[$row['item_id']];
673-
$tmpDao->parent_id = $row['folder_id'];
674-
675-
/*
676-
* The new naming convention makes sure that no two (or more) items have the same name in a folder,
677-
* although items can have same name when they are in different subfolders
678-
*/
679-
/*
680-
if(isset($listNamesArray[$tmpDao->getName()]))
681-
{
682-
$listNamesArray[$tmpDao->getName()]++;
683-
$tmpDao->setName($tmpDao->getName().' ('.$listNamesArray[$tmpDao->getName()].')');
684-
}
685-
else
670+
$item = $this->initDao('Item', $row);
671+
$folders = $item->getFolders();
672+
673+
foreach($folders as $folder)
686674
{
687-
$listNamesArray[$tmpDao->getName()] = 0;
675+
if(in_array($folder->getKey(), $folderIds))
676+
{
677+
$tmpDao = clone $item;
678+
$tmpDao->policy = $policyArray[$row['item_id']];
679+
$tmpDao->parent_id = $folder->getKey();
680+
$return[] = $tmpDao;
681+
}
688682
}
689-
*/
690-
$return[] = $tmpDao;
691683
unset($policyArray[$row['item_id']]);
692684
}
693685
}
694-
695686
$this->Component->Sortdao->field = 'name';
696687
$this->Component->Sortdao->order = 'asc';
697688
usort($return, array($this->Component->Sortdao, 'sortByName'));

0 commit comments

Comments
 (0)