Attention : vous consultez actuellement la documentation dédiée aux versions 1.x de Moodle. La documentation pour les versions 2.x de Moodle est consultable ici : admin/report/customsql/index, celle pour les versions 3.x de Moodle est consultable ici : admin/report/customsql/index et celle pour Moodle 4.x est consultable là : admin/report/customsql/index.

admin/report/customsql/index

De MoodleDocs
Aller à :navigation, rechercher

Remarque : la traduction de cet article n'est pas terminée. N'hésitez pas à traduire tout ou partie de cette page ou à la compléter. Vous pouvez aussi utiliser la page de discussion pour vos recommandations et suggestions d'améliorations.


Créé par "The Open University"

Ce plugin de rapport personnalisé permet aux administrateurs de mettre en place des requêtes SQL personnalisées pour créer les rapports de leur choix. Les rapports peuvent être de deux types : soit exécutés à la demande ou planifiés pour s'exécuter automatiquement. Les autres utilisateurs possédant la capacité sur ces rapports peuvent voir une liste de requêtes auxquelles ils ont accès. Les résultats peuvent être visualisés sur l'écran ou téléchargé au format CSV.

Installer les rapports personnalisés

Suivre les instructions habituelles d'installation en:Installing contributed modules or plugins.

Captures d'écran

Here are two example screen shots, showing the two main screens.

thumb|none|600px|The list of available reports thumb|none|600px|The results of running one of the reports

(Note, these screen shots are in the OU theme, not the standard Moodle theme, and iCMA is OU-jargon for quiz.)

Interface pour les utilisateurs standards

Liste des requêtes disponibles

Users with the report/customsql:view capability can access the list of reports in the admin block. Each query is accessible only to a certain people. There are three levels of access:

  • Available to any one who can access the report at all (those with report/customsql:view).
  • Available to people who are able to see other system reports (those with moodle/site:viewreports)
  • Available to administrators only (those with moodle/site:config)

When you go to the list, it will only show the queries you have access to. There is a note beside each query saying when it was last run, and how long it took to generate.

The list shows on-demand and scheduled queries separately.


Running an on-demand query

To run an on-demand query, click on its name in the list of queries.

The query will be run, and the results will be displayed as a table. Any URLs in the table will automatically be made into hyperlinks.

A description of the query may appear above the table.

The summary of when the query was run and how long it took is shown at the bottom, along with a link to download the CSV file (for example to get the data into Excel) and a link back to the list of all available queries.


Viewing the results of scheduled queries

Scheduled queries can work in one of two ways. Either each run of the report generates and entire table of reasults, or each run just creates one line of results, and the report builds up a row at a time.

When you click the name in the list of queries, you get taken to a display of the latest results, just like in the on-demand case.

However, if each scheduled run generates a complete report, then at the bottom of a page there will be a list of all the previous runs of the report, so that you can go and see how the report changed over time.


Interface pour les administrateurs

Administrators (that is, users with report/customsql:definequeries) see everything that other users see, but with some additions.


Additional controls in the staff interface

Administrators get shown who each report in the list is available to.

They also get an edit and a delete icon next to each query.

There is an Add new query button at the end of the list of queries.

When viewing a particular query, Administrators get an edit and a delete link underneath the table of results.


Ajouter ou modifier une requête

When you click the Add new query button, you get taken to an editing form that lets you define the query.

You must give the query a name.

You can optionally enter a description that is displayed above the results table. You should use this to explain what the results of the query mean.

You must enter the SQL to generate the results you want displayed. This must be an SQL select statement. You must use the prefix prefix_ for table names. It should not be possible to enter any SQL that would alter the contents of the database.

You choose who you want the query to be accessible to.

You choose whether the query should be run on-demand or scheduled weekly or monthly. If the report is scheduled, you can say whether the each run returns one row to be added to a single table, or whether each run generates a separate table.

When you save the new query, the SQL is checked to make sure that it will execute without errors. If you have said that the report will only return a single row, this is also checked. After saving the query, if this was a manual query, you are taken to the query results page, so you can see what the results look like. If it was an automatic query or if you cancel the form, you are taken to the list of available queries.

Editing an existing query uses the same form as for adding a new query, but to change the properties of an existing query.

Note that at the OU, weeks start on Saturday. If you don't like that, there is a fairly obvious constant to hack at the top of locallib.php.

Supprimer une requête

When you click the delete icon or link for a query, you are taken to a confirmation page that shows you SQL of the query you are about to delete. The query is only deleted if you click Yes on the confirmation page.

After deleting a query, you are taken back to the list of queries.

Partagez vos requêtes utiles

Si vous avez créé des requêtes intéressantes et utiles avec les rapports personnalisées, merci de les partager ici.

Tentatives de Tests dans la dernière semaine/mois

Spécifiez ceci comme requête :

SELECT COUNT(*) FROM prefix_quiz_attempts WHERE timefinish > %%STARTTIME%%

   AND timefinish <= %%ENDTIME%%
   AND preview = 0

Ceci doit être défini comme une requête Planifiée, le premier jour de chaque semaine ou Planifiée, le premier jour de chaque mois, sinon, cela ne fonctionnera pas.

Résumé de la plateforme

Ce rapport montre un peu l'équivalent des statistiques envoyées à moodle.org lorsque vous enregistrez votre site. Celles qui sont agrégées sur http://moodle.org/stats/

SELECT (SELECT COUNT(id) FROM prefix_course) - 1 AS Cours, (SELECT COUNT(id) FROM prefix_user WHERE deleted = 0 AND confirmed = 1) AS Utilisateurs, (SELECT COUNT(id) FROM prefix_role_assignments) AS "Attributions de rôle", (SELECT COUNT(id) FROM prefix_forum_posts) AS "Messages de forum", (SELECT COUNT(id) FROM prefix_resource) AS Ressources, (SELECT COUNT(id) FROM prefix_question) AS Questions

Cours totalements ouverts (invités sans clé)

Cette requête retourne la liste des cours ouverts aux invités, visibles aux étudiants et sans clé d'inscription. En gros, ouverts à tout le monde !

SELECT category, id, fullname, shortname, enrollable FROM `prefix_course` WHERE `guest` =1 AND `password` = "" AND `visible` =1

Quasiment la même requête, mise en forme avec des liens, et un tri :

SELECT CONCAT('<a target="_new" href="%%WWWROOT%%/course/category.php?id=',category,'">',category,'</a>') AS Catégorie , CONCAT('<a target="_new" href="%%WWWROOT%%/course/view.php?id=',id,'">',id,'</a>') AS id , CONCAT('<a target="_new" href="%%WWWROOT%%/course/view.php?id=',id,'">',fullname,'</a>') AS Cours , `shortname` , `enrollable` FROM `prefix_course` WHERE `guest` =1 AND `password` = "" AND `visible` =1 ORDER BY category, id

Dérogations aux permissions sur des catégories

SELECT rc.id, ct.instanceid, ccat.name, rc.roleid, rc.capability, rc.permission, DATE_FORMAT( FROM_UNIXTIME(rc.timemodified), '%Y-%m-%d') AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth FROM `prefix_role_capabilities` AS rc INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid AND `contextlevel` = 40

Quasiment la même requête, mise en forme avec des liens :

SELECT rc.id, CONCAT('<a target="_new" href="%%WWWROOT%%/course/category.php?id=',ct.instanceid,'">',ct.instanceid,'</a>') AS Catégorie , CONCAT('<a target="_new" href="%%WWWROOT%%/course/category.php?id=',ct.instanceid,'">',ccat.name,'</a>') AS Nom, rc.roleid, rc.capability, rc.permission, DATE_FORMAT( FROM_UNIXTIME(rc.timemodified), '%Y-%m-%d') AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth FROM `prefix_role_capabilities` AS rc INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid AND `contextlevel` = 40

Autres requêtes

Vous pourrez trouver d'autres requêtes toutes prêtes :

Voir aussi