Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Importing data (solved)


Reply


4 Posts   195 Views

Avatar
cumquat

Community Member, 198 Posts

20 August 2014 at 11:54pm

Hi there,

Ive extended the CsvBulkLoader (code below) but i have two wee problems one the dates are screwy, the spreadsheets im importing from have the dates in dd/mm/yy hh:mm format and even though i have the site set you UK date when the importer gets a date it imports the data as mm/dd/yy hh:mm if the dates are correct. ie 01/02/2014 10:22 (1st Feb 2014) is imported as 02/01/2014 10:22 (2nd Jan 2014) any help or pointers on that please?

The second problem is that i'd like to set a boolean to 1 if a record has been imported but without adding a field to the spreadsheet to set this i'm unsure how to flag that, any ideas on that?

Hope you can help

Mick

class TheSearchCsvBulkLoader extends CsvBulkLoader{
   public $columnMap = array(
      //Straight Import fields
         'Date Missing' => 'DateMissing',
         'Date Found' => 'DateFound',
         'Gender' => 'Gender',
         'Age' => 'Age',
         'Time of Day' => 'TOD',
         'IPP Grid' => 'IPPGR',
         'Find Grid' => 'FindGR',
         'Destination Grid' => 'DestGR',
         'Track Offset (m)' => 'TrackOff',
         'Area Type' => 'AreaType',
         'Notes' => 'Notes',
      //Mappings
         'Area' => 'Area.Name',
         'Type' => 'Mipser.Name',
         'Location Type' => 'Location.Name',
         'Survivability' => 'Survivability.Name',
         'Missing From' => 'MissingLoc.Name'
      );
   public $duplicateChecks = array(
      //'SearchID' => 'ID' // This stops duplicate entries
      );
   public $relationCallbacks = array(
      'Area.Name' => array(
         'relationname' => 'Area',
         'callback' => 'getAreabyName'
      ),
      'Mipser.Name' => array(
         'relationname' => 'Misper',
         'callback' => 'getMisperbyName'
      ),
      'Location.Name' => array(
         'relationname' => 'Location',
         'callback' => 'getLocationbyName'
      ),
      'Survivability.Name' => array(
         'relationname' => 'Survivability',
         'callback' => 'getSurvivabilitybyName'
      ),
      'MissingLoc.Name' => array(
         'relationname' => 'MissingLoc',
         'callback' => 'getMissingLocbyName'
      )

   );

   public static function getAreabyName($obj, $val, $record){
      return Team::get()->filter('Name', $val)->First();
   }
   public static function getMisperbyName($obj, $val, $record){
      return Type::get()->filter('Name', $val)->First();
   }
   public static function getLocationbyName($obj, $val, $record){
      return Location::get()->filter('Name', $val)->First();
   }
   public static function getSurvivabilitybyName($obj, $val, $record){
      return Survivability::get()->filter('Name', $val)->First();
   }
   public static function getMissingLocbyName($obj, $val, $record){
      return MissingLoc::get()->filter('Name', $val)->First();
   }
}

Avatar
cumquat

Community Member, 198 Posts

23 August 2014 at 5:45am

anyone?

Avatar
cumquat

Community Member, 198 Posts

26 August 2014 at 8:50pm

Is there any function like onbeforewrite etc that i can extend/use with regards to importing data to add a flag or boolean?

Mick

Avatar
cumquat

Community Member, 198 Posts

28 August 2014 at 4:39am

Ok i ended up being a bit hacky and added a function to a date conversion function see below.

public static function getDateMissing(&$obj, $val, $record){
      if(!empty($val)){
         $obj->DateMissing = self::convertDate($val);
         $obj->Imported = 1;
      }
   }


Mick