1 | <?php |
||
12 | class DMSDocument_versions extends DataObject |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @var bool $enable_versions Flag that turns on or off versions of |
||
17 | * documents when replacing them |
||
18 | */ |
||
19 | public static $enable_versions = true; |
||
20 | |||
21 | private static $db = array( |
||
|
|||
22 | 'VersionCounter' => 'Int', |
||
23 | 'VersionViewCount' => 'Int' |
||
24 | ); |
||
25 | |||
26 | private static $has_one = array( |
||
27 | 'Document' => 'DMSDocument' |
||
28 | ); |
||
29 | |||
30 | private static $defaults = array( |
||
31 | 'VersionCounter' => 0 |
||
32 | ); |
||
33 | |||
34 | private static $display_fields = array( |
||
35 | 'VersionCounter' => 'Version Counter', |
||
36 | 'FilenameWithoutID' => 'Filename', |
||
37 | 'LastEdited' => 'Last Changed' |
||
38 | ); |
||
39 | |||
40 | private static $summary_fields = array( |
||
41 | 'VersionCounter', |
||
42 | 'FilenameWithoutID' |
||
43 | ); |
||
44 | |||
45 | private static $field_labels = array( |
||
46 | 'FilenameWithoutID'=>'Filename' |
||
47 | ); |
||
48 | |||
49 | private static $default_sort = array( |
||
50 | 'LastEdited' => 'DESC' |
||
51 | ); |
||
52 | |||
53 | |||
54 | /** |
||
55 | * Creates a new version of a document by moving the current file and |
||
56 | * renaming it to the versioned filename. |
||
57 | * |
||
58 | * This method assumes that the method calling this is just about to upload |
||
59 | * a new file to replace the old file. |
||
60 | * |
||
61 | * @static |
||
62 | * @param DMSDocument $doc |
||
63 | * |
||
64 | * @return bool Success or failure |
||
65 | */ |
||
66 | public static function create_version(DMSDocument $doc) |
||
99 | |||
100 | public function delete() |
||
110 | |||
111 | /** |
||
112 | * Returns a DataList of all previous Versions of a document (check the |
||
113 | * LastEdited date of each object to find the correct one). |
||
114 | * |
||
115 | * @static |
||
116 | * @param DMSDocument $doc |
||
117 | * |
||
118 | * @return DataList List of Document objects |
||
119 | */ |
||
120 | public static function get_versions(DMSDocument $doc) |
||
127 | |||
128 | public function __construct($record = null, $isSingleton = false, $model = null) |
||
147 | |||
148 | /** |
||
149 | * Returns a link to download this document from the DMS store. |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getLink() |
||
157 | |||
158 | /** |
||
159 | * Document versions are always hidden from outside viewing. Only admins can |
||
160 | * download them. |
||
161 | * |
||
162 | * @return bool |
||
163 | */ |
||
164 | public function isHidden() |
||
168 | |||
169 | /** |
||
170 | * Returns the full filename of the document stored in this object. Can |
||
171 | * optionally specify which filename to use at the end. |
||
172 | * |
||
173 | * @param string |
||
174 | * |
||
175 | * @return string |
||
176 | */ |
||
177 | public function getFullPath($filename = null) |
||
184 | |||
185 | /** |
||
186 | * @return string |
||
187 | */ |
||
188 | public function getFilenameWithoutID() |
||
195 | |||
196 | /** |
||
197 | * Creates a new filename for the current Document's file when replacing the |
||
198 | * current file with a new file. |
||
199 | * |
||
200 | * @param DMSDocument $filename The original filename |
||
201 | * |
||
202 | * @return string The new filename |
||
203 | */ |
||
204 | protected function generateVersionedFilename(DMSDocument $doc, $versionCounter) |
||
224 | |||
225 | /** |
||
226 | * Return the extension of the file associated with the document. |
||
227 | * |
||
228 | * @return string |
||
229 | */ |
||
230 | public function getExtension() |
||
234 | |||
235 | /** |
||
236 | * @return string |
||
237 | */ |
||
238 | public function getSize() |
||
244 | |||
245 | /** |
||
246 | * Return the size of the file associated with the document. |
||
247 | * |
||
248 | * @return string |
||
249 | */ |
||
250 | public function getAbsoluteSize() |
||
254 | |||
255 | /** |
||
256 | * An alias to DMSDocument::getSize() |
||
257 | * |
||
258 | * @return string |
||
259 | */ |
||
260 | public function getFileSizeFormatted() |
||
264 | |||
265 | /** |
||
266 | * @return DMSDocument_versions |
||
267 | */ |
||
268 | public function trackView() |
||
280 | } |
||
281 |