NEWMODULE FAQ

Jump to: navigation, search

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.

Where do I have to start?

A: The content of your module is in moodle/mod/widget/view.php If you look inside that file you will find the row: "Write your code here".

How can I check required variables like "Course Module ID" and "widget ID"?

A: Use

$id = optional_param('id', 0, PARAM_INT); // Course Module ID
or
$a = optional_param('a' , 0, PARAM_INT); // widget ID

An example of use of these two checks can be easily found in your moodle/mod/widget/view.php (rows 15 to 41).

Warning: If you miss this step, the file can be called directly by writing the address in the web browser and unauthorized users can get them.

Are some more variables needed to check for security reasons?

A: ???????????

What is provided "for free" by the Moodle environment? That is, which set of variables are provided as "ready to use"?

A: You have availability of all the global Moodle variables ($CFG->xxx), the object $USER (in which all the information the current user entered in his/her login form is saved). Moreover, you have the availability of the $course array and of some information about your specific widget module. The following is a description of the variables you are free to use:

$CFG->$USER
$course->id
$cm->id

There are a lot more variables that are beyong the scope of this Moodle docs page that are, for this reason, going to be neglected. Belonging to this list of neglected variables, for instance, is $THEME, $???. Some examples:

if ($CFG->xxx == '') {
 
}

Why is this set of variables so important?

A: At any moment you may need to:

  • reload the widget page

To call the instance of you module page, you need to call:

$CFG->wwwroot.'/mod/newmodule/view.php?id='.$cm->id

$cm stands for course module (Is this true??????????)

  • return to the main course page

To return back to the course page, you need to call:

$CFG->wwwroot.'/course/view.php?id='.$course->id

My module lives in the view.php page only. How can I tell my code I want an output (of something) in a different page and not at the bottom of the view.php page?

A:

How can I add a form to a module?

A:

How can I distinguish part of code for admins/teachers/ from the code for simple users? That is, how can I take advantages of the new features available in Moodle 1.9?

  • groups
  • role
  • capabilities

A:

How can I provide the needed code to

  • backup my widget module?
  • restore my widget module?

A:

How can I provide the needed code to:

  • upgrade the XML tables my module is based on?

A: Use the moodle->

How can I push students' grades from the module into the Moodle gradebook?

A: ???