Nests items
@param array $aAll The items to nest
@param string $sProperty The property to which to assign children
@param null $iParentId The parent ID to check against
@return array
@throws NailsException
777656
protected function nestItems(array $aAll, $sProperty, $iParentId = null)
    {
        $aOut       = [];
        $sIdCol     = $this->tableIdColumn;
        $sParentCol = $this->tableParentColumn;

        foreach ($aAll as $oItem) {

            //  Check the parent ID column exists
            if (!property_exists($oItem, $sParentCol)) {
                throw new NailsException('Parent column "' . $sParentCol . '" is not defined on result set.');
            }

            $iThisParentId = $oItem->{$sParentCol};

            if ($iThisParentId == $iParentId) {
                $oItem->{$sProperty} = $this->nestItems($aAll, $sProperty, $oItem->{$sIdCol});
                $aOut[]              = $oItem;
            } else if (!property_exists($oItem, $sProperty)) {
                $oItem->{$sProperty} = [];
            }
        }

        return $aOut;
    }
1148914
public static function tree(
        array $array,
        string $first,
        string $pid,
        string $id,
        string $child = 'son'
    ): array {
        $tree = [];
        foreach ($array as $item) {
            $tree[$item[$id]] = $item;
        }
        foreach ($tree as $item) {
            $tree[$item[$pid]][$child][] = &$tree[$item[$id]];
        }
        return $tree[$first][$child] ?? [];
    }
1047234
function autoCreateParent($access_name, $url) {
        $path          = str_replace('.', '._items_.', $access_name);
        $arr           = explode('.', $access_name);
        $tmp           = array_pop($arr);
        $default_title = ucwords(str_replace('_', ' ', $tmp));
        if(!Arr::get($this->items, $path . '._items_')) {
            Arr::set($this->items, $path . '._items_', []);
        }
        Arr::set($this->items, $path . '.access_name', $access_name);
        if(!Arr::get($this->items, $path . '.text')) {
            Arr::set($this->items, $path . '.text', $default_title);
        }
        if(!Arr::get($this->items, $path . '.url')) {
            Arr::set($this->items, $path . '.url', null);
        }
        if(!Arr::get($this->items, $path . '.icon')) {
            Arr::set($this->items, $path . '.icon', null);
        }
        if(!Arr::get($this->items, $path . '.childs')) {
            Arr::set($this->items, $path . '.childs', []);
        }
        if(!Arr::get($this->items, $path . '.labels')) {
            Arr::set($this->items, $path . '.labels', []);
        }
        if($url) {
            $childs   = Arr::get($this->items, $path . '.childs');
            $childs[] = $url;
            $childs   = array_unique($childs);
            Arr::set($this->items, $path . '.childs', $childs);
        }
    }
410702
public function findMountPointPropertiesByPageIdOrByRootLineParentPageIds(int $mountedPageUid, array $rootLineParentPageIds = []) : array
    {
        if (array_filter($rootLineParentPageIds, 'is_int') !== $rootLineParentPageIds) {
            throw new \InvalidArgumentException('Given $rootLineParentPageIds array is not valid. Allowed only the arrays with the root line page UIDs as integers.', 1502459711);
        }

        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder->select('uid', 'uid AS mountPageDestination', 'mount_pid AS mountPageSource', 'mount_pid_ol AS mountPageOverlayed')->from($this->table);
        $queryBuilder = $this->addWhereClauseForMountpointDestinationProperties($queryBuilder, $mountedPageUid, $rootLineParentPageIds);
        $result = $queryBuilder->execute()->fetchAll();
        return $result;
    }
988334
public static function getChildElements(DOMElement $parent, $childName)
    {
        $listElements = $parent->getElementsByTagName($childName);
        if ($listElements->length > 0) {
            $list = [];

            for ($i = 0; $i < $listElements->length; $i++) {
                $currentItem = $listElements->item($i);

                if (!$parent->isSameNode($currentItem->parentNode)) {
                    continue;
                }

                $list[] = $currentItem;
            }

            return $list;
        }

        return [];
    }
793246
static function createAttributeLookupElement( $attributeValues = array(), $variablePlacement = false )
    {
        if ( is_numeric( $attributeValues ) )
            $attributeValues = array( eZTemplateNodeTool::createNumericElement( $attributeValues, $variablePlacement ) );
        else if ( !is_array( $attributeValues ) )
            $attributeValues = array( eZTemplateNodeTool::createStringElement( $attributeValues, $variablePlacement ) );
        return array( eZTemplate::TYPE_ATTRIBUTE,
                      $attributeValues, $variablePlacement );
    }
271674
private function addDescendancy(&$list, $pid, $parents = false, $generations = -1): void
    {
        $person = Individual::getInstance($pid, $this->tree);
        if ($person === null) {
            return;
        }
        if (!isset($list[$pid])) {
            $list[$pid] = $person;
        }
        if (!isset($list[$pid]->generation)) {
            $list[$pid]->generation = 0;
        }
        foreach ($person->spouseFamilies() as $family) {
            if ($parents) {
                $husband = $family->husband();
                $wife    = $family->wife();
                if ($husband) {
                    $list[$husband->xref()] = $husband;
                    if (isset($list[$pid]->generation)) {
                        $list[$husband->xref()]->generation = $list[$pid]->generation - 1;
                    } else {
                        $list[$husband->xref()]->generation = 1;
                    }
                }
                if ($wife) {
                    $list[$wife->xref()] = $wife;
                    if (isset($list[$pid]->generation)) {
                        $list[$wife->xref()]->generation = $list[$pid]->generation - 1;
                    } else {
                        $list[$wife->xref()]->generation = 1;
                    }
                }
            }

            $children = $family->children();

            foreach ($children as $child) {
                if ($child) {
                    $list[$child->xref()] = $child;

                    if (isset($list[$pid]->generation)) {
                        $list[$child->xref()]->generation = $list[$pid]->generation + 1;
                    } else {
                        $list[$child->xref()]->generation = 2;
                    }
                }
            }
            if ($generations == -1 || $list[$pid]->generation + 1 < $generations) {
                foreach ($children as $child) {
                    $this->addDescendancy($list, $child->xref(), $parents, $generations); // recurse on the childs family
                }
            }
        }
    }
424451
public function hasProperty($strProperty){
		$strProperty = $this->_formatPropertyName($strProperty);
		if(in_array($strProperty, $this->_arrProperties)){
			return true;
		}
		return false;
	}
646725
private static function _getSelectTreeChildren(&$target,$pId,$source,$idField,$pidField,$titleField,$separator,$prefix,$level,$currentLevel)
    {
        if($level<0){
            $level=9999;
        }
        if($currentLevel>$level){
            return;
        }
        $sep="";
        for($i=0;$i<$currentLevel;$i++){
            $sep.=$separator;
        }
        foreach ($source as $item){
            $_pid=$item[$pidField];
            if($_pid==$pId){
                $id=$item[$idField];
                $title=$sep.$prefix.$item[$titleField];
                $target[$id]=$title;
                self::_getSelectTreeChildren($target,$id,$source,$idField,$pidField,$titleField,$separator,$prefix,$level,$currentLevel+1);

            }
        }
    }
552427
public function automaticParentId($data)
	{
		if (!isset($data['parent_id']))
		{
			$data['parent_id'] = 0;
		}

		if ((!isset($data['id']) || !$data['id'])
		 && ($data['parent_id'] == 0))
		{
			$data['parent_id'] = self::getRootId();
		}

		return $data['parent_id'];
	}
861718
private function setOptionsForSelect($aElements, $sDefaultValue, $featArray = null)
    {
        if (is_null($featArray)) {
            $featArray = [];
        }
        $sReturn  = [];
        $crtGroup = null;
        foreach ($aElements as $key => $value) {
            $aFH       = $this->setOptionGroupFooterHeader($featArray, $value, $crtGroup);
            $crtGroup  = $aFH['crtGroup'];
            $sReturn[] = $aFH['groupFooterHeader']
                . '<option value="' . $key . '"' . $this->setOptionSelected($key, $sDefaultValue)
                . $this->featureArraySimpleTranslated($featArray, 'styleForOption') . '>'
                . str_replace(['&', $crtGroup], ['&amp;', ''], $value) . '</option>';
        }
        $sReturn[] = $this->setOptionGroupEnd($crtGroup, $featArray);
        return $this->featureArraySimpleTranslated($featArray, 'include_null') . implode('', $sReturn);
    }
1095861
public static function discoverTypes(array &$aArray): void
    {
        $aLocations = [
            NAILS_COMMON_PATH . 'config/email_types.php',
        ];

        foreach (Components::modules() as $oModule) {
            $aLocations[] = $oModule->path . $oModule->moduleName . '/config/email_types.php';
        }

        $aLocations[] = NAILS_APP_PATH . 'application/config/email_types.php';

        foreach ($aLocations as $sPath) {
            static::loadTypes($sPath, $aArray);
        }
    }
1061999
private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent)
    {
        foreach ($importedParent->childNodes as $childNode) {
            $parentNode->appendChild($parentNode->ownerDocument->importNode($childNode, true));
        }
    }
1089461
public static function property(string $sPropertyName, ?string $sComponentName = '')
    {
        $mProperty = self::getService('properties', $sPropertyName, $sComponentName);

        if (is_callable($mProperty)) {
            return $mProperty();
        } else {
            return $mProperty;
        }
    }
1175582
function appendInternal(that, propertyList, args, options) {
    var arrayToAppend = args[0]
    if(arrayToAppend.length === 0) return; //nothing to do

    var array = getPropertyValue(that.subject, propertyList)
    var originalLength = array.length

    var spliceArgs = [originalLength, 0]
    spliceArgs = spliceArgs.concat(arrayToAppend)
    var oldLength = array.length
    array.splice.apply(array, spliceArgs)

    var internalObservees = unionizeList(array, oldLength, array.length, options.union)

    var event = {type: 'added', property: propertyList, index: originalLength, count: arrayToAppend.length}
    if(options.data !== undefined) event.data = event.id = options.data
    that.emit('change', event)

    unionizeListEvents(that, internalObservees, propertyList, options.union)
}
164443
protected function buildList(array $items, string $marker, int $nestingLevel = 0, int $parentWidth = 0): string
	{
		$width  = $this->calculateWidth($items, $marker);
		$number = 0;
		$list   = '';

		foreach($items as $item)
		{
			if(is_array($item))
			{
				$list .= $this->buildList($item, $marker, ($nestingLevel + 1), ($width['marker'] - 1 + $parentWidth));
			}
			else
			{
				$list .= $this->buildListItem($item, $marker, $width['number'], ++$number, $nestingLevel, $parentWidth);
			}
		}

		return $list;
	}
1314295
public function getCustomField($sProperty)
    {
        return property_exists($this->oCustomField, $sProperty) ? $this->oCustomField->{$sProperty} : null;
    }