documentcore.inc.php
8.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
/**
* $Id$
*
* Copyright (c) 2006 Jam Warehouse http://www.jamwarehouse.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; using version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* -------------------------------------------------------------------------
*
* You can contact the copyright owner regarding licensing via the contact
* details that can be found on the KnowledgeTree web site:
*
* http://www.ktdms.com/
*/
require_once(KT_LIB_DIR . '/ktentity.inc');
class KTDocumentCore extends KTEntity {
var $_bUsePearError = true;
/** The original creator of the document */
var $iCreatorId;
/** The creation time of the document */
var $dCreated;
/** The user that last modified the document */
var $iModifiedUserId;
/** The time of the last modification to the document */
var $dModified;
/** The parent folder of the document */
var $iFolderId;
/** List of folder from the root to the document */
var $sParentFolderIds;
/** Fully qualified path of the document */
var $sFullPath;
/** Status of the document (live, deleted, archived, &c.) */
var $iStatusId;
/** Where the document receives its permission information from */
var $iPermissionObjectId;
/** The fully looked-up permission information for this document */
var $iPermissionLookupId;
/** The most recent metadata version for the object */
var $iMetadataVersionId;
var $iMetadataVersion;
var $bIsCheckedOut;
var $iCheckedOutUserId;
var $_aFieldToSelect = array(
"iId" => "id",
// transaction-related
"iCreatorId" => 'creator_id',
"dCreated" => 'created',
"iModifiedUserId" => 'modified_user_id',
"dModified" => 'modified',
"iMetadataVersionId" => 'metadata_version_id',
"iMetadataVersion" => 'metadata_version',
// location-related
"iFolderId" => 'folder_id',
"sParentFolderIds" => 'parent_folder_ids',
"sFullPath" => 'full_path',
// status
"iStatusId" => 'status_id',
"bIsCheckedOut" => 'is_checked_out',
"iCheckedOutUserId" => 'checked_out_user_id',
// permission-related
"iPermissionObjectId" => 'permission_object_id',
"iPermissionLookupId" => 'permission_lookup_id',
"iOwnerId" => 'owner_id',
);
function KTDocument() {
}
// {{{ getters/setters
function getCreatorId() { return $this->iCreatorId; }
function setCreatorId($iNewValue) { $this->iCreatorId = $iNewValue; }
function getOwnerId() { return $this->iOwnerId; }
function setOwnerId($iNewValue) { $this->iOwnerId = $iNewValue; }
function getCreatedDateTime() { return $this->dCreated; }
function getModifiedUserId() { return $this->iModifiedUserId; }
function setModifiedUserId($iNewValue) { $this->iModifiedUserId = $iNewValue; }
function getLastModifiedDate() { return $this->dModified; }
function setLastModifiedDate($dNewValue) { $this->dModified = $dNewValue; }
function getFolderId() { return $this->iFolderId; }
function setFolderId($iNewValue) { $this->iFolderId = $iNewValue; }
function getStatusId() { return $this->iStatusId; }
function setStatusId($iNewValue) { $this->iStatusId = $iNewValue; }
function getIsCheckedOut() { return $this->bIsCheckedOut; }
function setIsCheckedOut($bNewValue) { $this->bIsCheckedOut = KTUtil::anyToBool($bNewValue); }
function getCheckedOutUserId() { return $this->iCheckedOutUserId; }
function setCheckedOutUserId($iNewValue) { $this->iCheckedOutUserId = $iNewValue; }
function getPermissionObjectId() { return $this->iPermissionObjectId; }
function setPermissionObjectId($iNewValue) { $this->iPermissionObjectId = $iNewValue; }
function getPermissionLookupId() { return $this->iPermissionLookupId; }
function setPermissionLookupId($iNewValue) { $this->iPermissionLookupId = $iNewValue; }
function getMetadataVersionId() { return $this->iMetadataVersionId; }
function setMetadataVersionId($iNewValue) { $this->iMetadataVersionId = $iNewValue; }
function getMetadataVersion() { return $this->iMetadataVersion; }
function setMetadataVersion($iNewValue) { $this->iMetadataVersion = $iNewValue; }
function getFullPath() { return $this->sFullPath; }
// }}}
// {{{ getParentId
/**
* Allows documents to be treated like folders in terms of finding
* their parent objects.
*/
function getParentId() {
return $this->getFolderId();
}
// }}}
// {{{ ktentity requirements
function _fieldValues () {
$this->sFullPath = Folder::generateFolderPath($this->iFolderId);
$this->sParentFolderIds = Folder::generateFolderIds($this->iFolderId);
return parent::_fieldValues();
}
/**
* Returns a comma delimited string containing the parent folder ids, strips leading /
*
* @return String comma delimited string containing the parent folder ids
*/
function _generateFolderIds($iFolderId) {
$sFolderIds = KTDocumentCore::_generateParentFolderIds($iFolderId);
return substr($sFolderIds, 1, strlen($sFolderIds));
}
/**
* Recursively generates forward slash deliminated string giving full path of document
* from file system root url
*/
function _generateFullFolderPath($iFolderId) {
//if the folder is not the root folder
if (empty($iFolderId)) {
return;
}
$sTable = KTUtil::getTableName('folders');
$sQuery = sprintf("SELECT name, parent_id FROM %s WHERE Id = ?", $sTable);
$aParams = array($iFolderId);
$aRow = DBUtil::getOneResult(array($sQuery, $aParams));
return KTDocumentCore::_generateFullFolderPath($aRow["parent_id"]) . "/" . $aRow["name"];
}
/**
* Returns a forward slash deliminated string giving full path of document, strips leading /
*/
function _generateFolderPath($iFolderId) {
return Folder::generateFolderPath($iFolderId);
/*
$sPath = KTDocumentCore::_generateFullFolderPath($iFolderId);
$sPath = substr($sPath, 1, strlen($sPath));
return $sPath;
*/
}
// }}}
// {{{ create
function create() {
if (empty($this->dCreated)) {
$this->dCreated = getCurrentDateTime();
}
if (empty($this->dModified)) {
$this->dModified = getCurrentDateTime();
}
if (empty($this->iModifiedUserId)) {
$this->iModifiedUserId = $this->iCreatorId;
}
if (empty($this->iOwnerId)) {
$this->iOwnerId = $this->iCreatorId;
}
if (empty($this->iMetadataVersion)) {
$this->iMetadataVersion = 0;
}
if (empty($this->bIsCheckedOut)) {
$this->bIsCheckedOut = false;
}
$oFolder = Folder::get($this->getFolderId());
$this->iPermissionObjectId = $oFolder->getPermissionObjectId();
$res = parent::create();
if ($res === true) {
KTPermissionUtil::updatePermissionLookup($this);
}
return $res;
}
// }}}
// {{{ update
function update($bPathMove = false) {
$res = parent::update();
if (($res === true) && ($bPathMove === true)) {
KTPermissionUtil::updatePermissionLookup($this);
}
return $res;
}
// }}}
// {{{ get
function &get($iId) {
return KTEntityUtil::get('KTDocumentCore', $iId);
}
// }}}
// {{{ getList
function &getList($sWhere = null, $aOptions) {
return KTEntityUtil::getList2('KTDocumentCore', $sWhere, $aOptions);
}
// }}}
// {{{ _table
function _table() {
return KTUtil::getTableName('documents');
}
// }}}
// {{{ getPath
/**
* Get the full path for a document
*
* @return string full path of document
*/
function getPath() {
return Folder::getFolderPath($this->iFolderId) . $this->sFileName;
}
// }}}
function &createFromArray($aOptions) {
return KTEntityUtil::createFromArray('KTDocumentCore', $aOptions);
}
}
?>