Commit d7397a6fe97556eb2a23ad03a5600c2f98c51171

Authored by michael
1 parent 2ecefae3

tidied comments and formatting

changed seDocTypeFieldID to more sensible getByFieldAndTypeIDs method that returns an object


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2310 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/DocumentTypeFieldLink.inc
1 1 <?php
  2 +require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentField.inc");
2 3  
3 4 /**
4   -*
5   -* Class DocumentTypeFieldLink
6   -*
7   -* Represents a document type field link as per the database table document_types_fields_link
8   -*
9   -* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
10   -* @date 19 January 2003
11   -* @package lib.documentmanagement
12   -*/
13   -
  5 + *
  6 + * Class DocumentTypeFieldLink
  7 + *
  8 + * Represents a document type field link as per the database table document_types_fields_link
  9 + *
  10 + * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
  11 + * @date 19 January 2003
  12 + * @package lib.documentmanagement
  13 + */
14 14 class DocumentTypeFieldLink {
15 15  
16 16 /** document field link primary key */
... ... @@ -156,9 +156,10 @@ class DocumentTypeFieldLink {
156 156 global $default, $lang_err_database, $lang_err_object_key;
157 157 if ($this->iId >= 0) {
158 158 $sql = $default->db;
159   - $result = $sql->query("UPDATE " . $default->owl_document_type_fields_table . " SET " .
  159 + $sQuery = "UPDATE " . $default->owl_document_type_fields_table . " SET " .
160 160 "document_type_id = $this->iDocumentTypeID, field_id = $this->iFieldID, is_mandatory = '" . $this->bIsMandatory . "'" .
161   - "WHERE id = $this->iId");
  161 + "WHERE id = $this->iId";
  162 + $result = $sql->query($sQuery);
162 163 if ($result) {
163 164 return true;
164 165 }
... ... @@ -202,7 +203,7 @@ class DocumentTypeFieldLink {
202 203 * @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"]
203 204 */
204 205 function & get($iDocumentTypeFieldLinkID) {
205   - global $default, $lang_err_doc_not_exist;
  206 + global $default;
206 207 $sql = $default->db;
207 208 $sql->query("SELECT * FROM " . $default->owl_document_type_fields_table . " WHERE id = " . $iDocumentTypeFieldLinkID);
208 209 if ($sql->next_record()) {
... ... @@ -210,92 +211,62 @@ class DocumentTypeFieldLink {
210 211 $oDocumentTypeFieldLink->iId = $iDocumentTypeFieldLinkID;
211 212 return $oDocumentTypeFieldLink;
212 213 }
213   - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentTypeID . " table = $default->owl_document_type_fields_table";
214 214 return false;
215 215 }
216 216  
217   -
218   -
219   - /*
220   - * static function
221   - *
222   - * find out wot doctype belongs to wot field
  217 + /**
  218 + * Static- Lookup a document field associated with a document type id
223 219 *
224   - * @param false or a value
225   - *
  220 + * @param integer the document type id
  221 + * @return integer a document field id
226 222 */
227   -
228   - function docTypeBelongsToField($doctypeId)
229   - {
230   - global $default;
231   -
232   - $value = lookupField("$default->owl_document_type_fields_table", "field_id", "document_type_id", $doctypeId );
233   -
234   - return $value;
235   -
  223 + function docTypeBelongsToField($iDocTypeID) {
  224 + global $default;
  225 + return lookupField("$default->owl_document_type_fields_table", "field_id", "document_type_id", $iDocTypeID );
236 226 }
237   -
238 227  
239   -/*
240   - * static function
241   - *
242   - * sets the id of the groupunit using their groupid
  228 + /**
  229 + * Static- Lookup the DocumentTypeFieldLink by document type and document field ids
243 230 *
244   - * @param String
245   - * The unit_ID
246   - *
  231 + * @param integer the document type id
  232 + * @param integer the document field id
  233 + * @return DocumentTypeFieldLink the object representing this database row
247 234 */
248   -
249   - function setDocTypeFieldID($iDocTypeID, $iDocFieldID)
250   - {
  235 + function getByFieldAndTypeIDs($iDocTypeID, $iDocFieldID) {
251 236 global $default;
252 237 $sql = $default->db;
253   - $result = $sql->query("SELECT id FROM $default->owl_document_type_fields_table WHERE field_id = $iDocFieldID and document_type_id = $iDocTypeID ");
  238 + $sQuery = "SELECT id FROM $default->owl_document_type_fields_table WHERE field_id = $iDocFieldID AND document_type_id = $iDocTypeID";
  239 + $result = $sql->query($sQuery);
254 240 if ($result) {
255 241 if ($sql->next_record()) {
256   - $id = $sql->f("id");
257   -
258   - }else{
259   - $_SESSION["errorMessage"] = $lang_err_database;
  242 + return DocumentTypeFieldLink::get($sql->f("id"));
  243 + } else{
260 244 return false;
261 245 }
262   -
263   - }else{
264   - $_SESSION["errorMessage"] = $lang_err_database;
  246 + } else {
265 247 return false;
266 248 }
267   -
268   - $this->iId = $id;
269   -
270 249 }
271 250  
272   -
273   -
274   -
275   - /* Static function. Given a documenttype...will find all fields belongin to it
276   - *
277   - * @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"]
278   - */
279   - function getSpecificFields($iDocTypeID) {
280   - global $default, $lang_err_database;
281   - $aFields;
282   - settype($aFields, "array");
  251 + /**
  252 + * Static- Returns DocumentFields mapped to a DocumentType
  253 + *
  254 + * @param integer primary key of the document type
  255 + * @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"]
  256 + */
  257 + function getDocumentTypeFields($iDocTypeID) {
  258 + global $default;
  259 + $aFields = array();
283 260 $sql = $default->db;
284   - $result = $sql->query("SELECT field_id FROM " . $default->owl_document_type_fields_table . " Where document_type_id = ". $iDocTypeID);
  261 + $result = $sql->query("SELECT field_id FROM " . $default->owl_document_type_fields_table . " WHERE document_type_id = ". $iDocTypeID);
285 262 if ($result) {
286   - $iCount = 0;
287 263 while ($sql->next_record()) {
288   -
289   - $aFields[$iCount] = $sql->f("field_id");
290   - $iCount++;
  264 + $aFields[] = DocumentField::get($sql->f("field_id"));
291 265 }
292 266 return $aFields;
293 267 }
294   - $_SESSION["errorMessage"] = $lang_err_database;
295 268 return false;
296 269 }
297   -
298   -
299 270 }
300 271  
301 272  
... ...