Example #1
0
    $example->authorid = $USER->id;
    $example->example = 1;
}
$canmanage = has_capability('mod/teamwork:manageexamples', $teamwork->context);
$canassess = has_capability('mod/teamwork:peerassess', $teamwork->context);
$refasid = $DB->get_field('teamwork_assessments', 'id', array('submissionid' => $example->id, 'weight' => 1));
if ($example->id and ($canmanage or $teamwork->assessing_examples_allowed() and $canassess)) {
    // ok you can go
} elseif (is_null($example->id) and $canmanage) {
    // ok you can go
} else {
    print_error('nopermissions', 'error', $teamwork->view_url(), 'view or manage example submission');
}
if ($id and $delete and $confirm and $canmanage) {
    require_sesskey();
    $teamwork->delete_submission($example);
    redirect($teamwork->view_url());
}
if ($id and $assess and $canmanage) {
    // reference assessment of an example is the assessment with the weight = 1. There should be just one
    // such assessment
    require_sesskey();
    if (!$refasid) {
        $refasid = $teamwork->add_allocation($example, $USER->id, 1);
    }
    redirect($teamwork->exassess_url($refasid));
}
if ($id and $assess and $canassess) {
    // training assessment of an example is the assessment with the weight = 0
    require_sesskey();
    $asid = $DB->get_field('teamwork_assessments', 'id', array('submissionid' => $example->id, 'weight' => 0, 'reviewerid' => $USER->id));