Commit 4b20daa4789a36056cf5c3b80284fce6700dcd72
1 parent
50d74899
Initial revision. Object that represents the documents table in the database
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@229 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
284 additions
and
0 deletions
lib/documentmanagement/Document.inc
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | +* Class Document | |
| 4 | +* | |
| 5 | +* Represents a document as per the documents database table | |
| 6 | +* | |
| 7 | +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | |
| 8 | +* @date 15 January 2003 | |
| 9 | +* | |
| 10 | +*/ | |
| 11 | + | |
| 12 | +require_once("$default->owl_root_url/lib/foldermanagement/FolderLib.inc"); | |
| 13 | + | |
| 14 | +class Document { | |
| 15 | + /** primary key */ | |
| 16 | + var $iId; | |
| 17 | + /** document type primary key */ | |
| 18 | + var $iDocumentTypeID; | |
| 19 | + /** document name */ | |
| 20 | + var $sName; | |
| 21 | + /** document file name (path to document on file system) */ | |
| 22 | + var $sFileName; | |
| 23 | + /** document file size */ | |
| 24 | + var $iSize | |
| 25 | + /** primary key of user who created document */ | |
| 26 | + var $iCreatorID; | |
| 27 | + /** date the document was last modified */ | |
| 28 | + var $dModified; | |
| 29 | + /** file description */ | |
| 30 | + var $sDescription | |
| 31 | + /** primary key of file mime type */ | |
| 32 | + var $iMimeTypeID; | |
| 33 | + /** primary key of folder under which document is stored */ | |
| 34 | + var $iFolderID; | |
| 35 | + /** major revision number */ | |
| 36 | + var $iMajorVersion; | |
| 37 | + /** minor revision number */ | |
| 38 | + var $iMinorVersion; | |
| 39 | + /** document checked out status */ | |
| 40 | + var $bIsCheckedOut; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Create a new document | |
| 44 | + * | |
| 45 | + * @param $sName File Name | |
| 46 | + * @param $iSize File size in bytes | |
| 47 | + * @param $iCreatorID Primary key of user who created document | |
| 48 | + * @param $sDescription Description | |
| 49 | + * @param $iMimeID Primary key of file mime type | |
| 50 | + * @param $iFolderID Primary key of folder to which document belongs | |
| 51 | + * | |
| 52 | + * @return Document document on successful creation, false otherwise and set $_SESSION["errorMessage"] | |
| 53 | + * | |
| 54 | + */ | |
| 55 | + function Document($sNewName, $iNewSize, $iNewCreatorID, $sNewDescription, $iNewMimeID, $iNewFolderID) { | |
| 56 | + $this->iId = -1; //primary key not set as document is not stored yet | |
| 57 | + $this->sName = $sNewName; | |
| 58 | + $this->iSize = $iNewSize; | |
| 59 | + $this->iCreatorID = $iNewCreatorID; | |
| 60 | + $this->sDescription = $sNewDescription; | |
| 61 | + $this->iMimeTypeID = $iNewMimeID; | |
| 62 | + $this->iFolderID = $iNewFolderID; | |
| 63 | + $this->iDocumentTypeID = FolderLib::getFolderDocumentType($this->iFolderID); | |
| 64 | + $this->iMajorRevision = 0; | |
| 65 | + $this->iMinorRevision = 1; | |
| 66 | + $this->bIsCheckOut = false; | |
| 67 | + } | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Insert the current document into the database | |
| 71 | + * | |
| 72 | + * @return boolean true on successful insert, false otherwise and set $_SESSION["errorMessage"] | |
| 73 | + */ | |
| 74 | + function create() { | |
| 75 | + global $default, $lang_err_doc_exist, $lang_err_database; | |
| 76 | + if (!DocumentManager::documentExists($sName, $iFolderID)) { | |
| 77 | + $sql = new Owl_DB(); | |
| 78 | + $result = $sql->query("INSERT INTO " . $default->owl_documents_table . " (document_type_id, name, file_name, size, creator_id, modified, description, mime_id, folder_id, major_version, minor_version, is_checked_out" . | |
| 79 | + "VALUES (" . $this->iDocumentTypeID . ", '. " addslashes($this->sName) . "', '" . addslashes($this->sFileName) . "', $this->iSize, $this->iCreatorID, " . getCurrentDateTime() . ", '" . addslashes($this->sDescription) . "', $this->iMimeTypeID, $this->iFolderID, $this->iMajorRevision, $this->iMinorRevision, $this->bIsCheckOut)"); | |
| 80 | + if ($result) { | |
| 81 | + //set the current documents primary key | |
| 82 | + $this->iId = $sql->insert_id(); | |
| 83 | + return true; | |
| 84 | + } | |
| 85 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 86 | + return false; | |
| 87 | + } | |
| 88 | + $_SESSION["errorMessage"] = $lang_err_doc_exist . "name = " . $sName . " folder_id = " . $iFolderID; | |
| 89 | + return false; | |
| 90 | + } | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * Update the documents current values in the database | |
| 94 | + * | |
| 95 | + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | |
| 96 | + */ | |
| 97 | + function update() { | |
| 98 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 99 | + if ($this->iId >= 0) { | |
| 100 | + $sql = new Owl_DB(); | |
| 101 | + $result = $sql->query("UPDATE " . $default->owl_documents_table . " SET " . | |
| 102 | + "document_typeid = $this->iDocumentTypeID, " . | |
| 103 | + "file_name = '" . addslashes($this->file_name)"', " . | |
| 104 | + "size = $this->iSize, " . | |
| 105 | + "creator_id = $this->iCreatorID, " . | |
| 106 | + "modified = " . getCurrentDateTime() . ", " . | |
| 107 | + "description = '" . addslashes($this->sDescription) . "', " . | |
| 108 | + "mime_id = $this->iMimeTypeID, " . | |
| 109 | + "folder_id = $this->iFolderID, " . | |
| 110 | + "major_revision = $this->iMajorRevision, " . | |
| 111 | + "minor_revision = $this->iMinorRevision, " . | |
| 112 | + "is_checked_out = $this->bIsCheckedOut " . | |
| 113 | + "WHERE id = $this->id"); | |
| 114 | + if ($result) { | |
| 115 | + return true; | |
| 116 | + } | |
| 117 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 118 | + return false; | |
| 119 | + } | |
| 120 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 121 | + return false; | |
| 122 | + | |
| 123 | + } | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * Delete the current document from the database. Set the primary key to -1 | |
| 127 | + * on successful deletion | |
| 128 | + * | |
| 129 | + * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"] | |
| 130 | + */ | |
| 131 | + function delete() { | |
| 132 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 133 | + if ($this->iId >= 0) { | |
| 134 | + $sql = new Owl_DB(); | |
| 135 | + $result = $sql->query("DELETE FROM " . $default->owl_documents_table . " WHERE id = $this->id"); | |
| 136 | + if ($result) { | |
| 137 | + $this->iId = -1; | |
| 138 | + return true; | |
| 139 | + } | |
| 140 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 141 | + return false; | |
| 142 | + } | |
| 143 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 144 | + return false; | |
| 145 | + } | |
| 146 | + | |
| 147 | + | |
| 148 | + /** | |
| 149 | + * | |
| 150 | + * Static function. Given a document primary key will create | |
| 151 | + * a document object and populate it with the corresponding | |
| 152 | + * database values | |
| 153 | + * | |
| 154 | + * @return Document populated Document object on success, false otherwise and set $_SESSION["errorMessage"] | |
| 155 | + */ | |
| 156 | + function & get($iDocumentID) { | |
| 157 | + global $default, $lang_err_doc_not_exist; | |
| 158 | + $sql = new Owl_DB(); | |
| 159 | + $sql->query("SELECT * FROM " . $default->owl_documents_table " WHERE id = " $iDocumentID); | |
| 160 | + if ($sql->next_record()) { | |
| 161 | + doc = new Document(stripslashes($sql->f("name")), $sql->("size"), $sql->f("creator_id"), $sql->f("description"), $sql->f("mime_id"), $sql->f("folder_id")); | |
| 162 | + doc->setDocumentTypeID($sql->f("document_type_id")); | |
| 163 | + doc->setMajorRevision($sql->f("major_revision")); | |
| 164 | + doc->setMinorRevision($sql->f("minor_revision")); | |
| 165 | + doc->setIsCheckedOut(sql->f("is_checked_out")); | |
| 166 | + return doc; | |
| 167 | + } | |
| 168 | + $_SESSION["errorMessage"] = $lang_err_doc_not_exist . "id " . $iDocumentID; | |
| 169 | + return false; | |
| 170 | + } | |
| 171 | + | |
| 172 | + /** Get the document type id */ | |
| 173 | + function getDocumentTypeID() { | |
| 174 | + return $this->iDocumentTypeID; | |
| 175 | + } | |
| 176 | + | |
| 177 | + /** set the document type id */ | |
| 178 | + function setDocumentTypeID($sNewValue) { | |
| 179 | + $this->iDocumentTypeID = $sNewValue; | |
| 180 | + } | |
| 181 | + | |
| 182 | + /** get the document name */ | |
| 183 | + function getName() { | |
| 184 | + return $this->sName; | |
| 185 | + } | |
| 186 | + | |
| 187 | + /** set the document name */ | |
| 188 | + function setName($sNewValue) { | |
| 189 | + $this->sName = $sNewValue; | |
| 190 | + } | |
| 191 | + | |
| 192 | + /** get the document path on the file system */ | |
| 193 | + function getFileName() { | |
| 194 | + return $this->sFileName; | |
| 195 | + } | |
| 196 | + | |
| 197 | + /** set the document path on the file system */ | |
| 198 | + function setFileName() { | |
| 199 | + $this->sFileName = $sNewValue; | |
| 200 | + } | |
| 201 | + | |
| 202 | + /** get the document file size in bytes */ | |
| 203 | + function getFileSize() { | |
| 204 | + return $this->iSize; | |
| 205 | + } | |
| 206 | + | |
| 207 | + /** set the document file size in bytes */ | |
| 208 | + function setFileSize($iNewValue) { | |
| 209 | + $this->iSize = $iNewValue; | |
| 210 | + } | |
| 211 | + | |
| 212 | + /** get the document creator id */ | |
| 213 | + function getCreatorID() { | |
| 214 | + return $this->iCreatorID; | |
| 215 | + } | |
| 216 | + | |
| 217 | + /** set the document creator id */ | |
| 218 | + function setCreatorID($iNewValue) { | |
| 219 | + $this->iCreatorID = $iNewValue; | |
| 220 | + } | |
| 221 | + | |
| 222 | + /** get the document last modified date */ | |
| 223 | + function getLastModifiedDate() { | |
| 224 | + return $this->dModified; | |
| 225 | + } | |
| 226 | + | |
| 227 | + /** set the document last modified date */ | |
| 228 | + function setLastModifiedDate($dNewValue) { | |
| 229 | + $this->dModified = $dNewValue; | |
| 230 | + } | |
| 231 | + | |
| 232 | + /** get the document description */ | |
| 233 | + function getDescription() { | |
| 234 | + return $this->sDescription; | |
| 235 | + } | |
| 236 | + | |
| 237 | + /** set the document description */ | |
| 238 | + function setDescription($sNewValue) { | |
| 239 | + $this->sDescription = $sNewValue; | |
| 240 | + } | |
| 241 | + | |
| 242 | + /** get the document mime type primary key */ | |
| 243 | + function getMimeTypeID() { | |
| 244 | + return $this->iMimeTypeID; | |
| 245 | + } | |
| 246 | + | |
| 247 | + /** get the document mime type primary key */ | |
| 248 | + function setMimeTypeID($iNewValue) { | |
| 249 | + $this->iMimeTypeID = $iNewValue; | |
| 250 | + } | |
| 251 | + | |
| 252 | + /** get the major version number */ | |
| 253 | + function getMajorVersionNumber() { | |
| 254 | + return $this->iMajorVersion; | |
| 255 | + } | |
| 256 | + | |
| 257 | + /** set the major version number */ | |
| 258 | + function setMajorVersionNumber($iNewValue) { | |
| 259 | + $this->iMajorVersion = $iNewValue; | |
| 260 | + } | |
| 261 | + | |
| 262 | + /** get the minor version number */ | |
| 263 | + function getMinorVersionNumber() { | |
| 264 | + return $this->iMinorVersion; | |
| 265 | + } | |
| 266 | + | |
| 267 | + /** set the minor version number */ | |
| 268 | + function setMinorVersionNumber($iNewValue) { | |
| 269 | + $this->iMinorVersionNumber = $iNewValue; | |
| 270 | + } | |
| 271 | + | |
| 272 | + /** get the document check out status */ | |
| 273 | + function getIsCheckedOut() { | |
| 274 | + return $this->bCheckedOut; | |
| 275 | + } | |
| 276 | + | |
| 277 | + /** set the document check out status */ | |
| 278 | + function setIsCheckedOut($bNewValue) { | |
| 279 | + $this->bCheckedOut = $bNewValue; | |
| 280 | + } | |
| 281 | + | |
| 282 | +} | |
| 283 | + | |
| 284 | +?> | ... | ... |