Skip to content

Commit

Permalink
WOADD-417 :: Grade discrepancy build done (#33)
Browse files Browse the repository at this point in the history
* Updated test cases

* Eli fix for >22 grades

* Raw changes :: 12-2-2020 - UI changes applied

* Raw changes :: 12-3-2020 - build done

* remove else if in grade comparison

* remove var_dump comment
  • Loading branch information
m-aquino committed Dec 3, 2020
1 parent fd18244 commit 7591671
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 96 deletions.
2 changes: 1 addition & 1 deletion local/gugcat/add/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
$gradereason = $fromform->otherreason;
}
else{
$gradereason = local_gugcat::$REASONS[$fromform->reasons];
$gradereason = local_gugcat::get_reasons()[$fromform->reasons];
}

$gradeitemid = local_gugcat::add_grade_item($courseid, $gradereason, $module->id);
Expand Down
5 changes: 5 additions & 0 deletions local/gugcat/amd/build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ define(['jquery', 'core/str' ], function($, Str) {
$(".input-reason").val($(this).val());
});

//Show 'grade discrepancy' when grade discrepancy exist
if($('td > .grade-discrepancy').length > 0){
$("#btn-grddisc").show();
}

// Hide elements on add grade form page
if(checkCurrentUrl('gugcat/add')){
$("#btn-approve").hide();
Expand Down
5 changes: 5 additions & 0 deletions local/gugcat/amd/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ define(['jquery', 'core/str' ], function($, Str) {
$(".input-reason").val($(this).val());
});

//Show 'grade discrepancy' when grade discrepancy exist
if($('td > .grade-discrepancy').length > 0){
$("#btn-grddisc").show();
}

// Hide elements on add grade form page
if(checkCurrentUrl('gugcat/add')){
$("#btn-approve").hide();
Expand Down
2 changes: 1 addition & 1 deletion local/gugcat/classes/form/addgradeform.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function definition() {
$mform = $this->_form; // Don't forget the underscore!
$mform->addElement('html', '<div class="mform-container">');

$mform->addElement('select', 'reasons', 'Reason for additional grade', local_gugcat::$REASONS,['class' => 'mform-custom']);
$mform->addElement('select', 'reasons', 'Reason for additional grade', local_gugcat::get_reasons(),['class' => 'mform-custom']);
$mform->setType('reasons', PARAM_NOTAGS);
$mform->setDefault('reasons', "Select Reason");

Expand Down
60 changes: 6 additions & 54 deletions local/gugcat/grade_capture_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@

class grade_capture_item{

/**
* The id of the user/ student.
* @var int $id
*/
public $id;

/**
* The student number from student info.
* @var int $studentno
Expand All @@ -58,54 +52,6 @@ class grade_capture_item{
*/
public $firstgrade;

/**
* The second grade of the student in a specific activity.
* @var string $secondgrade
*/
public $secondgrade;

/**
* The third grade of the student in a specific activity.
* @var string $thirdgrade
*/
public $thirdgrade;

/**
* The good cause grade of the student in a specific activity.
* @var string $goodcausegrade
*/
public $goodcausegrade;

/**
* The late penalty grade of the student in a specific activity.
* @var string $latepenaltygrade
*/
public $latepenaltygrade;

/**
* The capped grade of the student in a specific activity.
* @var string $cappedgrade
*/
public $cappedgrade;

/**
* The agreed grade of the student in a specific activity.
* @var string $agreedgrade
*/
public $agreedgrade;

/**
* The moderate grade of the student in a specific activity.
* @var string $moderategrade
*/
public $moderategrade;

/**
* The custom grade of the student given by the staff in a specific activity.
* @var array $othergrade
*/
public $othergrade;

/**
* The provisional grade of the student that needs to be approve in a specific activity.
* @var string $provisionalgrade
Expand All @@ -117,4 +63,10 @@ class grade_capture_item{
* @var array $grades
*/
public $grades;

/**
* Boolean value if 1st/2nd/3rd grades of the student have discrepancies.
* @var boolean $discrepancy
*/
public $discrepancy;
}
10 changes: 10 additions & 0 deletions local/gugcat/lang/en/local_gugcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
$string['forename'] = 'Forename';
$string['gugcat'] = 'Grade Capture and Aggregation Tool';
$string['gradebookgrade'] = 'Gradebook Grade ';
$string['gradediscrepancy'] = 'Grade Discrepancy';
$string['navname'] = 'Grade Capture and Aggregation';
$string['nograde'] = 'Null – awaiting grading';
$string['overviewaggregrade'] = 'Overview & Aggregated Grade';
Expand All @@ -51,3 +52,12 @@
$string['surname'] = 'Surname';
$string['title'] = 'Grade capture and score aggregation';

// Grade item names
$string['gi_agreedgrade'] = 'Agreed Grade';
$string['gi_cappedgrade'] = 'Capped Grade';
$string['gi_conductpenalty'] = 'Conduct Penalty';
$string['gi_goodcause'] = 'Good Cause';
$string['gi_latepenalty'] = 'Late Penalty';
$string['gi_moderatedgrade'] = 'Moderated Grade';
$string['gi_secondgrade'] = 'Second Grade';
$string['gi_thirdgrade'] = 'Third Grade';
79 changes: 53 additions & 26 deletions local/gugcat/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,9 @@ class local_gugcat {
* Database tables.
*/
const TBL_GRADE_ITEMS = 'grade_items';
const TBL_GRADE_CATEGORIES = 'grade_categories';
const TBL_GRADE_GRADES = 'grade_grades';

public static $REASONS = array(
0=>"Good Cause",
1=>"Late Penalty",
2=>"Capped Grade",
3=>"Second Grade",
4=>"Third Grade",
5=>"Agreed Grade",
6=>"Moderated Grade",
7=>"Conduct Penalty",
8=>"Other"
);

public static $GRADES = array(
22=>"A1",
21=>"A2",
Expand All @@ -76,6 +65,20 @@ class local_gugcat {
0 =>"H"
);

public static function get_reasons(){
return array(
0=>get_string('gi_goodcause', 'local_gugcat'),
1=>get_string('gi_latepenalty', 'local_gugcat'),
2=>get_string('gi_cappedgrade', 'local_gugcat'),
3=>get_string('gi_secondgrade', 'local_gugcat'),
4=>get_string('gi_thirdgrade', 'local_gugcat'),
5=>get_string('gi_agreedgrade', 'local_gugcat'),
6=>get_string('gi_moderatedgrade', 'local_gugcat'),
7=>get_string('gi_conductpenalty', 'local_gugcat'),
8=>get_string('reasonother', 'local_gugcat')
);
}

/**
* Returns all activities/modules for specific course
*
Expand Down Expand Up @@ -103,7 +106,7 @@ public static function get_grade_grade_items($course, $module){
$select = 'courseid = '.$course->id.' AND '.self::compare_iteminfo();
$gradeitems = $DB->get_records_select(self::TBL_GRADE_ITEMS, $select, ['iteminfo' => $module->id]);
$sort = 'id';
$fields = 'userid, id, finalgrade, timemodified';
$fields = 'userid, itemid, id, finalgrade, timemodified';
foreach($gradeitems as $item) {
$item->grades = $DB->get_records('grade_grades', array('itemid' => $item->id), $sort, $fields);
}
Expand All @@ -128,6 +131,13 @@ public static function grade_capture_get_rows($course, $module, $students){
global $gradeitems, $prvgradeid;
$grading_info = grade_get_grades($course->id, 'mod', $module->modname, $module->instance, array_keys($students));
$gradeitems = self::get_grade_grade_items($course, $module);

//---------ids needed for grade discrepancy
if(!$agreedgradeid = self::get_grade_item_id($course->id, $module->id, get_string('gi_agreedgrade', 'local_gugcat'))){
$secondgradeid = self::get_grade_item_id($course->id, $module->id, get_string('gi_secondgrade', 'local_gugcat'));
$thirdgradeid = self::get_grade_item_id($course->id, $module->id, get_string('gi_thirdgrade', 'local_gugcat'));
};

$i = 1;
foreach ($students as $student) {
$gbgrade = $grading_info->items[0]->grades[$student->id]->grade;
Expand All @@ -146,8 +156,20 @@ public static function grade_capture_get_rows($course, $module, $students){
$grade = is_null($rawgrade) ? $firstgrade : self::convert_grade($rawgrade);
$gradecaptureitem->provisionalgrade = $grade;
}else{
$grdobj = new stdClass();
$grade = is_null($rawgrade) ? 'N/A' : self::convert_grade($rawgrade);
array_push($gradecaptureitem->grades, $grade);
$grdobj->grade = $grade;
$grdobj->discrepancy = false;
//check grade discrepancy
if(!$agreedgradeid && $gbgrade){
if($item->id === $secondgradeid || $item->id === $thirdgradeid){
$grdobj->discrepancy = is_null($rawgrade) ? false : (($rawgrade != $gbgrade) ? true : false);
}
}
if($grdobj->discrepancy){
$gradecaptureitem->discrepancy = true;
}
array_push($gradecaptureitem->grades, $grdobj);
}
}
}
Expand Down Expand Up @@ -182,23 +204,28 @@ public static function get_prv_grade_id($courseid, $modid){
return $prvgrdid;
}

public static function add_grade_item($courseid, $reason, $modid){
public static function get_grade_item_id($courseid, $modid, $itemname){
global $DB;
//get category id
$categoryid = $DB->get_field('grade_categories', 'id', array('courseid' => $courseid, 'parent' => null), MUST_EXIST);

// check if gradeitem already exists using $reason, $courseid, $activityid
$select = 'courseid = :courseid AND '.self::compare_iteminfo(). ' AND categoryid = :categoryid AND itemname = :itemname ';
$select = 'courseid = :courseid AND '.self::compare_iteminfo(). ' AND itemname = :itemname ';
$params = [
'courseid' => $courseid,
'categoryid' => $categoryid,
'itemname' => $reason,
'itemname' => $itemname,
'iteminfo' => $modid
];
if(!$gradeitemid = $DB->get_record_select(self::TBL_GRADE_ITEMS, $select, $params, 'id')){
// create new gradeitem
return $DB->get_field_select(self::TBL_GRADE_ITEMS, 'id', $select, $params);
}

public static function add_grade_item($courseid, $reason, $modid){
global $DB;

// check if gradeitem already exists using $reason, $courseid, $activityid
if(!$gradeitemid = self::get_grade_item_id($courseid, $modid, $reason)){
// create new gradeitem
$gradeitem = new grade_item(array('id'=>0, 'courseid'=>$courseid));


// get category id
$categoryid = $DB->get_field(self::TBL_GRADE_CATEGORIES, 'id', array('courseid' => $courseid, 'parent' => null), MUST_EXIST);

$gradeitem->weightoverride = 0;
$gradeitem->gradepass = 0;
$gradeitem->grademin = 0;
Expand All @@ -216,7 +243,7 @@ public static function add_grade_item($courseid, $reason, $modid){
}

else {
return $gradeitemid->id;
return $gradeitemid;
}
}

Expand Down
15 changes: 10 additions & 5 deletions local/gugcat/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function display_grade_capture($activities, $rows, $columns) {
'addallgrdstr' =>get_string('addallnewgrade', 'local_gugcat'),
'downloadcsvstr' =>get_string('downloadcsv', 'local_gugcat'),
'saveallbtnstr' =>get_string('saveallnewgrade', 'local_gugcat'),
'grddiscrepancystr' => get_string('gradediscrepancy', 'local_gugcat'),
'activities' => $activities_,
]);
$html .= '<form action="index.php?id=' . $courseid . '&amp;activityid=' . $modid . '" method="post" id="multigradesform">';
Expand Down Expand Up @@ -97,9 +98,13 @@ private function display_table($rows, $columns) {
$html .= '<td>'.$row->studentno.'</td>';
$html .= '<td>'.$row->surname.'</td>';
$html .= '<td>'.$row->forename.'</td>';
$html .= '<td>'.$row->firstgrade.'</td>';
foreach((array) $row->grades as $grade) {
$html .= '<td>'.$grade.'</td>';
$html .= '<td>'. (($row->discrepancy)
? '<div class="grade-discrepancy">'.$row->firstgrade.'</div>'
: $row->firstgrade ) .'</td>';
foreach((array) $row->grades as $item) {
$html .= '<td>'. (($item->discrepancy)
? '<div class="grade-discrepancy">'.$item->grade.'</div>'
: $item->grade ).'</td>';
}
$html .= '<td class="togglemultigrd">
<input type="hidden" name="grades['.$row->studentno.'][id]" value="'.$row->studentno.'" />
Expand All @@ -110,7 +115,7 @@ private function display_table($rows, $columns) {
</td>';
$html .= '<td class="togglemultigrd">
'.$this->display_custom_select(
local_gugcat::$REASONS,
local_gugcat::get_reasons(),
'reason',
get_string('selectreason', 'local_gugcat'),
'multi-select-reason',
Expand All @@ -121,7 +126,7 @@ private function display_table($rows, $columns) {
$html .= '<td>
<a href="'.$CFG->wwwroot.'/local/gugcat/add/index.php?id='.$courseid.'&amp;activityid='.$selectedmodule->id.'&amp;studentid='.$row->studentno.'">
<button type="button" class="btn btn-default">
'.get_string('addgrade', 'local_gugcat').'
'.get_string('addnewgrade', 'local_gugcat').'
</button>
</a>
</td>';
Expand Down
Loading

0 comments on commit 7591671

Please sign in to comment.