<?php //$Id$
require_once ($CFG->libdir.'/formslib.php');
-if(!empty($CFG->enablecompletion)) {
+if (!empty($CFG->enablecompletion) or !empty($CFG->enableavailability)) {
require_once($CFG->libdir.'/completionlib.php');
}
-if(!empty($CFG->enableavailability)) {
- require_once($CFG->libdir.'/conditionlib.php');
-}
/**
* This class adds extra methods to form wrapper specific to be used for module
*
* @var mixed
*/
- var $_instance;
+ protected $_instance;
/**
* Section of course that module instance will be put in or is in.
* This is always the section number itself (column 'section' from 'course_sections' table).
*
* @var mixed
*/
- var $_section;
+ protected $_section;
/**
* Coursemodle record of the module that is being updated. Will be null if this is an 'add' form and not an
* update one.
*
* @var mixed
*/
- var $_cm;
+ protected $_cm;
/**
* List of modform features
*/
- var $_features;
-
+ protected $_features;
/**
* @var array Custom completion-rule elements, if enabled
*/
- var $_customcompletionelements;
+ protected $_customcompletionelements;
+ /**
+ * @var string name of module
+ */
+ protected $_modname;
function moodleform_mod($instance, $section, $cm) {
$this->_instance = $instance;
$this->_section = $section;
$this->_cm = $cm;
+ // Guess module name
+ $matches = array();
+ if (!preg_match('/^mod_([^_]+)_mod_form$/', get_class($this), $matches)) {
+ debugging('Use $modname parameter or rename form to mod_xx_mod_form, where xx is name of your module');
+ print_error('unknownmodulename');
+ }
+ $this->_modname = $matches[1];
+ $this->init_features();
parent::moodleform('modedit.php');
}
+ protected function init_features() {
+ global $CFG;
+
+ $this->_features = new object();
+ $this->_features->groups = plugin_supports('mod', $this->_modname, FEATURE_GROUPS, true);
+ $this->_features->groupings = plugin_supports('mod', $this->_modname, FEATURE_GROUPINGS, false);
+ $this->_features->groupmembersonly = plugin_supports('mod', $this->_modname, FEATURE_GROUPMEMBERSONLY, false);
+ $this->_features->outcomes = (!empty($CFG->enableoutcomes) and plugin_supports('mod', $this->_modname, FEATURE_GRADE_OUTCOMES, true));
+ $this->_features->hasgrades = plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false);
+ $this->_features->idnumber = plugin_supports('mod', $this->_modname, FEATURE_IDNUMBER, true);
+ $this->_features->introeditor = plugin_supports('mod', $this->_modname, FEATURE_MODEDIT_INTRO_EDITOR, true);
+ $this->_features->defaultcompletion = plugin_supports('mod', $this->_modname, FEATURE_MODEDIT_DEFAULT_COMPLETION, true);
+
+ $this->_features->gradecat = ($this->_features->outcomes or $this->_features->hasgrades);
+ }
+
/**
* Only available on moodleform_mod.
*
/**
* Adds all the standard elements to a form to edit the settings for an activity module.
- *
- * @param mixed $features array or object describing supported features - groups, groupings, groupmembersonly, etc.
- * @param string $modname Name of module e.g. 'label'
*/
- function standard_coursemodule_elements($features=null, $modname=null){
+ function standard_coursemodule_elements(){
global $COURSE, $CFG, $DB;
$mform =& $this->_form;
- // Guess module name if not supplied
- if (!$modname) {
- $matches=array();
- if (!preg_match('/^mod_([^_]+)_mod_form$/', $this->_formname, $matches)) {
- debugging('Use $modname parameter or rename form to mod_xx_mod_form, where xx is name of your module');
- print_error('unknownmodulename');
- }
- $modname=$matches[1];
- }
-
- // deal with legacy $supportgroups param
- if ($features === true or $features === false) {
- $groupmode = $features;
- $this->_features = new object();
- $this->_features->groups = $groupmode;
-
- } else if (is_array($features)) {
- $this->_features = (object)$features;
-
- } else if (empty($features)) {
- $this->_features = new object();
-
- } else {
- $this->_features = $features;
- }
-
- if (!isset($this->_features->groups)) {
- $this->_features->groups = true;
- }
-
- if (!isset($this->_features->groupings)) {
- $this->_features->groupings = false;
- }
-
- if (!isset($this->_features->groupmembersonly)) {
- $this->_features->groupmembersonly = false;
- }
-
- if (!isset($this->_features->outcomes)) {
- $this->_features->outcomes = true;
- }
-
- if (!isset($this->_features->gradecat)) {
- $this->_features->gradecat = true;
- }
-
- if (!isset($this->_features->idnumber)) {
- $this->_features->idnumber = true;
- }
-
- if (!isset($this->_features->defaultcompletion)) {
- $this->_features->defaultcompletion = true;
- }
-
$outcomesused = false;
- if (!empty($CFG->enableoutcomes) and $this->_features->outcomes) {
+ if ($this->_features->outcomes) {
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
$outcomesused = true;
$mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
$mform->setHelpButton('availableuntil', array('conditiondates', get_string('help_conditiondates', 'condition'), 'condition'));
// Conditions based on grades
- $gradeoptions=array();
- $items=grade_item::fetch_all(array('courseid'=>$COURSE->id));
- $items=$items ? $items : array();
+ $gradeoptions = array();
+ $items = grade_item::fetch_all(array('courseid'=>$COURSE->id));
+ $items = $items ? $items : array();
foreach($items as $id=>$item) {
// Do not include grades for current item
if (!empty($this->_cm) && $this->_cm->instance == $item->iteminstance
&& $item->itemtype == 'mod') {
continue;
}
- $gradeoptions[$id]=$item->get_name();
+ $gradeoptions[$id] = $item->get_name();
}
asort($gradeoptions);
- $gradeoptions=array(0=>get_string('none','condition'))+$gradeoptions;
+ $gradeoptions = array(0=>get_string('none','condition'))+$gradeoptions;
- $grouparray=array();
+ $grouparray = array();
$grouparray[] =& $mform->createElement('select','conditiongradeitemid','',$gradeoptions);
$grouparray[] =& $mform->createElement('static', '', '',' '.get_string('grade_atleast','condition').' ');
$grouparray[] =& $mform->createElement('text', 'conditiongrademin','',array('size'=>3));
// Get version with condition info and store it so we don't ask
// twice
if(!empty($this->_cm)) {
- $ci = new condition_info($this->_cm,CONDITION_MISSING_EXTRATABLE);
- $this->_cm=$ci->get_full_course_module();
- $count=count($this->_cm->conditionsgrade)+1;
+ $ci = new condition_info($this->_cm, CONDITION_MISSING_EXTRATABLE);
+ $this->_cm = $ci->get_full_course_module();
+ $count = count($this->_cm->conditionsgrade)+1;
} else {
- $count=1;
+ $count = 1;
}
- $this->repeat_elements(array($group),$count,array(),'conditiongraderepeats','conditiongradeadds',2,
- get_string('addgrades','condition'),true);
+ $this->repeat_elements(array($group), $count, array(), 'conditiongraderepeats', 'conditiongradeadds', 2,
+ get_string('addgrades', 'condition'), true);
$mform->setHelpButton('conditiongradegroup[0]', array('gradecondition', get_string('help_gradecondition', 'condition'), 'condition'));
// Conditions based on completion
$completion = new completion_info($COURSE);
if ($completion->is_enabled()) {
- $completionoptions=array();
- $modinfo=get_fast_modinfo($COURSE);
+ $completionoptions = array();
+ $modinfo = get_fast_modinfo($COURSE);
foreach($modinfo->cms as $id=>$cm) {
// Add each course-module if it:
// (a) has completion turned on
}
}
asort($completionoptions);
- $completionoptions=array(0=>get_string('none','condition'))+$completionoptions;
+ $completionoptions = array(0=>get_string('none','condition'))+$completionoptions;
$completionvalues=array(
COMPLETION_COMPLETE=>get_string('completion_complete','condition'),
COMPLETION_COMPLETE_PASS=>get_string('completion_pass','condition'),
COMPLETION_COMPLETE_FAIL=>get_string('completion_fail','condition'));
- $grouparray=array();
+ $grouparray = array();
$grouparray[] =& $mform->createElement('select','conditionsourcecmid','',$completionoptions);
$grouparray[] =& $mform->createElement('select','conditionrequiredcompletion','',$completionvalues);
$group = $mform->createElement('group','conditioncompletiongroup',
get_string('completioncondition', 'condition'),$grouparray);
- $count=empty($this->_cm) ? 1 : count($this->_cm->conditionscompletion)+1;
+ $count = empty($this->_cm) ? 1 : count($this->_cm->conditionscompletion)+1;
$this->repeat_elements(array($group),$count,array(),
'conditioncompletionrepeats','conditioncompletionadds',2,
get_string('addcompletions','condition'),true);
/** True if module can provide a grade */
define('FEATURE_GRADE_HAS_GRADE', 'grade_has_grade');
+/** True if module supports outcomes */
+define('FEATURE_GRADE_OUTCOMES', 'outcomes');
+
/** True if module has code to track whether somebody viewed it */
define('FEATURE_COMPLETION_TRACKS_VIEWS', 'completion_tracks_views');
/** True if module has custom completion rules */
define('FEATURE_COMPLETION_HAS_RULES', 'completion_has_rules');
+/** True if module supports outcomes */
+define('FEATURE_IDNUMBER', 'idnumber');
+/** True if module supports groups */
+define('FEATURE_GROUPS', 'groups');
+/** True if module supports groupings */
+define('FEATURE_GROUPINGS', 'groupings');
+/** True if module supports groupmembersonly */
+define('FEATURE_GROUPMEMBERSONLY', 'groupmembersonly');
+
+/** True if module supports intro editor */
+define('FEATURE_MODEDIT_INTRO_EDITOR', 'modedit_intro_editor');
+/** True if module has default completion */
+define('FEATURE_MODEDIT_DEFAULT_COMPLETION', 'modedit_default_completion');
/// PARAMETER HANDLING ////////////////////////////////////////////////////
*/
function assignment_supports($feature) {
switch($feature) {
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
- case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_OUTCOMES: return true;
+
default: return null;
}
}
-?>
$mform->addElement('header', 'typedesc', get_string('type'.$type,'assignment'));
$assignmentinstance->setup_elements($mform);
- $features = new stdClass;
- $features->groups = true;
- $features->groupings = true;
- $features->groupmembersonly = true;
- $this->standard_coursemodule_elements($features);
+ $this->standard_coursemodule_elements();
$this->add_action_buttons();
}
-
-
}
-?>
+
}
}
-?>
+/**
+ * @param string $feature FEATURE_xx constant for requested feature
+ * @return mixed True if module supports feature, null if doesn't know
+ */
+function chat_supports($feature) {
+ switch($feature) {
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
+ case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
+ case FEATURE_GRADE_HAS_GRADE: return false;
+ case FEATURE_GRADE_OUTCOMES: return true;
+
+ default: return null;
+ }
+}
+
$mform->addElement('selectyesno', 'studentlogs', get_string('studentseereports', 'chat'));
- $features = new stdClass;
- $features->groups = true;
- $features->groupings = true;
- $features->groupmembersonly = true;
- $this->standard_coursemodule_elements($features);
+ $this->standard_coursemodule_elements();
$this->add_action_buttons();
}
*/
function choice_supports($feature) {
switch($feature) {
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_GRADE_HAS_GRADE: return false;
+ case FEATURE_GRADE_OUTCOMES: return false;
+
default: return null;
}
}
//-------------------------------------------------------------------------------
- $features = new stdClass;
- $features->groups = true;
- $features->groupings = true;
- $features->groupmembersonly = true;
- $features->gradecat = false;
$this->standard_coursemodule_elements($features);
//-------------------------------------------------------------------------------
$this->add_action_buttons();
*/
function data_supports($feature) {
switch($feature) {
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
- case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_OUTCOMES: return true;
+
default: return null;
- }
+ }
}
function data_export_csv($export, $delimiter_name, $dataname, $count, $return=false) {
global $CFG;
$mform->disabledIf('scale', 'assessed');
- $this->standard_coursemodule_elements(array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true));
+ $this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
*/
function feedback_supports($feature) {
switch($feature) {
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_GRADE_HAS_GRADE: return false;
+ case FEATURE_GRADE_OUTCOMES: return false;
+
default: return null;
}
}
$mform->addElement('htmleditor', 'page_after_submit', get_string("page_after_submit", "feedback"), array('rows' => 20));
$mform->setType('page_after_submit', PARAM_RAW);
//-------------------------------------------------------------------------------
- $features = new stdClass;
- $features->groups = true;
- $features->groupings = true;
- $features->groupmembersonly = true;
- $features->gradecat = false;
- $features->idnumber = false;
- $this->standard_coursemodule_elements($features);
+ $this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
*/
function forum_supports($feature) {
switch($feature) {
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
- case FEATURE_COMPLETION_HAS_RULES: return true;
+ case FEATURE_COMPLETION_HAS_RULES: return true;
+ case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_OUTCOMES: return true;
+
default: return null;
}
}
$mform->disabledIf('warnafter', 'blockperiod', 'eq', 0);
//-------------------------------------------------------------------------------
- $features = new stdClass;
- $features->groups = true;
- $features->groupings = true;
- $features->groupmembersonly = true;
- $this->standard_coursemodule_elements($features);
+ $this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
*/
function glossary_supports($feature) {
switch($feature) {
+ case FEATURE_GROUPS: return false;
+ case FEATURE_GROUPINGS: return false;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
- case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_OUTCOMES: return true;
+
default: return null;
}
}
$mform->disabledIf('assesstimefinish', 'ratingtime');
//-------------------------------------------------------------------------------
- $this->standard_coursemodule_elements(array('groups'=>false, 'groupmembersonly'=>true));
+ $this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
return array('moodle/site:accessallgroups');
}
+/**
+ * @param string $feature FEATURE_xx constant for requested feature
+ * @return mixed True if module supports feature, null if doesn't know
+ */
+function label_supports($feature) {
+ switch($feature) {
+ case FEATURE_IDNUMBER: return false;
+ case FEATURE_GROUPS: return false;
+ case FEATURE_GROUPINGS: return false;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return false;
+ case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
+ case FEATURE_GRADE_HAS_GRADE: return false;
+ case FEATURE_GRADE_OUTCOMES: return false;
+
+ default: return null;
+ }
+}
+
?>
$mform->addRule('content', get_string('required'), 'required', null, 'client');
$mform->setHelpButton('content', array('questions', 'richtext2'), false, 'editorhelpbutton');
- $features = array('groups'=>false, 'groupings'=>false, 'groupmembersonly'=>true,
- 'outcomes'=>false, 'gradecat'=>false, 'idnumber'=>false);
- $this->standard_coursemodule_elements($features);
+ $this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
*/
function lesson_supports($feature) {
switch($feature) {
+ case FEATURE_GROUPS: return false;
+ case FEATURE_GROUPINGS: return false;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
- case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_OUTCOMES: return true;
+
default: return null;
}
}
$mform->setDefault('lessondefault', 0);
//-------------------------------------------------------------------------------
- $features = new stdClass;
- $features->groups = false;
- $features->groupings = true;
- $features->groupmembersonly = true;
- $this->standard_coursemodule_elements($features);
+ $this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
*/
function quiz_supports($feature) {
switch($feature) {
- case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_OUTCOMES: return true;
+
default: return null;
}
}
}
//-------------------------------------------------------------------------------
- $features = new stdClass;
- $features->groups = true;
- $features->groupings = true;
- $features->groupmembersonly = true;
- $this->standard_coursemodule_elements($features);
+ $this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
*/
function resource_supports($feature) {
switch($feature) {
+ case FEATURE_GROUPS: return false;
+ case FEATURE_GROUPINGS: return false;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_GRADE_HAS_GRADE: return false;
+ case FEATURE_GRADE_OUTCOMES: return false;
+
default: return null;
}
}
$mform->addElement('header', 'typedesc', resource_get_name($type));
$this->_resinstance->setup_elements($mform);
- $this->standard_coursemodule_elements(array('groups'=>false, 'groupmembersonly'=>true, 'gradecat'=>false));
+ $this->standard_coursemodule_elements();
$this->add_action_buttons();
}
send_stored_file($file, $lifetime, 0, false);
}
-?>
+/**
+ * @param string $feature FEATURE_xx constant for requested feature
+ * @return mixed True if module supports feature, null if doesn't know
+ */
+function scorm_supports($feature) {
+ switch($feature) {
+ case FEATURE_GROUPS: return false;
+ case FEATURE_GROUPINGS: return false;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
+ case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_OUTCOMES: return true;
+
+ default: return null;
+ }
+}
+
//-------------------------------------------------------------------------------
- $features = new stdClass;
- $features->groups = false;
- $features->groupings = true;
- $features->groupmembersonly = true;
- $this->standard_coursemodule_elements($features);
+ $this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
return array('moodle/site:accessallgroups');
}
-?>
+/**
+ * @param string $feature FEATURE_xx constant for requested feature
+ * @return mixed True if module supports feature, null if doesn't know
+ */
+function survey_supports($feature) {
+ switch($feature) {
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
+ case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_OUTCOMES: return true;
+
+ default: return null;
+ }
+}
\ No newline at end of file
$mform->addElement('textarea', 'intro', get_string('customintro', 'survey'), 'wrap="virtual" rows="20" cols="75"');
$mform->setType('intro', PARAM_RAW);
- $features = new stdClass;
- $features->groups = true;
- $features->groupings = true;
- $features->groupmembersonly = true;
- $this->standard_coursemodule_elements($features);
+ $this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
* completely rewrite file handling
* rewrite backup/restore
* rewrite trusstext support - new db table columns needed
+* migrade all module features from mod_edit.php form to lib.php/modulename_supports() function
optional - no changes needed in older code:
* portfolio support
* course completion tracking support
-* lib.php/xxx_supports() may describe module features and capabilities
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
}
-?>
+/**
+ * @param string $feature FEATURE_xx constant for requested feature
+ * @return mixed True if module supports feature, null if doesn't know
+ */
+function wiki_supports($feature) {
+ switch($feature) {
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MODEDIT_INTRO_EDITOR: return true;
+ case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_GRADE_HAS_GRADE: return false;
+ case FEATURE_GRADE_OUTCOMES: return true;
+
+ default: return null;
+ }
+}
\ No newline at end of file
$mform->setAdvanced('initialcontent');
//-------------------------------------------------------------------------------
- $features = new stdClass;
- $features->groups = true;
- $features->groupings = true;
- $features->groupmembersonly = true;
- $this->standard_coursemodule_elements($features);
+ $this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();