/** * Creates all tokens that should exist, but do not exist * * NOTE: When overruling this function you should not create tokens because they * were deleted by the user * * @param \Gems_Tracker_RespondentTrack $respTrack The respondent track to check * @param int $userId Id of the user who takes the action (for logging) * @return int The number of tokens created by this code */ protected function addNewTokens(\Gems_Tracker_RespondentTrack $respTrack, $userId) { $orgId = $respTrack->getOrganizationId(); $respId = $respTrack->getRespondentId(); $respTrackId = $respTrack->getRespondentTrackId(); // $this->t $sql = "SELECT gro_id_round, gro_id_survey, gro_id_order, gro_icon_file, gro_round_description\n FROM gems__rounds\n WHERE gro_id_track = ? AND\n gro_active = 1 AND\n gro_id_round NOT IN (SELECT gto_id_round FROM gems__tokens WHERE gto_id_respondent_track = ?) AND\n (gro_organizations IS NULL OR gro_organizations LIKE CONCAT('%|',?,'|%'))\n ORDER BY gro_id_order"; $newRounds = $this->db->fetchAll($sql, array($this->_trackId, $respTrackId, $orgId)); $this->db->beginTransaction(); foreach ($newRounds as $round) { $values = array(); // From the respondent track $values['gto_id_respondent_track'] = $respTrackId; $values['gto_id_respondent'] = $respId; $values['gto_id_organization'] = $orgId; $values['gto_id_track'] = $this->_trackId; // From the rounds $values['gto_id_round'] = $round['gro_id_round']; $values['gto_id_survey'] = $round['gro_id_survey']; $values['gto_round_order'] = $round['gro_id_order']; $values['gto_icon_file'] = $round['gro_icon_file']; $values['gto_round_description'] = $round['gro_round_description']; // All other values are not changed by this query and get the default DB value on insertion $this->tracker->createToken($values, $userId); } $this->db->commit(); return count($newRounds); }
/** * Creates an almost exact copy of this token at the same place in the track, * only without answers and other source data * * Returns the new token id * * @param string $newComment Description of why the token was replaced * @param int $userId The current user * @return string The new token */ public function createReplacement($newComment, $userId) { $values['gto_id_respondent_track'] = $this->_gemsData['gto_id_respondent_track']; $values['gto_id_round'] = $this->_gemsData['gto_id_round']; $values['gto_id_respondent'] = $this->_gemsData['gto_id_respondent']; $values['gto_id_organization'] = $this->_gemsData['gto_id_organization']; $values['gto_id_track'] = $this->_gemsData['gto_id_track']; $values['gto_id_survey'] = $this->_gemsData['gto_id_survey']; $values['gto_round_order'] = $this->_gemsData['gto_round_order']; $values['gto_round_description'] = $this->_gemsData['gto_round_description']; $values['gto_valid_from'] = $this->_gemsData['gto_valid_from']; $values['gto_valid_from_manual'] = $this->_gemsData['gto_valid_from_manual']; $values['gto_valid_until'] = $this->_gemsData['gto_valid_until']; $values['gto_valid_until_manual'] = $this->_gemsData['gto_valid_until_manual']; $values['gto_mail_sent_date'] = $this->_gemsData['gto_mail_sent_date']; $values['gto_comment'] = $newComment; $tokenId = $this->tracker->createToken($values, $userId); return $tokenId; }