From: <gem...@li...> - 2012-11-15 17:48:03
|
Revision: 1020 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1020&view=rev Author: matijsdejong Date: 2012-11-15 17:47:56 +0000 (Thu, 15 Nov 2012) Log Message: ----------- Fix for always getting last set of answers Fix for new Databasemodel save options Modified Paths: -------------- trunk/library/classes/Gems/Tracker/Model/SingleSurveyTokenModel.php trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php trunk/library/classes/MUtil/Model/TableModel.php Modified: trunk/library/classes/Gems/Tracker/Model/SingleSurveyTokenModel.php =================================================================== --- trunk/library/classes/Gems/Tracker/Model/SingleSurveyTokenModel.php 2012-11-15 16:18:58 UTC (rev 1019) +++ trunk/library/classes/Gems/Tracker/Model/SingleSurveyTokenModel.php 2012-11-15 17:47:56 UTC (rev 1020) @@ -83,7 +83,8 @@ * @param array $oldKeys The original keys as they where before the changes * @return array The values for this table as they were updated */ - protected function _saveTableData(Zend_Db_Table_Abstract $table, array $newValues, array $oldKeys = null) + protected function _saveTableData(Zend_Db_Table_Abstract $table, array $newValues, + array $oldKeys = null, $saveMode = self::SAVE_MODE_ALL) { $table_name = $this->_getTableName($table); @@ -98,7 +99,7 @@ return $tokenData; } else { - return parent::_saveTableData($table, $newValues, $oldKeys); + return parent::_saveTableData($table, $newValues, $oldKeys, $saveMode); } } Modified: trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-11-15 16:18:58 UTC (rev 1019) +++ trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-11-15 17:47:56 UTC (rev 1020) @@ -791,7 +791,9 @@ $token = $this->_getToken($tokenId); try { - $values = $lsDb->fetchRow("SELECT * FROM $lsTab WHERE token = ?", $token); + // Order by ID desc to get the same answers used as in the row retrieved by + // getRawTokenAnswerRows() in case of double rows + $values = $lsDb->fetchRow("SELECT * FROM $lsTab WHERE token = ? ORDER BY id DESC", $token); } catch (Zend_Db_Statement_Exception $exception) { $this->logger->logError($exception, $this->request); $values = false; @@ -874,16 +876,17 @@ // this way other sources that don't perform changes on the token field don't have to loop // over this field. The survey(answer)model could possibly perform the translation for this source if ($rows) { + $map = $this->_getFieldMap($sourceSurveyId); if (isset($filter[$tokenField])) { foreach ($rows as $values) { $token = $originals[$values['token']]; - $results[$token] = $this->_getFieldMap($sourceSurveyId)->mapKeysToTitles($values); + $results[$token] = $map->mapKeysToTitles($values); } return $results; } else { //@@TODO If we do the mapping in the select statement, maybe we can gain some performance here foreach ($rows as $values) { - $results[] = $this->_getFieldMap($sourceSurveyId)->mapKeysToTitles($values); + $results[] = $map->mapKeysToTitles($values); } return $results; } @@ -1052,9 +1055,13 @@ $lsTab = $this->_getSurveyTableName($sourceSurveyId); $lsTokenId = $this->_getToken($token->getTokenId()); + // MUtil_Echo::track($answers); + $answers = $this->_getFieldMap($sourceSurveyId)->mapTitlesToKeys($answers); $answers = $this->_filterAnswersOnly($sourceSurveyId, $answers); + // MUtil_Echo::track($answers); + if ($lsDb->fetchOne("SELECT token FROM $lsTab WHERE token = ?", $lsTokenId)) { $where = $lsDb->quoteInto("token = ?", $lsTokenId); $lsDb->update($lsTab, $answers, $where); @@ -1067,7 +1074,6 @@ $answers['startdate'] = $current; $lsDb->insert($lsTab, $answers); - } } Modified: trunk/library/classes/MUtil/Model/TableModel.php =================================================================== --- trunk/library/classes/MUtil/Model/TableModel.php 2012-11-15 16:18:58 UTC (rev 1019) +++ trunk/library/classes/MUtil/Model/TableModel.php 2012-11-15 17:47:56 UTC (rev 1020) @@ -119,6 +119,6 @@ { // $this->_saveTableData returns the new row values, including any automatic changes. // add $newValues to throw nothing away. - return $this->_saveTableData($this->_table, $newValues, $filter) + $newValues; + return $this->_saveTableData($this->_table, $newValues, $filter, parent::SAVE_MODE_ALL) + $newValues; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |