Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

A class for loading and preparing grade data from import.

Copyright: 2014 Adrian Greeve <adrian@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 665 lines (27 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class


Class: gradeimport_csv_load_data  - X-Ref

A class for loading and preparing grade data from import.

load_csv_content($text, $encoding, $separator, $previewrows)   X-Ref
Load CSV content for previewing.

param: string $text The grade data being imported.
param: string $encoding The type of encoding the file uses.
param: string $separator The separator being used to define each field.
param: int $previewrows How many rows are being previewed.

fetch_grade_items($courseid)   X-Ref
Gets all of the grade items in this course.

param: int $courseid Course id;
return: array An array of grade items for the course.

trim_headers()   X-Ref
Cleans the column headers from the CSV file.


raise_limits()   X-Ref
Raises the php execution time and memory limits for importing the CSV file.


insert_grade_record(stdClass $record, int $studentid, grade_item $gradeitem)   X-Ref
Inserts a record into the grade_import_values table. This also adds common record information.

param: stdClass $record The grade record being inserted into the database.
param: int $studentid The student ID.
param: grade_item $gradeitem Grade item.
return: mixed true or insert id on success. Null if the grade value is too high or too low or grade item not exist.

import_new_grade_item($header, $key, $value)   X-Ref
Insert the new grade into the grade item buffer table.

param: array $header The column headers from the CSV file.
param: int $key Current row identifier.
param: string $value The value for this row (final grade).
return: stdClass new grade that is ready for commiting to the gradebook.

check_user_exists($value, $userfields)   X-Ref
Check that the user is in the system.

param: string $value The value, from the csv file, being mapped to identify the user.
param: array $userfields Contains the field and label being mapped from.
return: int Returns the user ID if it exists, otherwise null.

create_feedback($courseid, $itemid, $value)   X-Ref
Check to see if the feedback matches a grade item.

param: int $courseid The course ID.
param: int $itemid The ID of the grade item that the feedback relates to.
param: string $value The actual feedback being imported.
return: object Creates a feedback object with the item ID and the feedback value.

update_grade_item($courseid, $map, $key, $verbosescales, $value)   X-Ref
This updates existing grade items.

param: int $courseid The course ID.
param: array $map Mapping information provided by the user.
param: int $key The line that we are currently working on.
param: bool $verbosescales Form setting for grading with scales.
param: string $value The grade value.
return: array grades to be updated.

cleanup_import($notification)   X-Ref
Clean up failed CSV grade import. Clears the temp table for inserting grades.

param: string $notification The error message to display from the unsuccessful grade import.

map_user_data_with_value($mappingidentifier, $value, $header, $map, $key, $courseid, $feedbackgradeid,$verbosescales)   X-Ref
Check user mapping.

param: string $mappingidentifier The user field that we are matching together.
param: string $value The value we are checking / importing.
param: array $header The column headers of the csv file.
param: array $map Mapping information provided by the user.
param: int $key Current row identifier.
param: int $courseid The course ID.
param: int $feedbackgradeid The ID of the grade item that the feedback relates to.
param: bool $verbosescales Form setting for grading with scales.

prepare_import_grade_data($header, $formdata, $csvimport, $courseid, $separatemode, $currentgroup,$verbosescales)   X-Ref
Checks and prepares grade data for inserting into the gradebook.

param: array $header Column headers of the CSV file.
param: object $formdata Mapping information from the preview page.
param: object $csvimport csv import reader object for iterating over the imported CSV file.
param: int $courseid The course ID.
param: bool $separatemode If we have groups are they separate?
param: mixed $currentgroup current group information.
param: bool $verbosescales Form setting for grading with scales.
return: bool True if the status for importing is okay, false if there are errors.

get_headers()   X-Ref
Returns the headers parameter for this class.

return: array returns headers parameter for this class.

get_error()   X-Ref
Returns the error parameter for this class.

return: string returns error parameter for this class.

get_iid()   X-Ref
Returns the iid parameter for this class.

return: int returns iid parameter for this class.

get_previewdata()   X-Ref
Returns the preview_data parameter for this class.

return: array returns previewdata parameter for this class.

get_gradebookerrors()   X-Ref
Returns the gradebookerrors parameter for this class.

return: array returns gradebookerrors parameter for this class.