Created
January 19, 2016 13:50
-
-
Save tony13tv/80e8fca712931b0d7515 to your computer and use it in GitHub Desktop.
Bulk uploading with images for SilverStripe
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
OfficeName | OfficeLogo | |
---|---|---|
LJHooker | assets/Uploads/RO/LJHooker.jpg | |
Bayleys Office | assets/Uploads/RO/bayleys-logo.png |
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 | |
/** | |
* RealEstateOffice Class | |
*/ | |
class RealEstateOffice extends DataObject { | |
private static $singular_name = "Real Estate Office"; | |
private static $plural_name = "Real Estate Offices"; | |
private static $db = array( | |
'OfficeName' => 'Varchar(100)' | |
); | |
private static $has_one = array( | |
'OfficeLogo' => 'Image' | |
); | |
private static $summary_fields = array( | |
'OfficeName', | |
'OfficeLogo' | |
); | |
} | |
/* | |
* RealEstateOfficeAdmin Class | |
*/ | |
class RealEstateOfficeAdmin extends ModelAdmin { | |
private static $managed_models = array( | |
'RealEstateOffice' | |
); | |
private static $model_importers = array( | |
'RealEstateOffice' => 'RealEstateOfficeCsvBulkLoader' | |
); | |
private static $url_segment = 'realestateoffices'; | |
private static $menu_icon = 'framework/admin/images/menu-icons/16x16/document.png'; | |
private static $menu_title = 'Real Estate Offices'; | |
} |
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 | |
/** | |
* RealEstateOfficeCsvBulkLoader Class Bulk CSV uploading | |
*/ | |
class RealEstateOfficeCsvBulkLoader extends CsvBulkLoader { | |
public $columnMap = array( | |
'Office Name' => 'OfficeName', | |
'Logo Filename' => 'OfficeLogo.Filename' | |
); | |
public $relationCallbacks = array( | |
'OfficeLogo.Filename' => array( | |
'relationname' => 'OfficeLogo', | |
'callback' => 'getImageByFilename' | |
) | |
); | |
public static function getImageByFilename(&$obj, $val, $record) { | |
return Image::get()->filter('Filename', $val)->First(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment