Welcome, Guest
Username: Password: Remember me

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

field "group_order" on the DB wrong when create a new survey [bug and solution] 2 months 9 hours ago #105272

  • emimarz
  • emimarz's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 21
  • Thank you received: 5
  • Karma: 1
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
The administrator has disabled public write access.
Time to create page: 0.124 seconds
Donation Image