public function getChildRecords($arrParentIds, $strTable, $blnSorting = false, $arrReturn = array(), $strWhere = '')
{
if (!is_array($arrParentIds)) {
$arrParentIds = array($arrParentIds);
}
if (empty($arrParentIds)) {
return $arrReturn;
}
$arrParentIds = array_map('intval', $arrParentIds);
$objChilds = $this->query("SELECT id, pid FROM " . $strTable . " WHERE pid IN(" . implode(',', $arrParentIds) . ")" . ($strWhere ? " AND {$strWhere}" : "") . ($blnSorting ? " ORDER BY " . $this->findInSet('pid', $arrParentIds) . ", sorting" : ""));
if ($objChilds->numRows > 0) {
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, $strWhere);
} else {
$arrChilds = $objChilds->fetchEach('id');
$arrReturn = array_merge($arrChilds, $this->getChildRecords($arrChilds, $strTable, $blnSorting, $arrReturn, $strWhere));
}
}
return $arrReturn;
}