Framework
3.9
|
Import data from a cvs file. More...
Public Member Functions | |
__construct ($class_name, $id="") | |
column ($field, $position, $label="", $options=array(), $importer="", $update_empty=true) | |
Adds a data import column definition. More... | |
additional ($field, $label="", $template="", $update_empty) | |
If values are set using logic that does not refer to data in a particular column, use additional with a callback function as the template. More... | |
match () | |
formatList ($items, $nameField) | |
When instantiating a DataImportColumn, use this function to build an array of option key/value pairs for lookup. More... | |
import () | |
Import and save the data. More... | |
button ($text, $url, $confirm=null, $isScript=false) | |
Adds a custom button to the form. More... | |
loadData ($fp) | |
Load the data from the spreadsheet (cvs file) into the DataItem objects. More... | |
log ($text) | |
Store info, errors, and warnings in a log file and ouput. More... | |
writeLog () | |
Output the log. More... | |
importOneRow ($row, $row_number) | |
Given a data row, set the value into each field of the DataItem object. More... | |
preProcessRow ($obj) | |
If implementing classes may wish to add custom logic for handling a row before it is saved or displayed in preview. More... | |
getSavedObj ($obj) | |
Called by the build preview table method. More... | |
findMatch ($obj) | |
Check the db for a record that matches the values for the field(s) given in the matches array. More... | |
setFilter ($obj, $old) | |
If a match to a saved obj is found, set the filter to include only those fields that have changed. More... | |
getColumn ($field) | |
init (&$obj, $row_number) | |
save () | |
formatSaveLogText ($row_number, $obj, $new) | |
For each row saved, output text stating the row was updated and which fields set. More... | |
getPrimaryKey () | |
getClassName () | |
Get the display (prettified) version of the class name for the import. More... | |
buildInputTable () | |
Describe the expected columns to the user above the Browse File form. More... | |
writeScript () | |
drawView () | |
preview () | |
Load the data into preview objects and display in a table. More... | |
drawForm () | |
Display the expected input column layout and show a File upload renderer for the user to select the csv file to be imported. More... | |
uploadDataImportFile () | |
drawButtons () | |
Draws any additional buttons specified in the calling script. More... | |
openFile () | |
getFilePath () | |
Implementing classes may wish to retrieve differently (e.g., document library) More... | |
buildPreviewTable () | |
Display in a DataListView the values read in and set into the data objects and show a Warnings column to list values not found in the lookup table. More... | |
previewRowStyle ($obj) | |
createPreviewData () | |
Clone each of the objs that would be saved to the db on import and set into a preview object that has the formatted value for each field and any warning info or other details for display. More... | |
formatPreviewCell ($obj, $column) | |
When building the preview table, format the column using the supplied DataImportColumn preview template callback. More... | |
importCell ($column, $obj, $value) | |
Given the input value read in, set the value into the field of the object. More... | |
formatRowIndex ($obj) | |
Public Attributes | |
$class_name | |
name of data item class to be updated More... | |
$id | |
$log | |
$objs = array() | |
Contains data read in from the input file. More... | |
$import = false | |
$preview = false | |
whether we are in preview mode More... | |
$matches = array() | |
Field(s) to use to check for a match in db - can be empty. More... | |
$savedObjs = array() | |
Matches found in the db for data in the import file, indexed by primary key. More... | |
$onPreProcessRow = null | |
callback for after each row of data is loaded and before it is saved or displayed in preview table More... | |
$filepath = null | |
optionally set known file path for csv file; otherwise provide form for user to specify More... | |
$validateDataFile | |
optional callback to validate data contents of the file More... | |
$buttons = array() | |
The custom buttons collection. More... | |
$onSaveComplete = null | |
Callback event handler that is fired after all the imported rows are saved. More... | |
$field = "csv_file" | |
$cssClass = "" | |
$table | |
$quiet = false | |
Quiet mode - generate no output to the HTML stream. More... | |
Import data from a cvs file.
Requires specifying the columns to be imported and their position in the csv file.
You may wish to instantiate a helper file for custom handling.
e.g.,
$helper = new UserImportHelper();
$mgr = new DataImportManager(SiteUser, "import_users"); $mgr->column("first_name", 1); $mgr->column("last_name", 2); $mgr->column("email", 3); $mgr->column("role", 4);
$mgr->match("email");
$mgr->onPreProcessRow = array($helper, preProcessRow); $mgr->onSaveComplete = array($helper, sendEmail);
$script .= $mgr->writeScript(); $mgr->drawView();
If a column needs special handling such as finding a key based on a text string in a reference table, use a callback.
If the input column will provide a name value and the import manager will retrieve its key value, then instantiate the column as follows:
$this->column("grade_id", 1, "Grade", $this->formatList($grades, "grade_name"));
Definition at line 73 of file data_import_manager.inc.
DataImportManager::__construct | ( | $class_name, | |
$id = "" |
|||
) |
String | $class_name | - name of the DataItem class being imported |
Definition at line 98 of file data_import_manager.inc.
DataImportManager::additional | ( | $field, | |
$label = "" , |
|||
$template = "" , |
|||
$update_empty | |||
) |
If values are set using logic that does not refer to data in a particular column, use additional with a callback function as the template.
string | $field | |
string | $label | |
string | $template | |
boolean | $update_empty |
Definition at line 140 of file data_import_manager.inc.
DataImportManager::buildInputTable | ( | ) |
Describe the expected columns to the user above the Browse File form.
Definition at line 548 of file data_import_manager.inc.
DataImportManager::buildPreviewTable | ( | ) |
Display in a DataListView the values read in and set into the data objects and show a Warnings column to list values not found in the lookup table.
Definition at line 752 of file data_import_manager.inc.
DataImportManager::button | ( | $text, | |
$url, | |||
$confirm = null , |
|||
$isScript = false |
|||
) |
Adds a custom button to the form.
string | $text | the button label text |
string | $url | the URL to handle the button press |
string | $confirm | optional confirmation message |
boolean | $isScript | true if the url is javascript code to execute, false if it is a URL to redirect to |
Definition at line 213 of file data_import_manager.inc.
DataImportManager::column | ( | $field, | |
$position, | |||
$label = "" , |
|||
$options = array() , |
|||
$importer = "" , |
|||
$update_empty = true |
|||
) |
Adds a data import column definition.
string | $field | - column name for table imported to |
number | $position | - column order/position in import |
string | $label | - label for the column |
array | $options | - set of valid options for the imported data, if lookup is used |
callback | $importer | - optional custom import function for the column |
Definition at line 118 of file data_import_manager.inc.
DataImportManager::createPreviewData | ( | ) |
Clone each of the objs that would be saved to the db on import and set into a preview object that has the formatted value for each field and any warning info or other details for display.
Definition at line 792 of file data_import_manager.inc.
DataImportManager::drawButtons | ( | ) |
Draws any additional buttons specified in the calling script.
Definition at line 677 of file data_import_manager.inc.
DataImportManager::drawForm | ( | ) |
Display the expected input column layout and show a File upload renderer for the user to select the csv file to be imported.
Definition at line 634 of file data_import_manager.inc.
DataImportManager::drawView | ( | ) |
Definition at line 569 of file data_import_manager.inc.
DataImportManager::findMatch | ( | $obj | ) |
Check the db for a record that matches the values for the field(s) given in the matches array.
obj | $obj |
Definition at line 359 of file data_import_manager.inc.
DataImportManager::formatList | ( | $items, | |
$nameField | |||
) |
When instantiating a DataImportColumn, use this function to build an array of option key/value pairs for lookup.
Array | $items | - array of DataItem objects in the lookup table |
String | $nameField | - the field in the table that supplies the name that is meant to match the input value of the spreadsheet. |
Definition at line 168 of file data_import_manager.inc.
DataImportManager::formatPreviewCell | ( | $obj, | |
$column | |||
) |
When building the preview table, format the column using the supplied DataImportColumn preview template callback.
obj | $obj | |
obj | $column |
Definition at line 828 of file data_import_manager.inc.
DataImportManager::formatRowIndex | ( | $obj | ) |
Definition at line 865 of file data_import_manager.inc.
DataImportManager::formatSaveLogText | ( | $row_number, | |
$obj, | |||
$new | |||
) |
For each row saved, output text stating the row was updated and which fields set.
If new row, write inserted.
number | $row_number | |
obj | $obj | |
boolean | $new |
Definition at line 485 of file data_import_manager.inc.
DataImportManager::getClassName | ( | ) |
Get the display (prettified) version of the class name for the import.
Definition at line 537 of file data_import_manager.inc.
DataImportManager::getColumn | ( | $field | ) |
Definition at line 418 of file data_import_manager.inc.
DataImportManager::getFilePath | ( | ) |
Implementing classes may wish to retrieve differently (e.g., document library)
Definition at line 729 of file data_import_manager.inc.
DataImportManager::getPrimaryKey | ( | ) |
Definition at line 526 of file data_import_manager.inc.
DataImportManager::getSavedObj | ( | $obj | ) |
Called by the build preview table method.
If during import, a record was found in the db that matched the given object, that match was saved to the savedObjs array.
obj | $obj |
Definition at line 341 of file data_import_manager.inc.
DataImportManager::import | ( | ) |
Import and save the data.
Definition at line 188 of file data_import_manager.inc.
DataImportManager::importCell | ( | $column, | |
$obj, | |||
$value | |||
) |
Given the input value read in, set the value into the field of the object.
If this data column is set using the options lookup and the value is not found, save the warning to display in the DataListView row.
$obj | |
$column | |
$value |
Definition at line 851 of file data_import_manager.inc.
DataImportManager::importOneRow | ( | $row, | |
$row_number | |||
) |
Given a data row, set the value into each field of the DataItem object.
$row | |
$row_number |
Definition at line 276 of file data_import_manager.inc.
DataImportManager::init | ( | & | $obj, |
$row_number | |||
) |
Definition at line 442 of file data_import_manager.inc.
DataImportManager::loadData | ( | $fp | ) |
Load the data from the spreadsheet (cvs file) into the DataItem objects.
Definition at line 222 of file data_import_manager.inc.
DataImportManager::log | ( | $text | ) |
Store info, errors, and warnings in a log file and ouput.
$text |
Definition at line 256 of file data_import_manager.inc.
DataImportManager::match | ( | ) |
Definition at line 152 of file data_import_manager.inc.
DataImportManager::openFile | ( | ) |
Definition at line 709 of file data_import_manager.inc.
DataImportManager::preProcessRow | ( | $obj | ) |
If implementing classes may wish to add custom logic for handling a row before it is saved or displayed in preview.
$obj |
Definition at line 310 of file data_import_manager.inc.
DataImportManager::preview | ( | ) |
Load the data into preview objects and display in a table.
Definition at line 594 of file data_import_manager.inc.
DataImportManager::previewRowStyle | ( | $obj | ) |
Definition at line 776 of file data_import_manager.inc.
DataImportManager::save | ( | ) |
Definition at line 448 of file data_import_manager.inc.
DataImportManager::setFilter | ( | $obj, | |
$old | |||
) |
If a match to a saved obj is found, set the filter to include only those fields that have changed.
obj | $obj | |
obj | $old |
Definition at line 391 of file data_import_manager.inc.
DataImportManager::uploadDataImportFile | ( | ) |
Definition at line 647 of file data_import_manager.inc.
DataImportManager::writeLog | ( | ) |
Output the log.
Definition at line 264 of file data_import_manager.inc.
DataImportManager::writeScript | ( | ) |
Definition at line 564 of file data_import_manager.inc.
DataImportManager::$buttons = array() |
The custom buttons collection.
Definition at line 86 of file data_import_manager.inc.
DataImportManager::$class_name |
name of data item class to be updated
Definition at line 75 of file data_import_manager.inc.
DataImportManager::$cssClass = "" |
Definition at line 89 of file data_import_manager.inc.
DataImportManager::$field = "csv_file" |
Definition at line 88 of file data_import_manager.inc.
DataImportManager::$filepath = null |
optionally set known file path for csv file; otherwise provide form for user to specify
Definition at line 84 of file data_import_manager.inc.
DataImportManager::$id |
Definition at line 76 of file data_import_manager.inc.
DataImportManager::$import = false |
Definition at line 79 of file data_import_manager.inc.
DataImportManager::$log |
Definition at line 77 of file data_import_manager.inc.
DataImportManager::$matches = array() |
Field(s) to use to check for a match in db - can be empty.
Definition at line 81 of file data_import_manager.inc.
DataImportManager::$objs = array() |
Contains data read in from the input file.
Definition at line 78 of file data_import_manager.inc.
DataImportManager::$onPreProcessRow = null |
callback for after each row of data is loaded and before it is saved or displayed in preview table
Definition at line 83 of file data_import_manager.inc.
DataImportManager::$onSaveComplete = null |
Callback event handler that is fired after all the imported rows are saved.
Definition at line 87 of file data_import_manager.inc.
DataImportManager::$preview = false |
whether we are in preview mode
Definition at line 80 of file data_import_manager.inc.
DataImportManager::$quiet = false |
Quiet mode - generate no output to the HTML stream.
Definition at line 91 of file data_import_manager.inc.
DataImportManager::$savedObjs = array() |
Matches found in the db for data in the import file, indexed by primary key.
Definition at line 82 of file data_import_manager.inc.
DataImportManager::$table |
Definition at line 90 of file data_import_manager.inc.
DataImportManager::$validateDataFile |
optional callback to validate data contents of the file
Definition at line 85 of file data_import_manager.inc.