From: <gem...@li...> - 2011-12-01 14:57:17
|
Revision: 324 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=324&view=rev Author: matijsdejong Date: 2011-12-01 14:57:08 +0000 (Thu, 01 Dec 2011) Log Message: ----------- Inactive rounds that are not being answered are now removed from existing tracks, when checking them. Modified Paths: -------------- branches/1.5.0-pulse/library/classes/Gems/Tracker/ChangeTracker.php branches/1.5.0-pulse/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php Modified: branches/1.5.0-pulse/library/classes/Gems/Tracker/ChangeTracker.php =================================================================== --- branches/1.5.0-pulse/library/classes/Gems/Tracker/ChangeTracker.php 2011-12-01 11:59:09 UTC (rev 323) +++ branches/1.5.0-pulse/library/classes/Gems/Tracker/ChangeTracker.php 2011-12-01 14:57:08 UTC (rev 324) @@ -27,7 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * + * * @package Gems * @subpackage Tracker * @author Matijs de Jong <mj...@ma...> @@ -49,6 +49,7 @@ public $checkedTokens = 0; public $createdTokens = 0; public $checkedRespondentTracks = 0; + public $deletedTokens = 0; public $resultDataChanges = 0; public $roundChangeUpdates = 0; public $roundCompletionCauses = 0; @@ -82,6 +83,9 @@ if ($this->roundChangeUpdates) { $messages[] = sprintf($t->_('Round changes propagated to %d tokens.'), $this->roundChangeUpdates); } + if ($this->deletedTokens) { + $messages[] = sprintf($t->_('%d tokens deleted by round changes.'), $this->deletedTokens); + } if ($this->createdTokens) { $messages[] = sprintf($t->_('%d tokens created to by round changes.'), $this->createdTokens); } Modified: branches/1.5.0-pulse/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php =================================================================== --- branches/1.5.0-pulse/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2011-12-01 11:59:09 UTC (rev 323) +++ branches/1.5.0-pulse/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2011-12-01 14:57:08 UTC (rev 324) @@ -248,6 +248,7 @@ $sql = "SELECT gro_id_round, gro_id_survey, gro_id_order, gro_round_description FROM gems__rounds WHERE gro_id_track = ? AND + gro_active = 1 AND gro_id_round NOT IN (SELECT gto_id_round FROM gems__tokens WHERE gto_id_respondent_track = ?) ORDER BY gro_id_order"; @@ -389,10 +390,13 @@ //Step one: update existing tokens $changes->roundChangeUpdates += $this->checkExistingRoundsFor($respTrack, $userId); - // Step two: create lacking tokens + //Step two: deactivate inactive rounds + $changes->deletedTokens += $this->removeInactiveRounds($respTrack, $userId); + + // Step three: create lacking tokens $changes->createdTokens += $this->addNewTokens($respTrack, $userId); - // Step three: set the dates and times + // Step four: set the dates and times $changed = $this->checkTokensFromStart($respTrack, $userId); if ($changed) { $changes->tokenDateCauses++; @@ -758,6 +762,28 @@ } /** + * Remove the unanswered tokens for inactive rounds. + * + * @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 changed by this code + */ + protected function removeInactiveRounds(Gems_Tracker_RespondentTrack $respTrack, $userId) + { + $qTrackId = $this->db->quote($this->_trackId); + $qRespTrackId = $this->db->quote($respTrack->getRespondentTrackId()); + + $where = "gto_start_time IS NULL AND + gto_id_respondent_track = $qRespTrackId AND + gto_id_round IN (SELECT gro_id_round + FROM gems__rounds + WHERE gro_active = 0 AND + gro_id_track = $qTrackId)"; + + return $this->db->delete('gems__tokens', $where); + } + + /** * Saves the field data for the respondent track id. * * @param int $respTrackId Gems respondent track id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |