Manual allocator uses the new subrendering feature

This commit is contained in:
David Mudrak
2010-01-04 17:46:33 +00:00
parent 6e3099730e
commit 66c9894dbc
9 changed files with 501 additions and 456 deletions
-106
View File
@@ -57,114 +57,8 @@ interface workshop_allocator {
*
* If a form is part of the UI, the caller should have call $PAGE->set_url(...)
*
* @access public
* @return string HTML to be displayed
*/
public function ui();
}
/**
* Return list of available allocation methods
*
* @access public
* @return array Array ['string' => 'string'] of localized allocation method names
*/
function workshop_installed_allocators() {
$installed = get_list_of_plugins('mod/workshop/allocation');
$forms = array();
foreach ($installed as $allocation) {
$forms[$allocation] = get_string('allocation' . $allocation, 'workshop');
}
// usability - make sure that manual allocation appears the first
if (isset($forms['manual'])) {
$m = array('manual' => $forms['manual']);
unset($forms['manual']);
$forms = array_merge($m, $forms);
}
return $forms;
}
/**
* Returns instance of submissions allocator
*
* @param object $workshop Workshop record
* @param object $method The name of the allocation method, must be PARAM_ALPHA
* @return object Instance of submissions allocator
*/
function workshop_allocator_instance(workshop $workshop, $method) {
$allocationlib = dirname(__FILE__) . '/' . $method . '/allocator.php';
if (is_readable($allocationlib)) {
require_once($allocationlib);
} else {
throw new moodle_exception('missingallocator', 'workshop');
}
$classname = 'workshop_' . $method . '_allocator';
return new $classname($workshop);
}
/**
* Returns the list of submissions and assessments allocated to them in the given workshop
*
* Submissions without allocated assessment are returned too, having assessment attributes null.
* This also fetches all other associated information (like details about the author and reviewer)
* needed to produce allocation reports.
* The returned structure is recordset of objects with following properties:
* [submissionid] [submissiontitle] [authorid] [authorfirstname]
* [authorlastname] [authorpicture] [authorimagealt] [assessmentid]
* [timeallocated] [reviewerid] [reviewerfirstname] [reviewerlastname]
* [reviewerpicture] [reviewerimagealt]
*
* @param object $workshop The workshop object
* @return object Recordset of allocations
*/
function workshop_get_allocations(workshop $workshop) {
global $DB;
$sql = 'SELECT s.id AS submissionid, s.title AS submissiontitle, s.userid AS authorid,
author.firstname AS authorfirstname, author.lastname AS authorlastname,
author.picture AS authorpicture, author.imagealt AS authorimagealt,
a.id AS assessmentid, a.timecreated AS timeallocated, a.userid AS reviewerid,
reviewer.firstname AS reviewerfirstname, reviewer.lastname AS reviewerlastname,
reviewer.picture as reviewerpicture, reviewer.imagealt AS reviewerimagealt
FROM {workshop_submissions} s
LEFT JOIN {workshop_assessments} a ON (s.id = a.submissionid)
LEFT JOIN {user} author ON (s.userid = author.id)
LEFT JOIN {user} reviewer ON (a.userid = reviewer.id)
WHERE s.workshopid = ?
ORDER BY author.lastname,author.firstname,reviewer.lastname,reviewer.firstname';
return $DB->get_recordset_sql($sql, array($workshop->id));
}
/**
* Allocate a submission to a user for review
*
* @param object $workshop Workshop record
* @param object $submission Submission record
* @param int $reviewerid User ID
* @access public
* @return int ID of the new assessment or an error code
*/
function workshop_add_allocation(workshop $workshop, stdClass $submission, $reviewerid) {
global $DB;
if ($DB->record_exists('workshop_assessments', array('submissionid' => $submission->id, 'userid' => $reviewerid))) {
return WORKSHOP_ALLOCATION_EXISTS;
}
$now = time();
$assessment = new stdClass();
$assessment->submissionid = $submission->id;
$assessment->userid = $reviewerid;
$assessment->timecreated = $now;
$assessment->timemodified = $now;
return $DB->insert_record('workshop_assessments', $assessment);
}