Index: mod/quiz/lib.php =================================================================== RCS file: /home/cvs_repositories/globalcvs/ou-moodle/mod/quiz/lib.php,v retrieving revision 1.28 diff -u -r1.28 lib.php --- mod/quiz/lib.php 21 May 2008 11:48:40 -0000 1.28 +++ mod/quiz/lib.php 3 Jun 2008 16:34:46 -0000 @@ -1211,4 +1211,13 @@ } return ''; } + +function quiz_supports($feature) { + switch($feature) { + case FEATURE_GRADE_HAS_GRADE: return true; + case FEATURE_COMPLETION_TRACKS_VIEWS: return true; + default: return false; + } +} + ?> Index: lib/moodlelib.php =================================================================== RCS file: /home/cvs_repositories/globalcvs/ou-moodle/lib/moodlelib.php,v retrieving revision 1.126 diff -u -r1.126 moodlelib.php --- lib/moodlelib.php 23 May 2008 15:04:38 -0000 1.126 +++ lib/moodlelib.php 3 Jun 2008 16:34:46 -0000 @@ -6413,6 +6413,48 @@ return $plugins; } +// Feature constants +/** True if module can provide a grade */ +define('FEATURE_GRADE_HAS_GRADE','grade_has_grade'); +/** 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'); + +/** + * Checks whether a plugin supports a specified feature. + * + * @param string $type Plugin type e.g. 'mod' + * @param string $name Plugin name + * @param string $feature Feature code (FEATURE_xx constant) + * @return Feature result (false if not supported, usually true but may have + * other feature-specific value otherwise) + */ +function plugin_supports($type,$name,$feature) { + global $CFG; + switch($type) { + case 'mod' : + $file=$CFG->dirroot.'/mod/'.$name.'/lib.php'; + $function=$name.'_supports'; + break; + default: + throw new Exception('Unsupported plugin type ('.$type.')'); + } + + // Load library and look for function + require_once($file); + if(function_exists($function)) { + // Function exists, so just return function result + return $function($feature); + } else { + switch($feature) { + // If some features can also be checked in other ways + // for legacy support, this could be added here + default: return false; + } + } +} + /** * Returns true if the current version of PHP is greater that the specified one. *