FOF30\Model\TreeModel::getNestedList PHP Méthode

getNestedList() public méthode

This is useful for creating HTML select elements showing the hierarchy in a human readable format.
public getNestedList ( string $column = 'title', null $key = null, string $seperator = ' ' ) : array
$column string
$key null
$seperator string
Résultat array
    public function getNestedList($column = 'title', $key = null, $seperator = '  ')
    {
        $db = $this->getDbo();
        $fldLft = $db->qn($this->getFieldAlias('lft'));
        $fldRgt = $db->qn($this->getFieldAlias('rgt'));
        if (empty($key) || !$this->hasField($key)) {
            $key = $this->getIdFieldName();
        }
        if (empty($column)) {
            $column = 'title';
        }
        $fldKey = $db->qn($this->getFieldAlias($key));
        $fldColumn = $db->qn($this->getFieldAlias($column));
        $query = $db->getQuery(true)->select(array($db->qn('node') . '.' . $fldKey, $db->qn('node') . '.' . $fldColumn, '(COUNT(' . $db->qn('parent') . '.' . $fldKey . ') - 1) AS ' . $db->qn('depth')))->from($db->qn($this->tableName) . ' AS ' . $db->qn('node'))->join('CROSS', $db->qn($this->tableName) . ' AS ' . $db->qn('parent'))->where($db->qn('node') . '.' . $fldLft . ' >= ' . $db->qn('parent') . '.' . $fldLft)->where($db->qn('node') . '.' . $fldLft . ' <= ' . $db->qn('parent') . '.' . $fldRgt)->group($db->qn('node') . '.' . $fldLft)->order($db->qn('node') . '.' . $fldLft . ' ASC');
        $tempResults = $db->setQuery($query)->loadAssocList();
        $ret = array();
        if (!empty($tempResults)) {
            foreach ($tempResults as $row) {
                $ret[$row[$key]] = str_repeat($seperator, $row['depth']) . $row[$column];
            }
        }
        return $ret;
    }