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

Mehr
3 Jahre 8 Monate her #105272 von emimarz
emimarz erstellte das Thema field "group_order" on the DB wrong when create a new survey [bug and
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

Bitte Anmelden um an der Konversation teilzunehmen.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten