adopts resource locator of children by iteration.

@param ResourceSegmentBehavior $document
@param int $userId
496210
private function adaptResourceLocators(ResourceSegmentBehavior $document, $userId)
    {
        if (!$document instanceof ChildrenBehavior) {
            return;
        }

        $webspaceKey = $this->documentInspector->getWebspace($document);
        $languageCode = $this->documentInspector->getOriginalLocale($document);

        $node = $this->documentInspector->getNode($document);
        $node->getSession()->save();

        foreach ($document->getChildren() as $childDocument) {
            // skip documents without assigned resource segment
            if (!$childDocument instanceof ResourceSegmentBehavior
                || !($currentResourceLocator = $childDocument->getResourceSegment())
            ) {
                $this->adaptResourceLocators($childDocument, $userId);

                continue;
            }

            // build new resource segment based on parent changes
            $parentUuid = $this->documentInspector->getUuid($document);
            $childPart = $this->getChildPart($currentResourceLocator);
            $newResourceLocator = $this->generate($childPart, $parentUuid, $webspaceKey, $languageCode);

            // save new resource locator
            $childNode = $this->documentInspector->getNode($childDocument);
            $templatePropertyName = $this->nodeHelper->getTranslatedPropertyName('template', $languageCode);
            $template = $childNode->getPropertyValue($templatePropertyName);
            $structure = $this->structureManager->getStructure($template);

            $property = $structure->getPropertyByTagName('sulu.rlp');
            $property->setValue($newResourceLocator);
            $contentType = $this->contentTypeManager->get($property->getContentTypeName());
            $translatedProperty = $this->nodeHelper->getTranslatedProperty($property, $languageCode);
            $contentType->write($childNode, $translatedProperty, $userId, $webspaceKey, $languageCode, null);

            $childDocument->setResourceSegment($newResourceLocator);

            // do not save routes if unpublished
            if (!$childDocument->getPublished()) {
                $this->adaptResourceLocators($childDocument, $userId);
            } else {
                $this->save($childDocument, $userId);
            }
        }
    }
255980
private function handleChildrenGroup(Lexer $lexer, int $useragentPosition) : int
    {
        $childPosition = 0;

        do {
            $code = $lexer->lex();

            if (self::JSON_OBJECT_START === $code) {
                $code = $this->handleChildBlock($lexer, $useragentPosition, $childPosition);
                ++$childPosition;
            }
        } while (self::JSON_ARRAY_END !== $code);

        return $lexer->lex();
    }
692380
public static function user_competency_viewed_in_course($competencyid, $userid, $courseid) {
        $params = self::validate_parameters(self::user_competency_viewed_in_course_parameters(), array(
            'competencyid' => $competencyid,
            'userid' => $userid,
            'courseid' => $courseid
        ));
        $ucc = api::get_user_competency_in_course($params['courseid'], $params['userid'], $params['competencyid']);
        $result = api::user_competency_viewed_in_course($ucc);

        return $result;
    }
962323
public function updateResourceTracking(ResourceNode $node, User $user, \DateTime $date)
    {
        $this->evalutionManager->updateResourceUserEvaluationData(
            $node,
            $user,
            $date,
            ['status' => AbstractResourceEvaluation::STATUS_PARTICIPATED]
        );
    }
1051186
public function onBeforeDeleteUser(UserEvent $event)
    {
        $user = $event->getUser();

        $locks = $this->entityManager->getRepository('PhlexibleElementBundle:ElementLock')
            ->findBy(['userId' => $user->getId()]);

        foreach ($locks as $lock) {
            $this->entityManager->remove($lock);
        }
    }
112254
public function noteListAction($resourceId, $page, User $user)
    {
        $notesQB = $this->getNoteActionManager()->getNotesForPagination($resourceId, $user);
        $pager = $this->paginateQuery($notesQB, $page);

        return array('pager' => $pager, 'resourceId' => $resourceId);
    }
587692
public function createElement(ElementSource $elementSource, $masterLanguage, $userId)
    {
        $element = new Element();
        $element
            ->setElementtypeId($elementSource->getElementtypeId())
            ->setMasterLanguage($masterLanguage)
            ->setLatestVersion(1)
            ->setCreateUserId($userId)
            ->setCreatedAt(new \DateTime());

        $elementVersion = new ElementVersion();
        $elementVersion
            ->setVersion(1)
            ->setElement($element)
            ->setElementSource($elementSource)
            ->setCreateUserId($userId)
            ->setCreatedAt(new \DateTime());

        $this->fieldMapper->apply($elementVersion);

        $this->elementManager->updateElement($element, false);
        $this->elementVersionManager->updateElementVersion($elementVersion);

        $this->elementHistoryManager->insert(
            ElementHistoryManagerInterface::ACTION_CREATE_ELEMENT,
            $element->getEid(),
            $userId,
            null,
            null,
            1,
            $masterLanguage
        );

        return $element;
    }
211239
public static function user_competency_start_review($userid, $competencyid) {
        $params = self::validate_parameters(self::user_competency_start_review_parameters(), array(
            'userid' => $userid,
            'competencyid' => $competencyid
        ));

        $context = context_user::instance($params['userid']);
        self::validate_context($context);

        return api::user_competency_start_review($userid, $competencyid);
    }
866083
public function handlePersistDocument(PersistEvent $event)
    {
        /** @var ResourceSegmentBehavior $document */
        $document = $event->getDocument();

        if (!$this->supports($document)) {
            return;
        }

        $property = $this->getResourceSegmentProperty($document);
        // check if a property for the resource segment is available, this prevents the code from failing in case there
        // is no such property for some reason (e.g. the document doesn't have a structure)
        if ($property) {
            $this->persistDocument($document, $property);
        }
    }
551939
public function processFieldUpdate(\Gems_Tracker_RespondentTrack $respTrack, $userId)
    {
        $agenda = $this->loader->getAgenda();
        $change = false;
        $token  = $respTrack->getFirstToken();

        if (! $token) {
            return;
        }

        do {
            if ($token->isCompleted()) {
                continue;
            }

            $appId = $respTrack->getRoundAfterAppointmentId($token->getRoundId());

            // Not a round without appointment id
            if ($appId !== false) {
                if ($appId) {
                    $appointment = $agenda->getAppointment($appId);
                } else {
                    $appointment = null;
                }

                if ($appointment && $appointment->isActive()) {
                    $newCode = \GemsEscort::RECEPTION_OK;
                    $newText = null;
                } else {
                    $newCode = 'skip';
                    $newText = $this->_('Skipped until appointment is set');
                }
                $oldCode = \GemsEscort::RECEPTION_OK === $newCode ? 'skip' : \GemsEscort::RECEPTION_OK;
                $curCode = $token->getReceptionCode()->getCode();
                // \MUtil_Echo::track($token->getTokenId(), $curCode, $oldCode, $newCode);
                if (($oldCode === $curCode) && ($curCode !== $newCode)) {
                    $change = true;
                    $token->setReceptionCode($newCode, $newText, $userId);
                }
            }
        } while ($token = $token->getNextToken());

        if ($change) {
            $respTrack->refresh();
        }
    }
701463
protected function buildUserResourceUri($resource, $userId = null)
    {

        $userId = is_null($userId) ? $this->userId : $userId;
        return '/users/' . $userId . '/' . $resource;

    }
427085
public static function can_create_data_deletion_request_for_children(int $userid, int $requesterid = null): bool {
        global $USER;
        $requesterid = $requesterid ?: $USER->id;
        return has_capability('tool/dataprivacy:makedatadeletionrequestsforchildren', \context_user::instance($userid),
            $requesterid);
    }
1305741
public static function get_by_user_and_competency($userid, $competencyid) {
        global $DB;

        $sql = 'SELECT p.*
                  FROM {' . self::TABLE . '} p
             LEFT JOIN {' . plan_competency::TABLE . '} pc
                    ON pc.planid = p.id
                   AND pc.competencyid = :competencyid1
             LEFT JOIN {' . user_competency_plan::TABLE . '} ucp
                    ON ucp.planid = p.id
                   AND ucp.competencyid = :competencyid2
             LEFT JOIN {' . template_competency::TABLE . '} tc
                    ON tc.templateid = p.templateid
                   AND tc.competencyid = :competencyid3
                 WHERE p.userid = :userid
                   AND (pc.id IS NOT NULL
                    OR ucp.id IS NOT NULL
                    OR tc.id IS NOT NULL)
              ORDER BY p.id ASC';

        $params = array(
            'competencyid1' => $competencyid,
            'competencyid2' => $competencyid,
            'competencyid3' => $competencyid,
            'userid' => $userid
        );

        $plans = array();
        $records = $DB->get_records_sql($sql, $params);
        foreach ($records as $record) {
            $plans[$record->id] = new plan(0, $record);
        }

        return $plans;
    }
385234
public function loadOrGenerateByUser($userId)
    {
        $referenceClass = $this->referenceClass;
        $reference = new $referenceClass();
        $reference->setId(WorkflowRightInterface::NODE);

        $contentTypes = $this->contentTypeRepository->findAllNotDeletedInLastVersion();
        foreach ($contentTypes as $key => $contentType) {
            if (!$contentType->isDefiningStatusable()) {
                unset($contentTypes[$key]);
            }
        }
        $contentTypes[] = $reference;

        $workflowRight = $this->workflowRightRepository->findOneByUserId($userId);

        if (null === $workflowRight) {
            $workflowRightClass = $this->workflowRightClass;
            $workflowRight = new $workflowRightClass();
            $workflowRight->setUserId($userId);
        }

        return $this->authorizationWorkflowRightManager->cleanAuthorization($contentTypes, $workflowRight);
    }
1359623
public function scopeForUserWithNewMessages(Builder $query, $userId)
    {
        $participantTable = Models::table('participants');
        $threadsTable = Models::table('threads');

        return $query->join($participantTable, $this->getQualifiedKeyName(), '=', $participantTable . '.thread_id')
            ->where($participantTable . '.user_id', $userId)
            ->whereNull($participantTable . '.deleted_at')
            ->where(function (Builder $query) use ($participantTable, $threadsTable) {
                $query->where($threadsTable . '.updated_at', '>', $this->getConnection()->raw($this->getConnection()->getTablePrefix() . $participantTable . '.last_read'))
                    ->orWhereNull($participantTable . '.last_read');
            })
            ->select($threadsTable . '.*');
    }
552691
public static function user_competency_stop_review($userid, $competencyid) {
        static::require_enabled();
        $context = context_user::instance($userid);
        $uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
        if (!$uc || !$uc->can_read()) {
            throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
        } else if ($uc->get('status') != user_competency::STATUS_IN_REVIEW) {
            throw new coding_exception('The competency review can not be stopped at this stage.');
        } else if (!$uc->can_review()) {
            throw new required_capability_exception($context, 'moodle/competency:usercompetencyreview', 'nopermissions', '');
        }

        $uc->set('status', user_competency::STATUS_IDLE);
        $result = $uc->update();
        if ($result) {
            \core\event\competency_user_competency_review_stopped::create_from_user_competency($uc)->trigger();
        }
        return $result;
    }
644693
public function findFiltersForUserAndContext($context, $userId, $locale)
    {
        $filters = $this->filterRepository->findByUserAndContextAndLocale($locale, $context, $userId);
        array_walk(
            $filters,
            function(&$filter) use ($locale) {
                $filter = new Filter($filter, $locale);
            }
        );

        return $filters;
    }