3 * FusionForge Documentation Manager
5 * Copyright 2016-2017, Franck Villaume - TrivialDev
6 * http://fusionforge.org
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'include/FFError.class.php';
25 require_once $gfcommon.'docman/DocumentVersion.class.php';
27 class DocumentVersionFactory extends FFError {
29 * The Document object.
31 * @var object $Document.
38 function __construct(&$Document) {
39 parent::__construct();
40 if (!$Document || !is_object($Document)) {
41 $this->setError(_('No Valid Document Object'));
44 if ($Document->isError()) {
45 $this->setError(_('Document')._(': ').$Document->getErrorMessage());
48 $this->Document =& $Document;
53 * getHTMLVersions - retrieve a limited number of version of a document
55 * @param int $limit the number of versions to retrieve. Default is 0 = No limit
56 * @param int $start Paging the retrieve. Start point. Default is 0.
57 * @return array Array of enriched version datas from database.
59 function getHTMLVersions($limit = 0, $start = 0) {
62 // everything but data_words! Too much memory consumption.
63 $res = db_query_params('SELECT serial_id, \'_\'||version as version, docid, current_version, title, updatedate, createdate, created_by, description, filename, filetype, filesize, vcomment FROM doc_data_version WHERE docid = $1 ORDER by version DESC',
64 array($this->Document->getID()), $limit, $start);
66 $numrows = db_numrows($res);
67 while ($arr = db_fetch_array($res)) {
68 $user = user_get_object($arr['created_by']);
69 $arr['created_by_username'] = util_display_user($user->getUnixName(), $user->getID(), $user->getRealName());
70 $arr['filesize_readable'] = human_readable_bytes($arr['filesize']);
71 if ($arr['updatedate']) {
72 $arr['lastdate'] = date(_('Y-m-d H:i'), $arr['updatedate']);
74 $arr['lastdate'] = date(_('Y-m-d H:i'), $arr['createdate']);
77 if ($arr['filetype'] == 'URL') {
81 if (preg_match('|^text/|i', $arr['filetype'])) { // text plain, text html, text x-patch, etc
85 if (preg_match('/html/i', $arr['filetype'])) { // text plain, text html, text x-patch, etc
88 $new_description = util_gen_cross_ref($arr['description'], $this->Document->Group->getID());
89 $arr['new_description'] = str_replace(array("\r\n", "\r", "\n"), "\\n", $new_description);
90 $arr['description'] = str_replace(array("\r\n", "\r", "\n"), "\\n", $arr['description']);
91 $arr['vcomment'] = str_replace(array("\r\n", "\r", "\n"), "\\n", $arr['vcomment']);
92 $arr['versionactions'][] = util_make_link('#', $HTML->getEditFilePic(_('Edit this version'), 'editversion'), array('id' => 'version_action_edit', 'onclick' => 'javascript:controllerListFile.toggleEditVersionView({title: \''.addslashes($arr['title']).'\', description: \''.addslashes($arr['description']).'\', new_description: \''.addslashes($arr['new_description']).'\', version: '.ltrim($arr['version'], '_').', current_version: '.$arr['current_version'].', isURL: '.$isURL.', isText: '.$isText.', isHtml: '.$isHtml.', filename: \''.addslashes($arr['filename']).'\', vcomment: \''.addslashes($arr['vcomment']).'\', docid: '.$arr['docid'].', groupId: '.$this->Document->Group->getID().'})'), true);
94 $arr['versionactions'][] = util_make_link('#', $HTML->getRemovePic(_('Permanently delete this version'), 'delversion'), array('id' => 'version_action_delete', 'onclick' => 'javascript:controllerListFile.deleteVersion({version: '.ltrim($arr['version'], '_').', docid: '.$arr['docid'].', groupId: '.$this->Document->Group->getID().'})'), true);
96 $versions[$arr['version']] = $arr;
103 function getVersions() {
105 // everything but data_words! Too much memory consumption.
106 $res = db_query_params('SELECT serial_id, version as version, docid, current_version, title, updatedate, createdate, created_by, description, filename, filetype, filesize, vcomment FROM doc_data_version WHERE docid = $1 ORDER by version DESC',
107 array($this->Document->getID()));
109 $numrows = db_numrows($res);
111 while ($arr = db_fetch_array($res)) {
112 $versions[$i] = $arr;
113 if ($arr['filetype'] != 'URL') {
114 $versions[$i]['storageref'] = DocumentStorage::instance()->get($arr['serial_id']);
116 $versions[$i]['storageref'] = null;
121 db_free_result($res);
125 function getSerialIDs() {
126 $serialids = array();
127 $res = db_query_params('SELECT serial_id FROM doc_data_version WHERE docid = $1', array($this->Document->getID()));
129 while ($arr = db_fetch_array($res)) {
130 $serialids[] = $arr[0];
132 $this->serialids = $serialids;
137 function getDBResVersionSerialIDs() {
138 return db_query_params('SELECT serial_id, version FROM doc_data_version WHERE docid = $1 ORDER BY version DESC', array($this->Document->getID()));