Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi

SUJET : Using createFieldMap()

Using createFieldMap() il y a 2 ans 6 mois #78095

  • tacman1123
  • Portrait de tacman1123
  • Hors ligne
  • LimeSurvey Team
  • Messages : 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
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Using createFieldMap() il y a 2 ans 6 mois #78106

  • Mazi
  • Portrait de Mazi
  • Hors ligne
  • LimeSurvey Team
  • Messages : 5331
  • Remerciements reçus 296
  • Karma: 249
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'"
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Using createFieldMap() il y a 2 ans 6 mois #78112

  • tacman1123
  • Portrait de tacman1123
  • Hors ligne
  • LimeSurvey Team
  • Messages : 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
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Using createFieldMap() il y a 2 ans 6 mois #78114

  • DenisChenu
  • Portrait de DenisChenu
  • Hors ligne
  • Moderator Lime
  • Messages : 6451
  • Remerciements reçus 844
  • Karma: 249
Hello:
For www.limesurvey.org/forum/development/780...eldmap?lang=fr#78095

Try:
$common_data = createFieldMap($sid,'full',true,false,$language);
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Using createFieldMap() il y a 2 ans 6 mois #78123

  • TMSWhite
  • Portrait de TMSWhite
  • Hors ligne
  • LimeSurvey Team
  • Messages : 759
  • Remerciements reçus 82
  • 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.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Using createFieldMap() il y a 2 ans 6 mois #78125

  • tacman1123
  • Portrait de tacman1123
  • Hors ligne
  • LimeSurvey Team
  • Messages : 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
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Using createFieldMap() il y a 2 ans 2 mois #84194

  • abita1
  • Portrait de abita1
  • Hors ligne
  • Senior Lime
  • Messages : 44
  • Remerciements reçus 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 !
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Using createFieldMap() il y a 2 ans 2 mois #84439

  • abita1
  • Portrait de abita1
  • Hors ligne
  • Senior Lime
  • Messages : 44
  • Remerciements reçus 1
  • Karma: 0
...placing questions, labels/sets, answers -and- subquestions into separate DB tables
L'administrateur a désactivé l'accès en écriture pour le public.
Modérateurs: ITEd
Temps de génération de la page : 0.303 secondes
Donation Image