Note:

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

Conditional activities API: Difference between revisions

From MoodleDocs
(Undo revision 31397 by Ankitfrenz (talk))
No edit summary
Line 5: Line 5:


== Functions ==
== Functions ==
<code>
The class condition_info defined in lib/conditionlib.php is the main conditional API in Moodle. Following are some important methods of the above mentioned class.
<code php>
  fill_availability_conditions(&$cm)
  fill_availability_conditions(&$cm)
get_grade_name($gradeitemobj)
  get_full_course_module()
  get_full_course_module()
  add_completion_condition($cmid, $requiredcompletion)
  add_completion_condition($cmid, $requiredcompletion)
Line 19: Line 19:
  update_cm_from_form($cm, $fromform, $wipefirst=true)
  update_cm_from_form($cm, $fromform, $wipefirst=true)
  completion_value_used_as_condition($course, $cm)
  completion_value_used_as_condition($course, $cm)
</code>
The basic functionality of these methods can be classified as:-
# Fetching information on conditions present
# Adding conditional clauses to activities
# Deleting conditions attached to activities
=== Fetching information on conditions present ===
<code php>
get_full_course_module()
get_full_information($modinfo=null)
</code>
==== get_full_course_module() ====
This method can fetches and returns all necessary information as a course module object which are required to determine the availability conditions.
Example:-
<code php>
$cm->id = $id;
$test = new condition_info($cm,CONDITION_MISSING_EVERYTHING);
$fullcm = $test->get_full_course_module();
</code>
==== get_full_information() ====
This function returns a string which describes the various conditions in place for the activity in the given context.Some possible outputs can be:-
<code>
a) From 13:05 on 14 Oct until 12:10 on 17 Oct (exact, exact)
b) From 14 Oct until 12:11 on 17 Oct (midnight, exact)
c) From 13:05 on 14 Oct until 17 Oct (exact, midnight 18 Oct)
</code>
Please refer the inline documentation in the code for detailed explanation of the logic and all possible cases.
Example:-
<code php>
$ci = new condition_info($mod);
$fullinfo = $ci->get_full_information();
</code>
=== Deleting conditions attached to activities ===
we have a simple function wipe_conditions() that can erase all conditions associated with the current activity.
consider an example:-
<code php>
$ci = new condition_info($cm, CONDITION_MISSING_EVERYTHING, false);
$ci->wipe_conditions();
</code>
</code>
== See Also ==
== See Also ==
[https://docs.moodle.org/en/Conditional_activities Conditional Activities]
[https://docs.moodle.org/en/Conditional_activities Conditional Activities]
[https://docs.moodle.org/en/Conditional_activities_settings Conditional Activities Settings]
[https://docs.moodle.org/en/Conditional_activities_settings Conditional Activities Settings]
[https://docs.moodle.org/en/Using_Conditional_activities Using Conditional Activities]
[https://docs.moodle.org/en/Using_Conditional_activities Using Conditional Activities]

Revision as of 05:45, 16 January 2012

Overview

Conditional Apis allow you to specify , if to show or hide an activity when the conditions associated with it are met/not met.

Files

The main file containing all important conditional stuff is located at lib/conditionlib.php

Functions

The class condition_info defined in lib/conditionlib.php is the main conditional API in Moodle. Following are some important methods of the above mentioned class.

fill_availability_conditions(&$cm)
get_full_course_module()
add_completion_condition($cmid, $requiredcompletion)
add_grade_condition($gradeitemid, $min, $max, $updateinmemory=false)
wipe_conditions()
get_full_information($modinfo=null)
is_midnight($time)
is_available(&$information, $grabthelot=false, $userid=0, $modinfo=null)
show_availability()
get_cached_grade_score($gradeitemid, $grabthelot=false, $userid=0)
update_cm_from_form($cm, $fromform, $wipefirst=true)
completion_value_used_as_condition($course, $cm)

The basic functionality of these methods can be classified as:-

  1. Fetching information on conditions present
  2. Adding conditional clauses to activities
  3. Deleting conditions attached to activities

Fetching information on conditions present

get_full_course_module() get_full_information($modinfo=null)

get_full_course_module()

This method can fetches and returns all necessary information as a course module object which are required to determine the availability conditions.

Example:-

$cm->id = $id; $test = new condition_info($cm,CONDITION_MISSING_EVERYTHING); $fullcm = $test->get_full_course_module();

get_full_information()

This function returns a string which describes the various conditions in place for the activity in the given context.Some possible outputs can be:-

a) From 13:05 on 14 Oct until 12:10 on 17 Oct (exact, exact)
b) From 14 Oct until 12:11 on 17 Oct (midnight, exact)
c) From 13:05 on 14 Oct until 17 Oct (exact, midnight 18 Oct)

Please refer the inline documentation in the code for detailed explanation of the logic and all possible cases.

Example:- $ci = new condition_info($mod); $fullinfo = $ci->get_full_information();

Deleting conditions attached to activities

we have a simple function wipe_conditions() that can erase all conditions associated with the current activity. consider an example:-

$ci = new condition_info($cm, CONDITION_MISSING_EVERYTHING, false); $ci->wipe_conditions();

See Also

Conditional Activities

Conditional Activities Settings

Using Conditional Activities