csv_functions.php
Table of Contents
Functions
- csv_upload_process() : bool
- Process the uploaded CSV
- csv_upload_get_info() : mixed
- csv_upload_log() : void
- Append text to csv log file
- get_csv_line_matching_resources() : array<string|int, mixed>
- Return the resources with the csv value found in the specified field.
- csv_check_utf8() : array<string|int, mixed>
- Checks if a passed csv file is valid for being processed, needs to be UTF-8 and if a BOM is present it will be stripped out before processing.
- csv_strip_bom() : bool
- Attempt to strip out BOM from passed csv file if present. Replaces the original file.
Functions
csv_upload_process()
Process the uploaded CSV
csv_upload_process(string $filename, array<string|int, mixed> &$meta, array<string|int, mixed> $resource_types, array<string|int, mixed> &$messages, array<string|int, mixed> $csv_set_options[, int $max_error_count = 100 ][, bool $processcsv = false ]) : bool
Parameters
- $filename : string
-
Path to CSV file
- $meta : array<string|int, mixed>
-
Array of resource types and associated fields returned by meta_get_map() in include/meta_functions.php
- $resource_types : array<string|int, mixed>
-
Array of resource type data, with the resource type ID as the key
- $messages : array<string|int, mixed>
-
Array to store processing, information and error messages, passed by reference
- $csv_set_options : array<string|int, mixed>
-
Array of CSV processsing options, includes CSV column to metadata field mappings and csv mode
- $max_error_count : int = 100
-
Maximum number of fatal errors to accept before aborting
- $processcsv : bool = false
-
Process data? If false data will be checked without making changes
Return values
boolcsv_upload_get_info()
csv_upload_get_info(mixed $filename, mixed &$messages) : mixed
Parameters
- $filename : mixed
- $messages : mixed
csv_upload_log()
Append text to csv log file
csv_upload_log(string $logfile, mixed $logtext) : void
Parameters
- $logfile : string
-
path to log file
- $logtext : mixed
-
text to append
get_csv_line_matching_resources()
Return the resources with the csv value found in the specified field.
get_csv_line_matching_resources(int $field, string $csv_value) : array<string|int, mixed>
Parameters
- $field : int
-
Resource type field ref - the field for csv upload to match on.
- $csv_value : string
-
The value from the csv to match.
Return values
array<string|int, mixed> —Array of resources which have the csv value in the given field.
csv_check_utf8()
Checks if a passed csv file is valid for being processed, needs to be UTF-8 and if a BOM is present it will be stripped out before processing.
csv_check_utf8(string $filename) : array<string|int, mixed>
Parameters
- $filename : string
-
Path to csv file
Return values
array<string|int, mixed> —Return an array with whether the file passed the check and a message
csv_strip_bom()
Attempt to strip out BOM from passed csv file if present. Replaces the original file.
csv_strip_bom(string $filename) : bool
Parameters
- $filename : string
-
Path to csv file
Return values
bool —Return whether BOM was able to be stripped or not