Always report the track should be created

@param \Gems\Agenda\AppointmentFilterInterface $filter
@param \Gems_Tracker_RespondentTrack $respTrack

@return boolean
770835
public function createFromStart($filter, $respTrack)
    {
        $createTrack = true;
        $curr        = $this->getAdmissionTime();
        $start       = $respTrack->getStartDate();
        $wait        = $filter->getWaitDays();

        if ((! $start) || ($curr->diffDays($start) <= $wait)) {
            $createTrack = false;
        }

        return $createTrack;
    }
479700
private static boolean isRunnable(FilterTargetData targetData, String[] filters) {
		if (filters == null || filters.length == 0) {
			return true;
		}
		
		for (String filter : filters) {
			String[] filterSplitted = filter.split(":");

			// We must evaluate all the filters and return only when there is a valid match
			if (
				(filterSplitted.length == 1 && targetData.anyMatch(filterSplitted[0])) || // Any filter
				("key".equalsIgnoreCase(filterSplitted[0]) && targetData.keyMatch(filterSplitted[1])) || // Key filter
				("name".equalsIgnoreCase(filterSplitted[0]) && targetData.nameMatch(filterSplitted[1])) || // Name filter
				("tag".equalsIgnoreCase(filterSplitted[0]) && targetData.tagMatch(filterSplitted[1])) || // Tag filter
				("ticket".equalsIgnoreCase(filterSplitted[0]) && targetData.ticketMatch(filterSplitted[1])) // Ticket filter
			) {
				return true;
			}
		}

		return false;
	}
471950
public function track()
    {
        if ($this->track === null) {
            $this->track = $this->config()->defaultTrack();
        }
        return $this->track;
    }
179879
public function getRespondentTracks($respondentId, $organizationId, $order = array('gr2t_start_date'))
    {
        $select = $this->db->select()
                ->from('gems__respondent2track')
                ->joinInner('gems__tracks', 'gr2t_id_track = gtr_id_track')
                ->joinInner('gems__reception_codes', 'gr2t_reception_code = grc_id_reception_code')
                ->where('gr2t_id_user = ? AND gr2t_id_organization = ?');
        if (!is_null($order)) {
            $select->order($order);
        }
        $rows   = $this->db->fetchAll($select, array($respondentId, $organizationId));
        $tracks = array();

        foreach ($rows as $row) {
            $tracks[$row['gr2t_id_respondent_track']] = $this->getRespondentTrack($row);
        }

        return $tracks;
    }
1261887
public function onResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();

        if ($request->isMethodSafe(false)) {
            return;
        }

        // In case we're using 'preview', the `_route` has been set to `contentlink`, because we're
        // viewing a single page, but `_original_route` will be `preview`, which should take
        // precedence, if set. See PR https://github.com/bolt/bolt/pull/7458
        /** @deprecated since 3.4 to be removed in 4.0 */
        $route = $request->attributes->get('_internal_route', $request->attributes->get('_route'));

        if (!in_array($route, $this->routes)) {
            return;
        }

        $response = $event->getResponse();

        if ($response->isRedirection() || $response->isEmpty() || $response->isInformational()) {
            return;
        }

        $response->headers->set('X-XSS-Protection', 0);
    }
1143136
public function checkHeaderInTracker(&$exclude)
    {
        if ($exclude) {
            Common::printDebug("Visit is already excluded, no need to check DoNotTrack support.");
            return;
        }

        $exclude = $this->isDoNotTrackFound();

        if($exclude) {

            IgnoreCookie::deleteThirdPartyCookieUIDIfExists();

            // this is an optional supplement to the site's tracking status resource at:
            //     /.well-known/dnt
            // per Tracking Preference Expression
            
            //Tracking Perference Expression has been updated to require Tk: N rather than Tk: 1
            Common::sendHeader('Tk: N');
        }
    }
1225250
public function onResponse(FilterResponseEvent $event)
    {
        $kernel   = $event->getKernel();
        $response = $event->getResponse();
        $content  = $response->getContent();

        foreach ($this->toolbar->getExtensions() as $extension) {
            $extension->buildData();
        }

        if (false !== strpos($content, '</body>')) {
            $debug = $this->engine->render('TridentDebugModule:Toolbar:toolbar.html.twig', [
                'extensions' => $this->toolbar->getExtensions()
            ]);

            $content = str_replace('</body>', $debug.PHP_EOL.'</body>', $content);

            $response->setContent($content);
        }
    }
803823
protected function _exportTrackTokens(\Gems_Tracker_RespondentTrack $track)
    {
        $groupSurveys = $this->_group;
        $token        = $track->getFirstToken();
        $engine       = $track->getTrackEngine();
        $surveys      = array();

        $table = $this->html->table(array('class' => 'browser table'));
        $table->th($this->_('Survey'))
              ->th($this->_('Round'))
              ->th($this->_('Token'))
              ->th($this->_('Status'));
        $this->html->br();

        while ($token) {
            //Should this token be in the list?
            if (!$this->_isTokenInFilter($token)) {
                $token = $token->getNextToken();
                continue;
            }

            $table->tr()->td($token->getSurveyName())
                        ->td(($engine->getTrackType() == 'T' ? $token->getRoundDescription() : $this->_('Single Survey')))
                        ->td(strtoupper($token->getTokenId()))
                        ->td($token->getStatus());

            //Should we display the answers?
            if (!$this->_displayToken($token)) {
                $token = $token->getNextToken();
                continue;
            }

            $showToken = false;
            if (! $groupSurveys) {
                // For single survey tracks or when $groupSurvey === false we show all tokens
                $showToken = true;
            } else {
                // For multi survey tracks and $groupSurveys === true, we show only the first token
                // as the snippet takes care of showing the other tokens
                if (!isset($surveys[$token->getSurveyId()])) {
                    $showToken = true;
                    $surveys[$token->getSurveyId()] = 1;
                }
            }

            if ($showToken) {
                $params = array(
                    'token'          => $token,
                    'tokenId'        => $token->getTokenId(),
                    'showHeaders'    => false,
                    'showButtons'    => false,
                    'showSelected'   => false,
                    'showTakeButton' => false,
                    'grouped'        => $groupSurveys);

                $snippets = $token->getAnswerSnippetNames();

                if (!is_array($snippets)) {
                    $snippets = array($snippets);
                }

                list($snippets, $snippetParams) = \MUtil_Ra::keySplit($snippets);
                $params = $params + $snippetParams;

                $this->html->snippet('Export_SurveyHeaderSnippet', 'token', $token);

                foreach($snippets as $snippet) {
                    $this->html->snippet($snippet, $params);
                }

                $this->html->br();
            }

            $token = $token->getNextToken();
        }
    }
111006
protected function checkCreateTracks($filters, $existingTracks, $tracker)
    {
        $tokenChanges = 0;

        // Check for tracks that should be created
        foreach ($filters as $filter) {
            if (!$filter->isCreator()) {
                continue;
            }

            $createTrack = true;

            // Find the method to use for this creator type
            $method      = $this->getCreatorCheckMethod($filter->getCreatorType());
            $trackId     = $filter->getTrackId();
            $tracks      = array_key_exists($trackId, $existingTracks) ? $existingTracks[$trackId] : [];

            foreach($tracks as $respTrack) {
                /* @var $respTrack \Gems_Tracker_RespondentTrack */
                if (!$respTrack->hasSuccesCode()) { continue; }

                $createTrack = $this->$method($filter, $respTrack);
                if ($createTrack === false) {
                    break;  // Stop checking
                }
            }

            // \MUtil_Echo::track($trackId, $createTrack, $filter->getName(), $filter->getSqlAppointmentsWhere(), $filter->getFilterId());
            if ($createTrack) {
                $respTrack = $this->_createTrack($filter, $tracker);
                $existingTracks[$trackId][] = $respTrack;

                $tokenChanges += $respTrack->getCount();
            }
        }

        return $tokenChanges;
    }
71288
protected function loadTrackSettings()
    {
        $respTracks = $this->tracker->getRespondentTracks(
                $this->formData['gto_id_respondent'],
                $this->formData['gto_id_organization']
                );
        $tracks = array();
        foreach ($respTracks as $respTrack) {
            if ($respTrack instanceof \Gems_Tracker_RespondentTrack) {
                if ($respTrack->hasSuccesCode()) {
                    $tracks[$respTrack->getRespondentTrackId()] = substr(sprintf(
                            $this->_('%s - %s'),
                            $respTrack->getTrackEngine()->getTrackName(),
                            $respTrack->getFieldsInfo()
                            ), 0, 100);
                }
            }
        }
        if ($tracks) {
            if (! isset($this->formData['gto_id_track'])) {
                reset($tracks);
                $this->formData['gto_id_track'] = key($tracks);
            }
        } else {
            $this->addMessageInvalid($this->_('Survey insertion impossible: respondent has no track!'));
            $tracks = $this->util->getTranslated()->getEmptyDropdownArray();
        }
        asort($tracks);
        $model = $this->getModel();
        $model->set('gto_id_track', 'multiOptions', $tracks);
        if (count($tracks) === 1) {
            $model->set('gto_id_track', 'elementClass', 'Exhibitor');
        }

        if (isset($this->formData['gto_id_track'])) {
            $this->respondentTrack = $respTracks[$this->formData['gto_id_track']];

            // Add relation field when survey is not for staff
            if ($this->survey && $this->survey->isTakenByStaff() === false) {
                $engine = $this->respondentTrack->getTrackEngine();
                if (method_exists($engine, 'getRespondentRelationFields')) {
                    $empty = array('-1' => $this->_('Patient'));
                    $relations = $empty + $engine->getRespondentRelationFields();
                    $model->set('gto_id_relationfield', 'label', $this->_('Fill out by'),
                        'multiOptions', $relations, 'elementClass', 'Select',
                    'required', true);
                }
            }
        }
    }
171930
public function checkTokensFromStart(\Gems_Tracker_RespondentTrack $respTrack, $userId)
    {
        $token = $respTrack->getFirstToken();
        if ($token instanceof \Gems_Tracker_Token) {
            return $this->checkTokensFrom($respTrack, $respTrack->getFirstToken(), $userId);
        } else {
            return 0;
        }
    }
959236
public function calculationStart(array $trackData)
    {
        if (isset($trackData['gr2t_id_respondent_track'])) {
            $this->_lastActiveKey = $trackData['gr2t_id_respondent_track'];
        } elseif (isset($trackData['gr2t_id_user'], $trackData['gr2t_id_organization'])) {
            $this->_lastActiveKey = $trackData['gr2t_id_user'] . '__' . $trackData['gr2t_id_organization'];
        } else {
            $this->_lastActiveKey = false;
        }
        if ($this->_lastActiveKey) {
            self::$_lastActiveAppointment[$this->_lastActiveKey]    = null;
            self::$_lastActiveAppointmentIds[$this->_lastActiveKey] = array();
        }

        return $this;
    }
434774
protected function updateTrackedInfo($session, $sessionKey, $trackInfoArray, $limit = 5)
    {
        // save the url, controller and action in the session
        $value = json_decode($session->get($sessionKey), true);
        if (is_null($value)) {
            $value = [];
        }
        // add new value as first value (to the top of the stack)
        array_unshift(
            $value,
            $trackInfoArray
        );

        // remove last value, if array has more than limit items
        if ($limit > 0 and count($value) > $limit) {
            array_pop($value);
        }

        // set the session value
        $session->set($sessionKey, json_encode($value));
    }
725667
protected function _isTrackInFilter(\Gems_Tracker_RespondentTrack $track)
    {
        $result    = false;
        $trackInfo = array(
            'code'        => $track->getCode(),
            'trackid'     => $track->getTrackId(),
            'resptrackid' => $track->getRespondentTrackId(),
            'respid'      => $track->getRespondentId(),
        );

        if (empty($this->trackFilter)) {
            $result = true;
        } else {
            // Now read the filter and split by track code or track id
            foreach($this->trackFilter as $filter) {
                $remaining = array_diff_assoc($filter, $trackInfo);
                if (empty($remaining)) {
                    $result = true;
                    break;
                }
            }
        }

        // Only if track has a success code
        if ($result && $track->getReceptionCode()->isSuccess()) {
            return true;
        }

        return false;
    }
458720
protected function startTracking(AggregateRootInterface $aggregate_root)
    {
        if ($this->tracked_aggregate_roots->contains($aggregate_root)) {
            throw new RuntimeError("Trying to checkout aggregate that already has a session open.");
        }

        $aggregate_root_id = $aggregate_root->getIdentifier();
        $this->tracked_aggregate_roots[$aggregate_root] = new EventStream([ 'identifier' => $aggregate_root_id ]);
    }
536531
public function track()
    {
        $this->out('<info>' . __d('cake_resque', 'Tracking job status') . '</info>');

        if (isset($this->args[0])) {
            $jobId = $this->args[0];
        } else {
            $this->out('<error>' . __d('cake_resque', 'Please provide a valid job ID') . "</error>\n");

            return false;
        }

        $jobStatus = CakeResque::getJobStatus($jobId);

        if ($jobStatus === false) {
            $this->out(__d('cake_resque', 'Status') . ' : <warning>' . __d('cake_resque', 'Unknown') . '</warning>');
        } else {
            $statusName = [
                Resque_Job_Status::STATUS_WAITING  => __d('cake_resque', 'waiting'),
                Resque_Job_Status::STATUS_RUNNING  => __d('cake_resque', 'running'),
                Resque_Job_Status::STATUS_FAILED   => __d('cake_resque', 'failed'),
                Resque_Job_Status::STATUS_COMPLETE => __d('cake_resque', 'complete'),
            ];

            $statusClass = [
                Resque_Job_Status::STATUS_WAITING  => 'info',
                Resque_Job_Status::STATUS_RUNNING  => 'info',
                Resque_Job_Status::STATUS_FAILED   => 'error',
                Resque_Job_Status::STATUS_COMPLETE => 'success',
            ];

            if (Configure::read('CakeResque.Scheduler.enabled') === true) {
                $statusClass[ Status::STATUS_SCHEDULED ] = 'info';
                $statusName[ Status::STATUS_SCHEDULED ] = __d('cake_resque', 'scheduled');
            }

            $this->out(
                sprintf(
                    __d('cake_resque', 'Status') . ' : <%1$s>%2$s</%1$s>',
                    (isset($statusClass[ $jobStatus ]) ? $statusClass[ $jobStatus ] : 'warning'),
                    isset($statusName[ $jobStatus ]) ? $statusName[ $jobStatus ] : __d('cake_resque', 'Unknown')
                )
            );

            if ($jobStatus === Resque_Job_Status::STATUS_FAILED) {
                $log = CakeResque::getFailedJobLog($jobId);
                if (!empty($log)) {
                    $this->hr();
                    $this->out('<comment>' . __d('cake_resque', 'Failed job details') . '</comment>');
                    $this->hr();
                    foreach ($log as $key => $value) {
                        $this->out(sprintf("<info>%-10s: </info>", strtoupper($key)), 0);
                        if (is_string($value)) {
                            $this->out($value);
                        } else {
                            $this->out('');
                            foreach ($value as $sKey => $sValue) {
                                $this->out(sprintf("    <info>%5s : </info>", $sKey), 0);
                                if (is_string($sValue)) {
                                    $this->out($sValue);
                                } else {
                                    $this->out(str_replace("\n", "\n            ", var_export($sValue, true)));
                                }
                            }
                        }
                    }
                }
            }
        }

        $this->out('');
    }
822580
public function track(TrackableInterface $trackable)
    {
        if ($trackable instanceof Collection) {
            $this->trackCollection($trackable);
        }

        if ($trackable instanceof PageController) {
            $this->trackCollection($trackable->getPageObject());
        }

        if ($trackable instanceof Controller) {
            $this->trackBlocks($trackable->getCollectionObject(), [$trackable]);
        }
    }