Monday, July 13, 2015

SimpleNav: Custom course format - Part 1

THE GOAL
I recently worked for a client in the food service that wanted users to view a quick overview of their company and complete a couple training exercises. So we setup a Moodle course with about 10 activities and 5 videos in the course the student had to complete. The intended time frame for completion was about 10 minutes or less.

The client asked for a streamlined user experience, eliminating confirmation screens and backtracking to the main course page. So in effect, the user could flow seamlessly between each consecutive activity in the course.

THE SOLUTION
The easiest solution for a new navigation between activities would be a new, custom course format. This would allow me to make custom changes without messing with core Moodle code. So the first thing I did was to build my new course format off of a classic:  the Topics format.
  1. Go into the moodle source code to:   moodle/course/format/
  2. Copy the "topics" folder and rename it to something else. I chose to name mine "simplenav" 
Now the fun part: re-naming everything. 
Open up the course format folder you just renamed. Let's start at the top and work our way down.

Lang Folder
  1. Open the lang folder and navigate to the only file in there:  format_(formatname).php. Rename this file using the new name you picked out like this:  format_simplenav.php
  2.  Open the file with a text editor, like Notepad++
  3. Let's rename some of the strings in there, so it matches our "simplenav" plugin. Here is an example:
              $string['pluginname'] = 'Simple Navigation format';
              $string['page-course-view-simplenav'] = 'Any course main page in simplenav format';          $string['page-course-view-simplenav-x'] = 'Any course page in simplenav format';
format.php
  1. Open this file in a text editor. You only need to change two lines. 
  2. Search for the keyword "topics," since that is the format name we'll be replacing.
  3. Near the end of the file, find these line and update it:
    1. $renderer = $PAGE->get_renderer('format_simplenav'); 
    2. $PAGE->requires->js('/course/format/simplenav/format.js');  
lib.php
  1.  Open this file in a text editor. Search for the keyword "topics"
  2. The first change is the class name, at the top of the file:
    1. class format_simplenav extends format_base {  
  3. Continue to search and replace.
renderer.php
This is the same process. Make sure you rename the class at the top of the file:
             class format_simplenav_renderer extends format_section_renderer_base {    

css.php
Same thing again. Re-name all the css classes from "topics" to "simple nav like this:
             .course-content ul.simplenav {margin:0;}             .course-content ul.simplenav li.section {list-style: none;margin:0 0 5px 0;padding:0;}             .course-content ul.simplenav li.section .content {margin:0 40px;}


version.php
You only need to change the last line:.
$plugin->component = 'format_simplenav';  
INSTALLATION 
Now that everything has been copied and renamed properly, it can be installed within moodle. 
  1. Login to your site as the Administrator. You should be automatically redirected to a new page, where you must install updates within your site. 
    1. If you are not automatically redirected, go to the Site Administration block, and click on "Notifications."
  2. You will be redirected to a page to update your site – the new “simplenav” course format will appear. Update your site to move forward. 
CHANGES TO COURSE ADMINISTRATION
We need to change the settings of our course to enable our new format.
  1.  Login to the Moodle website as an Administrator or Teacher.
  2. Go into your course and go to “Course Administration > Edit Settings.”
  3. Open up the “Course Format” section. If the simplenav format installed correctly, you’ll have a new option called “Simple Navigation.” Click on that one
YOU'RE READY!
Everything is ready to start customizing and using your new, custom course format! In the next blog post, we'll talk about the changes we need to make to have a linear activity flow.

Wednesday, July 8, 2015

New posts, plugins and moodle updates

I wanted to let everyone that follows this blog know that new content is coming. I'm been working on Moodle as a freelance developer for over the last six years and I'm still learning a lot about the platform with every new release that comes out. But now that I have the time, I will be writing new posts on other customizations I created:

  • Use the category and course hierarchy to change Moodle into a client web portal
  • Attaching themes to course categories
  • Add custom php pages to Moodle
  • New custom blocks
  • Custom graphs and charts based on HTML5
  • Custom course formats
    • Browse through activities without all the confirmation screens
  • Recreate the Moodle course
    • To have its own front page and navigation style
  • Sync Tools
    • Allow students to upload text files and parse the data for Moodle
The list could be longer, but these are some of the things I'll begin to tackle in my blog. I'm also considering to make these into public plugins that can be downloaded from my website. The price hasn't been decided yet, but I'd like to make them free if I can get some friendly donations coming in first. That would pay for the development and upkeep. 

For now if you have any questions, leave a comment below or visit my website for more Moodle examples: