Commit cde41478c526d072a73f83a33e83b7aeb3a6841d
1 parent
6a9cbbb9
Add KTDocumentCore, KTDocumentContentVersion, and
KTDocumentMetadataVersion for document normalisation. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4607 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
325 additions
and
0 deletions
lib/documentmanagement/documentcontentversion.inc.php
0 โ 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once(KT_LIB_DIR . '/ktentity.inc'); | |
| 4 | + | |
| 5 | +class KTDocumentContentVersion extends KTEntity { | |
| 6 | + var $_bUsePearError = true; | |
| 7 | + | |
| 8 | + /** Which document is this content a version of? */ | |
| 9 | + var $iDocumentId; | |
| 10 | + | |
| 11 | + /** What was the filename of the stored content */ | |
| 12 | + var $sFilename; | |
| 13 | + | |
| 14 | + /** How big was the stored content */ | |
| 15 | + var $iSize; | |
| 16 | + | |
| 17 | + /** Which MIME type was this content */ | |
| 18 | + var $iMimeId; | |
| 19 | + | |
| 20 | + /** User-specified major version for this content */ | |
| 21 | + var $iMajorVersion; | |
| 22 | + | |
| 23 | + /** User-specified minor version for this content */ | |
| 24 | + var $iMinorVersion; | |
| 25 | + | |
| 26 | + /** Where in the storage this file can be found */ | |
| 27 | + var $sStoragePath; | |
| 28 | + | |
| 29 | + var $_aFieldToSelect = array( | |
| 30 | + "iId" => "id", | |
| 31 | + | |
| 32 | + // transaction-related | |
| 33 | + "iDocumentId" => 'document_id', | |
| 34 | + "sFilename" => 'filename', | |
| 35 | + "iSize" => 'size', | |
| 36 | + "iMimeId" => 'mime_id', | |
| 37 | + "iMajorVersion" => 'major_version', | |
| 38 | + "iMinorVersion" => 'minor_version', | |
| 39 | + "sStoragePath" => 'storage_path', | |
| 40 | + ); | |
| 41 | + | |
| 42 | + function KTDocumentContentVersion() { | |
| 43 | + } | |
| 44 | + | |
| 45 | + | |
| 46 | +} | |
| 47 | + | |
| 48 | +?> | ... | ... |
lib/documentmanagement/documentcore.inc.php
0 โ 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once(KT_LIB_DIR . '/ktentity.inc'); | |
| 4 | + | |
| 5 | +class KTDocumentCore extends KTEntity { | |
| 6 | + var $_bUsePearError = true; | |
| 7 | + | |
| 8 | + /** The original creator of the document */ | |
| 9 | + var $iCreatorId; | |
| 10 | + | |
| 11 | + /** The creation time of the document */ | |
| 12 | + var $dCreated; | |
| 13 | + | |
| 14 | + /** The user that last modified the document */ | |
| 15 | + var $iModifiedUserId; | |
| 16 | + | |
| 17 | + /** The time of the last modification to the document */ | |
| 18 | + var $dModified; | |
| 19 | + | |
| 20 | + /** The parent folder of the document */ | |
| 21 | + var $iFolderId; | |
| 22 | + | |
| 23 | + /** List of folder from the root to the document */ | |
| 24 | + var $sParentFolderIds; | |
| 25 | + | |
| 26 | + /** Fully qualified path of the document */ | |
| 27 | + var $sFullPath; | |
| 28 | + | |
| 29 | + /** Status of the document (live, deleted, archived, &c.) */ | |
| 30 | + var $iStatusId; | |
| 31 | + | |
| 32 | + /** Where the document receives its permission information from */ | |
| 33 | + var $iPermissionObjectId; | |
| 34 | + /** The fully looked-up permission information for this document */ | |
| 35 | + var $iPermissionLookupId; | |
| 36 | + | |
| 37 | + /** The most recent metadata version for the object */ | |
| 38 | + var $iMetadataVersionId; | |
| 39 | + | |
| 40 | + var $_aFieldToSelect = array( | |
| 41 | + "iId" => "id", | |
| 42 | + | |
| 43 | + // transaction-related | |
| 44 | + "iCreatorId" => 'creator_id', | |
| 45 | + "dCreated" => 'created', | |
| 46 | + "iModifiedUserId" => 'modified_user_id', | |
| 47 | + "dModified" => 'modified', | |
| 48 | + | |
| 49 | + | |
| 50 | + // location-related | |
| 51 | + "iFolderId" => 'folder_id', | |
| 52 | + "sParentFolderIds" => 'parent_folder_ids', | |
| 53 | + "sFullPath" => 'full_path', | |
| 54 | + | |
| 55 | + // status | |
| 56 | + "iStatusId" => 'status_id', | |
| 57 | + | |
| 58 | + // permission-related | |
| 59 | + "iPermissionObjectId" => 'permission_object_id', | |
| 60 | + "iPermissionLookupId" => 'permission_lookup_id', | |
| 61 | + ); | |
| 62 | + | |
| 63 | + function KTDocument() { | |
| 64 | + } | |
| 65 | + | |
| 66 | + // {{{ getters/setters | |
| 67 | + function getCreatorId() { return $this->iCreatorId; } | |
| 68 | + function setCreatorId($iNewValue) { $this->iCreatorId = $iNewValue; } | |
| 69 | + function getCreatedDateTime() { return $this->dCreated; } | |
| 70 | + function getModifiedUserId() { return $this->iModifiedUserId; } | |
| 71 | + function setModifiedUserId($iNewValue) { $this->iModifiedUserId = $iNewValue; } | |
| 72 | + function getLastModifiedDate() { return $this->dModified; } | |
| 73 | + function setLastModifiedDate($dNewValue) { $this->dModified = $dNewValue; } | |
| 74 | + | |
| 75 | + function getFolderId() { return $this->iFolderId; } | |
| 76 | + function setFolderId($iNewValue) { $this->iFolderId = $iNewValue; } | |
| 77 | + | |
| 78 | + function getStatusId() { return $this->iStatusId; } | |
| 79 | + function setStatusId($iNewValue) { $this->iStatusId = $iNewValue; } | |
| 80 | + | |
| 81 | + function getPermissionObjectId() { return $this->iPermissionObjectId; } | |
| 82 | + function setPermissionObjectId($iNewValue) { $this->iPermissionObjectId = $iNewValue; } | |
| 83 | + function getPermissionLookupId() { return $this->iPermissionLookupId; } | |
| 84 | + function setPermissionLookupId($iNewValue) { $this->iPermissionLookupId = $iNewValue; } | |
| 85 | + // }}} | |
| 86 | + | |
| 87 | + // {{{ getParentId | |
| 88 | + /** | |
| 89 | + * Allows documents to be treated like folders in terms of finding | |
| 90 | + * their parent objects. | |
| 91 | + */ | |
| 92 | + function getParentId() { | |
| 93 | + return $this->getFolderId(); | |
| 94 | + } | |
| 95 | + // }}} | |
| 96 | + | |
| 97 | + // {{{ ktentity requirements | |
| 98 | + function _fieldValues () { | |
| 99 | + $this->sFullPath = KTDocument::_generateFolderPath($this->iFolderId); | |
| 100 | + $this->sParentFolderIds = KTDocument::_generateFolderIds($this->iFolderId); | |
| 101 | + return parent::_fieldValues(); | |
| 102 | + } | |
| 103 | + | |
| 104 | + /** | |
| 105 | + * Recursive function to generate a comma delimited string containing | |
| 106 | + * the parent folder ids | |
| 107 | + * | |
| 108 | + * @return String comma delimited string containing the parent folder ids | |
| 109 | + */ | |
| 110 | + function _generateParentFolderIds($iFolderId) { | |
| 111 | + $sTable = KTUtil::getTableName('folders'); | |
| 112 | + if (empty($iFolderId)) { | |
| 113 | + return; | |
| 114 | + } | |
| 115 | + | |
| 116 | + $sQuery = sprintf('SELECT parent_id FROM %s WHERE id = ?', $sTable); | |
| 117 | + $aParams = array($iFolderId); | |
| 118 | + $iParentId = DBUtil::getOneResultKey(array($sQuery, $aParams), 'parent_id'); | |
| 119 | + return Document::_generateParentFolderIds($iParentId) . ",$iFolderId"; | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Returns a comma delimited string containing the parent folder ids, strips leading / | |
| 124 | + * | |
| 125 | + * @return String comma delimited string containing the parent folder ids | |
| 126 | + */ | |
| 127 | + function _generateFolderIds($iFolderId) { | |
| 128 | + $sFolderIds = Document::_generateParentFolderIds($iFolderId); | |
| 129 | + return substr($sFolderIds, 1, strlen($sFolderIds)); | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * Recursively generates forward slash deliminated string giving full path of document | |
| 134 | + * from file system root url | |
| 135 | + */ | |
| 136 | + function _generateFullFolderPath($iFolderId) { | |
| 137 | + global $default; | |
| 138 | + //if the folder is not the root folder | |
| 139 | + if (empty($iFolderId)) { | |
| 140 | + return; | |
| 141 | + } | |
| 142 | + $sQuery = sprintf("SELECT name, parent_id FROM %s WHERE Id = ?", $sTable); | |
| 143 | + $aParams = array($iFolderId); | |
| 144 | + $aRow = DBUtil::getOneResult(array($sQuery, $aParams)); | |
| 145 | + return Document::_generateFullFolderPath($aRow["parent_id"]) . "/" . $aRow["name"]; | |
| 146 | + } | |
| 147 | + | |
| 148 | + /** | |
| 149 | + * Returns a forward slash deliminated string giving full path of document, strips leading / | |
| 150 | + */ | |
| 151 | + function _generateFolderPath($iFolderId) { | |
| 152 | + global $default; | |
| 153 | + $sPath = Document::_generateFullFolderPath($iFolderId); | |
| 154 | + $sPath = substr($sPath, 1, strlen($sPath)); | |
| 155 | + return $sPath; | |
| 156 | + } | |
| 157 | + // }}} | |
| 158 | + | |
| 159 | + // {{{ create | |
| 160 | + function create() { | |
| 161 | + if (empty($this->dCreated)) { | |
| 162 | + $this->dCreated = getCurrentDateTime(); | |
| 163 | + } | |
| 164 | + if (empty($this->dModified)) { | |
| 165 | + $this->dModified = getCurrentDateTime(); | |
| 166 | + } | |
| 167 | + if (empty($this->iModifiedUserId)) { | |
| 168 | + $this->iModifiedUserId = $this->iCreatorId; | |
| 169 | + } | |
| 170 | + $oFolder = Folder::get($this->getFolderId()); | |
| 171 | + $this->iPermissionObjectId = $oFolder->getPermissionObjectId(); | |
| 172 | + $res = parent::create(); | |
| 173 | + | |
| 174 | + if ($res === true) { | |
| 175 | + KTPermissionUtil::updatePermissionLookup($this); | |
| 176 | + } | |
| 177 | + | |
| 178 | + return $res; | |
| 179 | + } | |
| 180 | + // }}} | |
| 181 | + | |
| 182 | + // {{{ update | |
| 183 | + function update($bPathMove = false) { | |
| 184 | + $res = parent::update(); | |
| 185 | + if (($res === true) && ($bPathMove === true)) { | |
| 186 | + KTPermissionUtil::updatePermissionLookup($this); | |
| 187 | + } | |
| 188 | + return $res; | |
| 189 | + } | |
| 190 | + // }}} | |
| 191 | + | |
| 192 | + // {{{ get | |
| 193 | + function &get($iId) { | |
| 194 | + return KTEntityUtil::get('KTDocument', $iId); | |
| 195 | + } | |
| 196 | + // }}} | |
| 197 | + | |
| 198 | + | |
| 199 | +} | |
| 200 | + | |
| 201 | +?> | ... | ... |
lib/documentmanagement/documentmetadataversion.inc.php
0 โ 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once(KT_LIB_DIR . '/ktentity.inc'); | |
| 4 | + | |
| 5 | +class KTDocumentMetadataVersion extends KTEntity { | |
| 6 | + var $_bUsePearError = true; | |
| 7 | + | |
| 8 | + /** Which document we are a version of */ | |
| 9 | + var $iDocumentId; | |
| 10 | + | |
| 11 | + /** Which metadata version of the document we are describing */ | |
| 12 | + var $iMetadataVersion; | |
| 13 | + | |
| 14 | + /** Which content was associated with this metadata version */ | |
| 15 | + var $iContentVersionId; | |
| 16 | + | |
| 17 | + /** The document type of the document during this version */ | |
| 18 | + var $iDocumentTypeId; | |
| 19 | + | |
| 20 | + /** The name of the document during this version */ | |
| 21 | + var $sName; | |
| 22 | + | |
| 23 | + /** The description of the document during this version */ | |
| 24 | + var $sDescription; | |
| 25 | + | |
| 26 | + /** The status of the document during this version */ | |
| 27 | + var $iStatusId; | |
| 28 | + | |
| 29 | + /** When this version was created */ | |
| 30 | + var $dVersionCreated; | |
| 31 | + | |
| 32 | + /** Who created this version */ | |
| 33 | + var $iVersionCreatorId; | |
| 34 | + | |
| 35 | + var $_aFieldToSelect = array( | |
| 36 | + "iId" => "id", | |
| 37 | + | |
| 38 | + "iDocumentId" => 'document_id', | |
| 39 | + "iMetadataVersion" => 'metadata_version', | |
| 40 | + "iContentVersionId" => 'content_version_id', | |
| 41 | + | |
| 42 | + "iDocumentTypeId" => 'document_type_id', | |
| 43 | + | |
| 44 | + "sName" => 'name', | |
| 45 | + "sDescription" => 'description', | |
| 46 | + | |
| 47 | + "iStatusId" => 'status_id', | |
| 48 | + | |
| 49 | + "dVersionCreated" => 'version_created', | |
| 50 | + "iVersionCreatorId" => 'version_creator_id', | |
| 51 | + ); | |
| 52 | + | |
| 53 | + function KTDocumentMetadataVersion() { | |
| 54 | + } | |
| 55 | + | |
| 56 | + // {{{ getters/setters | |
| 57 | + function getDocumentId() { return $this->iDocumentId; } | |
| 58 | + function setDocumentId($iNewValue) { $this->iDocumentId = $iNewValue; } | |
| 59 | + function getMetadataVersion() { return $this->iMetadataVersion; } | |
| 60 | + function setMetadataVersion($iNewValue) { $this->iMetadataVersion = $iNewValue; } | |
| 61 | + function getDocumentTypeId() { return $this->iDocumentTypeId; } | |
| 62 | + function setDocumentTypeId($iNewValue) { $this->iDocumentTypeId = $iNewValue; } | |
| 63 | + function getName() { return $this->sName; } | |
| 64 | + function setName($sNewValue) { $this->sName = $sNewValue; } | |
| 65 | + function getDescription() { return $this->sDescription; } | |
| 66 | + function setDescription($sNewValue) { $this->sDescription = $sNewValue; } | |
| 67 | + function getStatusId() { return $this->sStatusId; } | |
| 68 | + function setStatusId($iNewValue) { $this->sStatusId = $iNewValue; } | |
| 69 | + function getVersionCreated() { return $this->dVersionCreated; } | |
| 70 | + function setVersionCreated($dNewValue) { $this->dVersionCreated = $dNewValue; } | |
| 71 | + function getVersionCreatorId() { return $this->iVersionCreatorId; } | |
| 72 | + function setVersionCreatorId($iNewValue) { $this->iVersionCreatorId = $iNewValue; } | |
| 73 | + // }}} | |
| 74 | +} | |
| 75 | + | |
| 76 | +?> | ... | ... |