_makePercentGrade.fnc.php 2.45 KB
Newer Older
Octopus in vitro's avatar
Octopus in vitro committed
1
<?php
2 3 4 5 6 7
/**
 * Make Percent Grade function
 *
 * @package RosarioSIS
 * @subpackage ProgramFunctions
 */
Octopus in vitro's avatar
Octopus in vitro committed
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/**
 * Make Percent Grade
 * From Grade ID or TITLE:
 * = (Grade breakoff + Previous Grade breakoff) / 2
 *
 * @example _makePercentGrade( $grade[1]['REPORT_CARD_GRADE_ID'], $course_period_id )
 *
 * @global $_ROSARIO uses $_ROSARIO['_makeLetterGrade']
 * @see _makeLetterGrade()
 *
 * @param  string  $grade_id_or_title Grade ID or TITLE.
 * @param  integer $course_period_id  Course Period ID (optional). Defaults to UserCoursePeriod().
 * @param  integer $staff_id          Staff ID (optional). Defaults to User( 'STAFF_ID' ).
 *
 * @return float Percent Grade or 0 if not found.
 */
function _makePercentGrade( $grade_id_or_title, $course_period_id = 0, $staff_id = 0 )
{
	global $_ROSARIO;
Octopus in vitro's avatar
Octopus in vitro committed
28

29 30 31 32 33 34
	if ( ! $grade_id_or_title )
	{
		return 0;
	}

	$course_period_id = $course_period_id ? $course_period_id : UserCoursePeriod();
Octopus in vitro's avatar
Octopus in vitro committed
35

36 37 38 39 40
	$staff_id = $staff_id ? $staff_id : User( 'STAFF_ID' );

	$gradebook_config = ProgramUserConfig( 'Gradebook', $staff_id );

	if ( ! isset( $_ROSARIO['_makeLetterGrade']['courses'][ $course_period_id ] ) )
Octopus in vitro's avatar
Octopus in vitro committed
41
	{
42
		$_ROSARIO['_makeLetterGrade']['courses'][ $course_period_id ] = DBGet( "SELECT DOES_BREAKOFF,GRADE_SCALE_ID
43
			FROM COURSE_PERIODS
44
			WHERE COURSE_PERIOD_ID='" . $course_period_id . "'" );
Octopus in vitro's avatar
Octopus in vitro committed
45
	}
46

47
	$does_breakoff = $_ROSARIO['_makeLetterGrade']['courses'][ $course_period_id ][1]['DOES_BREAKOFF'];
48

49
	$grade_scale_id = $_ROSARIO['_makeLetterGrade']['courses'][ $course_period_id ][1]['GRADE_SCALE_ID'];
Octopus in vitro's avatar
Octopus in vitro committed
50

51 52
	if ( ! isset( $_ROSARIO['_makeLetterGrade']['grades'][ $grade_scale_id ] ) )
	{
53
		$_ROSARIO['_makeLetterGrade']['grades'][ $grade_scale_id ] = DBGet( "SELECT TITLE,ID,BREAK_OFF
54 55 56 57
			FROM REPORT_CARD_GRADES
			WHERE SYEAR='" . UserSyear() . "'
			AND SCHOOL_ID='" . UserSchool() . "'
			AND GRADE_SCALE_ID='" . $grade_scale_id . "'
58
			ORDER BY BREAK_OFF IS NOT NULL DESC,BREAK_OFF DESC,SORT_ORDER" );
59
	}
Octopus in vitro's avatar
Octopus in vitro committed
60 61
	//$grades = array('A+','A','A-','B+','B','B-','C+','C','C-','D+','D','D-','F');

62
	foreach ( (array) $_ROSARIO['_makeLetterGrade']['grades'][ $grade_scale_id ] as $grade )
Octopus in vitro's avatar
Octopus in vitro committed
63 64
	{
		$prev = $crnt;
65 66 67 68 69 70 71 72 73 74 75

		$crnt = ( $does_breakoff === 'Y' ?
			$gradebook_config[ $course_period_id . '-' . $grade['ID'] ] :
			$grade['BREAK_OFF'] );

		if ( is_numeric( $grade_id_or_title ) ?
				$grade_id_or_title == $grade['ID'] :
				mb_strtoupper( $grade_id_or_title ) == mb_strtoupper( $grade['TITLE'] ) )
		{
			return ( $crnt + ( $crnt > $prev ? 100 : $prev ) ) / 2;
		}
Octopus in vitro's avatar
Octopus in vitro committed
76
	}
77

Octopus in vitro's avatar
Octopus in vitro committed
78 79
	return 0;
}