From: SourceForge.net <no...@so...> - 2009-04-30 03:59:50
|
Bugs item #2784037, was opened at 2009-04-29 16:20 Message generated for change (Comment added) made by kswartz You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=108956&aid=2784037&group_id=8956 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: User Group: 2.1.2 Status: Open Resolution: None Priority: 5 Private: No Submitted By: kswartz (kswartz) Assigned to: bishop (bishopb) Summary: Dashboard may report wrong status after first survey Initial Comment: If I have one survey completed, and another unfinished, the status should read "Some Finished, some Incomplete". In my case, it always reads "Finished" for anything other than the first survey in the dashboard. I tracked it down to this code fragment in the survey_get_from_sql function in espsurvey.inc: if (isset($surveys[$id])) { if ($needsConversion) { // we've collided, but not yet converted to an array: do so $surveys[$id] = array ($surveys[$id]); $needsConversion = false; } $surveys[$id][] = $row; } else { $surveys[$id] = $row; } If you have multiple responses, the block of code after $needsConversion will convert a single response into an array of responses. The problem occurs when you have more than one survey. We set $needsConversion to false after we convert the first time, but it doesn't get flipped back to true when we start cycling through the NEXT survey in the list (i.e.: when we have a new $id index). So, for surveys AFTER the first one, this creates an array inside an array, rather than an array of two surveys. The code in the dashboard only ever sees the results of the first response, since it is at the top-level, and reports "Finished" when it should say "Some finished, some incomplete". It's an easy fix, but requires two changes. Also, I've only tested this change on the dashboard, so I do NOT know if this change will impact anything else that calls these routines. First change: < } else { < $surveys[$id] = $row; < } --- > } else { > $surveys[$id] = $row; > $needsConversion = true; > } Second change is in the routine survey_get_responses: < $sql =<<<EOSQL < SELECT survey_id, username, submitted, complete, ip < FROM {$GLOBALS['ESPCONFIG']['response_table']} AS tblResponse < WHERE $limit < EOSQL; ---- > $sql =<<<EOSQL > SELECT survey_id, username, submitted, complete, ip > FROM {$GLOBALS['ESPCONFIG']['response_table']} AS tblResponse > WHERE $limit > ORDER BY survey_id > EOSQL; The second fix is necessary because without it, you'll run into problems if the $sql sent to survey_get_from_sql looks like this: survey_id other-stuff ---------------------------- 1 foo 1 ... 1 ... 3 ... 1 ... When it hits row 4, it resets $needsConversion to true. But on the next pass, it executes that against $surveys[1] instead of $surveys[3]. The change to the SQL ensures that we process all responses for a survey before building the structure for the next one. Steps to reproduce (I think): 1. Create two private surveys, allow multiple responses. 2. Log on to the dashboard, complete the first one once, then start again and save. 3. Now complete the second one once, then start again and save. 4. The dashboard will show the right thing for the first survey, but "Finished" (incorrectly) for the second survey. This same problem may appear in other places (like historical surveys). The second change may be needed in the other survey_get_* functions. (But I think it can't hurt.) Sorry, don't have svn working yet, so can't verify in upcoming 2.1.3. ---------------------------------------------------------------------- >Comment By: kswartz (kswartz) Date: 2009-04-29 20:59 Message: Actually, there's a much easier fix than what I proposed (don't know why I didn't think of this first). It only requires changing survey_get_from_sql function. Remove ALL references to $needsConversion, and change one line: < if ($needsConversion) { --- > if (! array_key_exists(0,$surveys[$id])) { ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=108956&aid=2784037&group_id=8956 |