Welcome, Guest
Username: Password: Remember me

TOPIC: Using createFieldMap()

Using createFieldMap() 2 years 1 week ago #78095

  • tacman1123
  • tacman1123's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 125
  • Karma: 1
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
The administrator has disabled public write access.

Re: Using createFieldMap() 2 years 1 week ago #78106

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5275
  • Thank you received: 289
  • Karma: 246
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Using createFieldMap() 2 years 1 week ago #78112

  • tacman1123
  • tacman1123's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 125
  • Karma: 1
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
The administrator has disabled public write access.

Re: Using createFieldMap() 2 years 1 week ago #78114

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 5834
  • Thank you received: 712
  • Karma: 221
Hello:
For www.limesurvey.org/forum/development/780...eldmap?lang=fr#78095

Try:
$common_data = createFieldMap($sid,'full',true,false,$language);
The administrator has disabled public write access.

Re: Using createFieldMap() 2 years 1 week ago #78123

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 81
  • Karma: 36
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.
The administrator has disabled public write access.

Re: Using createFieldMap() 2 years 1 week ago #78125

  • tacman1123
  • tacman1123's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 125
  • Karma: 1
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
The administrator has disabled public write access.

Re: Using createFieldMap() 1 year 8 months ago #84194

  • abita1
  • abita1's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 43
  • Thank you received: 1
  • Karma: 0
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 !
The administrator has disabled public write access.

Re: Using createFieldMap() 1 year 8 months ago #84439

  • abita1
  • abita1's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 43
  • Thank you received: 1
  • Karma: 0
...placing questions, labels/sets, answers -and- subquestions into separate DB tables
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.293 seconds
Donation Image