Using createFieldMap()

More
5 years 2 weeks ago #78095 by tacman1123
tacman1123 created the topic: Using createFieldMap()
I'm trying to get a list of all the fields in an active survey, using this code from a script called from /admin/admin.php:
if ($sid) {
  $common_data['surveyinfo'] = getSurveyInfo($sid);
  require_once(dirname(__FILE__).'/sessioncontrol.php'); // stab in the dark.
  $common_data['fieldmap'] = createFieldMap($sid,'full',false,false,$language);
}

Most, but not all, of the time fieldmap is only returning the common result data -- id, submitdate, lastquestion, etc. Not the SGQA codes, which is really what I'm trying to get to. Is there some other call that needs to be made? Or maybe there's another call to get field information?

Thx,

Tac

Please Log in to join the conversation.

More
5 years 2 weeks ago #78106 by Mazi
Mazi replied the topic: Using createFieldMap()
This code snippet created the full fieldmap:
$fieldmap = createFieldMap($surveyid);
echo "<pre>";
print_r($fieldmap);
echo "</pre>";

The SGQA can be found at 'fieldname', example:
[34174X4X30] => Array
(
[fieldname] => 34174X4X30
[type] => N
[sid] => 34174
[gid] => 4
[qid] => 30
[aid] =>
[title] => d_bd1
[question] => Bitte geben Sie Ihr Geburtsjahr an
[group_name] => H_1
[mandatory] => Y
[hasconditions] => N
[usedinconditions] => N
[questionSeq] => 1
[groupSeq] => 0
[relevance] =>
[grelevance] =>
[preg] =>
[other] => N
[help] => z.B. 1980
)


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 2 weeks ago #78112 by tacman1123
tacman1123 replied the topic: Using createFieldMap()
There's some global/session magic going on with setting the language, when I added this things started to work:
// hack
if (isset($browselang) && $browselang!='')
{
    $_SESSION['browselang']=$browselang;
    $language=$_SESSION['browselang'];
}
elseif (isset($_SESSION['browselang']))
{
    $language=$_SESSION['browselang'];
    $languagelist = GetAdditionalLanguagesFromSurveyID($surveyid);
    $languagelist[]=GetBaseLanguageFromSurveyID($surveyid);
    if (!in_array($language,$languagelist))
    {
        $language = GetBaseLanguageFromSurveyID($surveyid);
    }
}
else
{
    $language = GetBaseLanguageFromSurveyID($surveyid);
}

There's probably a cleaner way!

Tac

Please Log in to join the conversation.

More
5 years 2 weeks ago #78114 by DenisChenu
DenisChenu replied the topic: Using createFieldMap()
Hello:
For www.limesurvey.org/forum/development/780...eldmap?lang=fr#78095

Try:
$common_data = createFieldMap($sid,'full',true,false,$language);

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
5 years 2 weeks ago #78123 by TMSWhite
TMSWhite replied the topic: Using createFieldMap()
It gets even trickier if you want to support language changes or randomization groups.

I'm currently consolidating all of the fieldmap and ancillary information into LimeExpressionManager->knownVars[]. However, as we move forward with 2.0/2.1, we may want to change the database storage model for questions so that createFieldMap becomes obsolete. I'd prefer that the database stores one row per question and sub-question. This will result in more total rows, but will remove the need to use code to process the database to generate the fieldmap, variable names, etc. I'd rather see the database model have everything we need (and let that be set by the GUI) so everyone can just do a simple SQL query to create the fieldmap and the knownVars array that EM uses.

Please Log in to join the conversation.

More
5 years 2 weeks ago #78125 by tacman1123
tacman1123 replied the topic: Using createFieldMap()
So you're thinking instead of having 'questions' and 'answers' as two tables, have one table that is 'questions', but includes an answer_code as well?

That'll be good for multiple choice. For radio, though, I'm not sure.

Also, I've wanted to introduce the idea of label references for questions. Right now, when building a survey the answer options are copied from a label set into 'answers'. There are times when it would be preferable to say 'this question gets its answers from this label set', and if the label set changes, the survey changes as well.

Obviously, this would be problematic for multiple choice / multiple answers with the current database structure for results, but would work for the Entity / Value data structure we've discussed elsewhere.

And maybe it's not even worth it, which is why I haven't brought it up elsewhere.

Anyway, how can I get a map from the current field names to question_code / answer_code? Does that knownVars[] method exist in 1.92? How can I call it?

Tac

Please Log in to join the conversation.

More
4 years 8 months ago #84194 by abita1
abita1 replied the topic: Using createFieldMap()
Re: #78123

Rigorous attention to normalized databases and normalized variable definitions w/i the code, early on, might have gotten rid of a slew of problems...

Your goal is worthwhile !

Please Log in to join the conversation.

More
4 years 8 months ago #84439 by abita1
abita1 replied the topic: Using createFieldMap()
...placing questions, labels/sets, answers -and- subquestions into separate DB tables

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.