How to map the country field with external database authentication?

How to map the country field with external database authentication?

by Florian Kohrt -
Number of replies: 4

After setting up the external database authentication including data mapping for the "Country" field I had hoped that the country of external users will also show up in their Moodle profiles. Unfortunately that does not happen, that is the country field in their Moodle profiles stays unselected.

Because mapping does for other fields I suspect the reason might be that country is not a free-form field but has a limited set of valid values. The external database provides country names in English language which just might not be the correct format.

Do you have any ideas on how to get country mapping right?

I am running Moodle 3.11.7+ (Build: 20220610).

Average of ratings: -
In reply to Florian Kohrt

Re: How to map the country field with external database authentication?

by Ken Task -
Picture of Particularly helpful Moodlers

Please see:

https://docs.moodle.org/400/en/Location

There is a small paragraph for All Country Codes linked page above (English).

It is not unusual for a point release or upgrade of Moodle to acquire new countries not previously in list.

https://github.com/moodle/moodle/blob/master/lang/en/countries.php

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: How to map the country field with external database authentication?

by Florian Kohrt -
Thank you for your answer, that was helpful!
In reply to Florian Kohrt

Re: How to map the country field with external database authentication?

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Core Moodle includes a user field that allows the selection from a list of ISO 3166 country names to be stored and displayed in the dropdown selection box on a user profile page. These values can be seen here.


The country name you are using may not always exactly map to the ISO name, e.g. the official name of what I think of as “The Czech Republic” is stored as the ISO country name of Czechia. These values are stored in a file called
lang\en\countries.php
in the form
$string['GB'] = 'United Kingdom';

So as you say it is not a free form field, but a key/pair mapping. It will also depend on what country name you are using (i.e. is it the ISO name as listed in that Wikipedia link)



Average of ratings: Useful (1)
In reply to Marcus Green

Re: How to map the country field with external database authentication?

by Florian Kohrt -
Thanks, that was helpful!