DataSourceTrait
Provides all the helpers to add a datasource easily.
Table of Contents
Properties
- $userJob : array<string|int, mixed>
- User job details.
- $userJobID : int
- User job id.
Methods
- __construct() : mixed
- Class constructor.
- checkPermission() : bool
- Determine if the current user has access to this data source.
- getColumnHeaders() : array<string|int, mixed>
- Get an array of column headers, if any.
- getUserJobID() : int|null
- Get the ID of the user job being acted on.
- purge() : array<string|int, mixed>
- Purge any datasource related assets when the datasource is dropped.
- setUserJobID() : void
- Set user job ID.
- trimNonBreakingSpaces() : string
- Trim non-breaking spaces in a multibyte-safe way.
- createTempTableFromColumns() : string
- getColumnNamesForUnnamedColumns() : array<string|int, mixed>
- Get suitable column names for when no header row is in use.
- getColumnNamesFromHeaders() : array<string|int, mixed>
- Get column names from the headers - munging to lower case etc.
- getSubmittedValue() : mixed
- Get submitted value.
- getUserJob() : array<string|int, mixed>
- Get User Job.
- updateUserJobDataSource() : void
- Update the data stored in the User Job about the Data Source.
- updateUserJobMetadata() : void
- Update the UserJob Metadata.
Properties
$userJob
User job details.
protected
array<string|int, mixed>
$userJob
This is the relevant row from civicrm_user_job.
$userJobID
User job id.
protected
int
$userJobID
This is the primary key of the civicrm_user_job table which is used to track the import.
Methods
__construct()
Class constructor.
public
__construct([int|null $userJobID = NULL ]) : mixed
Parameters
- $userJobID : int|null = NULL
checkPermission()
Determine if the current user has access to this data source.
public
checkPermission() : bool
Return values
boolgetColumnHeaders()
Get an array of column headers, if any.
public
getColumnHeaders() : array<string|int, mixed>
This is presented to the user in the MapField screen so that can see what fields they are mapping.
Tags
Return values
array<string|int, mixed>getUserJobID()
Get the ID of the user job being acted on.
public
getUserJobID() : int|null
Return values
int|nullpurge()
Purge any datasource related assets when the datasource is dropped.
public
purge([array<string|int, mixed> $newParams = [] ]) : array<string|int, mixed>
This is the datasource's chance to delete any tables etc that it created which will now not be used.
Parameters
- $newParams : array<string|int, mixed> = []
-
If the dataSource is being updated to another variant of the same class (eg. the csv upload was set to no column headers and they have resubmitted WITH skipColumnHeader (first row is a header) then the dataSource is still CSV and the params for the new instance are passed in. When changing from csv to SQL (for example) newParams is empty.
Tags
Return values
array<string|int, mixed> —The details to update the DataSource key in the userJob metadata to. Generally and empty array but it the datasource decided (for example) that the table it created earlier is still consistent with the new params then it might decided not to drop the table and would want to retain some metadata.
setUserJobID()
Set user job ID.
public
setUserJobID(int $userJobID) : void
Parameters
- $userJobID : int
trimNonBreakingSpaces()
Trim non-breaking spaces in a multibyte-safe way.
public
static trimNonBreakingSpaces(string $string) : string
See also dev/core#2127 - avoid breaking strings ending in à or any other unicode character sharing the same 0xA0 byte as a non-breaking space.
Parameters
- $string : string
Return values
string —The trimmed string
createTempTableFromColumns()
protected
createTempTableFromColumns(array<string|int, mixed> $columns) : string
Parameters
- $columns : array<string|int, mixed>
Tags
Return values
string —Temp table name.
getColumnNamesForUnnamedColumns()
Get suitable column names for when no header row is in use.
protected
getColumnNamesForUnnamedColumns(array<string|int, mixed> $row) : array<string|int, mixed>
The result is an array like 'column_1', column_2'. SQL columns cannot start with a number.
Parameters
- $row : array<string|int, mixed>
Return values
array<string|int, mixed>getColumnNamesFromHeaders()
Get column names from the headers - munging to lower case etc.
protected
getColumnNamesFromHeaders(array<string|int, mixed> $headers) : array<string|int, mixed>
Parameters
- $headers : array<string|int, mixed>
Return values
array<string|int, mixed>getSubmittedValue()
Get submitted value.
protected
getSubmittedValue(string $valueName) : mixed
Get a value submitted on the form.
Parameters
- $valueName : string
Tags
getUserJob()
Get User Job.
protected
getUserJob() : array<string|int, mixed>
API call to retrieve the userJob row.
Tags
Return values
array<string|int, mixed>updateUserJobDataSource()
Update the data stored in the User Job about the Data Source.
protected
updateUserJobDataSource(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Tags
updateUserJobMetadata()
Update the UserJob Metadata.
private
updateUserJobMetadata(string $key, array<string|int, mixed> $data) : void
Parameters
- $key : string
- $data : array<string|int, mixed>