Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
The site structure was not ordered properly for non-admins (#3423)
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Nov 3, 2011
1 parent 40d4716 commit 86393f8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Version 2.10.3 (XXXX-XX-XX)
- Fixed: do not index empty news/event/FAQ/newsletter reader pages (#3511)
- Fixed: group labels were not always loaded correctly (#3591)
- Fixed: added a rename() workaround for Windows to the FileCache class (#3390)
- Fixed: the site structure was not ordered properly for non-admins (#3423)
- Fixed a few minor issues

Version 2.10.2 (2011-10-10)
Expand Down
2 changes: 1 addition & 1 deletion system/drivers/DC_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function __construct($strTable)
// Get root records from global configuration file
elseif (is_array($GLOBALS['TL_DCA'][$table]['list']['sorting']['root']))
{
$this->root = $this->eliminateNestedPages($GLOBALS['TL_DCA'][$table]['list']['sorting']['root'], $table);
$this->root = $this->eliminateNestedPages($GLOBALS['TL_DCA'][$table]['list']['sorting']['root'], $table, true);
}
}

Expand Down
48 changes: 36 additions & 12 deletions system/libraries/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2794,24 +2794,47 @@ protected function createNewVersion($strTable, $intId)
* Return the IDs of all child records of a particular record (see #2475)
* @param mixed
* @param string
* @param boolean
* @param array
* @return array
* @author Andreas Schempp
*/
protected function getChildRecords($arrParenIds, $strTable)
protected function getChildRecords($arrParentIds, $strTable, $blnSorting=false, $arrReturn=array())
{
$arrReturn = array();

if (!is_array($arrParenIds))
if (!is_array($arrParentIds))
{
$arrParenIds = array($arrParenIds);
$arrParentIds = array($arrParentIds);
}

$objChilds = $this->Database->execute("SELECT id FROM " . $strTable . " WHERE pid IN(" . implode(',', array_map('intval', $arrParenIds)) . ")");
$arrParentIds = array_map('intval', $arrParentIds);
$objChilds = $this->Database->execute("SELECT id, pid FROM " . $strTable . " WHERE pid IN(" . implode(',', $arrParentIds) . ")" . ($blnSorting ? " ORDER BY " . $this->Database->findInSet('pid', $arrParentIds) . ", sorting" : ""));

if ($objChilds->numRows > 0)
{
$arrChilds = $objChilds->fetchEach('id');
$arrReturn = array_merge($arrChilds, $this->getChildRecords($arrChilds, $strTable));
if ($blnSorting)
{
$arrChilds = array();
$arrOrdered = array();

while ($objChilds->next())
{
$arrChilds[] = $objChilds->id;
$arrOrdered[$objChilds->pid][] = $objChilds->id;
}

foreach (array_reverse(array_keys($arrOrdered)) as $pid)
{
$pos = (int) array_search($pid, $arrReturn);
array_insert($arrReturn, $pos+1, $arrOrdered[$pid]);
}

$arrReturn = $this->getChildRecords($arrChilds, $strTable, $blnSorting, $arrReturn);
}
else
{
$arrChilds = $objChilds->fetchEach('id');
$arrReturn = array_merge($arrChilds, $this->getChildRecords($arrChilds, $strTable, $blnSorting));
}
}

return $arrReturn;
Expand Down Expand Up @@ -2910,9 +2933,10 @@ protected function eliminateNestedPaths($arrPaths)
* Take an array of pages and eliminate nested pages
* @param array
* @param string
* @param boolean
* @return array
*/
protected function eliminateNestedPages($arrPages, $strTable=null)
protected function eliminateNestedPages($arrPages, $strTable=null, $blnSorting=false)
{
if (!is_array($arrPages) || count($arrPages) < 1)
{
Expand All @@ -2924,9 +2948,9 @@ protected function eliminateNestedPages($arrPages, $strTable=null)
$strTable = 'tl_page';
}

// Thanks to Andreas Schempp (see #2475)
$arrPages = array_intersect($this->getChildRecords(0, $strTable), $arrPages);
$arrPages = array_values(array_diff($arrPages, $this->getChildRecords($arrPages, $strTable)));
// Thanks to Andreas Schempp (see #2475 and #3423)
$arrPages = array_intersect($this->getChildRecords(0, $strTable, $blnSorting), $arrPages);
$arrPages = array_values(array_diff($arrPages, $this->getChildRecords($arrPages, $strTable, $blnSorting)));

return $arrPages;
}
Expand Down

0 comments on commit 86393f8

Please sign in to comment.