APICHANGE: add DMSDocument->getFileExt(), remove DMSDocument_Controller::get_file_extension(), use the instance function where ever applicable.

This commit is contained in:
Normann Lou 2012-08-01 14:13:07 +12:00
parent 40631b12b1
commit 5e448c8d7b
2 changed files with 15 additions and 6 deletions

View File

@ -479,12 +479,19 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
return FRAMEWORK_DIR . "/images/app_icons/{$ext}_32.gif"; return FRAMEWORK_DIR . "/images/app_icons/{$ext}_32.gif";
} }
/**
* Return the extension of the file associated with the document
*/
function getFileExt() {
return pathinfo($this->Filename, PATHINFO_EXTENSION);
}
/** /**
* @return FieldList * @return FieldList
*/ */
protected function getFieldsForFile() { protected function getFieldsForFile() {
$extension = DMSDocument_Controller::get_file_extension($this->Filename); $extension = $this->getFileExt();
$previewField = new LiteralField("ImageFull", $previewField = new LiteralField("ImageFull",
"<img id='thumbnailImage' class='thumbnail-preview' src='{$this->Icon($extension)}?r=" . rand(1,100000) . "' alt='{$this->Title}' />\n" "<img id='thumbnailImage' class='thumbnail-preview' src='{$this->Icon($extension)}?r=" . rand(1,100000) . "' alt='{$this->Title}' />\n"
@ -539,10 +546,6 @@ class DMSDocument_Controller extends Controller {
'index' 'index'
); );
static function get_file_extension($filename) {
return pathinfo($filename, PATHINFO_EXTENSION);
}
/** /**
* Access the file download without redirecting user, so we can block direct access to documents. * Access the file download without redirecting user, so we can block direct access to documents.
*/ */
@ -585,7 +588,7 @@ class DMSDocument_Controller extends Controller {
} }
else { else {
// make do with what we have // make do with what we have
$ext = self::get_file_extension($path); $ext = $doc->getFileExt();
if ( $ext =='pdf') { if ( $ext =='pdf') {
$mime = 'application/pdf'; $mime = 'application/pdf';
}elseif ($ext == 'html' || $ext =='htm') { }elseif ($ext == 'html' || $ext =='htm') {

View File

@ -132,6 +132,12 @@ interface DMSDocumentInterface {
*/ */
function getDownloadLink(); function getDownloadLink();
/**
* Return the extension of the file associated with the document
*/
function getFileExt();
/** /**
* Takes a File object or a String (path to a file) and copies it into the DMS, replacing the original document file * Takes a File object or a String (path to a file) and copies it into the DMS, replacing the original document file
* but keeping the rest of the document unchanged. * but keeping the rest of the document unchanged.