new course format with automatic activity creation

new course format with automatic activity creation

by Francesco Pisano -
Number of replies: 6

Hello,

I have to create a new course format, very similar to the "topics format" but I need that it creates a quiz activity automatically on course creation, like the "topics format" automatically creates the "Announcements" activity .


I have already done the clone of "topics format".
But I don't know where, and how, I have to implement the automatic creation of that activity.


This is a step of a bigger job: I will work step by step.

My moodle version is 3.4


Thanks,

  Francesco


Average of ratings: -
In reply to Francesco Pisano

Re: new course format with automatic activity creation

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

Two things...

- You don't need a course format to do this at all. Unless you need a format to actually make the course look different. The best way to do things when the course is created is to make a local plugin that traps the course creation event and adds the new activities.  See https://docs.moodle.org/dev/Event_2#Event_observers

- There's no lack of sample code that creates courses. For example, the web service code to create courses (https://github.com/moodle/moodle/blob/MOODLE_34_STABLE/course/externallib.php#L688). You could even just use the webservice wink

In reply to Howard Miller

Re: new course format with automatic activity creation

by Francesco Pisano -

Thank you Howard,

I need to create a new course format because that is my project. 

I already did the course manually, but I have to reach the same result automatically on course creation.


I didn't understand how i can use "Event2". Can you explain it?


Than I'll take a look to webservice too.


Thanks

 Francesco

In reply to Francesco Pisano

Re: new course format with automatic activity creation

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

Yes - read the link smile

When a course is created an event is fired. Your course format (as a standard plugin) can capture that event and run some code. 

In reply to Howard Miller

Re: new course format with automatic activity creation

by Francesco Pisano -

Ok.

I understood.

I don't know if i able to do this but i understood. smile


Do you know where can i find the function to create quiz that will be launched on event "course creation"?

In reply to Francesco Pisano

Re: new course format with automatic activity creation

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 would start by looking at course/modedit.php. This is the code that processes the form when you create a new activity.