how to create a new course format for Moodle 2.0.x?

how to create a new course format for Moodle 2.0.x?

by Miguel Angel -
Number of replies: 8

where can i get detailed info for creating new course format for Moodle 2.0.x?

I read the "readme file" in the /course/format  directory, but, copying one of the standard ones (topics, weekly,  etc) and renaming the folder is not enough, and samples for previos versions (like  Flexible Page for 1.9.x) are not working.

thanks in advance for any help in this issue.

Average of ratings: -
In reply to Miguel Angel

Re: how to create a new course format for Moodle 2.0.x?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Miguel,

I'm not sure if there is a guide, but it is possible to create a new course format by copying the existing topics / weeks formats.  To make it work:

1. Copy the topics format and rename the folder - say 'newformat' - which I will use as an example below.

2. Edit lib.php and change all of the function names to the new format's name, i.e. callback_topics_get_section_name -> callback_newformat_get_section_name.

3. In lib.php change anything that references 'topics', i.e.

line 47

return $navigation->load_generic_course_sections($course, $coursenode, 'topics');

to

return $navigation->load_generic_course_sections($course, $coursenode, 'newformat');

line 57

return get_string('topic');

to

return get_string('sectionname','format_newformat');

line 67

return 'topic';

to

return 'newformat';

line 75

return get_string('section0name', 'format_topics');

to

return get_string('section0name', 'format_newformat');

line 77

return get_string('topic').' '.$section->section;

to

return get_string('sectionname', 'format_newformat').' '.$section->section;

 

4. Change lang/en/format_topics.php to lang/en/format_newformat.php.

5. Edit format_newformat.php and change to what is appropriate, i.e:

$string['sectionname'] = 'Topic';

to

$string['sectionname'] = 'New Format';

 

$string['pluginname'] = 'Topics format';

to

$string['pluginname'] = 'New Format format';

 

6. In format you may wish to change lines 33 and 284 to be a different parameter, i.e.:

$topic = optional_param('topic', -1, PARAM_INT);

to

$topic = optional_param('newformat', -1, PARAM_INT);

and

$select = new single_select(new moodle_url('/course/view.php', array('id'=>$course->id)), 'topic', $sectionmenu);

to

$select = new single_select(new moodle_url('/course/view.php', array('id'=>$course->id)), 'newformat', $sectionmenu);

 

That should get you started!  I've done this from memory and comparing topics with my collapsed topics format so might be incomplete but should get you most if not all of the way there.

Cheers,

Gareth

Average of ratings: Useful (2)
In reply to Gareth J Barnard

Re: how to create a new course format for Moodle 2.0.x?

by Miguel Angel -

Thanks a million Gareth!!

I´ll use the instructions you gave  and try!

 

In reply to Gareth J Barnard

Re: how to create a new course format for Moodle 2.0.x?

by Susana L. -

Very useful indeed. Thank you!

I will add here some extra info:

  1. I had to change in version.php: $plugin->component = 'format_newformat';
  2. The format name lenght must be less than 10 chars;
  3. If the new format is very similar to topics, in order to keep the 'show only topic x' functionality don't change:
  • $topic = optional_param('topic', -1, PARAM_INT);
  • $select = new single_select(new moodle_url('/course/view.php', array('id'=>$course->id)), 'topic', $sectionmenu);
Average of ratings: Useful (1)
In reply to Susana L.

Re: how to create a new course format for Moodle 2.0.x?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Susana,

Thanks for the information.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: how to create a new course format for Moodle 2.0.x?

by sohail aslam -

Dear Gareth,

Thanks for the step by step guideline.

Is this process will work for Moodle 2.3 as well?

 

Sohail

In reply to sohail aslam

Re: how to create a new course format for Moodle 2.0.x?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Sohail,

Given the changes, with copying the Topics format probably not, with copying the Social, probably it will.  Give it a bash smile

Cheers,

Gareth

In reply to Gareth J Barnard

Re: how to create a new course format for Moodle 2.0.x?

by sohail aslam -

Thanks for your quick reply Gareth.

One more thing. Is there any chances you will release Grid Course Format for moodle 2.3 soon?

In reply to sohail aslam

Re: how to create a new course format for Moodle 2.0.x?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Sohail,

No worries smile

As for the Grid format, I think it needs a bit more testing and indeed I'm not completely happy with the overloading in the child renderer class (although the code works) - please see lots of information on CONTRIB-3769.  And a stable release is up to Julian R, I've been working with him to get a version out.  What I've found really helps is 'testers' people who track down issues and tell you smile - this has really helped for Collapsed Topics as you can see from the credits in the Readme.

Cheers,

Gareth