Workshop planner tool now correctly counts the submissions and allocations

This commit is contained in:
David Mudrak 2010-01-04 18:09:18 +00:00
parent 6a8eca30c5
commit a3610b08f4
3 changed files with 15 additions and 24 deletions

View file

@ -35,7 +35,7 @@ $string['accesscontrol'] = 'Access control';
$string['agreeassessments'] = 'Assessments must be agreed';
$string['agreeassessmentsdesc'] = 'Authors may comment assessments of their work and agree/disagree with it';
$string['allocate'] = 'Allocate submissions';
$string['allocatedetails'] = 'expected: $a->expected<br />submitted: $a->submitted<br />allocated: $a->allocated';
$string['allocatedetails'] = 'expected: $a->expected<br />submitted: $a->submitted<br />to allocate: $a->allocate';
$string['allocationdone'] = 'Allocation done';
$string['allocationerror'] = 'Allocation error';
$string['allocation'] = 'Submission allocation';

View file

@ -417,6 +417,7 @@ class workshop {
$assessment->reviewerid = $reviewerid;
$assessment->timecreated = $now;
$assessment->timemodified = $now;
$assessment->weight = 1; // todo better handling of the weight value/default
return $DB->insert_record('workshop_assessments', $assessment, true, $bulk);
}
@ -700,7 +701,7 @@ class workshop {
}
$phase->tasks['instructreviewers'] = $task;
}
if (has_capability('mod/workshop:submit', $context, $userid)) {
if (has_capability('mod/workshop:submit', $context, $userid, false)) {
$task = new stdClass();
$task->title = get_string('tasksubmit', 'workshop');
$task->link = $this->submission_url();
@ -718,28 +719,18 @@ class workshop {
$task = new stdClass();
$task->title = get_string('allocate', 'workshop');
$task->link = $this->allocation_url();
$authors = array();
$allocations = array(); // 'submissionid' => isallocated
$records = $this->get_allocations();
foreach ($records as $allocation) {
if (!isset($authors[$allocation->authorid])) {
$authors[$allocation->authorid] = true;
}
if (isset($allocation->submissionid)) {
if (!isset($allocations[$allocation->submissionid])) {
$allocations[$allocation->submissionid] = false;
}
if (!empty($allocation->reviewerid)) {
$allocations[$allocation->submissionid] = true;
}
}
}
$numofauthors = count($authors);
$numofsubmissions = count($allocations);
$numofallocated = count(array_filter($allocations));
$numofauthors = count(get_users_by_capability($context, 'mod/workshop:submit', 'u.id', '', '', '',
'', '', false, true));
$numofsubmissions = $DB->count_records('workshop_submissions', array('workshopid'=>$this->id, 'example'=>0));
$sql = 'SELECT COUNT(s.id) AS nonallocated
FROM {workshop_submissions} s
LEFT JOIN {workshop_assessments} a ON (a.submissionid=s.id)
WHERE s.workshopid = :workshopid AND s.example=0 AND a.submissionid IS NULL';
$params['workshopid'] = $this->id;
$numnonallocated = $DB->count_records_sql($sql, $params);
if ($numofsubmissions == 0) {
$task->completed = null;
} elseif ($numofsubmissions == $numofallocated) {
} elseif ($numnonallocated == 0) {
$task->completed = true;
} elseif ($this->phase > self::PHASE_SUBMISSION) {
$task->completed = false;
@ -749,7 +740,7 @@ class workshop {
$a = new stdClass();
$a->expected = $numofauthors;
$a->submitted = $numofsubmissions;
$a->allocated = $numofallocated;
$a->allocate = $numnonallocated;
$task->details = get_string('allocatedetails', 'workshop', $a);
unset($a);
$phase->tasks['allocate'] = $task;

View file

@ -45,7 +45,7 @@ if ($id) {
require_login($course, true, $cm);
require_capability('mod/workshop:view', $PAGE->context);
add_to_log($course->id, 'workshop', 'view', 'view.php?id='.$cm->id, $workshop->id);
add_to_log($course->id, 'workshop', 'view', 'view.php?id=' . $cm->id, $workshop->name, $cm->id);
$workshop = new workshop($workshop, $cm, $course);