diff --git a/code/DMS.php b/code/DMS.php index 42d3b24..8949f89 100644 --- a/code/DMS.php +++ b/code/DMS.php @@ -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); diff --git a/code/DMSDocument.php b/code/DMSDocument.php index 24cda78..9bce72d 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -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. diff --git a/code/DMSSiteTreeExtension.php b/code/DMSSiteTreeExtension.php index 25492b8..4ad10e9 100644 --- a/code/DMSSiteTreeExtension.php +++ b/code/DMSSiteTreeExtension.php @@ -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 + ) + ); + } } \ No newline at end of file