Skip to content

Commit

Permalink
Fixed issue #10296: Problem with 0 equals empty string fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Feb 8, 2016
1 parent f1fbdbb commit 29bb025
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions application/helpers/common_helper.php
Expand Up @@ -594,23 +594,29 @@ function getGroupSum($surveyid, $lang)


/**
* getMaxGroupOrder($surveyid) queries the database for the maximum sortorder of a group and returns the next higher one.
*
* @param mixed $surveyid
*/
* Queries the database for the maximum sortorder of a group and returns the next higher one.
*
* @param string|int $surveyid
* @return int
*/
function getMaxGroupOrder($surveyid)
{
$s_lang = Survey::model()->findByPk($surveyid)->language;
$queryResult = QuestionGroup::model()->find(array(
'order' => 'group_order desc',
'limit' => '1'
));

This comment has been minimized.

Copy link
@c-schmitz

c-schmitz Feb 8, 2016

Contributor

You are pulling the maximum group order from ALL groups in the whole system - shouldn't this be limited to the current survey?

This comment has been minimized.

Copy link
@c-schmitz

c-schmitz Feb 8, 2016

Contributor

This comment has been minimized.

Copy link
@olleharstedt

olleharstedt Feb 8, 2016

Author Contributor

That's not how it worked before, I think. but sounds good. :) Will fix.

//$max_sql = "SELECT max( group_order ) AS max FROM ".db_table_name('groups')." WHERE sid =$surveyid AND language='{$s_lang}'" ;
$query = QuestionGroup::model()->find(array('order' => 'group_order desc'));
$current_max = !is_null($query) ? $query->group_order : '';
$current_max = !is_null($queryResult) ? $queryResult->group_order : "";

if($current_max!="")
if($current_max !== "")
{
$current_max += 1;
return $current_max;
}
else
{
return ++$current_max ;
return 0;
}
else return "0" ;
}


Expand Down

0 comments on commit 29bb025

Please sign in to comment.