Makes sure the track data is part of the $this->_respTrackData
320098
protected function _ensureTrackData()
    {
        if (! isset($this->_respTrackData['gtr_code'], $this->_respTrackData['gtr_name'])) {
            $select = $this->db->select();
            $select->from('gems__tracks')
                ->where('gtr_id_track = ?', $this->_respTrackData['gr2t_id_track']);

            if ($trackData = $this->db->fetchRow($select)) {
                $this->_respTrackData = $this->_respTrackData + $trackData;
            } else {
                $trackId = $this->_respTrackId;
                throw new \Gems_Exception("Track data missing for respondent track $trackId.");
            }
        }
    }
369863
public function isOpen()
    {
        if (isset($this->_respTrackData['gr2t_count'], $this->_respTrackData['gr2t_completed'])) {
            return $this->_respTrackData['gr2t_count'] > $this->_respTrackData['gr2t_completed'];
        }
        return true;
    }
345103
public function copyTrack($oldTrackId)
    {
        $trackModel = $this->tracker->getTrackModel();

        $roundModel = $this->getRoundModel(true, 'rounds');
        $fieldModel = $this->getFieldsMaintenanceModel();

        // First load the track
        $trackModel->applyParameters(array('id' => $oldTrackId));
        $track = $trackModel->loadFirst();

        // Create an empty track
        $newTrack = $trackModel->loadNew();
        unset($track['gtr_id_track'], $track['gtr_changed'], $track['gtr_changed_by'], $track['gtr_created'], $track['gtr_created_by']);
        $track['gtr_track_name'] .= $this->_(' - Copy');
        $newTrack = $track + $newTrack;
        // Now save (not done yet)
        $savedValues = $trackModel->save($newTrack);
        $newTrackId = $savedValues['gtr_id_track'];

        // Now copy the fields
        $fieldModel->applyParameters(array('id' => $oldTrackId));
        $fields = $fieldModel->load();

        if ($fields) {
            $oldIds = array();
            $numFields = count($fields);
            $newFields = $fieldModel->loadNew($numFields);
            foreach ($newFields as $idx => $newField) {
                $field = $fields[$idx];
                $oldIds[$idx] = $field['gtf_id_field'];
                unset($field['gtf_id_field'], $field['gtf_changed'], $field['gtf_changed_by'], $field['gtf_created'], $field['gtf_created_by']);
                $field['gtf_id_track'] = $newTrackId;
                $newFields[$idx] = $field + $newFields[$idx];
            }
            // Now save (not done yet)
            $savedValues = $fieldModel->saveAll($newFields);
            foreach($savedValues as $idx => $field) {
                $oldNewFieldMap[$oldIds[$idx]] = $field['gtf_id_field'];
            }
        } else {
            $numFields = 0;
        }

        // Now copy the rounds and map the gro_id_relation to the right field
        $roundModel->applyParameters(array('id' => $oldTrackId));
        $rounds = $roundModel->load();

        if ($rounds) {
            $numRounds = count($rounds);
            $newRounds = $roundModel->loadNew($numRounds);
            foreach ($newRounds as $idx => $newRound) {
                $round = $rounds[$idx];
                unset($round['gro_id_round'], $round['gro_changed'], $round['gro_changed_by'], $round['gro_created'], $round['gro_created_by']);
                $round['gro_id_track'] = $newTrackId;
                if (array_key_exists('gro_id_relationfield', $round) && $round['gro_id_relationfield']>0) {
                    $round['gro_id_relationfield'] = $oldNewFieldMap[$round['gro_id_relationfield']];
                }
                $newRounds[$idx] = $round + $newRounds[$idx];
            }
            // Now save (not done yet)
            $savedValues = $roundModel->saveAll($newRounds);
        } else {
            $numRounds = 0;
        }

        //MUtil_Echo::track($track, $copy);
        //MUtil_Echo::track($rounds, $newRounds);
        //MUtil_Echo::track($fields, $newFields);
        Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->addMessage(sprintf($this->_('Copied track, including %s round(s) and %s field(s).'), $numRounds, $numFields));

        return $newTrackId;
    }
511650
public function checkTrackAction()
    {
        $id    = $this->_getIdParam();
        $track = $this->getTrackEngine();
        $where = $this->db->quoteInto('gr2t_id_track = ?', $id);
        $batch = $this->loader->getTracker()->checkTrackRounds(
                'trackCheckRounds' . $id,
                $this->currentUser->getUserId(),
                $where
                );

        $title = sprintf($this->_("Checking round assignments for track %d '%s'."), $id, $track->getTrackName());
        $this->_helper->BatchRunner($batch, $title, $this->accesslog);

        $this->addSnippet('Track\\CheckRoundsInformation');
    }
1129305
def value(self, name):
        """"""
        return self.tracks.get(name).row_value(self.controller.row)
582296
private function ensureVisitorDataIsComplete()
    {
        $visitorData = $this->getVisitorData();
        $completed   = true;

        foreach ($this->visitorInfo as $key => $value) {
            if ($visitorData[$key] !== $value) {
                /** @var  \Arcanedev\LaravelTracker\Models\Visitor  $model */
                if ( ! isset($model))
                    $model = $this->getModel()->find($this->getVisitorId());

                $model->setAttribute($key, $value);
                $model->save();

                $completed = false;
            }
        }

        if ( ! $completed)
            $this->putSessionData($this->visitorInfo);
    }
188299
public function execute($trackId = null, $exportOrganizations = false)
    {
        $batch = $this->getBatch();
        $data  = $this->db->fetchRow("SELECT * FROM gems__tracks WHERE gtr_id_track = ?", $trackId);
        $orgs  = $exportOrganizations ? $data['gtr_organizations'] : false;

        unset($data['gtr_id_track'], $data['gtr_track_type'], $data['gtr_active'], $data['gtr_survey_rounds'], $data['gtr_organizations'],
                $data['gtr_changed'],
                $data['gtr_changed_by'], $data['gtr_created'], $data['gtr_created_by']);

        // Main track data
        $this->exportTypeHeader('track');
        $this->exportFieldHeaders($data);
        $this->exportFieldData($data);

        if ($orgs) {
            // Organizations
            $this->exportTypeHeader('organizations');
            $this->exportFieldHeaders(array('gor_id_organization' => null, 'gor_name' => null));
            foreach (explode('|', $orgs) as $orgId) {
                if ($orgId) {
                    $org = $this->loader->getOrganization($orgId);
                    if ($org) {
                        $this->exportFieldData(array($orgId, $org->getName()));
                    }
                }
            }
            $batch->addMessage($this->_('Trackdata exported with organizations.'));
        } else {
            $batch->addMessage($this->_('Trackdata exported without organizations.'));
        }

        $this->exportFlush();
    }
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;
    }
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);
                }
            }
        }
    }
1302163
def _load_track_estimates(track, estimates_dir, output_dir):
    """"""
    user_results = {}
    track_estimate_dir = os.path.join(
        estimates_dir,
        track.subset,
        track.name
    )
    for target in glob.glob(
        track_estimate_dir + '/*.wav'
    ):

        target_name = op.splitext(
            os.path.basename(target)
        )[0]
        try:
            target_audio, _ = sf.read(
                target,
                always_2d=True
            )
            user_results[target_name] = target_audio
        except RuntimeError:
            pass

    if user_results:
        eval_mus_track(
            track,
            user_results,
            output_dir=output_dir
        )

    return None
351865
public function checkDATA() {
        if (!defined(DATA))
                define(DATA,
                    __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR);

        if (!is_dir(DATA)) mkdir(DATA, 0777, true);

        return $this;
    }
410578
function TrackSkippedSchema() {
    /**
     * The track of value
     * @member
     * @type { Track }
     */
    this.track = Object.create(Track.prototype);
    /**
     * The album of value
     * @member
     * @type { Album }
     */
    this.album = Object.create(Album.prototype);

}
3427
public function saveData()
    {
        $model = $this->getModel();

        if ($this->formData['gto_valid_until']) {
            // Make sure date based units are valid until the end of the day.
            $date = new \MUtil_Date(
                    $this->formData['gto_valid_until'],
                    $model->get('gto_valid_until', 'dateFormat')
                    );
            $date->setTimeToDayEnd();
            $this->formData['gto_valid_until'] = $date;
        }

        // Save the token using the model
        parent::saveData();
        // $this->token->setValidFrom($this->formData['gto_valid_from'], $this->formData['gto_valid_until'], $this->loader->getCurrentUser()->getUserId());

        // \MUtil_Echo::track($this->formData);

        // Refresh (NOT UPDATE!) token with current form data
        $updateData['gto_valid_from']         = $this->formData['gto_valid_from'];
        $updateData['gto_valid_from_manual']  = $this->formData['gto_valid_from_manual'];
        $updateData['gto_valid_until']        = $this->formData['gto_valid_until'];
        $updateData['gto_valid_until_manual'] = $this->formData['gto_valid_until_manual'];
        $updateData['gto_comment']            = $this->formData['gto_comment'];

        $this->token->refresh($updateData);

        $respTrack = $this->token->getRespondentTrack();
        $userId    = $this->loader->getCurrentUser()->getUserId();
        $changed   = $respTrack->checkTrackTokens($userId, $this->token);

        if ($changed) {
            $this->addMessage(sprintf($this->plural(
                    '%d token changed by recalculation.',
                    '%d tokens changed by recalculation.',
                    $changed
                    ), $changed));
        }
    }
320170
protected function validate_data() {
        parent::validate_data();

        if (!isset($this->relateduserid)) {
            debugging('The \'relateduserid\' value must be specified in the event.', DEBUG_DEVELOPER);
            $this->relateduserid = $this->objectid;
        }
    }
1239537
public function hasActiveTracks()
    {
        $select = $this->db->select()
                ->from('gems__respondent2track', ['gr2t_id_respondent_track'])
                ->joinInner('gems__reception_codes', 'gr2t_reception_code = grc_id_reception_code', [])
                ->where('grc_success = 1')
                ->where('gr2t_id_user = ?', $this->respondentId)
                ->where('gr2t_id_organization = ?', $this->organizationId)
                ->limit(1);

        return (boolean) $this->db->fetchOne($select);
    }
1343999
protected function _exportTrack(\Gems_Tracker_RespondentTrack $respTrack)
    {
        if (!$this->_isTrackInFilter($respTrack)) {
            return;
        }

        $trackModel = $this->loader->getTracker()->getRespondentTrackModel();
        $trackModel->applyDetailSettings($respTrack->getTrackEngine(), false);
        $trackModel->resetOrder();
        $trackModel->set('gtr_track_name',    'label', $this->_('Track'));
        $trackModel->set('gr2t_track_info',   'label', $this->_('Description'),
            'description', $this->_('Enter the particulars concerning the assignment to this respondent.'));
        $trackModel->set('assigned_by',       'label', $this->_('Assigned by'));
        $trackModel->set('gr2t_start_date',   'label', $this->_('Start'),
            'formatFunction', $this->util->getTranslated()->formatDate,
            'default', \MUtil_Date::format(new \Zend_Date(), 'dd-MM-yyyy'));
        $trackModel->set('gr2t_reception_code');
        $trackModel->set('gr2t_comment',       'label', $this->_('Comment'));
        $trackModel->setFilter(array('gr2t_id_respondent_track' => $respTrack->getRespondentTrackId()));
        $trackData = $trackModel->loadFirst();

        $this->html->h4($this->_('Track') . ' ' . $trackData['gtr_track_name']);

        $bridge = $trackModel->getBridgeFor('itemTable', array('class' => 'browser table'));
        $bridge->setRepeater(\MUtil_Lazy::repeat(array($trackData)));
        $bridge->th($this->_('Track information'), array('colspan' => 2));
        $bridge->setColumnCount(1);
        foreach($trackModel->getItemsOrdered() as $name) {
            if ($label = $trackModel->get($name, 'label')) {
                $bridge->addItem($name, $label);
            }
        }

        $tableContainer = \MUtil_Html::create()->div(array('class' => 'table-container'));
        $tableContainer[] = $bridge->getTable();
        $this->html[] = $tableContainer;
        $this->html->br();

        $this->_exportTrackTokens($respTrack);

        $this->html->hr();
    }
690442
public function execute($respTrackData = null, $userId = null)
    {
        $batch     = $this->getBatch();
        $tracker   = $this->loader->getTracker();
        $respTrack = $tracker->getRespondentTrack($respTrackData);

        $i = $batch->addToCounter('checkedRespondentTracks');

        if ($result = $respTrack->checkTrackTokens($userId)) {
            $a = $batch->addToCounter('tokenDateCauses');
            $b = $batch->addToCounter('tokenDateChanges', $result);
            $batch->setMessage('tokenDateChanges',
                    sprintf($this->_('%2$d token date changes in %1$d tracks.'), $a, $b)
                    );
        }

        $batch->setMessage('checkedRespondentTracks', sprintf($this->_('Checked %d tracks.'), $i));
    }