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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Get CSV Filename in CsvBulkLoader


Go to End


2 Posts   921 Views

Avatar
quanto

Community Member, 91 Posts

19 March 2015 at 5:07am

Edited: 19/03/2015 5:23am

Hi,

I'm trying to get the name of my CSV file (it's the date) to load into a CsvBulkLoader. Is there any way to fix that?

My code:

<?php

class MyAdmin extends ModelAdmin {

    private static $managed_models = array(
        'Kortebaan',
        'Wedstrijd',
        'Uitslag'
    );
    
    private static $model_importers = array(
      'Uitslag'=>'UitslagCsvBulkLoader'
    );
    
    private static $url_segment = 'wedstrijden';

    private static $menu_title = 'Wedstrijdoverzicht';
    
}

class UitslagCsvBulkLoader extends CsvBulkLoader {
   public $columnMap = array(
      'Paardnaam' => 'Paard.Naam',
      'Afstand'=>'Afstand',
      'Positie'=>'Positie',
      'Pikeurnaam'=>'Pikeur.Naam',
      'Wedstrijd'=>'->getWedstrijd'
   );
   public $duplicateChecks = array(
      'Paard' => 'Paard',
      'Pikeur' => 'Pikeur'
   );
   
   public $relationCallbacks = array( 
      'Paard.Naam' => array(
         'relationname' => 'Paard',
         'callback' => 'getPaardByNaam'
      ),
      'Pikeur.Naam' => array(
         'relationname' => 'Pikeur',
         'callback' => 'getPikeurByNaam'
      )
      
   );
   
   public static function getWedstrijd(&$obj, $val, $record) {
      $obj->Wedstrijd = '!!!HERE DO I WANT THE FILENAME!!!';
      //return Paard::get()->filter('Naam', $val)->First();
   }
   
   public static function getPaardByNaam(&$obj, $val, $record) {
      return Paard::get()->filter('Naam', $val)->First();
   }
   public static function getPikeurByNaam(&$obj, $val, $record) {
      return Pikeur::get()->filter('Naam', $val)->First();
   }
   
   
}

Avatar
quanto

Community Member, 91 Posts

24 March 2015 at 10:22pm

Hmm it seems to be not possible as no one comments it..

Maybe another way:
I want to import a csv file by ModelAdmin, but want to give a extra parameter (dropdown form dataobject) once with it, with a datafield that's not in the csv file. Is that possible? My code so far: http://pastebin.com/eA74Ky5z

Attached Files