Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

NEWMODULE FAQ: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
Line 1: Line 1:
 
== Q: Where do I have to start? ==
== Q: Where do I have to start?<br /> ==
 
A: The content of your module is in moodle/mod/widget/view.php
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".
If you look inside that file you will find the row: "Write your code here".


Q: How can I check required variables like "Course Module ID" and "widget ID"?<br />
== Q: How can I check required variables like "Course Module ID" and "widget ID"? ==
A: Use
A: Use
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or

Revision as of 13:41, 28 March 2008

Q: 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".

Q: 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 check can be easily found in your moodle/mod/widget/view.php (row 15 to 41) If you miss this step, the file can be called directly by writing their address in the web browser and unauthorized user can get them.

Q: Are some more variables needed to check for security reasons?
A: ???????????

Q: What is provided "for free" by the Moodle environment, alias, 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 it is saved all the information the current user entered in his/her login form) More over you have the availability of the $course array and of some information about your specific widget module. It follow the 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. Belong to this list of neglected variables, for instance, $THEME, $??? Some examples: if (CFG->xxx == ) {

}

Q: 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

Q: 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:

Q: How to put a form into a module.
A:

Q: How can I distinguish part of code for admins/teachers/ from the code for simple users, alias, how can I take advantages of the new feature offered up to Moodle 1.9 like:

  • groups
  • role
  • capabilities

A:

Q: How can I provide the needed code to:

  • backup my widget module
  • restore my widget module

A:

Q: How can I provide the needed code to:

  • upgrade the XML tables my module is based on

A: Use the moodle->