What is the best way to package course data with a plugin? (3.2.1)

What is the best way to package course data with a plugin? (3.2.1)

by Yael Namen -
Number of replies: 5

I am using moodle for one of our apps.

I am developing an authentication plugin that relies on specific cohorts and courses existing.

My goal is to:

  1.  Create cohorts (working)
  2. Create courses that have a self-enrolment record, limited to folks in one of the cohorts made above,
  3.  authenticate against another system (working), 
  4. slot users into cohorts based on information in that system (not done, but I have no concerns about it).

# 1 is where the problem lies.

I am using create_course, from /course/lib.php. This fails, since it tries to rebuild the course cache, which cannot be done during install/upgrade.

What is the proper way to handle this?

is there a different method I should use?

direct $DB calls?

importing a CSV programmatically?

Just add the courses in a separate step? (technically, the plugin only needs to care about the cohorts.)


Thanks.


Average of ratings: -
In reply to Yael Namen

Re: What is the best way to package course data with a plugin? (3.2.1)

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Why would an authentication plugin be creating courses (a) at all and (b) during install time?

In reply to Howard Miller

Re: What is the best way to package course data with a plugin? (3.2.1)

by Yael Namen -

Originally I was going to write a corresponding enrolment plugin, and include the courses and such there. Then I discovered that self-enrolment supports limiting to specific cohorts, which suits our needs.

I looked through all the plugin types and didn't see any obvious place to include it.

As I mentioned, this is site-specific, meaning just for this installation, not intended for general consumption.

As I also mentioned, the plugin just needs to know about cohorts, as they will be assigned based on information in the system I am authenticating agaist. Now, if there is a different type of plugin that should provide the cohorts, I'm all ears.

What I very specifically need is for the creation of the courses to be automated. I cannot be a manual post-deployment step.

I had thought that including the courses with the plugin that would be managing enrolment in them would be the easiest way. 

Is there a better way?

In reply to Yael Namen

Re: What is the best way to package course data with a plugin? (3.2.1)

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think you need to step back and explain what you are trying to do (at a slightly higher level). 

How does an enrolment plugin 'include the courses'? It sounds like you are creating a new course for a user when they enrol on the course or something along those lines? If so, that's an odd thing to do. 

In reply to Howard Miller

Re: What is the best way to package course data with a plugin? (3.2.1)

by Yael Namen -

Not sure why you need to know the overarching problem to answer how best to automate creation of courses during deployment of { THE SYSTEM | THE PLUGIN } but okay.

The external system I am authenticating against -- call it AUTHSRC -- provides a field -- call it FOO -- and based on that value, I want to give the user access to be able to enrol in particular courses.

So, if user has a FOO of FOO_A, they get access to COURSE_A, FOO_B to COURSE_B, etc. These FOO_*'s and COURSE_*'s are in order, so when the user completes the test we want to communicate that completion back to AUTHSRC and immediately give access the next COURSE_* in the chain. (This chaining, and reporting back to AUTHSRC is not relevant to this specific issue, but drive the implementation decisions around it.)

Putting people into a corresponding COHORT_*, with a self-enrolment record on the COURSE_*, restricted to the cohort seems like an obvious implementation, and saves the trouble of writing my own enrolment plugin.

My specific problem is that I need to ensure the courses are creating during deployment. If having the plugin be responsible is not the right way to do that, fine. I acknowledged as much in my opening post.

Is it a cli step to be run after installing the plugin?

Should that script make direct add_course() calls? Should it automate the process of uploading a CSV? Should it automate restoring the courses from a backup?

In reply to Yael Namen

Re: What is the best way to package course data with a plugin? (3.2.1)

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

So, presumably, you want to be able to create the same course over and over from a template? And you don't know how many instances of these courses there will be ahead of time? Is that it?

I know there are tools out there that use the backup/restore API to duplicate courses. So presumably, a plugin could do the same. You would just need to have a Moodle backup of the course somewhere, and then use it to run the restore functions.

If you need to create new course shells, there are plugins in the plugins database that do this (e.g. https://moodle.org/plugins/local_course_merge). And some that create new courses from templates (e.g. https://moodle.org/plugins/local_course_template). You could use those as examples

mike