public function ajaxTreeView($id, $level)
{
if (!\Environment::get('isAjaxRequest')) {
return '';
}
$return = '';
$table = $this->strTable;
$blnPtable = false;
// Load parent table
if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 6) {
$table = $this->ptable;
\System::loadLanguageFile($table);
$this->loadDataContainer($table);
$blnPtable = true;
}
$blnProtected = false;
// Check protected pages
if ($table == 'tl_page') {
$objParent = \PageModel::findWithDetails($id);
$blnProtected = $objParent->protected ? true : false;
}
$margin = $level * 20;
$hasSorting = $this->Database->fieldExists('sorting', $table);
$arrIds = array();
// Get records
$objRows = $this->Database->prepare("SELECT id FROM " . $table . " WHERE pid=?" . ($hasSorting ? " ORDER BY sorting" : ""))->execute($id);
while ($objRows->next()) {
$arrIds[] = $objRows->id;
}
/** @var SessionInterface $objSession */
$objSession = \System::getContainer()->get('session');
$blnClipboard = false;
$arrClipboard = $objSession->get('CLIPBOARD');
// Check clipboard
if (!empty($arrClipboard[$this->strTable])) {
$blnClipboard = true;
$arrClipboard = $arrClipboard[$this->strTable];
}
for ($i = 0, $c = count($arrIds); $i < $c; $i++) {
$return .= ' ' . trim($this->generateTree($table, $arrIds[$i], array('p' => $arrIds[$i - 1], 'n' => $arrIds[$i + 1]), $hasSorting, $margin, $blnClipboard ? $arrClipboard : false, $id == $arrClipboard['id'] || is_array($arrClipboard['id']) && in_array($id, $arrClipboard['id']) || !$blnPtable && !is_array($arrClipboard['id']) && in_array($id, $this->Database->getChildRecords($arrClipboard['id'], $table)), $blnProtected));
}
return $return;
}