@param Wiki $wiki
@param User $user
@param bool $isAdmin

@return array|string $tree
515585
public function buildSectionTree(Wiki $wiki, User $user = null, $isAdmin = false)
    {
        $queryBuilder = $this->createQueryBuilder('section')
            ->join('section.activeContribution', 'contribution')
            ->leftJoin('section.author', 'author')
            ->select('section, contribution, author, IDENTITY(section.parent) as parent')
            ->andWhere('section.root = :rootId')
            ->orderBy('section.root, section.left', 'ASC')
            ->setParameter('rootId', $wiki->getRoot()->getId());
        $queryBuilder->andWhere(
            $queryBuilder->expr()->orX(
                'section.deleted = :deleted',
                $queryBuilder->expr()->isNull('section.deleted')
            )
        )->setParameter('deleted', false);
        if (false === $isAdmin && null !== $user) {
            $queryBuilder
                ->andWhere(
                    $queryBuilder->expr()->orX(
                        'section.visible = :visible',
                        'section.author = :userId'
                    )
                )->setParameter('visible', true)->setParameter('userId', $user->getId());
        }
        if (false === $isAdmin && null === $user) {
            $queryBuilder
                ->andWhere('section.visible = :visible')
                ->setParameter('visible', true);
        }
        $options = ['decorate' => false];
        $tree = $this->buildTree($queryBuilder->getQuery()->getArrayResult(), $options);

        return $tree;
    }
1269784
public function getPageTree(Website $website, $isAdmin, $isMenu)
    {
        return $this->pageRepository->buildPageTree($website, $isAdmin, $isMenu);
    }
1181112
public function indexAction(User $user = null)
    {
        return [
            'isAdmin' => !is_null($user) ? $user->hasRole('ROLE_ADMIN') : false,
            'resourceTypes' => array_map(function (ResourceType $type) {
                return $this->resourceTypeSerializer->serialize($type);
            }, $this->resourceTypeRepo->findBy([], ['name' => 'ASC'])),
        ];
    }
1114532
public function findOneByWidgetType($type, $id, User $user, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('w')
            ->andWhere($this->getWigetInstanceString($type))
            ->andWhere('w.id = :id')
            ->andWhere('w.user = :user')
            ->setParameters([
                'id' => $id,
                'user' => $user,
            ])
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getSingleResult() : $queryBuilder->getQuery();
    }
905927
public function getListAction(Tree $tree, UserInterface $user): ResponseInterface
    {
        Auth::checkComponentAccess($this, 'list', $tree, $user);
      
        $listController = new ListController(app(IndividualListService::class), app(LocalizationService::class));
        return $listController->sourceList($tree);
    }
404549
public function getAdminAction(ServerRequestInterface $request, UserInterface $user, Tree $tree = null): ResponseInterface
    {
        // We need a tree to work with.
        if ($tree === null) {
            throw new NotFoundHttpException();
        }

        // Admins only.
        if (!Auth::isAdmin($user)) {
            throw new AccessDeniedHttpException();
        }

        $plugin = $request->get('plugin', '');
        $xref   = $request->get('xref', '');

        $plugins = $this->getPluginList();
        $plugin  = $plugins[$plugin] ?? null;

        $curr_xref = '';
        $prev_xref = '';
        $next_xref = '';

        // Don't do any processing until a plugin is chosen.
        if ($plugin !== null) {
            $plugin->getOptions($request);

            $all_data = $this->allData($plugin, $tree);

            // Make sure that our requested record really does need updating.
            // It may have been updated in another session, or may not have
            // been specified at all.
            if (array_key_exists($xref, $all_data) && $plugin->doesRecordNeedUpdate($this->getRecord($all_data[$xref], $tree))) {
                $curr_xref = $xref;
            }

            // The requested record doesn't need updating - find one that does
            if ($curr_xref === '') {
                $curr_xref = $this->findNextXref($plugin, $xref, $all_data, $tree);
            }
            if ($curr_xref === '') {
                $curr_xref = $this->findPrevXref($plugin, $xref, $all_data, $tree);
            }

            // If we've found a record to update, get details and look for the next/prev
            if ($curr_xref !== '') {
                $prev_xref = $this->findPrevXref($plugin, $xref, $all_data, $tree);
                $next_xref = $this->findNextXref($plugin, $xref, $all_data, $tree);
            }
        }

        return $this->viewResponse('modules/batch_update/admin', [
            'auto_accept' => (bool) $user->getPreference('auto_accept'),
            'plugins'     => $plugins,
            'curr_xref'   => $curr_xref,
            'next_xref'   => $next_xref,
            'plugin'      => $plugin,
            'record'      => GedcomRecord::getInstance($curr_xref, $tree),
            'prev_xref'   => $prev_xref,
            'title'       => I18N::translate('Batch update'),
            'tree'        => $tree,
            'trees'       => Tree::getNameList(),
        ]);
    }
298222
protected function doBuild($user, $isApi = false)
    {
        $this->register($user, $isApi);

        $this->container->setAlias(
            $this->alias($user, $isApi),
            $this->definition($user, $isApi)
        );

        return $this->container;
    }
207213
public static function get_users_in_context(userlist $userlist) {
        $context = $userlist->get_context();

        if (!is_a($context, \context_user::class)) {
            return;
        }

        $params = [
            'contextlevel' => CONTEXT_USER,
            'contextid' => $context->id,
        ];

        $sql = "SELECT instanceid AS userid
                  FROM {context}
                 WHERE id = :contextid
                       AND contextlevel = :contextlevel";

        $userlist->add_from_sql('userid', $sql, $params);
    }
504167
public function update(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
    {
        $contact_method = (string) $request->get('contact_method');
        $email          = (string) $request->get('email');
        $language       = (string) $request->get('language');
        $real_name      = (string) $request->get('real_name');
        $password       = (string) $request->get('password');
        $rootid         = (string) $request->get('root_id');
        $theme          = (string) $request->get('theme');
        $time_zone      = (string) $request->get('timezone');
        $user_name      = (string) $request->get('user_name');
        $visible_online = (string) $request->get('visible_online');

        // Change the password
        if ($password !== '') {
            $user->setPassword($password);
        }

        // Change the username
        if ($user_name !== $user->userName()) {
            if ($this->user_service->findByUserName($user_name) === null) {
                $user->setUserName($user_name);
            } else {
                FlashMessages::addMessage(I18N::translate('Duplicate username. A user with that username already exists. Please choose another username.'));
            }
        }

        // Change the email
        if ($email !== $user->email()) {
            if ($this->user_service->findByEmail($email) === null) {
                $user->setEmail($email);
            } else {
                FlashMessages::addMessage(I18N::translate('Duplicate email address. A user with that email already exists.'));
            }
        }

        $user
            ->setRealName($real_name)
            ->setPreference('contactmethod', $contact_method)
            ->setPreference('language', $language)
            ->setPreference('theme', $theme)
            ->setPreference('TIMEZONE', $time_zone)
            ->setPreference('visibleonline', $visible_online);

        $tree->setUserPreference($user, 'rootid', $rootid);

        // Switch to the new theme now
        Session::put('theme', $theme);

        // Switch to the new language now
        Session::put('language', $language);

        return redirect(route('my-account', ['ged' => $tree->name()]));
    }
1105301
public function getResourceUserPermission(ResourceInterface $resource, UserInterface $user)
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId AND r.user=:user')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->setParameter('user', $user)
            ->getQuery();

        return $query->getOneOrNullResult();
    }
655889
public function getChartAction(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
    {
        Auth::checkComponentAccess($this, 'chart', $tree, $user);

        $ajax  = (bool) $request->get('ajax');
        $scale = (int) $request->get('scale', self::SCALE_DEFAULT);
        $scale = min($scale, self::SCALE_MAX);
        $scale = max($scale, self::SCALE_MIN);

        $xrefs = $request->get('xrefs', []);

        // Find the requested individuals.
        $individuals = (new Collection($xrefs))
            ->unique()
            ->map(static function (string $xref) use ($tree): ?Individual {
                return Individual::getInstance($xref, $tree);
            })
            ->filter()
            ->filter(GedcomRecord::accessFilter());

        // Generate URLs omitting each xref.
        $remove_urls = [];

        foreach ($individuals as $exclude) {
            $xrefs_1 = $individuals
                ->filter(static function (Individual $individual) use ($exclude): bool {
                    return $individual->xref() !== $exclude->xref();
                })
                ->map(static function (Individual $individual): string {
                    return $individual->xref();
                });

            $remove_urls[$exclude->xref()] = route('module', [
                'module' => $this->name(),
                'action' => 'Chart',
                'ged'    => $tree->name(),
                'scale'  => $scale,
                'xrefs'  => $xrefs_1->all(),
            ]);
        }

        $individuals = array_map(static function (string $xref) use ($tree): ?Individual {
            return Individual::getInstance($xref, $tree);
        }, $xrefs);

        $individuals = array_filter($individuals, static function (?Individual $individual): bool {
            return $individual instanceof Individual && $individual->canShow();
        });

        if ($ajax) {
            return $this->chart($tree, $xrefs, $scale);
        }

        $ajax_url = route('module', [
            'ajax'   => true,
            'module' => $this->name(),
            'action' => 'Chart',
            'ged'    => $tree->name(),
            'scale'  => $scale,
            'xrefs'  => $xrefs,
        ]);

        $reset_url = route('module', [
            'module' => $this->name(),
            'action' => 'Chart',
            'ged'    => $tree->name(),
        ]);

        $zoom_in_url = route('module', [
            'module' => $this->name(),
            'action' => 'Chart',
            'ged'    => $tree->name(),
            'scale'  => min(self::SCALE_MAX, $scale + (int) ($scale * 0.2 + 1)),
            'xrefs'  => $xrefs,
        ]);

        $zoom_out_url = route('module', [
            'module' => $this->name(),
            'action' => 'Chart',
            'ged'    => $tree->name(),
            'scale'  => max(self::SCALE_MIN, $scale - (int) ($scale * 0.2 + 1)),
            'xrefs'  => $xrefs,
        ]);

        return $this->viewResponse('modules/timeline-chart/page', [
            'ajax_url'     => $ajax_url,
            'individuals'  => $individuals,
            'module_name'  => $this->name(),
            'remove_urls'  => $remove_urls,
            'reset_url'    => $reset_url,
            'title'        => $this->title(),
            'scale'        => $scale,
            'zoom_in_url'  => $zoom_in_url,
            'zoom_out_url' => $zoom_out_url,
        ]);
    }
351102
public function getWidgetDisplayConfigsByUserAndWidgets(
        User $user,
        array $widgetInstances,
        $executeQuery = true
    )
    {
        return count($widgetInstances) > 0 ?
            $this->widgetDisplayConfigRepo->findWidgetDisplayConfigsByUserAndWidgets(
                $user,
                $widgetInstances,
                $executeQuery
            ) :
            array();
    }
312830
public static WikiUser getUser(String wikiId, String siteurl) {

    WikiUser result = null;
    try {
      Properties props = getProperties(wikiId);
      result = new WikiUser();
      result.setUsername(props.getProperty("user"));
      result.setEmail(props.getProperty("email"));
      Crypt pcf = new Crypt(props.getProperty("cypher"),
          props.getProperty("salt"));
      result.setPassword(pcf.decrypt(props.getProperty("secret")));
    } catch (FileNotFoundException e) {
      String msg = help(wikiId, siteurl);
      LOGGER.log(Level.SEVERE, msg);
    } catch (IOException e) {
      LOGGER.log(Level.SEVERE, e.getMessage());
    } catch (GeneralSecurityException e) {
      LOGGER.log(Level.SEVERE, e.getMessage());
    }
    return result;
  }
880775
public function postAddFavoriteAction(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
    {
        $note  = $request->get('note', '');
        $title = $request->get('title', '');
        $url   = $request->get('url', '');
        $type  = $request->get('type', '');
        $xref  = $request->get($type . '-xref', '');

        $record = $this->getRecordForType($type, $xref, $tree);

        if (Auth::isManager($tree, $user)) {
            if ($type === 'url' && $url !== '') {
                $this->addUrlFavorite($tree, $url, $title ?: $url, $note);
            }

            if ($record instanceof GedcomRecord && $record->canShow()) {
                $this->addRecordFavorite($tree, $record, $note);
            }
        }

        $url = route('tree-page', ['ged' => $tree->name()]);

        return redirect($url);
    }
234016
public static function get_users_in_context(userlist $userlist) {
        $context = $userlist->get_context();

        if (!is_a($context, \context_module::class)) {
            return;
        }

        $params = [
            'modname' => 'wiki',
            'contextlevel' => CONTEXT_MODULE,
            'contextid' => $context->id,
        ];

        $sql = "
          SELECT s.userid
            FROM {modules} m
            JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
            JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
            JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
            WHERE ctx.id = :contextid";

        $userlist->add_from_sql('userid', $sql, $params);

        $sql = "
          SELECT p.userid
            FROM {modules} m
            JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
            JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
            JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
            JOIN {wiki_pages} p ON p.subwikiid = s.id
            WHERE ctx.id = :contextid";

        $userlist->add_from_sql('userid', $sql, $params);

        $sql = "
          SELECT v.userid
            FROM {modules} m
            JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
            JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
            JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
            JOIN {wiki_pages} p ON p.subwikiid = s.id
            JOIN {wiki_versions} v ON v.pageid = p.id
            WHERE ctx.id = :contextid";

        $userlist->add_from_sql('userid', $sql, $params);

        $sql = "
          SELECT l.userid
            FROM {modules} m
            JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
            JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
            JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
            JOIN {wiki_pages} p ON p.subwikiid = s.id
            JOIN {wiki_locks} l ON l.pageid = p.id
            WHERE ctx.id = :contextid";

        $userlist->add_from_sql('userid', $sql, $params);
        \core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_wiki', 'wiki_page', $context->id);
    }
737198
private static function is_super_admin( $user_id ) {
            $is_super_admin = false;

            $user = self::_get_user_by_id( $user_id );

            if ( $user instanceof FS_User && ! empty( $user->email ) ) {
                self::require_pluggable_essentials();

                $wp_user = get_user_by( 'email', $user->email );

                if ( $wp_user instanceof WP_User ) {
                    $super_admins   = get_super_admins();
                    $is_super_admin = ( is_array( $super_admins ) && in_array( $wp_user->user_login, $super_admins ) );
                }
            }

            return $is_super_admin;
        }
168188
public function getUsersWithNodeVersionLock(NodeTranslation $nodeTranslation, $isPublicNodeVersion, BaseUser $userToExclude = null)
    {
        return  array_reduce(
            $this->getNodeVersionLocksByNodeTranslation($nodeTranslation, $isPublicNodeVersion, $userToExclude),
            function ($return, NodeVersionLock $item) {
                $return[] = $item->getOwner();

                return $return;
            },
            []
        );
    }