General developer forum

 
 
Picture of Gregory JB
Creating a forum remotely
 

Good evening all. I am working on a special (very unusual) project that involves creating something like an 'API' for Moodle that allows some of its forum functions to be exported to other environments. For example, a user would be able to post to a moodle discussion from a mobile device. To make this possible, I bypassed all of Moodle's built-in functions and went straight for the database.

Now the project is nearly complete. The last thing left to do is allow users to create new forums remotely. The problem is, since I am using the database directly, I needed to know every table that I would have to update so that the new forum is seamlessly integrated into the site. I know that more than one table is affected by a new forum, including forum and context. Can anyone explain the context table to me? Or at least direct me to the code that adds new forums to Moodle?

 
Average of ratings: -
Picture of Andrew Nicols
Re: Creating a forum remotely
Group DevelopersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

Hi Gregory,

You don't say what version of Moodle you're developing for, but there is already an infrastructure for exactly this which is the recommended approach. It's called Web Services, and configuration and details for it can be found in your Moodle Settings block at Site administration -> Plugins -> Web services.

At present there are only forum-related web service functions for:

  • get_forums_by_cours
  • get_forum_discussions

However, you should be able to write your own web services using the plugin infrastructure which will allow you to achieve what you intend without accessing the database directly. This has the main advantage that you're using established APIs which are updated when changes are made to core Moodle systems.

Alternatively, you could contribute new functions to the existing plugins and submit them back to the Moodle project so that others can benefit from them.

Andrew

 
Average of ratings: -
Picture of Gregory JB
Re: Creating a forum remotely
 

Thank you. So how exactly do I go about creating my own function for adding a forum? I see in Moodle that there is a list of functions that I can add to external services. So I created an external service and I want to write a new function to use with it. And how do I call these functions from outside of Moodle?

By the way, I'm using version 2.4

 
Average of ratings: -
Picture of Jitendra Gaur
Re: Creating a forum remotely
 

Hi Gregory,

I have given this ans in following link,  look into that.

Hope it will help you.

http://stackoverflow.com/questions/12959507/create-forum-in-moodle-via-external-php/13762266#13762266

 
Average of ratings: -
Picture of Gregory JB
Re: Creating a forum remotely
 

Thank you! I will use this code to implement my function, as soon as I find out where to add it.

 
Average of ratings: -
Picture of Gregory JB
Re: Creating a forum remotely
 

Do you by any chance know what the path field in the context table represents?

 
Average of ratings: -
Dan at desk in Moodle HQ, Perth
Re: Creating a forum remotely
Group DevelopersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

It is the hierarchy of contexts (parent context id, the parent of that parent context id etc, e.g. /sitecontextid/categorycontextid/coursecontextid/modulecontextid). Its used for speed optimisation of permission checking.

 
Average of ratings: -