14/08/2012 1:21pm

PHP | Problem - SGalleryImage


<?php


class SGalleryImage extends DataObject {
/*
public static $plural_name = 'Gallery Images';
public static $singular_name = 'Gallery Image';
*/

static $db = array(
'Name' => 'Varchar(255)',
'Caption' => 'Text',
'ImageLinkHTML' => 'Text',
'ImageLinkDropDown' => 'Text',
'SortID' => 'Int',
'isFeatured' => 'boolean',
'isTopItem' => 'boolean'
);
static $has_one = array(
'Image' => 'Image',
'SGallery' => 'SGallery'
);
static $has_many = array(
// 'SGalleryImageTextFields' =>'SGalleryImageTextField'
);
static $many_many = array(
'Categories' => 'SGalleryImageCategory'
);
// Summary fields
public static $summary_fields = array(
'SortID' => 'SortID',
'Image.CMSThumbnail' => 'Image',
'Title' => 'Title',
'ID' => 'ID'
);
public static $default_sort = 'SortID Asc';
public static $defaults = array(
);
/*
* CMSFields
* **************************************
*/

function getCMSFields() {
$fields = parent::getCMSFields();
$gridFieldCategoriesConfig = GridFieldConfig_RelationEditor::create();
$gridFieldCategories = new GridField("Categories", "Categories", $this->Categories, $gridFieldCategoriesConfig);
$fields->addFieldToTab("Root.GalleryImageCategories", $gridFieldCategories);
return $fields;
}


/*
* Extra Functions
* **************************************
*/

function onBeforeWrite() {
parent::onBeforeWrite();
if (!$this->SortID) {
return $this->SortID = $this->getNextSortID();
}
}

public function getNextSortID() {
$getDataList = $this->SGallery()->Images;
if (!$getDataList) {
return '1';
} else {
return $getDataList->Last()->SortID + 1;
}
}

public static function ThumbnailImage() {

}

public static function FullImage() {

}

}



Post Comment