MDL-17827 Workshop 2.0 supports scale usage checks now

This commit is contained in:
David Mudrak
2010-06-01 14:55:33 +00:00
parent 75a8ba5461
commit 7a2d0f6125
6 changed files with 125 additions and 26 deletions
+17
View File
@@ -302,6 +302,23 @@ class workshop_accumulative_strategy implements workshop_strategy {
return $diminfo;
}
/**
* Is a given scale used by the instance of workshop?
*
* @param int $scaleid id of the scale to check
* @param int|null $workshopid id of workshop instance to check, checks all in case of null
* @return bool
*/
public static function scale_used($scaleid, $workshopid=null) {
global $DB;
$conditions['grade'] = -$scaleid;
if (!is_null($workshopid)) {
$conditions['workshopid'] = $workshopid;
}
return $DB->record_exists('workshopform_accumulative', $conditions);
}
////////////////////////////////////////////////////////////////////////////////
// Internal methods //
////////////////////////////////////////////////////////////////////////////////
+13
View File
@@ -291,6 +291,19 @@ class workshop_comments_strategy implements workshop_strategy {
return $diminfo;
}
/**
* Is a given scale used by the instance of workshop?
*
* This grading strategy does not use scales.
*
* @param int $scaleid id of the scale to check
* @param int|null $workshopid id of workshop instance to check, checks all in case of null
* @return bool
*/
public static function scale_used($scaleid, $workshopid=null) {
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Internal methods //
////////////////////////////////////////////////////////////////////////////////
+14
View File
@@ -100,4 +100,18 @@ interface workshop_strategy {
* @return moodle_recordset
*/
public function get_assessments_recordset($restrict=null);
/**
* Is a given scale used by the instance of workshop?
*
* If the grading strategy does not use scales, it should just return false. If the strategy
* supports scales, it returns true if the given scale is used.
* If workshopid is null, it checks for any workshop instance. If workshopid is provided,
* it checks the given instance only.
*
* @param int $scaleid id of the scale to check
* @param int|null $workshopid id of workshop instance to check, checks all in case of null
* @return bool
*/
public static function scale_used($scaleid, $workshopid=null);
}
+16 -3
View File
@@ -323,9 +323,22 @@ class workshop_numerrors_strategy implements workshop_strategy {
return $dimrecords;
}
////////////////////////////////////////////////////////////////////////////////
// Internal methods //
////////////////////////////////////////////////////////////////////////////////
/**
* Is a given scale used by the instance of workshop?
*
* This grading strategy does not use scales.
*
* @param int $scaleid id of the scale to check
* @param int|null $workshopid id of workshop instance to check, checks all in case of null
* @return bool
*/
public static function scale_used($scaleid, $workshopid=null) {
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Internal methods //
////////////////////////////////////////////////////////////////////////////////
/**
* Loads the fields of the assessment form currently used in this workshop
+13
View File
@@ -334,6 +334,19 @@ class workshop_rubric_strategy implements workshop_strategy {
return $DB->get_records_sql($sql, $params);
}
/**
* Is a given scale used by the instance of workshop?
*
* This grading strategy does not use scales.
*
* @param int $scaleid id of the scale to check
* @param int|null $workshopid id of workshop instance to check, checks all in case of null
* @return bool
*/
public static function scale_used($scaleid, $workshopid=null) {
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Internal methods //
////////////////////////////////////////////////////////////////////////////////
+52 -23
View File
@@ -254,41 +254,70 @@ function workshop_get_participants($workshopid) {
}
/**
* This function returns if a scale is being used by one workshop
* if it has support for grading and scales. Commented code should be
* modified if necessary. See forum, glossary or journal modules
* as reference.
* Is a given scale used by the instance of workshop?
*
* @param int $workshopid ID of an instance of this module
* @return mixed
* @todo Finish documenting this function
* The function asks all installed grading strategy subplugins. The workshop
* core itself does not use scales. Both grade for submission and grade for
* assessments do not use scales.
*
* @param int $workshopid id of workshop instance
* @param int $scaleid id of the scale to check
* @return bool
*/
function workshop_scale_used($workshopid, $scaleid) {
$return = false;
global $CFG; // other files included from here
//$rec = get_record("workshop","id","$workshopid","scale","-$scaleid");
//
//if (!empty($rec) && !empty($scaleid)) {
// $return = true;
//}
$strategies = get_plugin_list('workshopform');
foreach ($strategies as $strategy => $strategypath) {
$strategylib = $strategypath . '/lib.php';
if (is_readable($strategylib)) {
require_once($strategylib);
} else {
throw new coding_exception('the grading forms subplugin must contain library ' . $strategylib);
}
$classname = 'workshop_' . $strategy . '_strategy';
if (method_exists($classname, 'scale_used')) {
if (call_user_func_array(array($classname, 'scale_used'), array($scaleid, $workshopid))) {
// no need to include any other files - scale is used
return true;
}
}
}
return $return;
return false;
}
/**
* Checks if scale is being used by any instance of workshop.
* This function was added in 1.9
* Is a given scale used by any instance of workshop?
*
* This is used to find out if scale used anywhere
* @param $scaleid int
* @return boolean True if the scale is used by any workshop
* The function asks all installed grading strategy subplugins. The workshop
* core itself does not use scales. Both grade for submission and grade for
* assessments do not use scales.
*
* @param int $scaleid id of the scale to check
* @return bool
*/
function workshop_scale_used_anywhere($scaleid) {
if ($scaleid and record_exists('workshop', 'grade', -$scaleid)) {
return true;
} else {
return false;
global $CFG; // other files included from here
$strategies = get_plugin_list('workshopform');
foreach ($strategies as $strategy => $strategypath) {
$strategylib = $strategypath . '/lib.php';
if (is_readable($strategylib)) {
require_once($strategylib);
} else {
throw new coding_exception('the grading forms subplugin must contain library ' . $strategylib);
}
$classname = 'workshop_' . $strategy . '_strategy';
if (method_exists($classname, 'scale_used')) {
if (call_user_func(array($classname, 'scale_used'), $scaleid)) {
// no need to include any other files - scale is used
return true;
}
}
}
return false;
}
/**