/** * Returns string representation of grade value * * @param float $value The grade value * @param object $grade_item Grade item object passed by reference to prevent scale reloading * @param bool $localized use localised decimal separator * @param int $displaytype type of display. For example GRADE_DISPLAY_TYPE_REAL, GRADE_DISPLAY_TYPE_PERCENTAGE, GRADE_DISPLAY_TYPE_LETTER * @param int $decimals The number of decimal places when displaying float values * @return string */ function grade_format_gradevalue($value, &$grade_item, $localized = true, $displaytype = null, $decimals = null) { if ($grade_item->gradetype == GRADE_TYPE_NONE or $grade_item->gradetype == GRADE_TYPE_TEXT) { return ''; } // no grade yet? if (is_null($value)) { return '-'; } if ($grade_item->gradetype != GRADE_TYPE_VALUE and $grade_item->gradetype != GRADE_TYPE_SCALE) { //unknown type?? return ''; } if (is_null($displaytype)) { $displaytype = $grade_item->get_displaytype(); } if (is_null($decimals)) { $decimals = $grade_item->get_decimals(); } switch ($displaytype) { case GRADE_DISPLAY_TYPE_REAL: return grade_format_gradevalue_real($value, $grade_item, $decimals, $localized); case GRADE_DISPLAY_TYPE_PERCENTAGE: return grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized); case GRADE_DISPLAY_TYPE_LETTER: return grade_format_gradevalue_letter($value, $grade_item); case GRADE_DISPLAY_TYPE_REAL_PERCENTAGE: return grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ')'; case GRADE_DISPLAY_TYPE_REAL_LETTER: return grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_letter($value, $grade_item) . ')'; case GRADE_DISPLAY_TYPE_PERCENTAGE_REAL: return grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ')'; case GRADE_DISPLAY_TYPE_LETTER_REAL: return grade_format_gradevalue_letter($value, $grade_item) . ' (' . grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ')'; case GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE: return grade_format_gradevalue_letter($value, $grade_item) . ' (' . grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ')'; case GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER: return grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_letter($value, $grade_item) . ')'; default: return ''; } }
function grade_format_local($value, $grade_item, $displaytype, $localized, $decimals) { switch ($displaytype) { case GRADE_DISPLAY_TYPE_REAL: // return format_float($value, $decimals, $localized); return grade_format_gradevalue_real($value, $grade_item, $decimals, $localized); case GRADE_DISPLAY_TYPE_PERCENTAGE: // return format_float($value, $decimals, $localized) .'%'; return grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized); case GRADE_DISPLAY_TYPE_LETTER: return grade_format_gradevalue_letter($value, $grade_item); case GRADE_DISPLAY_TYPE_REAL_PERCENTAGE: // return format_float($value, $decimals, $localized) .'(' // . format_float($value, $decimals, $localized) .'%)'; return grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ')'; case GRADE_DISPLAY_TYPE_REAL_LETTER: // return format_float($value, $decimals, $localized) .'(' // . grade_format_gradevalue_letter($value, $grade_item) .')'; return grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_letter($value, $grade_item) . ')'; case GRADE_DISPLAY_TYPE_PERCENTAGE_REAL: // return format_float($value, $decimals, $localized) .'% (' // . format_float($value, $decimals, $localized) .')'; return grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ')'; case GRADE_DISPLAY_TYPE_LETTER_REAL: // return grade_format_gradevalue_letter($value, $grade_item) .'(' // . format_float($value, $decimals, $localized) .')'; return grade_format_gradevalue_letter($value, $grade_item) . ' (' . grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ')'; case GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE: // return grade_format_gradevalue_letter($value, $grade_item) .'(' // . format_float($value, $decimals, $localized) .'%)'; return grade_format_gradevalue_letter($value, $grade_item) . ' (' . grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ')'; case GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER: // return format_float($value, $decimals, $localized) .'% (' // . grade_format_gradevalue_letter($value, $grade_item) .')'; return grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_letter($value, $grade_item) . ')'; default: return ''; } }
} $user_id = $students['userid'][$row_ite]; $grade_item = $DB->get_record("grade_items", array('courseid' => $course->id, 'itemtype' => 'course')); $sql = "SELECT *\n FROM mdl_grade_grades\n WHERE itemid = (\n SELECT id\n FROM mdl_grade_items\n WHERE courseid ={$course->id}\n AND itemtype = 'course' )\n AND userid ={$user_id}"; // $credithours=$course->credithours; $credithours = explode("+", $course->credithours); $credithours = $credithours[0] + $credithours[1]; $grade = $DB->get_record_sql($sql); // print_r($grade); $attendance = get_percent_absent($students["userid"][$row_ite], $course); $course_sess_att = get_grade($students["userid"][$row_ite], $course); $course_sessions = get_maxgrade($students["userid"][$row_ite], $course); $all_sessions += $course_sessions; $course_sess_missed = $course_sessions - $course_sess_att; $all_sessions_missed += $course_sess_missed; $subjgrade = grade_format_gradevalue_letter($grade->finalgrade, $grade_item); if ($grade) { // $grade->finalgrade= number_format(($grade->finalgrade), 0); switch ($subjgrade) { case $subjgrade == 'A': $gradepoint = 4.0; break; case $subjgrade == 'B+': $gradepoint = 3.5; break; case $subjgrade == 'B': $gradepoint = 3.0; break; case $subjgrade == 'C+': $gradepoint = 2.5; break;
function coursecompletion_checkcompletion(&$course) { global $DB, $CFG, $USER; $hasoutstanding = false; $completionmessage = ''; $completionmessages = array(); $completion_elements = $DB->get_records("course_availability", array('courseid' => $course->id)); if ($completion_elements && sizeof($completion_elements) > 0) { foreach ($completion_elements as $ce) { // echo "grademin ". $ce->grademin." gradefinal ".$grade->finalgrade ." grademax ". $ce->grademax; $sql = "SELECT *\n FROM mdl_grade_grades\n WHERE itemid = (\n SELECT id\n FROM mdl_grade_items\n WHERE courseid ={$ce->sourcecourseid}\n And\n\t\t itemtype='course' )"; //echo $sql; // $credithours=$course->credithours; // $grade_item=$DB->get_record_sql($sql); $grade_item = $DB->get_record("grade_items", array('courseid' => $ce->sourcecourseid, 'itemtype' => 'course')); $source_course = $DB->get_record('course', array('id' => $ce->sourcecourseid)); if (!$source_course) { continue; } //If the conditional course is missing/deleted the condition can never be met if (!$grade_item) { // echo "grademin ". $ce->grademin." gradefinal ".$grade->finalgrade ." grademax ". $ce->grademax; $hasoutstanding = true; if ($source_course) { $completionmessages[] = get_string('mustcompletecourse', 'core_coursecondition', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$source_course->id}\">{$source_course->fullname}</a>") . " " . get_string('beforeyoucanenter', 'core_coursecondition', $course->fullname); } continue; } $sql = "SELECT e.courseid as courseid, fullname,e.timecreated as timecreated\n\t\t\t\t\t FROM mdl_user_enrolments ue\n\t\t\t\t\t JOIN mdl_enrol e ON ( e.id = ue.enrolid )\n\t\t\t\t\t JOIN mdl_course c ON ( c.id = e.courseid )\n\t\t\t\t\t AND ue.userid ={$USER->id} AND c.id={$ce->sourcecourseid}"; $courses = $DB->get_record_sql($sql); if (empty($courses)) { $hasoutstanding = true; $completionmessages[] = get_string('mustcompletecourse', 'core_coursecondition', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$source_course->id}\">{$source_course->fullname}</a>") . " " . get_string('beforeyoucanenter', 'core_coursecondition', $course->fullname); } $ngrade = $DB->get_record('grade_grades', array('itemid' => $grade_item->id, 'userid' => $USER->id)); $grade = grade_format_gradevalue_letter($ngrade->finalgrade, $grade_item); //hina if ($ce->grademin != "0" && $ce->grademax != "0") { if (!$grade) { $hasoutstanding = true; $completionmessages[] = get_string('mustcompletecourse', 'core_coursecondition', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$source_course->id}\">{$source_course->fullname}</a>") . " " . get_string('beforeyoucanenter', 'core_coursecondition', $course->fullname); } elseif (!empty($ce->grademin) && $grade < $ce->grademin) { $hasoutstanding = true; $completionmessages[] = get_string('mustcompletecourse', 'core_coursecondition', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$source_course->id}\">{$source_course->fullname}</a>") . " " . get_string('gradelessthan', 'core_coursecondition') . " " . $ce->grademax . " " . get_string('beforeyoucanenter', 'core_coursecondition', $course->fullname) . ". " . get_string('currentlyyourgradeis', 'core_coursecondition', $grade) . "."; } elseif (!empty($ce->grademax) && $grade > $ce->grademax) { $hasoutstanding = true; $completionmessages[] = get_string('mustcompletecourse', 'core_coursecondition', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$source_course->id}\">{$source_course->fullname}</a>") . " " . get_string('gradebetween', 'core_coursecondition') . " " . $ce->grademax . " " . get_string('and', 'core_coursecondition') . " " . $ce->grademin . " " . get_string('beforeyoucanenter', 'core_coursecondition', $course->fullname) . ". " . get_string('currentlyyourgradeis', 'core_coursecondition', $grade) . "."; } } } } //prepare the report of requirements for the user if (sizeof($completionmessages) > 0) { $completionmessage = "<ul><li>" . implode("</li><li>", $completionmessages) . "</li></ul>"; } if ($hasoutstanding) { //return "grademin ". $ce->grademin." gradefinal ".$grade->finalgrade ." grademax ". $ce->grademax; return $completionmessage; } return false; }