Check out the LimeSurvey source code on GitHub!

Change value of Checkbox from 'Y' to '1' Before Inserting into Respondent Table

More
3 years 4 months ago - 3 years 4 months ago #100009 by utsi
Suppose I have a survey with id '123'.

Someone comes across a multiple choice question and selects 2 out of the 5 options. Now I would like to store '1' in the database for checked options and '0' for the other 3 options (instead of blank) in the lime_survey_123 table.

I'm finding it difficult to locate the file which handles the live survey post data. I can figure out where to change the values if I know which file is responsible for inserting data into the survey respondant table.

Any ideas on where I should look for that file?

Thanks.
Last Edit: 3 years 4 months ago by utsi.

Please Log in to join the conversation.

More
3 years 4 months ago #100010 by holch
I don't where to change this either, but just want to point you to something: if you change that, many other things (reporting, etc.) of limesurvey might brake.

Why do you need to change this on creation? Because if it is for external analysis, you can change that during the download process.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
3 years 4 months ago #100012 by utsi
I'm aware that some things might get affected if I do that. But I'm willing to take the risk. I'll test locally first and see what the consequences would be and if whether it is worth the risk or not.

Coming back to this weird requirement, to put it in simple terms the main aim is to differentiate between questions which have been shown to respondents and which didn't.

For example:
If a multi question is displayed, the answers that are checked should be stored as 1 in database and unchecked answer options as 0.

And if a multi question is not shown, then the present system of nothing being stored database should kick in.

My requirement is pretty similar to the one mentioned here limesurvey.org/en/forum/future-features/...tion-not-shown#99752

Please Log in to join the conversation.

More
3 years 3 months ago #100026 by utsi
I finally managed to track down the page which deals with insertion to the database. I modified the original code from
if (is_null($val))
{
	$setter[] = dbQuoteID($key) . "=NULL";
}
else
{						
	$setter[] = dbQuoteID($key) . "=" . dbQuoteAll($val);
}

to
if (is_null($val))
{
	$setter[] = dbQuoteID($key) . "=NULL";
}
else
{
	if($type == 'M')
	{	
		if($val == '' || empty($val))
		{
			$val = '0';
		}
		$setter[] = dbQuoteID($key) . "=" . dbQuoteAll($val);
	}
	else
	{							
		$setter[] = dbQuoteID($key) . "=" . dbQuoteAll($val);	
	}						                        
}

This is working as expected i.e. if the question of type "M" is shown to the respondent and he checks 2 out of the 5 checkboxes, the checked checked values are stored as "Y" while the rest unchecked values are stored as 0 AND if the question of type "M" is skipped due to masking, nothing gets stored in the database.

The only thing I need to verify now is that this doesn't mess up the values of other questions of the survey.

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form