@param null   $node
@param bool   $direct
@param null   $sortByField
@param string $direction
@param bool   $includeNode
@param string $viewStatus

@return array
503944
public function getChildrenByStatus(
        $node = null,
        $direct = false,
        $sortByField = null,
        $direction = 'ASC',
        $includeNode = false,
        $viewStatus = Page::STATUS_PUBLISHED
    ) {
        $qb = $this->childrenQueryBuilder($node, $direct, $sortByField, $direction, $includeNode);
        $aliases = $qb->getRootAliases();
        if ($viewStatus == Page::STATUS_PUBLISHED) {
            $orx = $qb->expr()->orX();
            $conditionA = $qb->expr()->in('ps.id', $this->getLatestSnapshotIds());
            $conditionB = $qb->expr()->isNull('ps.id');
            $orx->addMultiple([$conditionA, $conditionB]);
            $qb->addSelect('ps.id AS ps_id')
                ->addSelect('ps.versionedData AS ps_versionedData')
                ->leftJoin(PageSnapshot::class,
                    'ps',
                    Expr\Join::WITH,
                    sprintf('%s.page = ps.page ', $aliases[0])
                )
                ->andWhere($orx)
                ->leftJoin('ps.contentRoute', 'cr');
        } else {
            $qb->leftJoin(sprintf('%s.page', $aliases[0]), 'p')
                ->leftJoin('p.contentRoute', 'cr')
                ->addSelect('p');
        }
        $qb->addSelect('cr.path AS path');
        $results = $qb->getQuery()->getResult();

        $menuItems = [];
        foreach ($results as $item) {
            $menuItem = $item[0];
            if ($menuItem->getPage()) {
                if ($viewStatus == Page::STATUS_PUBLISHED) {
                    if (!$item['path'] || !$item['ps_id']) {
                        continue;
                    } else {
                        if (!$this->pageHelper->jsonPageIsActive($item['ps_versionedData'])) {
                            continue;
                        }
                        $menuItem->setPath($item['path']);
                    }
                } else {
                    if (!$item['path']) {
                        continue;
                    } else {
                        $menuItem->setPath($item['path']);
                    }
                }
            }
            $menuItems[] = $menuItem;
        }

        return $menuItems;
    }
838371
function getDeletedEmbedIDArray( $includeTrash = false )
    {
        $arr = array();
        if ( $this->deletedEmbeddedNodeIDArray )
            $arr['nodes'] = $this->deletedEmbeddedNodeIDArray;
        if ( $this->deletedEmbeddedObjectIDArray )
            $arr['objects'] = $this->deletedEmbeddedObjectIDArray;
        if ( $includeTrash && $this->thrashedEmbeddedObjectIDArray )
            $arr['trash'] = $this->thrashedEmbeddedObjectIDArray;
        return $arr;
    }
335534
private function getStructures($direct = true, $rootClass = 'nav navbar-nav', $dropDown = false, $rootId = '')
    {
        $repo = $this->em->getRepository('WebCMS\Entity\Page');

        $structs = $repo->findBy(array(
            'language' => $this->language,
            'parent' => NULL,
        ));

        $structures = array();
        foreach ($structs as $s) {
            $structures[$s->getTitle()] = $this->getStructure($this, $s, $repo, $direct, $rootClass, $dropDown, true, null, '', null, $rootId);
        }

        return $structures;
    }
522230
public function sortByFieldFilter($content, $sort_by = null, $direction = 'asc') {

        if (is_a($content, 'Doctrine\Common\Collections\Collection')) {
            $content = $content->toArray();
        }

        if (!is_array($content)) {
            throw new \InvalidArgumentException('Variable passed to the sortByField filter is not an array');
        } elseif (count($content) < 1) {
            return $content;
        } elseif ($sort_by === null) {
            throw new Exception('No sort by parameter passed to the sortByField filter');
        } elseif (!self::isSortable(current($content), $sort_by)) {
            throw new Exception('Entries passed to the sortByField filter do not have the field "' . $sort_by . '"');
        } else {
            // Unfortunately have to suppress warnings here due to __get function
            // causing usort to think that the array has been modified:
            // usort(): Array was modified by the user comparison function
            @usort($content, function ($a, $b) use ($sort_by, $direction) {
                $flip = ($direction === 'desc') ? -1 : 1;

                if (is_array($a))
                    $a_sort_value = $a[$sort_by];
                else if (method_exists($a, 'get' . ucfirst($sort_by)))
                    $a_sort_value = $a->{'get' . ucfirst($sort_by)}();
                else
                    $a_sort_value = $a->$sort_by;

                if (is_array($b))
                    $b_sort_value = $b[$sort_by];
                else if (method_exists($b, 'get' . ucfirst($sort_by)))
                    $b_sort_value = $b->{'get' . ucfirst($sort_by)}();
                else
                    $b_sort_value = $b->$sort_by;

                if ($a_sort_value == $b_sort_value) {
                    return 0;
                } else if ($a_sort_value > $b_sort_value) {
                    return (1 * $flip);
                } else {
                    return (-1 * $flip);
                }
            });
        }
        return $content;
    }
124951
public function getFlattenChildren(Node $node)
    {
        $flatten = array();
        foreach ($node->getNodes() as $subNode) {
            if (count($subNode->getNodes()) > 1 || isset($subNode->getTrace()['query_source']) || !empty($subNode->getValues())) {
                $flatten[] = $subNode;
            } else {
                $flatten = array_merge($flatten, $this->getFlattenChildren($subNode));
            }
        }

        return $flatten;
    }
134810
private function getDepthLevel(Element $node, int $parentDepth, int $siblingDepth): ?\stdClass {
        if (is_null($node) || !($node->parent() instanceof Element)) {
            return null;
        }

        if ($parentDepth > self::$MAX_PARENT_DEPTH) {
            return null;
        }

        // Find previous sibling element node
        $siblingNode = $node->preceding(function($node) {
            return $node instanceof Element;
        });

        if (is_null($siblingNode)) {
            return (object)[
                'node' => $node->parent(),
                'parentDepth' => $parentDepth + 1,
                'siblingDepth' => 0,
            ];
        }

        return (object)[
            'node' => $siblingNode,
            'parentDepth' => $parentDepth,
            'siblingDepth' => $siblingDepth + 1,
        ];
    }
610217
protected function getFirstExternalNode($node)
    {
        $nodes = func_get_args();
        foreach ($nodes as $node) {
            /** @var Node $node */
            if ($node->isLocalhost() === false) {
                return $node;
            }
        }

        return null;
    }
960289
public function moveNode( $sourceNode, $position, $relatedNode )
    {
        $sourceNode = (int) $sourceNode;
        $sourceRoot = $this->getMapper()
                           ->findRootOf( $sourceNode );

        if ( empty( $sourceRoot ) ||
             ! $sourceRoot->isEditable() )
        {
            return array(
                'sourceNode'    => null,
                'position'      => $position,
                'relatedNode'   => $relatedNode,
                'success'       => false,
            );
        }

        $relatedNode = (int) $relatedNode;
        $relatedRoot = $this->getMapper()
                            ->findRootOf( $relatedNode );

        if ( empty( $relatedRoot ) ||
             ! $relatedRoot->isEditable() )
        {
            return array(
                'sourceNode'    => $sourceNode,
                'position'      => $position,
                'relatedNode'   => null,
                'success'       => false,
            );
        }

        $success = $this->getMapper()
                        ->moveNode( $sourceNode,
                                    strtolower( $position ),
                                    $relatedNode );

        return array(
            'sourceNode'    => $sourceNode,
            'position'      => $position,
            'relatedNode'   => $relatedNode,
            'success'       => (bool) $success,
        );
    }
454800
public function getChildren(Node $node, $includeHiddenFromNav = true)
    {
        $this->init();
        $children = array();

        if (array_key_exists($node->getId(), $this->childNodes)) {
            $nodes = $this->childNodes[$node->getId()];
            /* @var Node $childNode */
            foreach ($nodes as $childNode) {
                $nodeTranslation = $childNode->getNodeTranslation(
                    $this->locale,
                    $this->includeOffline
                );
                if (!is_null($nodeTranslation)) {
                    $children[] = new NodeMenuItem(
                        $childNode,
                        $nodeTranslation,
                        false,
                        $this
                    );
                }
            }

            $children = array_filter(
                $children,
                function (NodeMenuItem $entry) use ($includeHiddenFromNav) {
                    if ($entry->getNode()->isHiddenFromNav(
                        ) && !$includeHiddenFromNav
                    ) {
                        return false;
                    }

                    return true;
                }
            );
        }

        return $children;
    }
379149
public function processNode(Node $node, Scope $scope): array
	{
		if (!$scope->isInClass()) {
			throw new \PHPStan\ShouldNotHappenException();
		}

		$propertyReflection = $scope->getClassReflection()->getNativeProperty($node->name->name);
		$returnType = $propertyReflection->getType();
		if ($returnType instanceof MixedType && !$returnType->isExplicitMixed()) {
			return [
				sprintf(
					'Property %s::$%s has no typehint specified.',
					$propertyReflection->getDeclaringClass()->getDisplayName(),
					$node->name->name
				),
			];
		}

		return [];
	}
899391
function ($node, direction) {
      var that = this;
      var $nodeContainer = $node.closest('table').parent();
      if ($nodeContainer.siblings().find('.spinner').length) {
        $node.closest('.orgchart').data('inAjax', false);
      }
      if (direction) {
        if (direction === 'left') {
          $nodeContainer.prevAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-right');
        } else {
          $nodeContainer.nextAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-left');
        }
      } else {
        $nodeContainer.prevAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-right');
        $nodeContainer.nextAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-left');
      }
      var $animatedNodes = $nodeContainer.siblings().find('.sliding');
      var $lines = $animatedNodes.closest('.nodes').prevAll('.lines').css('visibility', 'hidden');
      $animatedNodes.eq(0).one('transitionend', { 'node': $node, 'nodeContainer': $nodeContainer, 'direction': direction, 'animatedNodes': $animatedNodes, 'lines': $lines }, this.hideSiblingsEnd.bind(this));
    }
610568
public function move(Node\NodeInterface $node, $pos, $levelDiff, $undoMove = false)
	{
		if ( ! $this->locked) {
			//\Log::info('Should lock before changes');
		}

		$tableName = $this->tableName;
		$arrayHelper = $this->arrayHelper;
		$self = $this;
		
		// Calculate the old position to rollback to in case of some issue
		$oldPosition = $node->getLeftValue();
		
		if ($pos < $oldPosition) {
			$oldPosition = $node->getRightValue() + 1;
		}
		
		if ( ! $node instanceof Node\DoctrineNode) {
			throw new Exception\WrongInstance($node, 'Node\DoctrineNode');
		}
		
		// Transactional because need to rollback in case of trigger failure
		$this->entityManager->transactional(function(EntityManager $entityManager) use ($node, $pos, $levelDiff, $tableName, $arrayHelper, $self) {
			$left = $node->getLeftValue();
			$right = $node->getRightValue();
			$spaceUsed = $right - $left + 1;
			$moveA = null;
			$moveB = null;
			$a = null;
			$b = null;
			$min = null;
			$max = null;

			if ($pos > $left) {
				$a = $right + 1;
				$b = $pos - 1;
				$moveA = $pos - $left - $spaceUsed;
				$moveB = - $spaceUsed;
				$min = $left;
				$max = $pos - 1;
			} else {
				$a = $pos;
				$b = $left - 1;
				$moveA = $pos - $left;
				$moveB = $spaceUsed;
				$min = $pos;
				$max = $right;
			}

//			// NB! It's important to set "level" before "left" for MySQL!
//			$dql = "UPDATE {$className} e
//					SET e.level = e.level + IF(e.left BETWEEN {$left} AND {$right}, {$levelDiff}, 0),
//						e.left = e.left + IF(e.left BETWEEN {$left} AND {$right}, {$moveA}, IF(e.left BETWEEN {$a} AND {$b}, {$moveB}, 0)),
//						e.right = e.right + IF(e.right BETWEEN {$left} AND {$right}, {$moveA}, IF(e.right BETWEEN {$a} AND {$b}, {$moveB}, 0))
//					WHERE (e.left BETWEEN {$min} AND {$max}
//						OR e.right BETWEEN {$min} AND {$max})";
//
//			$dql .= $self->getAdditionalCondition('AND');
//
//			$query = $entityManager->createQuery($dql);
//			$query->execute();

			$sql = "UPDATE {$tableName}
					SET lvl = lvl + IF(lft BETWEEN {$left} AND {$right}, {$levelDiff}, 0),
						lft = lft + IF(lft BETWEEN {$left} AND {$right}, {$moveA}, IF(lft BETWEEN {$a} AND {$b}, {$moveB}, 0)),
						rgt = rgt + IF(rgt BETWEEN {$left} AND {$right}, {$moveA}, IF(rgt BETWEEN {$a} AND {$b}, {$moveB}, 0))
					WHERE (lft BETWEEN {$min} AND {$max}
						OR rgt BETWEEN {$min} AND {$max})";

			$sql .= $self->getAdditionalConditionSql('AND');

			$entityManager->getConnection()
					->exec($sql);
			
			// Change node parameters locally as well
			// TODO: how to rollback these changes if nested set post move trigger fails?
			$arrayHelper->move($node, $pos, $levelDiff);
		});
		
		// Trigger post move event. Only after transaction is commited because
		// public schema must update it's stuff as well
		try {
			$masterNode = $node->getMasterNode();
			$eventArgs = new Event\NestedSetEventArgs($masterNode, $this->entityManager);
			$this->entityManager->getEventManager()
					->dispatchEvent(Event\NestedSetEvents::nestedSetPostMove, $eventArgs);
		} catch (\Exception $e) {
			
			//TODO: new pages should be removed
			
			// Should not happen
			if ($undoMove) {
				throw $e;
			}
			
			// Undo move
			$this->move($node, $oldPosition, - $levelDiff, true);
			
			throw $e;
		}
	}
577001
public static function getBreadcrumbs(AbstractNavigationNode $node) {

        $breadcrumbs = [];

        if (true === ($node instanceof NavigationNode || $node instanceof BreadcrumbNode) && true === $node->getActive()) {
            $breadcrumbs[] = $node;
        }

        foreach ($node->getNodes() as $current) {
            if (false === ($current instanceof AbstractNavigationNode)) {
                continue;
            }
            $breadcrumbs = array_merge($breadcrumbs, self::getBreadcrumbs($current));
        }

        return $breadcrumbs;
    }
121499
private function hasNotAllowedChildren(MethodNode $node)
    {
        $children = $node->findChildrenOfType('ScopeStatement');

        $allowedChildren = explode(
            $this->getStringProperty('delimiter'),
            $this->getStringProperty('allowedChildren')
        );

        /** @var AbstractNode $child */
        foreach ($children as $child) {
            if (true === in_array($child->getImage(), $allowedChildren) || true === $this->isChildOfTry($child)) {
                continue;
            }

            return true;
        }

        return false;
    }
1206183
public static function all(string $orderField = null, string $orderDirection = null): array
    {
        $select = static::select();

        if ($orderField !== null) {
            $select->orderBy($orderField, $orderDirection);
        }

        $data = [];
        foreach ($select->fetchAll() as $r) {
            $data[] = new static($r);
        }

        return $data;
    }
200647
public function dumpNode(BaseNode $node)
    {
        return '<?php'.PHP_EOL.PHP_EOL.'return ['.parent::dumpNode($node).PHP_EOL.'];'.PHP_EOL;
    }
186966
protected function createAssociatedDirectivesOfType(Node $node, string $directiveClass): Collection
    {
        return (new Collection($node->directives))
            ->map(function (DirectiveNode $directive) use ($node) {
                return $this->create($directive->name->value, $node);
            })
            ->filter(function (Directive $directive) use ($directiveClass) {
                return $directive instanceof $directiveClass;
            });
    }