Process the data and do what must be done

Storing the changed $values is handled by the calling function.

@param \Gems_Tracker_RespondentTrack $respTrack Gems respondent track object
@param int   $userId The current userId
@return void
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();
        }
    }
1072908
public function is_tracked_user($userid) {
        return is_enrolled(context_course::instance($this->course->id), $userid, 'moodle/course:isincompletionreports', true);
    }
353010
protected function setUserCheckout($user_id)
    {
        $this->data_user = array();

        if (!is_numeric($user_id)) {
            $this->outputHttpStatus(403);
        }

        $this->data_user = $this->user->get($user_id);

        if (empty($this->data_user['status'])) {
            $this->outputHttpStatus(404);
        }

        $this->order_user_id = $user_id;
        $this->order_store_id = $this->data_user['store_id'];
    }
357644
public function saveSubscription(int $userId = null) : void
    {
        $json = \file_get_contents('php://input');

        if (!$json)
        {
            return;
        }

        $data = \json_decode($json, true);

        if (!$data || empty($data['endpoint']) || empty($data['publicKey']) || empty($data['authToken']))
        {
            return;
        }

        $row = $this->subscriptionTable->findActive()->where('endpoint', $data['endpoint'])->fetch();

        switch ($this->request->getMethod()) {
            case 'POST':
            case 'PUT':
            {
                if ($row)
                {
                    $row->update([
                        'user_id' => $userId ?: $row->user_id ?: null,
                        'key' => $data['publicKey'],
                        'token' => $data['authToken'],
                        'encoding' => $data['contentEncoding']
                    ]);
                    
                    return;
                }

                $row = $this->subscriptionTable->insert([
                    'user_id' => $userId,
                    'endpoint' => $data['endpoint'],
                    'key' => $data['publicKey'],
                    'token' => $data['authToken'],
                    'encoding' => $data['contentEncoding']
                ]);

                $this->sendNotification($row, 'Notifications enabled!', true);

                return;
            }
            case 'DELETE':
            {
                if ($row)
                {
                    $row->update([
                        'active' => 0
                    ]);
                }

                return;
            }
            default:
                throw new \Nette\Application\BadRequestException();
        }
    }
560624
public function getRespondentTrack()
    {
        static $respTrack;

        if ($respTrack instanceof \Gems_Tracker_RespondentTrack) {
            return $respTrack;
        }

        $respTrackId = $this->_getParam(\Gems_Model::RESPONDENT_TRACK);
        $tracker     = $this->loader->getTracker();

        if ($respTrackId) {
            $respTrack = $tracker->getRespondentTrack($respTrackId);
        } else {
            if ($this->isMultiTracks()) {
                throw new \Gems_Exception($this->_('No track specified for respondent!'));
            }

            $respondent = $this->getRespondent();
            $respTracks = $tracker->getRespondentTracks(
                    $respondent->getId(),
                    $respondent->getOrganizationId(),
                    array('grc_success DESC', 'gr2t_start_date')
                    );
            $trackId = $this->escort->getTrackId();
            if ($trackId) {
                foreach ($respTracks as $respTrack) {
                    if ($respTrack instanceof \Gems_Tracker_RespondentTrack) {
                        if ($trackId == $respTrack->getTrackId()) {
                            // Return the right track if it exists
                            break;
                        }
                    }
                }
            } else {
                $respTrack = reset($respTracks);
            }
        }
        if (! $respTrack instanceof \Gems_Tracker_RespondentTrack) {
            if ($this->isMultiTracks()) {
                throw new \Gems_Exception($this->_('No track found for respondent!'));
            } else {
                $this->menu->getParameterSource()->offsetSet('track_can_be_created', 1);
                return null;
            }
        }

        $respTrack->applyToMenuSource($this->menu->getParameterSource());

        // Otherwise return the last created track (yeah some implementations are not correct!)
        return $respTrack;
    }
939684
public function execute($tokenData = null, $userId = null)
    {
        $batch   = $this->getBatch();
        $tracker = $this->loader->getTracker();

        $batch->addToCounter('checkedTokens');
        $token = $tracker->getToken($tokenData);

        $wasAnswered = $token->isCompleted();

        if ($result = $token->checkTokenCompletion($userId)) {
            if ($result & \Gems_Tracker_Token::COMPLETION_DATACHANGE) {
                $i = $batch->addToCounter('resultDataChanges');
                $batch->setMessage('resultDataChanges', sprintf(
                        $this->_('Results and timing changed for %d tokens.'),
                        $i
                        ));

                if ($wasAnswered) {
                    $action  = 'token.data-changed';
                    $message = sprintf($this->_("Token '%s' data has changed."), $token->getTokenId());
                } else {
                    $action  = 'token.answered';
                    $message = sprintf($this->_("Token '%s' was answered."), $token->getTokenId());
                }
                if (! $this->request instanceof \Zend_Controller_Request_Abstract) {
                    $this->request = \Zend_Controller_Front::getInstance()->getRequest();
                }
                $this->accesslog->logEntry(
                        $this->request,
                        $action,
                        true,
                        $message,
                        $token->getArrayCopy(),
                        $token->getRespondentId()
                        );

            }
            if ($result & \Gems_Tracker_Token::COMPLETION_EVENTCHANGE) {
                $i = $batch->addToCounter('surveyCompletionChanges');
                $batch->setMessage('surveyCompletionChanges', sprintf(
                        $this->_('Answers changed by survey completion event for %d tokens.'),
                        $i
                        ));
            }
        }

        if ($token->isCompleted()) {
            $batch->setTask('Tracker_ProcessTokenCompletion', 'tokproc-' . $token->getTokenId(), $tokenData, $userId);
        }

        $batch->setMessage('checkedTokens', sprintf(
                $this->_('Checked %d tokens.'),
                $batch->getCounter('checkedTokens')
                ));

        // Free memory
        $tracker->removeToken($token);
    }
918539
void updateRack(HeartbeatImpl heartbeat,
                  UpdateRackHeartbeat updateRack)
  {
    for (UpdateServerHeartbeat serverUpdate : updateRack.getServers()) {
      if (serverUpdate == null) {
        continue;
      }
 
      update(serverUpdate);
      // updateTargetServers();
 
      ServerHeartbeat peerServer = findServer(serverUpdate.getAddress(),
                                              serverUpdate.getPort());
 
      if (peerServer.isSelf()) {
        continue;
      }
      
      heartbeat.updateServer(peerServer, serverUpdate);
      /*
      String externalId = serverUpdate.getExternalId();

      heartbeat.updateExternal(peerServer, externalId);

      if (peerServer.onHeartbeatUpdate(serverUpdate)) {
        if (peerServer.isUp()) {
          onServerStart(peerServer);
        }
        else {
          onServerStop(peerServer);
        }
      }
      */
    }

    update();
  }
699905
public function execute($tokenData = null, $userId = null)
    {
        $batch   = $this->getBatch();
        $tracker = $this->loader->getTracker();
        $token   = $tracker->getToken($tokenData);

        if ($token->isCompleted()) {
            $respTrack = $token->getRespondentTrack();
            $userId    = $userId ? $userId : $this->loader->getCurrentUser()->getUserId();

            if ($result = $respTrack->handleRoundCompletion($token, $userId)) {
                $a = $batch->addToCounter('roundCompletionCauses');
                $b = $batch->addToCounter('roundCompletionChanges', $result);
                $batch->setMessage('roundCompletionChanges',
                        sprintf($this->_('%d token round completion events caused changed to %d tokens.'), $a, $b)
                        );
            }

            $trackId = $respTrack->getRespondentTrackId();
            $batch->setTask('Tracker_CheckTrackTokens', 'chktrck-' . $trackId, $trackId, $userId);
        }

        // Free memory
        $tracker->removeToken($token);
    }
1150387
protected function _resetTracker($tracker)
    {
        if (!($tracker instanceof Iterator)) {
            throw $this->_createInvalidArgumentException($this->__('Can only reset an Iterator tracker'), null, null, $tracker);
        }

        $tracker->rewind();
    }
404152
public function userGet(int $user_id)
    {
        $value = get_user_meta($user_id, $this->getName(), true);

        if (! empty($value)) {
            $this->setValue($value);
        }
    }
366213
public function synchronizeSurveyBatch(\Gems_Task_TaskRunnerBatch $batch, $userId)
    {
        // Surveys in Gems
        $select = $this->_gemsDb->select();
        $select->from('gems__surveys', array('gsu_id_survey', 'gsu_surveyor_id'))
                ->where('gsu_id_source = ?', $this->getId())
                ->order('gsu_surveyor_id');

        $gemsSurveys = $this->_gemsDb->fetchPairs($select);
        if (!$gemsSurveys) {
            $gemsSurveys = array();
        }

        // Surveys in Source
        $sourceSurveys = $this->_getSourceSurveysForSynchronisation();
        if ($sourceSurveys) {
            $sourceSurveys = array_combine($sourceSurveys, $sourceSurveys);
        } else {
            $sourceSurveys = array();
        }

        // Always those already in the database
        foreach ($gemsSurveys as $surveyId => $sourceSurveyId) {

            if (isset($sourceSurveys[$sourceSurveyId])) {
                $batch->addTask('Tracker_CheckSurvey', $this->getId(), $sourceSurveyId, $surveyId, $userId);
                $batch->addTask('Tracker_AddRefreshQuestions', $this->getId(), $sourceSurveyId, $surveyId);
            } else {
                // Do not pass the source id when it no longer exists
                $batch->addTask('Tracker_CheckSurvey', $this->getId(), null, $surveyId, $userId);
            }
        }

        // Now add the new ones
        foreach (array_diff($sourceSurveys, $gemsSurveys) as $sourceSurveyId) {
            $batch->addTask('Tracker_CheckSurvey', $this->getId(), $sourceSurveyId, null, $userId);
            $batch->addTask('Tracker_AddRefreshQuestions', $this->getId(), $sourceSurveyId, null);
        }
    }
223928
public function markAsRead($userId)
    {
        try {
            $participant = $this->getParticipantFromUser($userId);
            $participant->last_read = new Carbon;
            $participant->save();
        } catch (ModelNotFoundException $e) {
            // do nothing
        }
    }
525384
void updateRack(UpdateRackHeartbeat updateRack)
  {
    ClusterHeartbeat cluster = findCluster(updateRack.getClusterId());

    if (cluster == null) {
      return;
    }
    
    RackHeartbeat rack;
    
    if (cluster != _serverSelf.getCluster()) {
      rack = cluster.createRack("external");
      ClusterTarget target = createClusterTarget(cluster);
    }
    else {
      rack = cluster.findRack(updateRack.getId());
    }
    
    if (rack == null) {
      return;
    }
    
    rack.updateRack(this, updateRack);
    
    updateHeartbeats();
  }
347089
function (value) {
                var t = shared.tracker.getTracker(value);
                shared.utils.dassert(t.tc() === this);
                this._mtx.rset.insert(t.id(), t.rev());
            }
107553
def update_user_trackers(sender, topic, user, request, response, **kwargs):
    
    TrackingHandler = get_class('forum_tracking.handler', 'TrackingHandler')  # noqa
    track_handler = TrackingHandler()
    track_handler.mark_topic_read(topic, user)
920335
public void setTrackStart(final double TRACK_START) {
        // check values
        if (Double.compare(TRACK_START, trackStop) == 0) {
            throw new IllegalArgumentException("Track start value cannot equal track stop value");
        }
        trackStart = TRACK_START;
        validate();
        fireStateChanged();
    }
326918
public function actionTrack(): void
	{
		if ($this->getPost('leave')) {
			$this->tracking->leave();
		}
		if ($this->getPost('url')) {
			$this->tracking->track();
		}
		$this->terminate();
	}