- Posts: 31
- Karma: 1
- Thank you received: 5
- Forum
- English support forums
- Future features
- 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]
5 years 2 days ago #105272
by emimarz
field "group_order" on the DB wrong when create a new survey [bug and solution] was created by 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
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
Please Log in or Create an account to join the conversation.