Contao\Database::getChildRecords PHP Метод

getChildRecords() публичный Метод

Return the IDs of all child records of a particular record (see #2475)
Автор: Andreas Schempp
public getChildRecords ( mixed $arrParentIds, string $strTable, boolean $blnSorting = false, array $arrReturn = [], string $strWhere = '' ) : array
$arrParentIds mixed An array of parent IDs
$strTable string The table name
$blnSorting boolean True if the table has a sorting field
$arrReturn array The array to be returned
$strWhere string Additional WHERE condition
Результат array An array of child record IDs
    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;
    }