Hi guys
I need to have a Dailyimport from CSV to a DataObject. I have got it reading the CSV and putting together then writing the DataObject but now I need it to also read a folder of images and import those into the DataObject has_many.
So far I have loaded all the images into an array, and checked them against the import. So is there a function I can use when looping over the images to import them into the assets/ folder and load them against the DataObject? The images will already be in a folder on the host.
Here are my objects:
class VehiclePreowned extends DataObject {
public static $db = array (
'UniqeNo' => 'Varchar(255)',
'StockNo' => 'Varchar(255)',
'Year' => 'Varchar(255)',
'Make' => 'Varchar(255)',
'Model' => 'Varchar(255)',
'Desc' => 'Varchar(255)',
'BodyStyle' => 'Varchar(255)',
'Doors' => 'INT',
'ChassisNo' => 'Varchar(255)',
'CC' => 'INT',
'FuelType' => 'Enum("Petrol,Diesel")',
'KM' => 'INT',
'ExtColour' => 'Varchar(255)',
'IntColour' => 'Varchar(255)',
'Comments' => 'HTMLText'
);
public static $has_one = array (
'Folder' => 'Folder'
);
public static $has_many = array (
'VehicleImages' => 'VehiclePreownedImage'
);
static $searchable_fields = array(
'Make',
'Model'
);
static $summary_fields = array(
'Make',
'Model'
);
function canCreate() {return true;}
function canEdit() {return true;}
function canDelete() {return true;}
function canPublish() {return true;}
public function getCMSFields() {
$fields = parent::getCMSFields();
//$fields->addFieldToTab("Root.Main",new TextField('Name','Name'));
return $fields;
}
function onBeforeWrite() {
parent::onBeforeWrite();
if(isset($_POST['Name'])) {
$clean_name = SiteTree::generateURLSegment($_POST['Name']);
if($this->FolderID) {
$this->Folder()->setName($clean_name);
$this->Folder()->Title = $clean_name;
$this->Folder()->write();
}
else {
$folder = Folder::findOrMake($clean_name);
$this->FolderID = $folder->ID;
}
}
}
}
Image DataObject and Image
class VehiclePreownedImage extends DataObject {
public static $db = array (
);
static $has_one = array(
'VehiclePreowned' => 'VehiclePreowned',
'VehicleImageFile' => 'VehiclePreownedImage_Image'
);
function canCreate() {return true;}
function canEdit() {return true;}
function canDelete() {return true;}
function canPublish() {return true;}
}
class VehiclePreownedImage_Image extends Image {
function generateVehicleImageListing($gd) {
return $gd->croppedResize(191,161);
}
function generateVehicleImageThumb($gd) {
return $gd->croppedResize(74,63);
}
function generateVehicleImageMain($gd) {
return $gd->croppedResize(383,325);
}
function generateVehicleImageLarge($gd) {
return $gd->croppedResize(700,600);
}
}
Any help is much appreciated
Cheers!!