@param Request $request

@return JsonResponse
@Route("/intrasiteroot", name="tree_link_intrasiteroot")

@throws \InvalidArgumentException if empty siteroot id given
971659
public function linkIntrasiterootAction(Request $request)
    {
        $siterootIds = explode(',', $request->get('siteroot_id'));
        $id = $request->get('node', 'root');
        $language = $request->get('language');
        $elementtypeIds = $request->get('element_type_ids', []);
        $targetTid = $request->get('value');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $iconResolver = $this->get('phlexible_element.icon_resolver');

        // TODO: switch to master language of element
        $defaultLanguage = $this->container->getParameter('phlexible_cms.languages.default');

        if (!$language) {
            $language = $defaultLanguage;
        }

        if ($elementtypeIds) {
            $elementtypeIds = explode(',', $elementtypeIds);
        } else {
            $elementtypeIds = [];
        }

        $targetTree = null;
        $targetNode = null;
        if ($targetTid) {
            $targetTree = $treeManager->getByNodeId($targetTid);
            $targetNode = $targetTree->get($targetTid);
        }

        if ($id === 'root') {
            $siterootManager = $this->get('phlexible_siteroot.siteroot_manager');
            if (!$siterootIds) {
                $siterootIds = array();
                foreach ($siterootManager->findAll() as $siteroot) {
                    $siterootIds[] = $siteroot->getId();
                }
            }
            $data = [];
            foreach ($siterootIds as $siterootId) {
                Assert::notEmpty($siterootId, 'Empty siteroot id given');
                $siteroot = $siterootManager->find($siterootId);
                $tree = $treeManager->getBySiteRootId($siteroot->getId());
                $rootNode = $tree->getRoot();

                $children = false;
                if ($targetTree && $siteroot->getId() === $targetTree->getSiterootId()) {
                    if (!count($elementtypeIds)) {
                        $mode = !$targetTid ? self::MODE_NOET_NOTARGET : self::MODE_NOET_TARGET;
                        $nodes = $tree->getChildren($rootNode);
                        $children = $this->recurseLinkNodes($nodes, $language, $mode, $targetNode);
                    } else {
                        $children = $this->findLinkNodes($tree->getSiterootId(), $language, $elementtypeIds);

                        if ($elementtypeIds) {
                            $children = $this->recursiveTreeStrip($children);
                        }
                    }
                }

                $data[] = [
                    'id' => $rootNode->getId(),
                    'eid' => $rootNode->getTypeId(),
                    'text' => $siteroot->getTitle(),
                    'icon' => $iconResolver->resolveTreeNode($rootNode, $language),
                    'children' => $children,
                    'leaf' => !$tree->hasChildren($rootNode),
                    'expanded' => false,
                ];
            }
        } else {
            $tree = $treeManager->getByNodeId($id);
            $startNode = $tree->get($id);

            if (!count($elementtypeIds)) {
                $mode = !$targetTid ? self::MODE_NOET_NOTARGET : self::MODE_NOET_TARGET;

                $nodes = $tree->getChildren($startNode);
                $data = $this->recurseLinkNodes($nodes, $language, $mode, $targetNode);
            } else {
                $data = $this->findLinkNodes($tree->getSiterootId(), $language, $elementtypeIds);

                if ($elementtypeIds) {
                    $data = $this->recursiveTreeStrip($data);
                }
            }
        }

        return new JsonResponse($data);
    }
262667
public function checkDeleteAction(Request $request)
    {
        $treeId = $request->get('id');
        $language = $request->get('language', 'de');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $treeMeditator = $this->get('phlexible_tree.mediator');
        $siterootManager = $this->get('phlexible_siteroot.siteroot_manager');

        $nodeId = $treeId[0];
        $tree = $treeManager->getByNodeId($nodeId);
        $node = $tree->get($nodeId);

        $instances = $treeManager->getInstanceNodes($node);

        if (count($instances) > 1) {
            $instancesArray = [];
            foreach ($instances as $instanceNode) {
                $siteroot = $siterootManager->find($instanceNode->getTree()->getSiterootId());
                $instanceTitle = $treeMeditator->getField($instanceNode, 'backend', $language);

                $instancesArray[] = [
                    $instanceNode->getId(),
                    $siteroot->getTitle(),
                    $instanceTitle,
                    $instanceNode->getCreatedAt()->format('Y-m-d H:i:s'),
                    (bool) $instanceNode->getTree()->isInstanceMaster($instanceNode),
                    (bool) ($instanceNode->getId() === $nodeId),
                ];
            }

            return new ResultResponse(true, '', $instancesArray);
        }

        return new ResultResponse(true, '', []);
    }
582480
public function copyAction(Request $request)
    {
        $parentId = $request->get('id');
        $sourceId = $request->get('for_tree_id');
        $prevId = $request->get('prev_id');

        $elementService = $this->get('phlexible_element.element_service');
        $treeManager = $this->get('phlexible_tree.tree_manager');

        $sourceTree = $treeManager->getByNodeId($sourceId);
        $sourceNode = $sourceTree->get($sourceId);

        $targetTree = $treeManager->getByNodeId($parentId);
        $parentNode = $targetTree->get($parentId);
        $prevNode = $targetTree->get($prevId);

        $sourceElement = $elementService->findElement($sourceNode->getTypeId());
        $sourceElementVersion = $elementService->findLatestElementVersion($sourceElement);
        $sourceStructure = $elementService->findElementStructure($sourceElementVersion);

        $targetElement = $elementService->createElement(
            $sourceElementVersion->getElementSource(),
            $sourceElement->getMasterLanguage(),
            $this->getUser()->getId()
        );

        // place new element in element_tree
        $targetNode = $targetTree->create(
            $parentNode,
            $prevNode,
            $sourceNode->getType(),
            $targetElement->getEid(),
            $sourceNode->getAttributes(),
            $this->getUser()->getId(),
            $sourceNode->getSortMode(),
            $sourceNode->getSortDir(),
            $sourceNode->getInNavigation()
        );

        $targetStructure = clone $sourceStructure;
        $targetStructure->setId(null);
        $targetStructure->setDataId(UuidUtil::generate());

        $rii = new \RecursiveIteratorIterator(new ElementStructureIterator($targetStructure->getStructures()), \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($rii as $structure) {
            $structure->setId(null);
            $structure->setDataId(UuidUtil::generate());
        }

        $targetElementVersion = $elementService->createElementVersion(
            $targetElement,
            $targetStructure,
            null,
            $this->getUser()->getId()
        );

        return new ResultResponse(true, 'Element copied.', ['id' => $targetNode->getId()]);
    }
636884
protected function matchSiterootUrl(Request $request)
    {
        $siteroot = $this->siterootRequestMatcher->matchRequest($request);
        if (!$siteroot) {
            return null;
        }

        return $siteroot->getDefaultUrl();
    }
491068
public function linkSpouseToIndividual(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref = $request->get('xref', '');

        $individual = Individual::getInstance($xref, $tree);

        Auth::checkIndividualAccess($individual, true);

        if ($individual->sex() === 'F') {
            $title = $individual->fullName() . ' - ' . I18N::translate('Add a husband using an existing individual');
            $label = I18N::translate('Husband');
        } else {
            $title = $individual->fullName() . ' - ' . I18N::translate('Add a wife using an existing individual');
            $label = I18N::translate('Wife');
        }

        return $this->viewResponse('edit/link-spouse-to-individual', [
            'individual' => $individual,
            'label'      => $label,
            'title'      => $title,
        ]);
    }
1170992
protected function loadRoots(Request $request)
    {
        $locale = $request->get('_locale', $this->defaultLocale);

        if (isset($this->roots[$locale])) {
            return $this->roots[$locale];
        }

        $connection = $this->em->getConnection();
        $where = 'lvl=0';

        if ($locale) {
            $where .= sprintf(' AND (language IS NULL OR language=%s)', $connection->quote($locale));
        } else {
            $where .= ' AND language IS NULL';
        }

        $rows = $connection->query('SELECT id, name, language, lft, rgt FROM menu_item WHERE ' . $where)->fetchAll(\PDO::FETCH_NUM);
        foreach ($rows as list($id, $name, $language, $lft, $rgt)) {
            // if the language is null, and the root items is already loaded; ignore it.
            if (null === $language && isset($this->roots[$name])) {
                continue;
            }

            $this->roots[$locale][$name] = [$id, $lft, $rgt];
        }

        if (!isset($this->roots[$locale])) {
            return [];
        }

        return $this->roots[$locale];
    }
20108
public function general(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $query = $request->get('query', '');

        // What type of records to search?
        $search_individuals  = (bool) $request->get('search_individuals');
        $search_families     = (bool) $request->get('search_families');
        $search_repositories = (bool) $request->get('search_repositories');
        $search_sources      = (bool) $request->get('search_sources');
        $search_notes        = (bool) $request->get('search_notes');

        // Default to individuals only
        if (!$search_individuals && !$search_families && !$search_repositories && !$search_sources && !$search_notes) {
            $search_individuals = true;
        }

        // What to search for?
        $search_terms = $this->extractSearchTerms($query);

        // What trees to seach?
        if (Site::getPreference('ALLOW_CHANGE_GEDCOM') === '1') {
            $all_trees = Tree::getAll();
        } else {
            $all_trees = [$tree];
        }

        $search_tree_names = (array) $request->get('search_trees', []);

        $search_trees = array_filter($all_trees, static function (Tree $tree) use ($search_tree_names): bool {
            return in_array($tree->name(), $search_tree_names, true);
        });

        if (empty($search_trees)) {
            $search_trees = [$tree];
        }

        // Do the search
        if ($search_individuals && !empty($search_terms)) {
            $individuals = $this->search_service->searchIndividuals($search_trees, $search_terms);
        } else {
            $individuals = new Collection();
        }

        if ($search_families && !empty($search_terms)) {
            $tmp1 = $this->search_service->searchFamilies($search_trees, $search_terms);
            $tmp2 = $this->search_service->searchFamilyNames($search_trees, $search_terms);

            $families = $tmp1->merge($tmp2)->unique();
        } else {
            $families = new Collection();
        }

        if ($search_repositories && !empty($search_terms)) {
            $repositories = $this->search_service->searchRepositories($search_trees, $search_terms);
        } else {
            $repositories = new Collection();
        }

        if ($search_sources && !empty($search_terms)) {
            $sources = $this->search_service->searchSources($search_trees, $search_terms);
        } else {
            $sources = new Collection();
        }

        if ($search_notes && !empty($search_terms)) {
            $notes = $this->search_service->searchNotes($search_trees, $search_terms);
        } else {
            $notes = new Collection();
        }

        // If only 1 item is returned, automatically forward to that item
        if ($individuals->count() === 1 && $families->isEmpty() && $sources->isEmpty() && $notes->isEmpty()) {
            return redirect($individuals->first()->url());
        }

        if ($individuals->isEmpty() && $families->count() === 1 && $sources->isEmpty() && $notes->isEmpty()) {
            return redirect($families->first()->url());
        }

        if ($individuals->isEmpty() && $families->isEmpty() && $sources->count() === 1 && $notes->isEmpty()) {
            return redirect($sources->first()->url());
        }

        if ($individuals->isEmpty() && $families->isEmpty() && $sources->isEmpty() && $notes->count() === 1) {
            return redirect($notes->first()->url());
        }

        $title = I18N::translate('General search');

        return $this->viewResponse('search-general-page', [
            'all_trees'           => $all_trees,
            'families'            => $families,
            'individuals'         => $individuals,
            'notes'               => $notes,
            'query'               => $query,
            'repositories'        => $repositories,
            'search_families'     => $search_families,
            'search_individuals'  => $search_individuals,
            'search_notes'        => $search_notes,
            'search_repositories' => $search_repositories,
            'search_sources'      => $search_sources,
            'search_trees'        => $search_trees,
            'sources'             => $sources,
            'title'               => $title,
        ]);
    }
579675
public function linkChildToFamilyAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref  = $request->get('xref', '');
        $famid = $request->get('famid', '');
        $PEDI  = $request->get('PEDI', '');

        $individual = Individual::getInstance($xref, $tree);
        Auth::checkIndividualAccess($individual, true);

        $family = Family::getInstance($famid, $tree);
        Auth::checkFamilyAccess($family, true);

        // Replace any existing child->family link (we may be changing the PEDI);
        $fact_id = '';
        foreach ($individual->facts(['FAMC']) as $fact) {
            if ($family === $fact->target()) {
                $fact_id = $fact->id();
                break;
            }
        }

        $gedcom = GedcomCodePedi::createNewFamcPedi($PEDI, $famid);
        $individual->updateFact($fact_id, $gedcom, true);

        // Only set the family->child link if it does not already exist
        $chil_link_exists = false;
        foreach ($family->facts(['CHIL']) as $fact) {
            if ($individual === $fact->target()) {
                $chil_link_exists = true;
                break;
            }
        }

        if (!$chil_link_exists) {
            $family->createFact('1 CHIL @' . $individual->xref() . '@', true);
        }

        return redirect($individual->url());
    }
633354
public function replaceURLAction(Request $request)
    {
        $response = new JsonResponse();

        $response->setData(['text' => $this->urlHelper->replaceUrl($request->get('text'))]);

        return $response;
    }
471360
public static function create(Request $request)
	{

		if ($request->hasParameter('classUri')) {
			$classUri = tao_helpers_Uri::decode($request->getParameter('classUri'));
			$class = new core_kernel_classes_Class($classUri);
			$hideNode = true;
		} elseif ($request->hasParameter('rootNode')) {
			$class = new core_kernel_classes_Class($request->getParameter('rootNode'));
			$hideNode = false;
		} else {
			throw new common_Exception('Missing node information for ' . __FUNCTION__);
		}

		$openNodes = array($class->getUri());
		$openNodesParameter = $request->getParameter('openNodes');
		$openParentNodesParameter = $request->getParameter('openParentNodes');

		if ($request->hasParameter('openNodes') && is_array($openNodesParameter)) {
			$openNodes = array_merge($openNodes, $openNodesParameter);
		} else if ($request->hasParameter('openParentNodes') && is_array($openParentNodesParameter)) {
			$childNodes = $openParentNodesParameter;
			$openNodes = TreeHelper::getNodesToOpen($childNodes, $class);
		}

		$limit = $request->hasParameter('limit') ? $request->getParameter('limit') : self::DEFAULT_LIMIT;
		$offset = $request->hasParameter('offset') ? $request->getParameter('offset') : 0;
		$showInstance = $request->hasParameter('hideInstances') ? !$request->getParameter('hideInstances') : true;
		$orderProp = $request->hasParameter('order') ? $request->getParameter('order') : OntologyRdfs::RDFS_LABEL;
		$orderDir = $request->hasParameter('orderdir') ? $request->getParameter('orderdir') : self::DEFAULT_ORDERDIR;

        $filterProperties = [];
		if ($request->hasParameter('filterProperties')) {
		    $filterProperties = $request->getParameter('filterProperties');
		    if (!is_array($filterProperties)) {
		        $filterProperties = [];
            }
        }

		return new self(
		    $class,
            $limit,
            $offset,
            $showInstance,
            $hideNode,
            $openNodes,
            [],
            [
                'order' => [
                    $orderProp => $orderDir
                ]
            ],
            $filterProperties
        );
	}
991998
public function linkChildToFamily(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref = $request->get('xref', '');

        $individual = Individual::getInstance($xref, $tree);

        Auth::checkIndividualAccess($individual, true);

        $title = $individual->fullName() . ' - ' . I18N::translate('Link this individual to an existing family as a child');

        return $this->viewResponse('edit/link-child-to-family', [
            'individual' => $individual,
            'title'      => $title,
        ]);
    }
536209
public function functionAction(Request $request)
    {
        $selectFieldProviders = $this->get('phlexible_elementtype.select_field_providers');

        $providerName = $request->get('provider');
        $siterootId = $request->get('siterootId');
        $language = $request->get('language');
        $interfaceLanguage = $this->getUser()->getInterfaceLanguage('en');

        $provider = $selectFieldProviders->get($providerName);
        $data = $provider->getData($siterootId, $interfaceLanguage, $language);

        return new JsonResponse(['data' => $data]);
    }
848960
public function select2Individual(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $page  = (int) $request->get('page');
        $query = $request->get('q', '');

        // Fetch one more row than we need, so we can know if more rows exist.
        $offset = $page * self::RESULTS_PER_PAGE;
        $limit  = self::RESULTS_PER_PAGE + 1;

        $results = $this->search_service
            ->searchIndividualNames([$tree], [$query], $offset, $limit)
            ->map(static function (Individual $individual): array {
                return [
                    'id'    => $individual->xref(),
                    'text'  => view('selects/individual', ['individual' => $individual]),
                    'title' => ' ',
                ];
            });

        return response([
            'results'    => $results->slice(0, self::RESULTS_PER_PAGE)->all(),
            'pagination' => [
                'more' => $results->count() > self::RESULTS_PER_PAGE,
            ],
        ]);
    }
566551
public static function getResponder(Request $request)
    {
        if ($request instanceof HttpRequest) {
            return self::getHttpResponder($request);
        } else {
            $requestType = get_class($request);
            throw new \InvalidArgumentException("Requests of type '{$requestType}' are not supported.");
        }
    }
1164014
public function select2Place(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $page  = (int) $request->get('page');
        $query = $request->get('q', '');

        return response($this->placeSearch($tree, $page, $query, true));
    }
1112782
public function addRequest(Request $request)
    {
        $attributes = $this->createAttributes($request);

        $exchange = $this->getExchange($request->server());

        $message = json_encode($request->params());

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new Exception\InvalidArgumentException('Error during json encoding');
        }

        $exchange->publish($message, $request->routingKey(), Constants::AMQP_NOPARAM, $attributes);

        if (null !== $request->id()) {
            $this->requestIds[] = $request->id();
        }

        if (0 !== $request->expiration() && ceil($request->expiration() / 1000) > $this->timeout) {
            $this->timeout = ceil($request->expiration() / 1000);
        }

        ++$this->countRequests;
    }
999527
public function treeAction(Request $request)
    {
        $siterootId = $request->get('siteroot_id');
        $tid = $request->get('node');
        $language = $request->get('language');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $elementService = $this->get('phlexible_element.element_service');
        $nodeSerializer = $this->get('phlexible_tree.node_serializer');

        // TODO: switch to master language of element
        $defaultLanguage = $this->container->getParameter('phlexible_cms.languages.default');

        $tree = $treeManager->getBySiteRootId($siterootId);
        $rootNode = $tree->getRoot();

        $data = [];
        if ($rootNode) {
            if ($tid === null || $tid < 1) {
                $data = [$nodeSerializer->serializeNode($rootNode, $language, $this->container->get('security.token_storage')->getToken())];
            } else {
                $node = $tree->get($tid);

                // check if children of this node should be shown
                $element = $elementService->findElement($node->getTypeId());
                $elementtype = $elementService->findElementtype($element);

                $nodes = $tree->getChildren($node);
                if (!empty($nodes) && !$elementtype->getHideChildren()) {
                    $data = $nodeSerializer->serializeNodes($nodes, $language, $this->container->get('security.token_storage')->getToken());
                }
            }
        }

        return new JsonResponse($data);
    }