Commit 0b9857ca91a05c453f1e4f038b0dfe8f582ada49
1 parent
8cbebbba
Initial revision. Object represents document_fields_link db table
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@347 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
202 additions
and
0 deletions
lib/documentmanagement/DocumentFieldLink.inc
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | +* Class DocumentFieldLink | ||
| 5 | +* | ||
| 6 | +* Represents a document field link as per the database table document_fields_link | ||
| 7 | +* | ||
| 8 | +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | ||
| 9 | +* @date 19 January 2003 | ||
| 10 | +*/ | ||
| 11 | + | ||
| 12 | +class DocumentFieldLink { | ||
| 13 | + | ||
| 14 | + /** document field link primary key */ | ||
| 15 | + var $iId; | ||
| 16 | + /** primary key of document to which field is linked */ | ||
| 17 | + var $iDocumentID; | ||
| 18 | + /** primary key of field to which document is linked */ | ||
| 19 | + var $iDocumentFieldID; | ||
| 20 | + /** field value */ | ||
| 21 | + var $sValue; | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * Default constructor | ||
| 26 | + * | ||
| 27 | + * @param Primary key of document to which field is linked | ||
| 28 | + * @param Primary key of field to which document is linked | ||
| 29 | + * @param Value of field | ||
| 30 | + * | ||
| 31 | + */ | ||
| 32 | + function DocumentFieldLink($iNewDocumentID, $iNewDocumentFieldID, $sNewValue) { | ||
| 33 | + //object not create in database yet | ||
| 34 | + $this->iId = -1; | ||
| 35 | + $this->iDocumentID = $iNewDocumentID; | ||
| 36 | + $this->iDocumentFieldID = $iNewDocumentFieldID; | ||
| 37 | + $this->sValue = $sNewValue; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * Get the document field link primary key | ||
| 42 | + * | ||
| 43 | + * @return int document field link primary key | ||
| 44 | + * | ||
| 45 | + */ | ||
| 46 | + function getID() { | ||
| 47 | + return $this->iId; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * Get the primary key of the document to which the field is linked | ||
| 52 | + * | ||
| 53 | + * @return int document primary key to which the field is linked | ||
| 54 | + * | ||
| 55 | + */ | ||
| 56 | + function getDocumentID() { | ||
| 57 | + return $this->iDocumentID; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * Set the primary key of the document to which the field is linked | ||
| 62 | + * | ||
| 63 | + * @param Document primary key to which field is linked | ||
| 64 | + * | ||
| 65 | + */ | ||
| 66 | + function setDocumentID($iNewValue) { | ||
| 67 | + $this->iDocumentID = $iNewValue; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * Get the primary key of the field to which the document is linked | ||
| 72 | + * | ||
| 73 | + * @return int primary key of field to which the document is related | ||
| 74 | + * | ||
| 75 | + */ | ||
| 76 | + function getDocumentFieldID() { | ||
| 77 | + return $this->iDocumentFieldID; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * Set the primary key of the field to which the document is related | ||
| 82 | + * | ||
| 83 | + * @param New primary key of field to which document is related | ||
| 84 | + * | ||
| 85 | + */ | ||
| 86 | + function setDocumentFieldID($iNewVale) { | ||
| 87 | + $this->iDocumentFieldID = $iNewValue; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * Get the value of the field | ||
| 92 | + * | ||
| 93 | + * @return String value of the field | ||
| 94 | + * | ||
| 95 | + */ | ||
| 96 | + function getValue() { | ||
| 97 | + return $this->sValue; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * Set the value of the field | ||
| 102 | + * | ||
| 103 | + * @param New value of the field | ||
| 104 | + * | ||
| 105 | + */ | ||
| 106 | + function setValue($sNewValue) { | ||
| 107 | + $this->sValue = $sNewValue; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * Insert the current document into the database | ||
| 112 | + * | ||
| 113 | + * @return boolean true on successful insert, false otherwise and set $_SESSION["errorMessage"] | ||
| 114 | + */ | ||
| 115 | + function create() { | ||
| 116 | + global $default, $lang_err_doc_exist, $lang_err_database; | ||
| 117 | + //if the id >= 0, then the object has already been created | ||
| 118 | + if ($this->iId < 0) { | ||
| 119 | + $sql = new Owl_DB(); | ||
| 120 | + $result = $sql->query("INSERT INTO " . $default->owl_document_fields_table . " (document_id, document_field_id, value) " . | ||
| 121 | + "VALUES ($this->iDocumentID, $this->iDocumentFieldID, '" . addslashes($this->sValue) . "')"); | ||
| 122 | + if ($result) { | ||
| 123 | + //set the current documents primary key | ||
| 124 | + $this->iId = $sql->insert_id(); | ||
| 125 | + return true; | ||
| 126 | + } | ||
| 127 | + $_SESSION["errorMessage"] = $lang_err_database; | ||
| 128 | + return false; | ||
| 129 | + } | ||
| 130 | + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_document_fields_table"; | ||
| 131 | + return false; | ||
| 132 | + | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * Update the documents current values in the database | ||
| 137 | + * | ||
| 138 | + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | ||
| 139 | + */ | ||
| 140 | + function update() { | ||
| 141 | + global $default, $lang_err_database, $lang_err_object_key; | ||
| 142 | + if ($this->iId >= 0) { | ||
| 143 | + $sql = new Owl_DB(); | ||
| 144 | + $result = $sql->query("UPDATE " . $default->owl_document_fields_table . " SET " . | ||
| 145 | + "document_id = $this->iDocumentID, document_field_id = $this->iDocumentFieldID, value = '" . addslashes($this->sValue) . "'" . | ||
| 146 | + "WHERE id = $this->iId"); | ||
| 147 | + if ($result) { | ||
| 148 | + return true; | ||
| 149 | + } | ||
| 150 | + $_SESSION["errorMessage"] = $lang_err_database; | ||
| 151 | + return false; | ||
| 152 | + } | ||
| 153 | + $_SESSION["errorMessage"] = $lang_err_object_key; | ||
| 154 | + return false; | ||
| 155 | + | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + /** | ||
| 159 | + * Delete the current document from the database. Set the primary key to -1 | ||
| 160 | + * on successful deletion | ||
| 161 | + * | ||
| 162 | + * @return boolean true and reset id to -1 on successful deletion, false otherwise and set $_SESSION["errorMessage"] | ||
| 163 | + */ | ||
| 164 | + function delete() { | ||
| 165 | + global $default, $lang_err_database, $lang_err_object_key; | ||
| 166 | + if ($this->iId >= 0) { | ||
| 167 | + $sql = new Owl_DB(); | ||
| 168 | + $result = $sql->query("DELETE FROM " . $default->owl_document_fields_table . " WHERE id = $this->iId"); | ||
| 169 | + if ($result) { | ||
| 170 | + $this->iId = -1; | ||
| 171 | + return true; | ||
| 172 | + } | ||
| 173 | + $_SESSION["errorMessage"] = $lang_err_database; | ||
| 174 | + return false; | ||
| 175 | + } | ||
| 176 | + $_SESSION["errorMessage"] = $lang_err_object_key; | ||
| 177 | + return false; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + | ||
| 181 | + /** | ||
| 182 | + * | ||
| 183 | + * Static function. Given a document fields link primary key will create | ||
| 184 | + * a DocumentFieldLink object and populate it with the corresponding | ||
| 185 | + * database values | ||
| 186 | + * | ||
| 187 | + * @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"] | ||
| 188 | + */ | ||
| 189 | + function & get($iDocumentFieldLinkID) { | ||
| 190 | + global $default, $lang_err_doc_not_exist; | ||
| 191 | + $sql = new Owl_DB(); | ||
| 192 | + $sql->query("SELECT * FROM " . $default->owl_document_fields_table . " WHERE id = " . $iDocumentFieldLinkID); | ||
| 193 | + if ($sql->next_record()) { | ||
| 194 | + $oDocumentFieldLink = & new DocumentFieldLink($sql->f("document_id"), $sql->f("document_field_id"), $sql->f("value")); | ||
| 195 | + $oDocumentFieldLink->iId = $iDocumentFieldLinkID; | ||
| 196 | + return $oDocumentFieldLink; | ||
| 197 | + } | ||
| 198 | + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentID . " table = $default->owl_document_fields_table"; | ||
| 199 | + return false; | ||
| 200 | + } | ||
| 201 | +} | ||
| 202 | +?> |