APICHANGE: change DMSDocumentInterface::downloadLink() to DMSDocumentInterface::getDownloadLink() so that a $DownloadLink could be used as a field to make GridField for DMSDocument to have a formatted linkable column

ENHANCEMENT: make "Filename" column of a GridField clickable hence make the document downlaodable.
ENHANCEMENT: make "Last Changed" column show as a "Ago" format, ie. 'A day ago' or 'there months ago'.
This commit is contained in:
Normann Lou 2012-08-01 12:27:30 +12:00
parent f361cab459
commit 09a8229ec0
4 changed files with 7 additions and 5 deletions

View File

@ -225,7 +225,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
* Returns a link to download this document from the DMS store
* @return String
*/
function downloadLink() {
function getDownloadLink() {
return Controller::join_links(Director::baseURL(),'dmsdocument/'.$this->ID);
}
@ -506,7 +506,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
new ReadonlyField("FileType", _t('AssetTableField.TYPE','File type') . ':', self::get_file_type($extension)),
new ReadonlyField("Size", _t('AssetTableField.SIZE','File size') . ':', File::format_size(filesize($this->getFullPath()))),
$urlField = new ReadonlyField('ClickableURL', _t('AssetTableField.URL','URL'),
sprintf('<a href="%s" target="_blank" class="file-url">%s</a>', $this->downloadLink(), $this->downloadLink())
sprintf('<a href="%s" target="_blank" class="file-url">%s</a>', $this->getDownloadLink(), $this->getDownloadLink())
),
new ReadonlyField("FilenameWithoutIDField", "Filename". ':', $this->getFilenameWithoutID()),
new DateField_Disabled("Created", _t('AssetTableField.CREATED','First uploaded') . ':', $this->Created),

View File

@ -19,7 +19,9 @@ class DMSSiteTreeExtension extends DataExtension {
//GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d')
);
$modelClass = DMS::$modelClass;
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields($modelClass::$display_fields);
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields($modelClass::$display_fields)
->setFieldCasting(array('LastChanged'=>"Date->Ago"))
->setFieldFormatting(array('FilenameWithoutID'=>'<a target=\'_blank\' class=\'file-url\' href=\'$DownloadLink\'>$FilenameWithoutID</a>'));
$gridField = GridField::create(
'Documents',
false,

View File

@ -130,7 +130,7 @@ interface DMSDocumentInterface {
* @abstract
* @return String
*/
function downloadLink();
function getDownloadLink();
/**
* Takes a File object or a String (path to a file) and copies it into the DMS, replacing the original document file

View File

@ -125,7 +125,7 @@ class DMSTest extends FunctionalTest {
//
// //store the first document
// $document = $dms->storeDocument(self::$testFile);
// $link = $document->downloadLink();
// $link = $document->getDownloadLink();
//
// Debug::Show($link);
// $d=new DMSDocument_Controller();