\n";
workshop_print_assessment($workshop, $assessment);
include('assessment_grading_form.html');
die;
}
/*************** insert (new) comment (by author, assessor or teacher) ***************************/
elseif ($action == 'insertcomment') {
$timenow = time();
$form = (object)$_POST;
if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
error("Unable to insert comment");
}
// save the comment...
$comment->workshopid = $workshop->id;
$comment->assessmentid = $assessment->id;
$comment->userid = $USER->id;
$comment->timecreated = $timenow;
$comment->comments = clean_param($form->comments, PARAM_CLEAN);
if (!$comment->id = insert_record("workshop_comments", $comment)) {
error("Could not insert workshop comment!");
}
add_to_log($course->id, "workshop", "comment", "view.php?id=$cm->id", "$comment->id");
print_continue("viewassessment.php?id=$cm->id&aid=$assessment->id");
}
/*********************** insert/update assignment elements (for teachers)***********************/
elseif ($action == 'insertelements') {
require_capability('mod/workshop:manage', $context);
$form = data_submitted();
// let's not fool around here, dump the junk!
delete_records("workshop_elements", "workshopid", $workshop->id);
// determine wich type of grading
switch ($workshop->gradingstrategy) {
case 0: // no grading
// Insert all the elements that contain something
foreach ($form->description as $key => $description) {
if ($description) {
unset($element);
$element->description = $description;
$element->workshopid = $workshop->id;
$element->elementno = $key;
if (!$element->id = insert_record("workshop_elements", $element)) {
error("Could not insert workshop element!");
}
}
}
break;
case 1: // accumulative grading
// Insert all the elements that contain something
foreach ($form->description as $key => $description) {
if ($description) {
unset($element);
$element->description = $description;
$element->workshopid = $workshop->id;
$element->elementno = clean_param($key, PARAM_INT);
if (isset($form->scale[$key])) {
$element->scale = $form->scale[$key];
switch ($WORKSHOP_SCALES[$form->scale[$key]]['type']) {
case 'radio' : $element->maxscore = $WORKSHOP_SCALES[$form->scale[$key]]['size'] - 1;
break;
case 'selection' : $element->maxscore = $WORKSHOP_SCALES[$form->scale[$key]]['size'];
break;
}
}
if (isset($form->weight[$key])) {
$element->weight = $form->weight[$key];
}
if (!$element->id = insert_record("workshop_elements", $element)) {
error("Could not insert workshop element!");
}
}
}
break;
case 2: // error banded grading...
case 3: // ...and criterion grading
// Insert all the elements that contain something, the number of descriptions is one less than the number of grades
foreach ($form->maxscore as $key => $themaxscore) {
unset($element);
$element->workshopid = $workshop->id;
$element->elementno = clean_param($key, PARAM_INT);
$element->maxscore = $themaxscore;
if (isset($form->description[$key])) {
$element->description = $form->description[$key];
} else {
$element->description = '@@ GRADE_MAPPING_ELEMENT @@';
}
if (isset($form->weight[$key])) {
$element->weight = $form->weight[$key];
} else {
$element->weight = 1;
}
if (!$element->id = insert_record("workshop_elements", $element)) {
error("Could not insert workshop element!");
}
}
break;
case 4: // ...and criteria grading
// Insert all the elements that contain something
foreach ($form->description as $key => $description) {
if ($description) {
unset($element);
$element->workshopid = $workshop->id;
$element->elementno = clean_param($key, PARAM_INT);
$element->description = $description;
$element->weight = $form->weight[$key];
for ($j=0;$j<5;$j++) {
if (empty($form->rubric[$key][$j]))
break;
}
$element->maxscore = $j - 1;
if (!$element->id = insert_record("workshop_elements", $element)) {
error("Could not insert workshop element!");
}
}
}
// let's not fool around here, dump the junk!
delete_records("workshop_rubrics", "workshopid", $workshop->id);
for ($i=0;$i<$workshop->nelements;$i++) {
for ($j=0;$j<5;$j++) {
unset($element);
if (empty($form->rubric[$i][$j])) { // OK to have an element with fewer than 5 items
break;
}
$element->workshopid = $workshop->id;
$element->elementno = $i;
$element->rubricno = $j;
$element->description = $form->rubric[$i][$j];
if (!$element->id = insert_record("workshop_rubrics", $element)) {
error("Could not insert workshop element!");
}
}
}
break;
} // end of switch
echo ""; // not sure where this one came from MDL-7861
redirect("view.php?id=$cm->id", get_string("savedok","workshop"));
}
/*********************** list assessments for grading (Student submissions)(by teachers)***********************/
elseif ($action == 'listungradedstudentsubmissions') {
require_capability('mod/workshop:manage', $context);
workshop_list_ungraded_assessments($workshop, "student");
print_continue("view.php?id=$cm->id");
}
/*********************** list assessments for grading (Teacher submissions) (by teachers)***********************/
elseif ($action == 'listungradedteachersubmissions') {
require_capability('mod/workshop:manage', $context);
workshop_list_ungraded_assessments($workshop, "teacher");
print_continue("view.php?id=$cm->id");
}
/****************** list teacher submissions ***********************/
elseif ($action == 'listteachersubmissions') {
workshop_list_teacher_submissions($workshop, $USER);
print_continue("view.php?id=$cm->id");
}
/******************* regrade student assessments ************************************/
elseif ($action == 'regradestudentassessments' ) {
$timenow = time();
require_capability('mod/workshop:manage', $context);
// get all the submissions...
if ($submissions = get_records("workshop_submissions", "workshopid", $workshop->id)) {
foreach ($submissions as $submission) {
// ...if cold...
if (($submission->timecreated + $CFG->maxeditingtime) < $timenow) {
// ...clear assessment count so workshop_grade_assessments() can do its thing
set_field("workshop_submissions", "nassessments", 0, "id", $submission->id);
}
}
}
echo "
";
workshop_grade_assessments($workshop);
echo '
';
print_continue("submissions.php?id=$cm->id&action=adminlist");
}
/*************** remove stock comment (by teacher ) ***************************/
elseif ($action == 'removestockcomment') {
if (empty($aid) or empty($stockcommentid)) {
error("Workshop Assessment id and/or Stock Comment id missing");
}
require_capability('mod/workshop:manage', $context);
if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
error("workshop assessment is misconfigured");
}
$form = data_submitted('nomatch'); //Nomatch because we can come from assess.php
// delete the comment from the stock comments table
if (!delete_records("workshop_stockcomments", "id", $stockcommentid)) {
error("Could not remove comment from the comment bank");
}
// now upate the assessment (just the elements, the assessment itself is not updated)
// first get the assignment elements for maxscores and weights...
$elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC");
if (count($elementsraw) < $workshop->nelements) {
print_string("noteonassignmentelements", "workshop");
}
if ($elementsraw) {
foreach ($elementsraw as $element) {
$elements[] = $element; // to renumber index 0,1,2...
}
} else {
$elements = null;
}
$timenow = time();
// don't fiddle about, delete all the old and add the new!
delete_records("workshop_grades", "assessmentid", $assessment->id);
//determine what kind of grading we have
switch ($workshop->gradingstrategy) {
case 0: // no grading
// Insert all the elements that contain something
for ($i =0; $i < $workshop->nelements; $i++) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $i;
$element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
}
$grade = 0; // set to satisfy save to db
break;
case 1: // accumulative grading
// Insert all the elements that contain something
foreach ($form->grade as $key => $thegrade) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = clean_param($key, PARAM_INT);
$element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
$element->grade = $thegrade;
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
}
// now work out the grade...
$rawgrade=0;
$totalweight=0;
foreach ($form->grade as $key => $grade) {
$maxscore = $elements[$key]->maxscore;
$weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
if ($weight > 0) {
$totalweight += $weight;
}
$rawgrade += ($grade / $maxscore) * $weight;
// echo "\$key, \$maxscore, \$weight, \$totalweight, \$grade, \$rawgrade : $key, $maxscore, $weight, $totalweight, $grade, $rawgrade ";
}
$grade = 100.0 * ($rawgrade / $totalweight);
break;
case 2: // error banded graded
// Insert all the elements that contain something
$error = 0.0;
for ($i =0; $i < $workshop->nelements; $i++) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $i;
$element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
$element->grade = $form->grade[$i];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
if (empty($form->grade[$i])){
$error += $WORKSHOP_EWEIGHTS[$elements[$i]->weight];
}
}
// now save the adjustment
unset($element);
$i = $workshop->nelements;
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $i;
$element->grade = $form->grade[$i];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
$grade = ($elements[intval($error + 0.5)]->maxscore + $form->grade[$i]) * 100 / $workshop->grade;
// do sanity check
if ($grade < 0) {
$grade = 0;
} elseif ($grade > 100) {
$grade = 100;
}
echo "".get_string("weightederrorcount", "workshop", intval($error + 0.5))."\n";
break;
case 3: // criteria grading
// save in the selected criteria value in element zero,
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = 0;
$element->grade = $form->grade[0];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
// now save the adjustment in element one
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = 1;
$element->grade = $form->grade[1];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
$grade = ($elements[$form->grade[0]]->maxscore + $form->grade[1]);
break;
case 4: // rubric grading (identical to accumulative grading)
// Insert all the elements that contain something
foreach ($form->grade as $key => $thegrade) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = clean_param($key, PARAM_INT);
$element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
$element->grade = $thegrade;
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
}
// now work out the grade...
$rawgrade=0;
$totalweight=0;
foreach ($form->grade as $key => $grade) {
$maxscore = $elements[$key]->maxscore;
$weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
if ($weight > 0) {
$totalweight += $weight;
}
$rawgrade += ($grade / $maxscore) * $weight;
}
$grade = 100.0 * ($rawgrade / $totalweight);
break;
} // end of switch
// any comment?
if (!empty($form->generalcomment)) { // update the object (no need to update the db record)
$assessment->generalcomment = clean_param($form->generalcomment, PARAM_CLEAN);
}
// redisplay form, going back to original returnto address
workshop_print_assessment($workshop, $assessment, true, true, $form->returnto);
// add_to_log($course->id, "workshop", "assess", "viewassessment.php?id=$cm->id&aid=$assessment->id", "$assessment->id", "$cm->id");
}
/*************** update assessment (by teacher or student) ***************************/
elseif ($action == 'updateassessment') {
if (empty($aid)) {
error("Workshop Assessment id missing");
}
if (! $assessment = get_record("workshop_assessments", "id", $aid)) {
error("workshop assessment is misconfigured");
}
// first get the assignment elements for maxscores and weights...
$elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC");
if (count($elementsraw) < $workshop->nelements) {
print_string("noteonassignmentelements", "workshop");
}
if ($elementsraw) {
foreach ($elementsraw as $element) {
$elements[] = $element; // to renumber index 0,1,2...
}
} else {
$elements = null;
}
$timenow = time();
// don't fiddle about, delete all the old and add the new!
delete_records("workshop_grades", "assessmentid", $assessment->id);
$form = data_submitted('nomatch'); //Nomatch because we can come from assess.php
//determine what kind of grading we have
switch ($workshop->gradingstrategy) {
case 0: // no grading
// Insert all the elements that contain something
for ($i = 0; $i < $workshop->nelements; $i++) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $i;
$element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
}
$grade = 0; // set to satisfy save to db
break;
case 1: // accumulative grading
// Insert all the elements that contain something
foreach ($form->grade as $key => $thegrade) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $key;
$element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
$element->grade = $thegrade;
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
}
// now work out the grade...
$rawgrade=0;
$totalweight=0;
foreach ($form->grade as $key => $grade) {
$maxscore = $elements[$key]->maxscore;
$weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
if ($weight > 0) {
$totalweight += $weight;
}
$rawgrade += ($grade / $maxscore) * $weight;
// echo "\$key, \$maxscore, \$weight, \$totalweight, \$grade, \$rawgrade : $key, $maxscore, $weight, $totalweight, $grade, $rawgrade ";
}
$grade = 100.0 * ($rawgrade / $totalweight);
break;
case 2: // error banded graded
// Insert all the elements that contain something
$error = 0.0;
for ($i =0; $i < $workshop->nelements; $i++) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $i;
$element->feedback = $form->{"feedback_$i"};
$element->grade = clean_param($form->grade[$i], PARAM_CLEAN);
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
if (empty($form->grade[$i])){
$error += $WORKSHOP_EWEIGHTS[$elements[$i]->weight];
}
}
// now save the adjustment
unset($element);
$i = $workshop->nelements;
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $i;
$element->feedback = '@@ GRADE_ADJUSTMENT @@';
$element->grade = $form->grade[$i];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
$grade = ($elements[intval($error + 0.5)]->maxscore + $form->grade[$i]) * 100 / $workshop->grade;
// do sanity check
if ($grade < 0) {
$grade = 0;
} elseif ($grade > 100) {
$grade = 100;
}
echo "".get_string("weightederrorcount", "workshop", intval($error + 0.5))."\n";
break;
case 3: // criteria grading
// save in the selected criteria value in element zero,
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = 0;
$element->grade = $form->grade[0];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
// now save the adjustment in element one
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = 1;
$element->grade = $form->grade[1];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
$grade = ($elements[$form->grade[0]]->maxscore + $form->grade[1]);
break;
case 4: // rubric grading (identical to accumulative grading)
// Insert all the elements that contain something
foreach ($form->grade as $key => $thegrade) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = clean_param($key, PARAM_INT);
$element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
$element->grade = $thegrade;
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop grade!");
}
}
// now work out the grade...
$rawgrade=0;
$totalweight=0;
foreach ($form->grade as $key => $grade) {
$maxscore = $elements[$key]->maxscore;
$weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
if ($weight > 0) {
$totalweight += $weight;
}
$rawgrade += ($grade / $maxscore) * $weight;
}
$grade = 100.0 * ($rawgrade / $totalweight);
break;
} // end of switch
// update the time of the assessment record (may be re-edited)...
set_field("workshop_assessments", "timecreated", $timenow, "id", $assessment->id);
if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) {
error ("Updateassessment: submission record not found");
}
// if the workshop does need peer agreement AND it's self assessment then set timeagreed
if ($workshop->agreeassessments and ($submission->userid == $assessment->userid)) {
set_field("workshop_assessments", "timeagreed", $timenow, "id", $assessment->id);
}
// set grade...
set_field("workshop_assessments", "grade", $grade, "id", $assessment->id);
// ...and clear the timegraded but set the graddinggrade to maximum, may be reduced subsequently...
set_field("workshop_assessments", "timegraded", 0, "id", $assessment->id);
set_field("workshop_assessments", "gradinggrade", 100, "id", $assessment->id);
// ...and the resubmission flag
set_field("workshop_assessments", "resubmission", 0, "id", $assessment->id);
// if there's examples or peer assessments clear the counter in the submission so that
// all assessments for this submission will be regraded
if ($workshop->ntassessments or $workshop->nsassessments) {
set_field("workshop_submissions", "nassessments", 0, "id", $submission->id);
workshop_grade_assessments($workshop);
} else { // it could be self assessment....
// now see if there's a corresponding assessment so that the gradinggrade can be set
if (workshop_is_teacher($workshop)) {
// see if there's are student assessments, if so set their gradinggrade
if ($assessments = workshop_get_assessments($submission)) {
foreach($assessments as $studentassessment) {
// skip if it's not a student assessment
if (!workshop_is_student($workshop, $studentassessment->userid)) {
continue;
}
$gradinggrade = workshop_compare_assessments($workshop, $assessment, $studentassessment);
set_field("workshop_assessments", "timegraded", $timenow, "id", $studentassessment->id);
set_field("workshop_assessments", "gradinggrade", $gradinggrade, "id", $studentassessment->id);
}
}
} else { //it's a student assessment, see if there's a corresponding teacher's assessment
if ($assessments = workshop_get_assessments($submission)) {
foreach($assessments as $teacherassessment) {
if (workshop_is_teacher($workshop, $teacherassessment->userid)) {
$gradinggrade = workshop_compare_assessments($workshop, $assessment, $teacherassessment);
set_field("workshop_assessments", "timegraded", $timenow, "id", $assessment->id);
set_field("workshop_assessments", "gradinggrade", $gradinggrade, "id", $assessment->id);
break; // only look for the first teacher assessment
}
}
}
}
}
// any comment?
if (!empty($form->generalcomment)) {
set_field("workshop_assessments", "generalcomment", clean_param($form->generalcomment, PARAM_CLEAN), "id", $assessment->id);
}
add_to_log($course->id, "workshop", "assess",
"viewassessment.php?id=$cm->id&aid=$assessment->id", "$assessment->id", "$cm->id");
// set up return address
if (!$returnto = $form->returnto) {
$returnto = "view.php?id=$cm->id";
}
// show grade if grading strategy is not zero
if ($workshop->gradingstrategy) {
echo ""; // MDL-7861, this is from
redirect($returnto, get_string("thegradeis", "workshop").": ".
number_format($grade * $workshop->grade / 100, 2).
" (".get_string("maximumgrade")." ".number_format($workshop->grade).")");
}
else {
redirect($returnto);
}
}
/****************** update comment (by author, assessor or teacher) ********************/
elseif ($action == 'updatecomment') {
$timenow = time();
$form = (object)$_POST;
// get the comment record...
if (!$comment = get_record("workshop_comments", "id", $_POST['cid'])) {
error("Update to Comment failed");
}
if (!$assessment = get_record("workshop_assessments", "id", $comment->assessmentid)) {
error("Update Comment: Assessment not found");
}
//save the comment for the assessment...
if (isset($form->comments)) {
set_field("workshop_comments", "comments", $form->comments, "id", $comment->id);
set_field("workshop_comments", "timecreated", $timenow, "id", $comment->id);
// ..and kick to comment into life (probably not needed but just in case)
set_field("workshop_comments", "mailed", 0, "id", $comment->id);
echo "".get_string("savedok", "workshop")."
\n";
add_to_log($course->id, "workshop", "comment",
"viewassessment.php?id=$cm->id&aid=$assessment->id", "$comment->id");
}
print_continue("viewassessment.php?id=$cm->id&aid=$assessment->id");
}
/****************** update grading (by teacher) ***************************/
elseif ($action == 'updategrading') {
$timenow = time();
require_capability('mod/workshop:manage', $context);
$form = (object)$_POST;
if (!$assessment = get_record("workshop_assessments", "id", $_POST['aid'])) {
error("Update Grading failed");
}
//save the comment and grade for the assessment
if (isset($form->teachercomment)) {
set_field("workshop_assessments", "teachercomment", $form->teachercomment, "id", $assessment->id);
set_field("workshop_assessments", "gradinggrade", $form->gradinggrade, "id", $assessment->id);
set_field("workshop_assessments", "timegraded", $timenow, "id", $assessment->id);
set_field("workshop_assessments", "mailed", 0, "id", $assessment->id);
set_field("workshop_assessments", "teachergraded", 1, "id", $assessment->id);
echo "".get_string("savedok", "workshop")." \n";
add_to_log($course->id, "workshop", "grade",
"viewassessment.php?id=$cm->id&aid=$assessment->id", "$assessment->id", "$cm->id");
}
redirect($form->redirect);
}
/****************** view all assessments ***********************/
elseif ($action == 'viewallassessments') {
if (!$submission = get_record("workshop_submissions", "id", $sid)) {
error("View All Assessments: submission record not found");
}
if ($assessments = workshop_get_assessments($submission)) {
foreach ($assessments as $assessment) {
workshop_print_assessment($workshop, $assessment);
}
}
// only called from list all submissions
print_continue("submissions.php?action=listallsubmissions&id=$cm->id");
}
/*************** no man's land **************************************/
else {
error("Fatal Error: Unknown Action: ".$action."\n");
}
print_footer($course);
?>