mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
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:
parent
0f6e7be3b9
commit
ed6a697b57
11
code/DMS.php
11
code/DMS.php
@ -7,19 +7,22 @@ class DMS implements DMSInterface {
|
|||||||
//The number should be a multiple of 10
|
//The number should be a multiple of 10
|
||||||
static $dmsFolderSize = 1000;
|
static $dmsFolderSize = 1000;
|
||||||
static $dmsPath; //DMS path set on creation
|
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.
|
* Factory method that returns an instance of the DMS. This could be any class that implements the DMSInterface.
|
||||||
* @static
|
* @static
|
||||||
* @return DMSInterface An instance of the Document Management System
|
* @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;
|
self::$dmsPath = BASE_PATH . DIRECTORY_SEPARATOR . self::$dmsFolder;
|
||||||
|
|
||||||
$dms = new DMS();
|
$dms = new DMS();
|
||||||
self::createStorageFolder(self::$dmsPath);
|
self::createStorageFolder(self::$dmsPath);
|
||||||
$dms->modelClass = $className;
|
|
||||||
return $dms;
|
return $dms;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +47,7 @@ class DMS implements DMSInterface {
|
|||||||
$filePath = self::transformFileToFilePath($file);
|
$filePath = self::transformFileToFilePath($file);
|
||||||
|
|
||||||
//create a new document and get its ID
|
//create a new document and get its ID
|
||||||
$modelClass = $this->modelClass;
|
$modelClass = self::$modelClass;
|
||||||
$doc = new $modelClass();
|
$doc = new $modelClass();
|
||||||
$doc->write();
|
$doc->write();
|
||||||
$doc->storeDocument($filePath);
|
$doc->storeDocument($filePath);
|
||||||
|
@ -12,6 +12,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
|||||||
'Pages' => 'SiteTree',
|
'Pages' => 'SiteTree',
|
||||||
'Tags' => 'DMSTag'
|
'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.
|
* Associates this document with a Page. This method does nothing if the association already exists.
|
||||||
|
@ -4,4 +4,20 @@ class DMSSiteTreeExtension extends DataExtension {
|
|||||||
static $belongs_many_many = array(
|
static $belongs_many_many = array(
|
||||||
'Documents' => 'DMSDocument'
|
'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
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user