General help

new course format with automatic activity creation

 
Picture of Francesco Pisano
new course format with automatic activity creation
 

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: -
Picture of Howard Miller
Re: new course format with automatic activity creation
Core developersDocumentation writersParticularly helpful MoodlersPlugin 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

 
Average of ratings: -
Picture of Francesco Pisano
Re: new course format with automatic activity creation
 

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

 
Average of ratings: -
Picture of Howard Miller
Re: new course format with automatic activity creation
Core developersDocumentation writersParticularly helpful MoodlersPlugin 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. 

 
Average of ratings: -
Picture of Francesco Pisano
Re: new course format with automatic activity creation
 

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"?

 
Average of ratings: -
Picture of Howard Miller
Re: new course format with automatic activity creation
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

I would start by looking at course/modedit.php. This is the code that processes the form when you create a new activity. 

 
Average of ratings: -
Picture of Francesco Pisano
Re: new course format with automatic activity creation
 

Thank you.

I'll take a look! smile

 
Average of ratings: -