Skip to content
Snippets Groups Projects
Commit cad84217 authored by Andrew Short's avatar Andrew Short
Browse files

MINOR: Added a link from a file to its current version.

parent 39ac1229
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,10 @@ class VersionedFileExtension extends DataObjectDecorator {
* @return array
*/
public function extraStatics() {
return array('has_many' => array('Versions' => 'FileVersion'));
return array (
'has_one' => array('CurrentVersion' => 'FileVersion'),
'has_many' => array('Versions' => 'FileVersion')
);
}
/**
......@@ -25,6 +28,15 @@ class VersionedFileExtension extends DataObjectDecorator {
);
}
/**
* Get the current file version number, if one is available.
*
* @return int|null
*/
public function getVersionNumber() {
if($this->owner->CurrentVersionID) return $this->owner->CurrentVersion()->VersionNumber;
}
/**
* Called by the edit form upon save, and handles replacing the file if a replacement is specified.
*
......@@ -55,6 +67,9 @@ class VersionedFileExtension extends DataObjectDecorator {
$version = new FileVersion();
$version->FileID = $this->owner->ID;
$version->write();
$this->owner->CurrentVersionID = $version->ID;
$this->owner->write();
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment