public static function fetch_users_grades($grade_item, $userids, $include_missing=true) {
        global $DB;

        // hmm, there might be a problem with length of sql query
        // if there are too many users requested - we might run out of memory anyway
        $limit = 2000;
        $count = count($userids);
        if ($count > $limit) {
            $half = (int)($count/2);
            $first  = array_slice($userids, 0, $half);
            $second = array_slice($userids, $half);
            return grade_grade::fetch_users_grades($grade_item, $first, $include_missing) + grade_grade::fetch_users_grades($grade_item, $second, $include_missing);
        }

        list($user_ids_cvs, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'uid0');
        $params['giid'] = $grade_item->id;
        $result = array();
        if ($grade_records = $DB->get_records_select('grade_grades', "itemid=:giid AND userid $user_ids_cvs", $params)) {
            foreach ($grade_records as $record) {
                $result[$record->userid] = new grade_grade($record, false);
            }
        }
        if ($include_missing) {
            foreach ($userids as $userid) {
                if (!array_key_exists($userid, $result)) {
                    $grade_grade = new grade_grade();
                    $grade_grade->userid = $userid;
                    $grade_grade->itemid = $grade_item->id;
                    $result[$userid] = $grade_grade;
                }
            }
        }

        return $result;
    }
public static function fetch_users_grades($grade_item, $userids, $include_missing=true) {
        global $DB;

        // hmm, there might be a problem with length of sql query
        // if there are too many users requested - we might run out of memory anyway
        $limit = 2000;
        $count = count($userids);
        if ($count > $limit) {
            $half = (int)($count/2);
            $first  = array_slice($userids, 0, $half);
            $second = array_slice($userids, $half);
            return grade_grade::fetch_users_grades($grade_item, $first, $include_missing) + grade_grade::fetch_users_grades($grade_item, $second, $include_missing);
        }

        list($user_ids_cvs, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'uid0');
        $params['giid'] = $grade_item->id;
        $result = array();
        if ($grade_records = $DB->get_records_select('grade_grades', "itemid=:giid AND userid $user_ids_cvs", $params)) {
            foreach ($grade_records as $record) {
                $result[$record->userid] = new grade_grade($record, false);
            }
        }
        if ($include_missing) {
            foreach ($userids as $userid) {
                if (!array_key_exists($userid, $result)) {
                    $grade_grade = new grade_grade();
                    $grade_grade->userid = $userid;
                    $grade_grade->itemid = $grade_item->id;
                    $result[$userid] = $grade_grade;
                }
            }
        }

        return $result;
    }
public static function fetch_users_grades ( $ grade_item , $ userids , $ include_missing = true ) { global $ DB ; // hmm, there might be a problem with length of sql query // if there are too many users requested - we might run out of memory anyway $ limit = 2000 ; $ count = count ( $ userids ) ; if ( $ count > $ limit ) { $ half = ( int ) ( $ count / 2 ) ; $ first = array_slice ( $ userids , 0 , $ half ) ; $ second = array_slice ( $ userids , $ half ) ; return grade_grade :: fetch_users_grades ( $ grade_item , $ first , $ include_missing ) + grade_grade :: fetch_users_grades ( $ grade_item , $ second , $ include_missing ) ; } list ( $ user_ids_cvs , $ params ) = $ DB -> get_in_or_equal ( $ userids , SQL_PARAMS_NAMED , 'uid0' ) ; $ params [ 'giid' ] = $ grade_item -> id ; $ result = array ( ) ; if ( $ grade_records = $ DB -> get_records_select ( 'grade_grades' , "itemid=:giid AND userid $user_ids_cvs" , $ params ) ) { foreach ( $ grade_records as $ record ) { $ result [ $ record -> userid ] = new grade_grade ( $ record , false ) ; } } if ( $ include_missing ) { foreach ( $ userids as $ userid ) { if ( ! array_key_exists ( $ userid , $ result ) ) { $ grade_grade = new grade_grade ( ) ; $ grade_grade -> userid = $ userid ; $ grade_grade -> itemid = $ grade_item -> id ; $ result [ $ userid ] = $ grade_grade ; } } } return $ result ; }
Returns array of grades for given grade_item+users

@param grade_item $grade_item
@param array $userids
@param bool $include_missing include grades that do not exist yet
@return array userid=>grade_grade array
Returns array of grades for given grade_item + users