field "group_order" on the DB wrong when create a new survey [bug and solution]

Plus d'informations
il y a 5 ans 9 mois #105272 par emimarz
The bug is:
create a survey
create a group (group1)
create N questions on group1

create a survey (S2)
create a group (group2) on S2
create a question (QN1) on group2

QN1 have the field "group_order" on the database with the value N+1
But why? if is another survey

application/helpers/common_helper.php
Line 810
/**
* getMaxGroupOrder($surveyid) queries the database for the maximum sortorder of a group and returns the next higher one.
*
* @param mixed $surveyid
*/
function getMaxGroupOrder($surveyid)
{
$s_lang = Survey::model()->findByPk($surveyid)->language;

//$max_sql = "SELECT max( group_order ) AS max FROM ".db_table_name('groups')." WHERE sid =$surveyid AND language='{$s_lang}'" ;
$query = Groups::model()->find(array('order' => 'group_order desc')); //here, not filter by survey and languague

$current_max = !is_null($query) ? $query->group_order : '';

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

Change to

/**
* getMaxGroupOrder($surveyid) queries the database for the maximum sortorder of a group and returns the next higher one.
*
* @param mixed $surveyid
*/
function getMaxGroupOrder($surveyid)
{
$s_lang = Survey::model()->findByPk($surveyid)->language;

$query = Groups::model()->findAllByAttributes(array('sid' => $surveyid, 'language' => $s_lang), array('order' => 'group_order desc'));

$current_max = !is_null($query) ? $query->group_order : '';

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

Maybe is not mandatory but if you use that field of the database to do something you got some error

Kindest regards
Emiliano

Connexion ou Créer un compte pour participer à la conversation.

LimeSurvey Partners

Commencez dès maintenant !

Créez simplement un compte et commencez à utiliser LimeSurvey dès aujourd'hui.

Inscrivez-vous maintenant

Inscrivez-vous à notre Newsletter!