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
(Category:FAQ added)
(21 intermediate revisions by 6 users not shown)
Line 1: Line 1:
Q: Where do I have to start?<br />
{{Template:Work in progress}}
{{New_Module}}
 
== Where do I have to start? ==
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"?
== 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
<code php>$id = optional_param('id', 0, PARAM_INT); // Course Module ID</code> or
$a = optional_param('a' , 0, PARAM_INT); // widget ID
<code php>$a = optional_param('a' , 0, PARAM_INT); // widget ID</code>
An example of use of these two check can be easily found in your moodle/mod/widget/view.php (row 15 to 41)
An example of use of these two checks can be easily found in your moodle/mod/widget/view.php (rows 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?
'''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: ???????????
A: ???????????


Q: What is provided "for free" by the Moodle environment, alias, which set of variables are provided as "ready to use"
== 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 it is saved all the information the current user entered in his/her login form)
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).
More over you have the availability of the $course array and of some information about your specific widget module.
Moreover, 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:
The following is a description of the variables you are free to use:
CFG->
<code php>$CFG->$USER
$USER
$course->id
$course->id
$cm->id
$cm->id</code>
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.
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, $???
Belonging to this list of neglected variables, for instance, is $THEME, $???.
Some examples:
Some examples:
if (CFG->xxx == '') {
<code php>if ($CFG->xxx == '') {


}
}</code>


Q: Why is this set of variables so important?
== Why is this set of variables so important? ==
A: At any moment you may need to:
A: At any moment you may need to:
- reload the widget page
*reload the widget page
To call the instance of you module page, you need to call:
To call the instance of you module page, you need to call:
$CFG->wwwroot.'/mod/newmodule/view.php?id='.$cm->id
<code php>$CFG->wwwroot.'/mod/newmodule/view.php?id='.$cm->id</code>
$cm stands for course module (Is this true??????????)
$cm stands for course module (Is this true??????????)
- return to the main course page
*return to the main course page
To return back to the course page, you need to call:
To return back to the course page, you need to call:
$CFG->wwwroot.'/course/view.php?id='.$course->id
<code php>$CFG->wwwroot.'/course/view.php?id='.$course->id</code>


Q: My module lives in the view.php page only.
== 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? ==
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:
A:


Q: How to put a form into a module.
== How can I add a form to a module? ==
A:
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:
== 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
*groups
- role
*role
- capabilities
*capabilities
A:
A:


Q: How can I provide the needed code to:
== How can I provide the needed code to ==
- backup my widget module
*backup my widget module?
- restore my widget module
*restore my widget module?
A:
A:


Q: How can I provide the needed code to:
== How can I provide the needed code to: ==
- upgrade the XML tables my module is based on
*upgrade the XML tables my module is based on?
A: Use the moodle->
A: Use the moodle->
== How can I push students' grades from the module into the Moodle gradebook? ==
A: ???
[[Category:FAQ]]

Revision as of 10:21, 9 November 2010

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