|
From: <gem...@li...> - 2011-09-15 10:46:10
|
Revision: 15
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=15&view=rev
Author: matijsdejong
Date: 2011-09-15 10:46:03 +0000 (Thu, 15 Sep 2011)
Log Message:
-----------
- system no longer gives error when token table does not exist
- bug #422, initial patch level of database set to 40
Modified Paths:
--------------
trunk/library/classes/Gems/Default/TrackRoundsAction.php
trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php
trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php
trunk/library/classes/Gems/Tracker/Snippets/EditRoundSnippetAbstract.php
trunk/library/configs/db/tables/gems__patch_levels.10.sql
trunk/library/snippets/EditTrackEngineSnippet.php
Modified: trunk/library/classes/Gems/Default/TrackRoundsAction.php
===================================================================
--- trunk/library/classes/Gems/Default/TrackRoundsAction.php 2011-09-15 09:47:09 UTC (rev 14)
+++ trunk/library/classes/Gems/Default/TrackRoundsAction.php 2011-09-15 10:46:03 UTC (rev 15)
@@ -87,7 +87,7 @@
$trackEngine->applyToMenuSource($menuSource);
$menuSource->setRequestId($trackId); // Tell the menu we're using track id as request id
- $this->addSnippets($trackEngine->getRoundEditSnippetNames(), 'trackEngine', $trackEngine, 'trackId', $trackId);
+ $this->addSnippets($trackEngine->getRoundEditSnippetNames(), 'trackEngine', $trackEngine, 'trackId', $trackId, 'userId', $this->session->user_id);
}
/**
@@ -149,7 +149,7 @@
$trackEngine->applyToMenuSource($menuSource);
$menuSource->setRequestId($trackId); // Tell the menu we're using track id as request id
- $this->addSnippets($trackEngine->getRoundEditSnippetNames(), 'roundId', $this->_getParam(Gems_Model::ROUND_ID), 'trackEngine', $trackEngine, 'trackId', $trackId);
+ $this->addSnippets($trackEngine->getRoundEditSnippetNames(), 'roundId', $this->_getParam(Gems_Model::ROUND_ID), 'trackEngine', $trackEngine, 'trackId', $trackId, 'userId', $this->session->user_id);
}
public function getTopic($count = 1)
Modified: trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php
===================================================================
--- trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2011-09-15 09:47:09 UTC (rev 14)
+++ trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2011-09-15 10:46:03 UTC (rev 15)
@@ -191,6 +191,43 @@
}
/**
+ * Update the track, both in the database and in memory.
+ *
+ * @param array $values The values that this token should be set to
+ * @param int $userId The current user
+ * @return int 1 if data changed, 0 otherwise
+ */
+ private function _update(array $values, $userId)
+ {
+ if ($this->tracker->filterChangesOnly($this->_trackData, $values)) {
+
+ if (Gems_Tracker::$verbose) {
+ $echo = '';
+ foreach ($values as $key => $val) {
+ $echo .= $key . ': ' . $this->_trackData[$key] . ' => ' . $val . "\n";
+ }
+ MUtil_Echo::r($echo, 'Updated values for ' . $this->_trackId);
+ }
+
+ if (! isset($values['gto_changed'])) {
+ $values['gtr_changed'] = new Zend_Db_Expr('CURRENT_TIMESTAMP');
+ }
+ if (! isset($values['gtr_changed_by'])) {
+ $values['gtr_changed_by'] = $userId;
+ }
+
+ // Update values in this object
+ $this->_trackData = $values + $this->_trackData;
+
+ // return 1;
+ return $this->db->update('gems__tracks', $values, array('gtr_id_track = ?' => $this->_trackId));
+
+ } else {
+ return 0;
+ }
+ }
+
+ /**
* Creates all tokens that should exist, but do not exist
*
* NOTE: When overruling this function you should not create tokens because they
@@ -266,6 +303,16 @@
}
/**
+ * Calculate the number of active rounds in this track from the database.
+ *
+ * @return int The number of rounds in this track.
+ */
+ public function calculateRoundCount()
+ {
+ return $this->db->fetchOne("SELECT COUNT(*) FROM gems__rounds WHERE gro_active = 1 AND gro_id_track = ?", $this->_trackId);
+ }
+
+ /**
* Checks all existing tokens and updates any changes to the original rounds (when necessary)
*
* @param Gems_Tracker_RespondentTrack $respTrack The respondent track to check
@@ -715,4 +762,17 @@
return 0;
}
+
+ /**
+ * Updates the number of rounds in this track.
+ *
+ * @param int $userId The current user
+ * @return int 1 if data changed, 0 otherwise
+ */
+ public function updateRoundCount($userId)
+ {
+ $values['gtr_survey_rounds'] = $this->calculateRoundCount();
+
+ return $this->_update($values, $userId);
+ }
}
Modified: trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php
===================================================================
--- trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php 2011-09-15 09:47:09 UTC (rev 14)
+++ trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php 2011-09-15 10:46:03 UTC (rev 15)
@@ -68,6 +68,13 @@
public function calculateFieldsInfo($respTrackId, array $data);
/**
+ * Calculate the number of active rounds in this track from the database.
+ *
+ * @return int The number of rounds in this track.
+ */
+ public function calculateRoundCount();
+
+ /**
* Check for the existence of all tokens and create them otherwise
*
* @param Gems_Tracker_RespondentTrack $respTrack The respondent track to check
@@ -303,4 +310,12 @@
* @return int The number of changed fields
*/
public function setFieldsData($respTrackId, array $data);
+
+ /**
+ * Updates the number of rounds in this track.
+ *
+ * @param int $userId The current user
+ * @return int 1 if data changed, 0 otherwise
+ */
+ public function updateRoundCount($userId);
}
Modified: trunk/library/classes/Gems/Tracker/Snippets/EditRoundSnippetAbstract.php
===================================================================
--- trunk/library/classes/Gems/Tracker/Snippets/EditRoundSnippetAbstract.php 2011-09-15 09:47:09 UTC (rev 14)
+++ trunk/library/classes/Gems/Tracker/Snippets/EditRoundSnippetAbstract.php 2011-09-15 10:46:03 UTC (rev 15)
@@ -77,6 +77,12 @@
protected $trackId;
/**
+ *
+ * @var int $userId The current user
+ */
+ protected $userId = 0;
+
+ /**
* @var Gems_Util
*/
protected $util;
@@ -199,6 +205,7 @@
if ($this->createData && (! $this->roundId)) {
$this->roundId = $this->formData['gro_id_round'];
}
+ $this->trackEngine->updateRoundCount($this->userId);
}
/**
Modified: trunk/library/configs/db/tables/gems__patch_levels.10.sql
===================================================================
--- trunk/library/configs/db/tables/gems__patch_levels.10.sql 2011-09-15 09:47:09 UTC (rev 14)
+++ trunk/library/configs/db/tables/gems__patch_levels.10.sql 2011-09-15 10:46:03 UTC (rev 15)
@@ -3,7 +3,7 @@
gpl_level int unsigned not null unique,
gpl_created timestamp not null default current_timestamp,
-
+
PRIMARY KEY (gpl_level)
)
ENGINE=InnoDB
@@ -11,5 +11,5 @@
INSERT INTO gems__patch_levels (gpl_level, gpl_created)
VALUES
- (26, CURRENT_TIMESTAMP);
+ (40, CURRENT_TIMESTAMP);
Modified: trunk/library/snippets/EditTrackEngineSnippet.php
===================================================================
--- trunk/library/snippets/EditTrackEngineSnippet.php 2011-09-15 09:47:09 UTC (rev 14)
+++ trunk/library/snippets/EditTrackEngineSnippet.php 2011-09-15 10:46:03 UTC (rev 15)
@@ -265,10 +265,10 @@
if (isset($this->formData['gtr_organisations']) && is_array($this->formData['gtr_organisations'])) {
$this->formData['gtr_organisations'] = '|' . implode('|', $this->formData['gtr_organisations']) . '|';
}
- if ($this->createData) {
+ if ($this->trackEngine) {
+ $this->formData['gtr_survey_rounds'] = $this->trackEngine->calculateRoundCount();
+ } else {
$this->formData['gtr_survey_rounds'] = 0;
- } else {
- $this->formData['gtr_survey_rounds'] = $this->db->fetchOne("SELECT COUNT(*) FROM gems__rounds WHERE gro_active = 1 AND gro_id_track = ?", $this->trackId);
}
parent::saveData();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|