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['agreeassessments'] = 'Assessments must be agreed';
$string['agreeassessmentsdesc'] = 'Authors may comment assessments of their work and agree/disagree with it'; $string['agreeassessmentsdesc'] = 'Authors may comment assessments of their work and agree/disagree with it';
$string['allocate'] = 'Allocate submissions'; $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['allocationdone'] = 'Allocation done';
$string['allocationerror'] = 'Allocation error'; $string['allocationerror'] = 'Allocation error';
$string['allocation'] = 'Submission allocation'; $string['allocation'] = 'Submission allocation';

View file

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

View file

@ -45,7 +45,7 @@ if ($id) {
require_login($course, true, $cm); require_login($course, true, $cm);
require_capability('mod/workshop:view', $PAGE->context); 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); $workshop = new workshop($workshop, $cm, $course);