Last active
August 29, 2015 14:18
-
-
Save jedateach/4a89fbb9428ee2add6e3 to your computer and use it in GitHub Desktop.
New BulkLoading Process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* process: | |
* raw data is extracted using BulkLoaderSource as iterable rows | |
* row data is mapped into a standardised form | |
* standard form is transformed into a placeholder dataobject | |
*/ | |
//raw data | |
$rawdata = "name,age,country | |
joe bloggs,62,NZ | |
alice smith,24,AU | |
"; | |
//CSVBulkLoaerSource parses raw into records | |
$rows = array( | |
array("name" => "joe bloggs", "age" => "62", "country" => "NZ"), | |
array("name" => "alice smith", "age" => "24", "country" => "AU") | |
); | |
//mapping for getting data into a standard form | |
//(either hard-coded, or defined by user) | |
$mapping = array( | |
"first name" => "FirstName", | |
"last name" => "Surname", | |
"name" => "Name", | |
"age" => "Age", | |
"country" => "Country.Code", | |
); | |
//first record after mapping has been performed | |
$record = array( | |
"Name" => "joe bloggs", | |
"Age" => "62", | |
"Country.Code" => "NZ" | |
); | |
//define how data will be transformed | |
$transforms = array( | |
"Name" => array( | |
'callback' => function($value, $obj){ | |
$name = explode(" ", $value); | |
$obj->FirstName = $name[0]; | |
$obj->Surname = $name[1]; | |
} | |
), | |
"Country.Code" => array( | |
"link" => true, //link up relations | |
"create" => false //don't creaet new relation objects | |
) | |
); | |
//dataobject record after tranformation | |
$dataobj->record = array( | |
"FirstName" => "Joe", | |
"Surname" => "Bloggs", | |
"CountryID" => 234 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment