Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

createFieldMap and how to get the name of a column by question code

  • bismark
  • bismark's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 6 months ago - 5 years 6 months ago #175591 by bismark
I need to retrieve the column name of lime_survey_123456-table by the title of a question
Code:
function getColumnName($response, $title)
    {
        $fieldmap = createFieldMap($response->survey, 'full', null, false, $response->attributes['startlanguage']);
 
        foreach ($response->attributes as $key => $value) {
            if (array_key_exists($key, $fieldmap)) {
                if (array_key_exists('title', $fieldmap[$key]) && $fieldmap[$key]['title'] === $title) {
                    return $key;
                }
            }
        }
 
        return false;
    }

So I can use this code
Code:
Yii::import('application.helpers.common_helper', true);
$response = SurveyDynamic::model(123456)->findByPk(1);
var_dump(getColumnName($response, 'completed')); // outputs '454344X20X386'

Is there already a method to do so?
Or is there already a method to update a lime_survey_123456 column directly?
Last edit: 5 years 6 months ago by bismark. Reason: enhancing the question
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 months ago - 5 years 5 months ago #175600 by DenisChenu
I need a lot such functionnality on 2 plugins … then i make a plugin helper plugin

Contribution are welcome : gitlab.com/SondagesPro/coreAndTools/getQuestionInformation

See gitlab.com/SondagesPro/coreAndTools/getQ...eyCodeHelper.php#L70

It does it by id, but do it by title/code seems easy with this helper

Else LimeSurvey use github.com/LimeSurvey/LimeSurvey/blob/c4...ager_helper.php#L840

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 5 years 5 months ago by DenisChenu. Reason: Else LimeSurvey use
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose