Commit bb078c4bd69d424082b03e65fdddbd519a65fe9d
1 parent
d0413f68
Initial revision. Relects the folder_doctypes_link table
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1175 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
150 additions
and
0 deletions
lib/foldermanagement/FolderDocTypeLink.inc
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | +* Represents an entry in the database as per the folder_doctype_link table | ||
| 4 | +* | ||
| 5 | +* @author Rob Cherry, Jam Warehouse South Africa (Pty) Ltd | ||
| 6 | +* @date 27 February 2003 | ||
| 7 | +* @package | ||
| 8 | +*/ | ||
| 9 | + | ||
| 10 | +class FolderDocTypeLink { | ||
| 11 | + | ||
| 12 | + /** primary key of object */ | ||
| 13 | + var $iId; | ||
| 14 | + /** primary key of folder */ | ||
| 15 | + var $iFolderID; | ||
| 16 | + /** primary key of document type */ | ||
| 17 | + var $iDocumentTypeID; | ||
| 18 | + | ||
| 19 | + function FolderDocTypeLink($iNewFolderID, $iNewDocumentTypeID) { | ||
| 20 | + $this->iId = -1; | ||
| 21 | + $this->iFolderID = $iNewFolderID; | ||
| 22 | + $this->iDocumentTypeID = $iNewDocumentTypeID; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * Create the current folder in the database | ||
| 27 | + * | ||
| 28 | + * @return boolean true and set $this->iId with new primary key, false otherwise and set $_SESSION["errorMessage"] | ||
| 29 | + */ | ||
| 30 | + function create() { | ||
| 31 | + global $default, $lang_err_database; $lang_err_object_exists; | ||
| 32 | + //if the object has not already been stored | ||
| 33 | + if ($this->iId < 0) { | ||
| 34 | + $sql = $default->db; | ||
| 35 | + $result = $sql->query("INSERT INTO " . $default->owl_folder_doctypes_table . " (folder_id, document_type_id) " . | ||
| 36 | + "VALUES ($this->iFolderID, $this->iDocumentTypeID)"); | ||
| 37 | + if ($result) { | ||
| 38 | + $this->iId = $sql->insert_id(); | ||
| 39 | + return true; | ||
| 40 | + } | ||
| 41 | + $_SESSION["errorMessage"] = $lang_err_database; | ||
| 42 | + return false; | ||
| 43 | + } | ||
| 44 | + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = folders"; | ||
| 45 | + return false; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Update the current folder values in the database | ||
| 50 | + * | ||
| 51 | + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | ||
| 52 | + */ | ||
| 53 | + function update() { | ||
| 54 | + global $default, $lang_err_database, $lang_err_object_key; | ||
| 55 | + //can only update the object if it has already been stored | ||
| 56 | + $sOldPath; | ||
| 57 | + if ($this->iId >= 0) { | ||
| 58 | + if ($bPathChange){ | ||
| 59 | + $sOldPath = $default->documentRoot . "/" . $this->sFullPath . "/" . $this->sName; | ||
| 60 | + } | ||
| 61 | + $sql = $default->db; | ||
| 62 | + $sQuery = "UPDATE " . $default->owl_folder_doctypes_table . " SET " . | ||
| 63 | + "folder_id = $this->iFolderID, " . | ||
| 64 | + "document_type_id = $this->iDocumentTypeID " . | ||
| 65 | + "WHERE id = " . $this->iId; | ||
| 66 | + $result = $sql->query($sQuery); | ||
| 67 | + if ($result) { | ||
| 68 | + return true; | ||
| 69 | + } | ||
| 70 | + $_SESSION["errorMessage"] = $lang_err_database; | ||
| 71 | + return false; | ||
| 72 | + } | ||
| 73 | + $_SESSION["errorMessage"] = $lang_err_object_key; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * Delete the current object from the database | ||
| 78 | + * | ||
| 79 | + * @return boolean true and reset id to -1 on successful delete, false otherwise and set $_SESSION["errorMessage"] | ||
| 80 | + */ | ||
| 81 | + function delete() { | ||
| 82 | + global $default, $lang_err_database, $lang_err_object_key; | ||
| 83 | + if ($this->iId >= 0) { | ||
| 84 | + $sql = $default->db; | ||
| 85 | + $result = $sql->query("DELETE FROM " . $default->owl_folder_doctypes_table . " WHERE id = " . $this->iId); | ||
| 86 | + if ($result) { | ||
| 87 | + $this->iId = -1; | ||
| 88 | + return true; | ||
| 89 | + } | ||
| 90 | + $_SESSION["errorMessage"] = $lang_err_database; | ||
| 91 | + return false; | ||
| 92 | + } | ||
| 93 | + $_SESSION["errorMessage"] = $lang_err_object_key; | ||
| 94 | + return false; | ||
| 95 | + | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * Static function. | ||
| 100 | + * Given a folder_doctype_link primary key will create | ||
| 101 | + * a FolderDocTypeLink object and populate it with the corresponding | ||
| 102 | + * database values | ||
| 103 | + * | ||
| 104 | + * @param $iFolderDocTypeID Primary key of folder to get | ||
| 105 | + * | ||
| 106 | + * @return Folder folder object on successful retrieval, false otherwise and set $_SESSION["errorMessage"] | ||
| 107 | + */ | ||
| 108 | + function get($iFolderDocTypeLinkID) { | ||
| 109 | + global $default, $lang_err_object_not_exist; | ||
| 110 | + $sql = $default->db; | ||
| 111 | + $sql->query("SELECT * FROM " . $default->owl_folder_doctypes_table . " WHERE id = " . $iFolderDocTypeLinkID); | ||
| 112 | + if ($sql->next_record()) { | ||
| 113 | + $oFolderDocTypeLink = & new FolderDocTypeLink($sql->f("folder_id"), $sql->f("document_type_id")); | ||
| 114 | + $oFolderDocTypeLink->iId = $iFolderDocTypeLinkID; | ||
| 115 | + return $oFolderDocTypeLink; | ||
| 116 | + } | ||
| 117 | + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iFolderID . " table = folders"; | ||
| 118 | + return false; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /** | ||
| 122 | + * Static function | ||
| 123 | + * Get a list of Documents | ||
| 124 | + * | ||
| 125 | + * @param String Where clause (not required) | ||
| 126 | + * | ||
| 127 | + * @return Array array of Documents objects, false otherwise and set $_SESSION["errorMessage"] | ||
| 128 | + */ | ||
| 129 | + function getList($sWhereClause = null) { | ||
| 130 | + global $default, $lang_err_database; | ||
| 131 | + $aFolderDocTypeLinkArray; | ||
| 132 | + settype($aFolderDocTypeLinkArray, "array"); | ||
| 133 | + $sql = $default->db; | ||
| 134 | + // TODO: join on sys_deleted | ||
| 135 | + $result = $sql->query("SELECT * FROM " . $default->owl_folder_doctypes_table . (isset($sWhereClause) ? " WHERE " . $sWhereClause : "")); | ||
| 136 | + if ($result) { | ||
| 137 | + $iCount = 0; | ||
| 138 | + while ($sql->next_record()) { | ||
| 139 | + $oFolderDocTypeLink = & FolderDocTypeLink::get($sql->f("id")); | ||
| 140 | + $aFolderDocTypeLinkArray[$iCount] = $oFolderDocTypeLink; | ||
| 141 | + $iCount++; | ||
| 142 | + } | ||
| 143 | + return $aFolderDocTypeLinkArray; | ||
| 144 | + } | ||
| 145 | + $_SESSION["errorMessage"] = $lang_err_database; | ||
| 146 | + return false; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | +} | ||
| 150 | +?> |