From 234ccb3b1c5f053407a052ff6566d3501856b27d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 22 Aug 2012 23:20:48 +0200 Subject: [PATCH] API Changed DMSDocument getters to be closer to existing File API Reduces friction when migration from File records (which will be fairly common) --- code/DMSDocument.php | 11 ++++++++--- code/interface/DMSDocumentInterface.php | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/code/DMSDocument.php b/code/DMSDocument.php index 923f8a7..e24d935 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -236,7 +236,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { * Returns a link to download this document from the DMS store * @return String */ - function getDownloadLink() { + function getLink() { return Controller::join_links(Director::baseURL(),'dmsdocument/'.$this->ID); } @@ -624,14 +624,19 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { /** * Return the extension of the file associated with the document */ - function getFileExt() { + function getExtension() { return strtolower(pathinfo($this->Filename, PATHINFO_EXTENSION)); } + + function getSize() { + $size = $this->getAbsoluteSize(); + return ($size) ? File::format_size($size) : false; + } /** * Return the size of the file associated with the document */ - function getFileSize() { + function getAbsoluteSize() { return filesize($this->getFullPath()); } diff --git a/code/interface/DMSDocumentInterface.php b/code/interface/DMSDocumentInterface.php index cc6377d..f237783 100644 --- a/code/interface/DMSDocumentInterface.php +++ b/code/interface/DMSDocumentInterface.php @@ -130,17 +130,26 @@ interface DMSDocumentInterface { * @abstract * @return String */ - function getDownloadLink(); + function getLink(); /** * Return the extension of the file associated with the document */ - function getFileExt(); + function getExtension(); /** - * Return the size of the file associated with the document + * Returns the size of the file type in an appropriate format. + * + * @return string */ - function getFileSize(); + function getSize(); + + /** + * Return the size of the file associated with the document, in bytes. + * + * @return int + */ + function getAbsoluteSize(); /**