php - Creating a custom CSV importer for SilverStripe -
i'm working on building custom import control silverstripe site because csv files going used unfortunately not formatted csv files , cannot improved (we have work we're given, basically). files contain semi-color separated data, , each line 1 entry:
"[id]";"[first name]";"[middle initial]";"[last name]";"[title]";"[university/college]";"[specialty]";"[graduation date]"
any of values empty (i.e. entry may not have middle initial or may not have speciality listed). these fields marked single space within pair of double quotes:
"[id]";"[first name]";" ";"[last name]";"[title]";"[university/college]";" ";"[graduation date]"
it's important note csv files not have headers, , unlikely able have them. have read csvbulkloader class silverstripe, seems that, without headers, difficult make use of it. plus, there issue empty fields mentioned.
is possible set file breaks data in csv files @ semi-colon? way each value on 1 line , map them fields in silverstripe admin model.
here admin model working on @ moment:
<?php class physicianeducationadmin extends modeladmin { private static $managed_models = array('physicianeducation'); private static $url_segment = 'physicianeducation'; private static $menu_title = 'physician education info'; } <?php class physicianeducation extends dataobject { private static $db = array( 'providerid' => 'varchar', 'firstname' => 'varchar(250)', 'middlename' => 'varchar(250)', 'lastname' => 'varchar(250)', 'title' => 'varchar(10)', 'institution' => 'varchar(550)', 'education' => 'varchar(250)', 'specialty' => 'varchar(250)', 'enddate' => 'date', ); public static $summary_fields = array( 'providerid' => 'provider id', 'firstname' => 'first name', 'middlename' => 'middle initial', 'lastname' => 'last name', 'title' => 'title', 'institution' => 'institution', 'education' => 'education', 'specialty' => 'speciality', 'enddate' => 'end date', ); }
you should able use fgetcsv() function http://php.net/manual/en/function.fgetcsv.php.
it allows specify delimiter (for ';'), , enclosure (for '"'), default.
Comments
Post a Comment