/**
  * Get config options for this token
  *
  * Order of reading is track/round, survey, survey code
  *
  * @param \Gems_Tracker_Token $token
  */
 public function getConfig($token)
 {
     try {
         $trackId = $token->getTrackId();
         $roundId = $token->getRoundId();
         $db = \Zend_Db_Table::getDefaultAdapter();
         $select = $db->select()->from('gems__chart_config')->where('gcc_tid = ?', $trackId)->where('gcc_rid = ?', $roundId);
         if ($result = $select->query()->fetch()) {
             $config = \Zend_Json::decode($result['gcc_config']);
             return $config;
         }
         $surveyId = $token->getSurveyId();
         $select = $db->select()->from('gems__chart_config')->where('gcc_sid = ?', $surveyId);
         if ($result = $select->query()->fetch()) {
             $config = \Zend_Json::decode($result['gcc_config']);
             return $config;
         }
         $surveyCode = $token->getSurvey()->getCode();
         $select = $db->select()->from('gems__chart_config')->where('gcc_code = ?', $surveyCode);
         $config = $select->query()->fetch();
         if ($config !== false) {
             $config = \Zend_Json::decode($config['gcc_config']);
         }
         return $config;
     } catch (\Exception $exc) {
         // Just ignore...
     }
     // If all fails, we might be missing the config table
     return false;
 }
 /**
  * Process the data and return the answers that should be filled in beforehand.
  *
  * Storing the changed values is handled by the calling function.
  *
  * @param \Gems_Tracker_Token $token Gems token object
  * @return array Containing the changed values
  */
 public function processTokenInsertion(\Gems_Tracker_Token $token)
 {
     if ($token->hasSuccesCode() && !$token->isCompleted()) {
         // Preparation for a more general object class
         $surveyId = $token->getSurveyId();
         $prev = $token;
         while ($prev = $prev->getPreviousToken()) {
             if ($prev->hasSuccesCode() && $prev->isCompleted()) {
                 // Check first on survey id and when that does not work by name.
                 if ($prev->getSurveyId() == $surveyId) {
                     return $prev->getRawAnswers();
                 }
             }
         }
     }
 }
 /**
  * The place to check if the data set in the snippet is valid
  * to generate the snippet.
  *
  * When invalid data should result in an error, you can throw it
  * here but you can also perform the check in the
  * checkRegistryRequestsAnswers() function from the
  * {@see \MUtil_Registry_TargetInterface}.
  *
  * @return boolean
  */
 public function hasHtmlOutput()
 {
     // Apply translations
     if (!$this->showAnswersTranslated) {
         // Here, not in e.g. __construct as these vars may be set during initiation
         $this->showAnswersNone = $this->_($this->showAnswersNone);
         $this->showAnswersRemoved = $this->_($this->showAnswersRemoved);
         $this->showAnswersSeparator = $this->_($this->showAnswersSeparator);
         $this->showAnswersTranslated = true;
     }
     // Overrule any setting of these values from source
     $this->data = null;
     $this->repeater = null;
     if (!$this->surveyId) {
         if ($this->token instanceof \Gems_Tracker_Token && $this->token->exists) {
             $this->surveyId = $this->token->getSurveyId();
         } elseif ($this->trackData && !$this->trackId) {
             // Look up key values from trackData
             if (isset($this->trackData['gsu_id_survey'])) {
                 $this->surveyId = $this->trackData['gsu_id_survey'];
             } elseif (isset($this->trackData['gro_id_survey'])) {
                 $this->surveyId = $this->trackData['gro_id_survey'];
             } elseif (!$this->trackId) {
                 if (isset($this->trackData['gtr_id_track'])) {
                     $this->trackId = $this->trackData['gtr_id_track'];
                 } elseif (isset($this->trackData['gro_id_track'])) {
                     $this->trackId = $this->trackData['gro_id_track'];
                 }
             }
         }
         if (!$this->trackId && $this->trackEngine) {
             $this->trackId = $this->trackEngine->getTrackId();
         }
         if ($this->trackId && !$this->surveyId) {
             // Use the track ID to get the id of the first active survey
             $this->surveyId = $this->db->fetchOne('SELECT gro_id_survey FROM gems__rounds WHERE gro_active = 1 AND gro_id_track = ? ORDER BY gro_id_order', $this->trackId);
         }
     }
     // \MUtil_Echo::track($this->surveyId, $this->trackId);
     // Get the survey
     if ($this->surveyId && !$this->survey instanceof \Gems_Tracker_Survey) {
         $this->survey = $this->loader->getTracker()->getSurvey($this->surveyId);
     }
     // Load the data
     if ($this->survey instanceof \Gems_Tracker_Survey && $this->survey->exists) {
         $this->data = \MUtil_Ra::addKey($this->survey->getQuestionInformation($this->locale->getLanguage()), 'key');
         //\MUtil_Echo::track($this->data);
     }
     return parent::hasHtmlOutput();
 }
 /**
  * Determines if this particular token should be included
  * in the report
  *
  * @param  \Gems_Tracker_Token $token
  * @return boolean This dummy implementation always returns true
  */
 protected function _isTokenInFilter(\Gems_Tracker_Token $token)
 {
     $result = false;
     // Only if token has a success code
     if ($token->getReceptionCode()->isSuccess()) {
         $result = true;
     }
     if ($result) {
         $tokenInfo = array('code' => $token->getSurvey()->getCode(), 'surveyid' => $token->getSurveyId(), 'tokenid' => $token->getTokenId());
         // Now check if the tokenfilter is true
         if (empty($this->tokenFilter)) {
             $result = true;
         } else {
             $result = false;
             // Now read the filter and split by track code or track id
             foreach ($this->tokenFilter as $filter) {
                 $remaining = array_diff_assoc($filter, $tokenInfo);
                 if (empty($remaining)) {
                     $result = true;
                     break;
                 }
             }
         }
     }
     return $result;
 }