If $return is false the resulting array will be printed
function($id, bool $deep = false, bool $return = false, bool $aliases = false)
{
if (($ret = $deep ? $this->rawTree($id) : $this->rawOptions($id))) {
$ret = $this->analyzeOut($ret);
$res = [];
$done = [];
$max = 3;
foreach ($ret['options'] as $i => $o) {
if (!$i || in_array($o[$this->fields['id_parent']], $done, true)) {
if (empty($o[$this->fields['id_alias']])) {
$res[] = $o;
$done[] = $o[$this->fields['id']];
}
}
}
while ($max && (count($res) < count($ret['options']))) {
foreach ($ret['options'] as $i => $o) {
if (!empty($o[$this->fields['id_alias']])
&& !in_array($o[$this->fields['id']], $done, true)
&& in_array($o[$this->fields['id_parent']], $done, true)
&& in_array($o[$this->fields['id_alias']], $done, true)
) {
$res[] = $o;
$done[] = $o[$this->fields['id']];
}
}
$max--;
}
if (count($res) < count($ret['options'])) {
foreach ($ret['options'] as $i => $o) {
if (!in_array($o[$this->fields['id_parent']], $done, true)) {
$o[$this->fields['id_parent']] = $this->getCodePath($o[$this->fields['id_parent']]);
}
if (!empty($o[$this->fields['id_alias']])
&& !in_array($o[$this->fields['id']], $done, true)
) {
if (!in_array($o[$this->fields['id_alias']], $done, true)) {
$code_path = $this->getCodePath($o[$this->fields['id_alias']]);
$o[$this->fields['id_alias']] = $code_path ?: $o[$this->fields['id_alias']];
}
$res[] = $o;
$done[] = $o[$this->fields['id']];
}
}
}
return $return ? $res : var_export($res, 1);
}
return null;
}