Base de dades externa: diferència entre les revisions

De MoodleDocs
Salta a:navegació, cerca
Línia 37: Línia 37:
El procés també desapunta els usuaris dels cursos si ja no són a la base de dades. Els registres d'usuaris queden associats a la base de dades o a un altre mètode d'autenticació, el primer amb què van ser creats. O sigui que des de la base de dades externa només es poden desapuntar els alumnes que havien entrat per primera vegada amb l'ajut del connector.
El procés també desapunta els usuaris dels cursos si ja no són a la base de dades. Els registres d'usuaris queden associats a la base de dades o a un altre mètode d'autenticació, el primer amb què van ser creats. O sigui que des de la base de dades externa només es poden desapuntar els alumnes que havien entrat per primera vegada amb l'ajut del connector.


== Enrolment & Roles ==
== Inscripció i Rols ==


The "enrol_db_defaultcourseroleid" setting in the plugin settings page specifies the role that the user will take when they are added to the course. The default setting will set them to the course default setting (initially "student"). However, you can specify a field in the external table (specified in the "enrol_db_remoterolefield" setting) that contains the short name for the user's role. This could, for example, be used to enrol both students and teachers into courses using a suitably configured database.  
La variable "enrol_db_defaultcourserolid" a la pàgina de variables del connector, especifica el rol que l'usuari prendrà la primera vegada que entri al curs. Establert inicialment com a "alumne", és així com el deixarà inscrit. Però podríeu fer servir un camp de la taula externa (especificat a la variable "enrol_db_remoterolfield") que contingués el nom curt del rol de l'usuari. Així es podria, per exemple, utilitzar una base de dades única que contingués ambdós: alumnat i professorat.


== Creating Courses ==
== Creating Courses ==

Revisió del 16:40, 17 jul 2007

Podeu utilitzar una base de dades externa (pràcticament qualsevol) per controlar l'autenticació d'usuaris. Assumim que la base de dades externa conté un camp que conté un identificador de curs, un camp amb un identificador d'usuari, i opcionalment, un camp que contingui un rol. Aquests camps es contrasten amb els camps que aparelleu al curs local, taules d'usuaris i taules de rols.

Les fonts de dades següents són les que tenen suport, però penseu que també haureu de compilar el PHP amb les opcions adequades per al controlador ODBC previst:

  • access
  • ado
  • mssql
  • borland_ibase
  • csv
  • db2
  • fbsql
  • firebird
  • ibase
  • informix72
  • informix
  • mysql
  • mysqlt
  • oci805
  • oci8
  • oci8po
  • odbc
  • odbc_mssql
  • odbc_oracle
  • oracle
  • postgres64
  • postgres7
  • postgres
  • proxy
  • sqlanywhere
  • sybase
  • vfp

Inscripció i anul·lació de la inscripció

La inscripció a través d'una base de dades externa es fa el moment que un usuari entra al Moodle. El connector intentarà apuntar l'estudiant en tots els cursos segons les dades contingudes a la base de dades externa i, opcionalment, crearà cursos buits si no hi havia el codi de curs que tenia l'alumne. Per comprovar que això passarà així, podeu entrar com si fóssiu un estudiant i veure si la seva llista de cursos és la que esperàveu.

El procés també desapunta els usuaris dels cursos si ja no són a la base de dades. Els registres d'usuaris queden associats a la base de dades o a un altre mètode d'autenticació, el primer amb què van ser creats. O sigui que des de la base de dades externa només es poden desapuntar els alumnes que havien entrat per primera vegada amb l'ajut del connector.

Inscripció i Rols

La variable "enrol_db_defaultcourserolid" a la pàgina de variables del connector, especifica el rol que l'usuari prendrà la primera vegada que entri al curs. Establert inicialment com a "alumne", és així com el deixarà inscrit. Però podríeu fer servir un camp de la taula externa (especificat a la variable "enrol_db_remoterolfield") que contingués el nom curt del rol de l'usuari. Així es podria, per exemple, utilitzar una base de dades única que contingués ambdós: alumnat i professorat.

Creating Courses

Optionally courses that do not exist in the Moodle site can be created. Switch the "enrol_db_autocreate" option to "yes" in the plugin settings. You can additionally specify the Category into which the new course will be placed and may also specify a "template" course from which the new course will be copied.

Synchronization Script

A script is provided that can synchronize all your user enrollments at once - both adding and removing user enrolments (and creating courses if specified). The script is called auth_database_sync.php and is found in the enrol/database folder.

This script is meant to be called from a system cronjob to sync moodle enrolments with enrolments in the external database. You need to make sure all the users present in the external enrolments are already created in moodle. If you are using external authentication plugins (db, ldap, etc.) you can use the scripts provided by those plugins to synchronize your users before running this script.

Example cron entry:

   # 5 minutes past 4am
   5 4 * * * /usr/bin/php -c /path/to/php.ini /path/to/moodle/enrol/database/auth_database_sync.php

Notes:

  • If you have a large number of enrolments, you may want to raise the memory limits by passing -d memory_limit=256M
  • For debugging & better logging, you are encouraged to use in the command line: -d log_errors=1 -d error_reporting=E_ALL -d display_errors=0 -d html_errors=0
  • This only works for users that already exist in your Moodle site (see comment above)

Setting It Up

You will need to perform (as a minimum) the following steps to enable external database enrolment - only a single table is required in the database which contains a record for every user/course combination. If the table is large it is a good idea to make sure appropriate indexes have been created:

  • Use an existing database or create a new one. Use an existing or create a new table with the following minimum fields:
    • course identifier (to match unique course identifier in Moodle)
    • user identifier (to match unique user identifier in Moodle)
    • (optional) role identifier (to match unique role identifier in Moodle)
  • Populate the database table. Each user/course combination to have a record in the table
  • In Moodle, go to Site Administration => Courses => Enrolments, find External Database in the list and click Settings
  • In the top panel, select the database type (make sure you have the necessary configuration in PHP for that type) and then supply the information to connect to the database.
  • The middle panel creates the mapping between Moodle and the external database. The first three settings are for the local (Moodle) field names and the last three for the remote (external database) settings. They are in the same order.
    • enrol_localcoursefield / enrol_remotecoursefield - in Moodle the name of the field in the course settings the uniquely identifies the course (e.g., idnumber). In the external database the name of the matching field.
    • enrol_localuserfield / enrol_remoteuserfield - in Moodle the name of the field in the user profile that uniquely identified the user (e.g., idnumber). In the external database the name of the matching field.
    • enrol_db_localrolefield / enrol_db_remoterolefield - (optional) in Moodle the name of the field in the role edit page the uniquely identifies the role (e.g., shortname). In the external database the name of the matching field.
  • The Roles panel specifies the role that the user will get in the course if their role is not specified in the external database.
  • The final panel enables auto creation of courses.
  • Save changes, and then tick the box to enable external database enrolment.

Field Mapping Example:

Choose your fields from the Moodle database:

  • enrol_localcoursefield: A course identifier from mdl_course, e.g. "idnumber"
  • enrol_localuserfield: A user identifier from mdl_user, e.g. "idnumber"
  • enrol_localrolefield: (optional) A role identifier from mdl_role, e.g. "shortname"

Create a view in your external database which matches the chosen field values from Moodle:

  • enrol_remotecoursefield: A matching course identifier from your external database table, e.g. "course_number"
  • enrol_remoteuserfield: A matching user identifier from your external database table, e.g. "userid"
  • enrol_remoterolefield: (optional) A matching role identifier from your external database table, e.g. "role_name"

See also