Find out if there are track calculation events and delegate to the event if needed

@param int $userId
480274
public function handleTrackCalculation($userId)
    {
        // Process any events
        $trackEngine = $this->getTrackEngine();

        // Places here instead of only in handle field update so it will run on new tracks too
        $this->assignTokensToRelations();

        if ($event = $trackEngine->getTrackCalculationEvent()) {
            return $event->processTrackCalculation($this, $userId);
        }

        return 0;
    }
501283
public static function convertUserIdToVisitorIdBin($userId)
    {
        require_once PIWIK_INCLUDE_PATH . '/libs/PiwikTracker/PiwikTracker.php';
        $userIdHashed = \PiwikTracker::getUserIdHashed($userId);

        return self::convertVisitorIdToBin($userIdHashed);
    }
961693
public function removeParticipant($userId)
    {
        $userIds = is_array($userId) ? $userId : (array) func_get_args();

        Models::participant()->where('thread_id', $this->id)->whereIn('user_id', $userIds)->delete();
    }
636432
protected function attachPermissionToUser($permission, $userId)
    {
        // Check if user exists
        if ($user = $this->userRepository->findById($userId)) {
            $user->attachPermission($permission);
            $this->info('Permission attached successfully to user');
        } else {
            $this->error('Not possible to attach permission. User not found');
        }
    }
54777
public function check_examples_assessed_before_submission($userid) {

        if ($this->useexamples and $this->examplesmode == self::EXAMPLES_BEFORE_SUBMISSION
            and !has_capability('mod/workshop:manageexamples', $this->context)) {

            // Check that all required examples have been assessed by the user.
            $examples = $this->get_examples_for_reviewer($userid);
            foreach ($examples as $exampleid => $example) {
                if (is_null($example->assessmentid)) {
                    $examples[$exampleid]->assessmentid = $this->add_allocation($example, $userid, 0);
                }
                if (is_null($example->grade)) {
                    return false;
                }
            }
        }
        return true;
    }
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();
        }
    }
1173345
public static function is_contact(int $userid, int $contactid) : bool {
        global $DB;

        $sql = "SELECT id
                  FROM {message_contacts} mc
                 WHERE (mc.userid = ? AND mc.contactid = ?)
                    OR (mc.userid = ? AND mc.contactid = ?)";
        return $DB->record_exists_sql($sql, [$userid, $contactid, $contactid, $userid]);
    }
336394
private function _update(array $values, $userId)
    {
        if ($this->tracker->filterChangesOnly($this->_trackData, $values)) {

            if (\Gems_Tracker::$verbose) {
                $echo = '';
                foreach ($values as $key => $val) {
                    $echo .= $key . ': ' . $this->_trackData[$key] . ' => ' . $val . "\n";
                }
                \MUtil_Echo::r($echo, 'Updated values for ' . $this->_trackId);
            }

            if (! isset($values['gto_changed'])) {
                $values['gtr_changed'] = new \MUtil_Db_Expr_CurrentTimestamp();
            }
            if (! isset($values['gtr_changed_by'])) {
                $values['gtr_changed_by'] = $userId;
            }

            // Update values in this object
            $this->_trackData = $values + $this->_trackData;

            // return 1;
            return $this->db->update('gems__tracks', $values, array('gtr_id_track = ?' => $this->_trackId));

        } else {
            return 0;
        }
    }
564998
protected function process_unlock_submission($userid = 0) {

        require_sesskey();

        if (!$userid) {
            $userid = required_param('userid', PARAM_INT);
        }

        return $this->unlock_submission($userid);
    }
1236864
public function isUnread($userId)
    {
        try {
            $participant = $this->getParticipantFromUser($userId);
            if ($this->updated_at > $participant->last_read) {
                return true;
            }
        } catch (ModelNotFoundException $e) {
            // do nothing
        }

        return false;
    }
458355
public static function can_read_user($userid) {
        $capability = 'moodle/competency:usercompetencyview';
        return has_capability($capability, context_user::instance($userid))
            || plan::can_read_user($userid);
    }
1265174
public function execute($sourceId = null, $userId = null)
    {
        $batch  = $this->getBatch();
        $source = $this->loader->getTracker()->getSource($sourceId);

        if (is_null($userId)) {
            $userId = $this->loader->getCurrentUser()->getUserId();
        }

        $surveyCount = $batch->addToCounter('sourceSyncSources');
        $batch->setMessage('sourceSyncSources', sprintf(
                $this->plural('Check %s source', 'Check %s sources', $surveyCount),
                $surveyCount
                ));

        $source->synchronizeSurveyBatch($batch, $userId);
    }
969799
public function hasParticipant($userId)
    {
        $participants = $this->participants()->where('user_id', '=', $userId);
        if ($participants->count() > 0) {
            return true;
        }

        return false;
    }
661691
public function execute($tokenData = null, $userId = null)
    {
        $tracker = $this->loader->getTracker();

        $token  = $tracker->getToken($tokenData[0]);
        $survey = $token->getSurvey();
        $source = $survey->getSource();
        if (method_exists($source, 'getCompletedTokens')) {
            $completed = $source->getCompletedTokens($tokenData, $survey->getSourceSurveyId());
        } else {
            // No bulk method, check all individually
            $completed = $tokenData;
        }

        if ($completed) {
            $batch   = $this->getBatch();
            foreach($completed as $tokenId) {
                $batch->setTask('Tracker_CheckTokenCompletion', 'tokchk-' . $tokenId, $tokenId, $userId);
            }
        }
    }
1301337
protected static function delete_data(int $userid) {
        global $DB;

        foreach (static::get_records($userid) as $record) {
            $DB->delete_records('message_airnotifier_devices', ['id' => $record->id]);
        }
    }
996311
protected function process_lock_submission($userid = 0) {

        require_sesskey();

        if (!$userid) {
            $userid = required_param('userid', PARAM_INT);
        }

        return $this->lock_submission($userid);
    }
155391
public function isInputtedTwoFactorAuthCodeCorrect($userId=null) {
        $inputted2faCode = $this->request->input('2facode');

        if (isset($userId)) {
            $sent2faCode     = $this->getUserSmsToken($userId);
        } else {
            $sent2faCode     = $this->request->session()->get('codeToInput');
        }


        if ($inputted2faCode == $sent2faCode) {
            return true;
        }

        return false;
    }