APICHANGE: use static $modelClass for DMS, instead of pass through a classname when getting a DMS instance.

FEATURE: add the "Documents" tab to page CMS fields, make the displayed fields customisable by DMSDocument subclass
This commit is contained in:
Normann Lou 2012-07-27 15:38:42 +12:00
parent 0f6e7be3b9
commit ed6a697b57
3 changed files with 30 additions and 4 deletions

View File

@ -7,19 +7,22 @@ class DMS implements DMSInterface {
//The number should be a multiple of 10
static $dmsFolderSize = 1000;
static $dmsPath; //DMS path set on creation
protected $modelClass;
static $modelClass = 'DMSDocument';
static function set_model_class($className){
self::$modelClass = $className;
}
/**
* Factory method that returns an instance of the DMS. This could be any class that implements the DMSInterface.
* @static
* @return DMSInterface An instance of the Document Management System
*/
static function getDMSInstance($className="DMSDocument") {
static function getDMSInstance() {
self::$dmsPath = BASE_PATH . DIRECTORY_SEPARATOR . self::$dmsFolder;
$dms = new DMS();
self::createStorageFolder(self::$dmsPath);
$dms->modelClass = $className;
return $dms;
}
@ -44,7 +47,7 @@ class DMS implements DMSInterface {
$filePath = self::transformFileToFilePath($file);
//create a new document and get its ID
$modelClass = $this->modelClass;
$modelClass = self::$modelClass;
$doc = new $modelClass();
$doc->write();
$doc->storeDocument($filePath);

View File

@ -12,6 +12,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
'Pages' => 'SiteTree',
'Tags' => 'DMSTag'
);
static $display_fields = array(
'ID'=>'ID',
'Title'=>'Title',
'Filename'=>'Filename',
'LastChanged'=>'LastChanged'
);
/**
* Associates this document with a Page. This method does nothing if the association already exists.

View File

@ -4,4 +4,20 @@ class DMSSiteTreeExtension extends DataExtension {
static $belongs_many_many = array(
'Documents' => 'DMSDocument'
);
function updateCMSFields(&$fields){
$documentsListConfig = GridFieldConfig_RecordEditor::create();
$modelClass = DMS::$modelClass;
$documentsListConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields($modelClass::$display_fields);
$fields->addFieldToTab(
'Root.Documents',
GridField::create(
'Documents',
false,
$this->owner->Documents(),
$documentsListConfig
)
);
}
}