/**
  * Returns/sets a password element.
  *
  * @return \Zend_Form_Element_Password
  */
 public function getTokenElement()
 {
     $element = $this->getElement($this->_tokenFieldName);
     if (!$element) {
         $tokenLib = $this->tracker->getTokenLibrary();
         $max_length = $tokenLib->getLength();
         // Veld token
         $element = new \Zend_Form_Element_Text($this->_tokenFieldName);
         $element->setLabel($this->translate->_('Token'));
         $element->setDescription(sprintf($this->translate->_('Enter tokens as %s.'), $tokenLib->getFormat()));
         $element->setAttrib('size', $max_length + 2);
         $element->setAttrib('maxlength', $max_length);
         $element->setRequired(true);
         $element->addFilter($this->tracker->getTokenFilter());
         $element->addValidator($this->tracker->getTokenValidator());
         $this->addElement($element);
     }
     return $element;
 }
 /**
  * Updates the gems__tokens table so all tokens stick to the (possibly) new token name rules.
  *
  * @param int $userId    Id of the user who takes the action (for logging)
  * @return int The number of tokens changed
  */
 protected function updateTokens($userId, $updateTokens = true)
 {
     $tokenLib = $this->tracker->getTokenLibrary();
     $sql = 'UPDATE gems__tokens
                 SET gto_id_token = ' . $this->_getTokenFromToSql($tokenLib->getFrom(), $tokenLib->getTo(), 'gto_id_token') . ',
                     gto_changed = CURRENT_TIMESTAMP,
                     gto_changed_by = ' . $this->_gemsDb->quote($userId) . '
                 WHERE ' . $this->_getTokenFromSqlWhere($tokenLib->getFrom(), 'gto_id_token') . ' AND
                     gto_id_survey IN (SELECT gsu_id_survey FROM gems__surveys WHERE gsu_id_source = ' . $this->_gemsDb->quote($this->getId()) . ')';
     return $this->_gemsDb->query($sql)->rowCount();
 }
 /**
  * Add a one-off survey to the existing track.
  *
  * @param type $surveyId    the gsu_id of the survey to add
  * @param type $surveyData
  * @param int $userId
  * @param boolean $checkTrack Should the track be checked? Set to false when adding more then one and check manually
  * @return \Gems_Tracker_Token
  */
 public function addSurveyToTrack($surveyId, $surveyData, $userId, $checkTrack = true)
 {
     //Do something to get a token and add it
     $tokenLibrary = $this->tracker->getTokenLibrary();
     //Now make sure the data to add is correct:
     $surveyData['gto_id_respondent_track'] = $this->_respTrackId;
     $surveyData['gto_id_organization'] = $this->_respTrackData['gr2t_id_organization'];
     $surveyData['gto_id_track'] = $this->_respTrackData['gr2t_id_track'];
     $surveyData['gto_id_respondent'] = $this->_respTrackData['gr2t_id_user'];
     $surveyData['gto_id_survey'] = $surveyId;
     $tokenId = $tokenLibrary->createToken($surveyData, $userId);
     if ($checkTrack === true) {
         //Now refresh the track to include the survey we just added (easiest way as order may change)
         $this->getTokens(true);
         $this->checkTrackTokens($userId, $this->_tokens[$tokenId]);
         // Update the track counter
         //$this->_checkTrackCount($userId);
         return $this->_tokens[$tokenId];
     }
     return $this->tracker->getToken($tokenId);
 }