Commit 25fc09b1ebeeabff97298e2fb00a2cfb5033e2f9

Authored by rob
1 parent fa363414

Finished off class


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1834 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/DocumentLink.inc
... ... @@ -4,7 +4,8 @@
4 4 * Class DocumentLink
5 5 *
6 6 * Represents a document link as per the database document_link table
7   -* Used to chain documents together in the collaboration process
  7 +* Links a child document to a parent document. Direction of relationship
  8 +* is defined through document collaboration
8 9 *
9 10 * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
10 11 * @date 14 May 2003
... ... @@ -17,11 +18,10 @@ class DocumentLink {
17 18 /** primary key value */
18 19 var $iId;
19 20 /** primary key of user responsible for creating document */
20   - var $iUserID;
  21 + var $iParentDocumentID;
21 22 /** document title name */
22   - var $sDocumentTitle;
23   - /** primary key of document to use as template */
24   - var $iTemplateDocumentID;
  23 + var $iChildDocumentID;
  24 +
25 25  
26 26 /**
27 27 * Default constructor
... ... @@ -30,14 +30,12 @@ class DocumentLink {
30 30 * @param Document field data type
31 31 *
32 32 */
33   - function DocumentLink($sNewDocumentTitle, $iUserID, $iNewTemplateDocumentID) {
  33 + function DocumentLink($iNewParentDocumentID, $iNewChildDocumentID) {
34 34 //object not created yet
35 35 global $default;
36 36 $this->iID = -1;
37   - $this->iUserID = $iUserID;
38   - $this->iTemplateDocumentID = $iNewTemplateDocumentID;
39   -
40   -
  37 + $this->iParentDocumentID = $iNewParentDocumentID;
  38 + $this->iChildDocumentID = $iNewChildDocumentID;
41 39 }
42 40  
43 41 /**
... ... @@ -47,87 +45,44 @@ class DocumentLink {
47 45 *
48 46 */
49 47 function getID() {
50   - return $this -> iId;
51   - }
52   -
53   - /**
54   - * Get the document field's name
55   - *
56   - * @return String document field's name
57   - *
58   - */
59   - function getName() {
60   - return $this -> sName;
61   - }
62   -
63   - /**
64   - * Set the document field's name
65   - *
66   - * @param Document field's new name
67   - *
68   - */
69   - function setName($sNewValue) {
70   - $this -> sName = $sNewValue;
71   - }
72   -
73   - /**
74   - * Get the document field's data type
75   - *
76   - * @return String document field's data type
77   - *
78   - */
79   - function getDataType() {
80   - return $this -> sDataType;
  48 + return $this->iId;
81 49 }
82 50  
83 51 /**
84   - * Set the document field's data type
85   - *
86   - * @param Document field's new data type
87   - *
88   - */
89   - function setDataType($sNewValue) {
90   - $this -> sDataType = $sNewValue;
91   - }
92   -
93   - /**
94   - * Get the document field's generic or not
95   - *
96   - * @return String document field's data type
97   - *
  52 + * Get the primary key of the parent document
98 53 */
99   - function getIsGeneric() {
100   - return $this -> bIsGeneric;
  54 + function getParentDocumentID() {
  55 + return $this->iParentDocumentID;
101 56 }
102 57  
103 58 /**
104   - * Set the document field's genericness
  59 + * Set the primary key of the parent document
105 60 *
106   - * @param Document field's new data type
  61 + * @param Primary key of parent document
107 62 *
108 63 */
109   - function setIsGeneric($sNewValue) {
110   - $this -> bIsGeneric = $sNewValue;
  64 + function setParentDocumentID($iNewValue) {
  65 + $this -> iParentDocumentID = $iNewValue;
111 66 }
112 67  
113 68 /**
114   - * Get the document field's lookup or not
  69 + * Get the child document's primary key
115 70 *
116   - * @return String document field's data type
  71 + * @return int primary key of child document
117 72 *
118 73 */
119   - function getHasLookup() {
120   - return $this -> bHasLookup;
  74 + function getChildDocumentID() {
  75 + return $this->iChildDocumentID;
121 76 }
122 77  
123 78 /**
124   - * Set the document field's lookup
  79 + * Set the child document's primary key
125 80 *
126   - * @param Document field's new data type
  81 + * @param Primary key of child document
127 82 *
128 83 */
129   - function setHasLookup($sNewValue) {
130   - $this -> bHasLookup = $sNewValue;
  84 + function setChildDocumentID($iNewValue) {
  85 + $this -> iChildDocumentID = $iNewValue;
131 86 }
132 87  
133 88 /**
... ... @@ -141,7 +96,7 @@ class DocumentLink {
141 96 //if the object hasn't been created
142 97 if ($this -> iId < 0) {
143 98 $sql = $default -> db;
144   - $result = $sql -> query("INSERT INTO ".$default -> owl_fields_table." (name, data_type,is_generic,has_lookup) VALUES ('".addslashes($this -> sName)."', '".addslashes($this -> sDataType)."', '".$this -> bIsGeneric."', '".$this -> bHasLookup."')");
  99 + $result = $sql -> query("INSERT INTO " . $default -> owl_document_link_table . " (parent_document_id, child_document_id) VALUES ($this->iParentDocumentID, $this->iChildDocumentID)");
145 100 if ($result) {
146 101 $this -> iId = $sql -> insert_id();
147 102 return true;
... ... @@ -164,7 +119,7 @@ class DocumentLink {
164 119 //only update if the object has been stored
165 120 if ($this -> iId > 0) {
166 121 $sql = $default -> db;
167   - $result = $sql -> query("UPDATE ".$default -> owl_fields_table." SET name = '".addslashes($this -> sName)."', data_type = '".addslashes($this -> sDataType)."', is_generic = '".$this -> bIsGeneric."', has_lookup = '".$this -> bHasLookup."' WHERE id = $this->iId");
  122 + $result = $sql -> query("UPDATE ".$default -> owl_document_link_table." SET parent_document_id = $this->iParentDocumentID, child_document_id = $this->iChildDocumentID WHERE id = $this->iId");
168 123 if ($result) {
169 124 return true;
170 125 }
... ... @@ -186,7 +141,7 @@ class DocumentLink {
186 141 //only delete the object if it exists in the database
187 142 if ($this -> iId >= 0) {
188 143 $sql = $default -> db;
189   - $result = $sql -> query("DELETE FROM $default->owl_fields_table WHERE id = $this->iId");
  144 + $result = $sql -> query("DELETE FROM $default->owl_document_link_table WHERE id = $this->iId");
190 145 if ($result) {
191 146 return true;
192 147 }
... ... @@ -205,118 +160,21 @@ class DocumentLink {
205 160 *
206 161 * @return DocumentField populated DocumentField object on successful query, false otherwise and set $_SESSION["errorMessage"]
207 162 */
208   - function & get($iDocumentFieldsID) {
  163 + function & get($iDocumentLinkID) {
209 164 global $default;
210 165 $sql = $default -> db;
211   - $result = $sql -> query("SELECT * FROM $default->owl_fields_table WHERE id = $iDocumentFieldsID");
  166 + $result = $sql -> query("SELECT * FROM $default->owl_document_link_table WHERE id = $iDocumentLinkID");
212 167 if ($result) {
213 168 if ($sql -> next_record()) {
214   - $oDocumentField = & new DocumentField(stripslashes($sql -> f("name")), stripslashes($sql -> f("data_type")), $sql -> f("is_generic"), $sql -> f("has_lookup"));
215   - $oDocumentField -> iId = $sql -> f("id");
216   - return $oDocumentField;
217   - }
218   - $_SESSION["errorMessage"] = $lang_err_object_not_exist."id = ".$iDocumentID." table = $default->owl_fields_table";
219   - return false;
220   - }
221   - $_SESSION["errorMessage"] = $lang_err_database;
222   - return false;
223   - }
224   -
225   - /**
226   - * Static function.
227   - * Gets all generic fields
228   - * DocumentFields object and populate it with the
229   - * corresponding database values
230   - *
231   - * @return DocumentField populated DocumentField object on successful query, false otherwise and set $_SESSION["errorMessage"]
232   - */
233   - function getGenericFields() {
234   - global $default, $lang_err_database;
235   - $aFields;
236   - settype($aFields, "array");
237   - $sql = $default -> db;
238   - $result = $sql -> query("SELECT name, id FROM ".$default -> owl_fields_table." Where is_generic = 1");
239   - if ($result) {
240   - $iCount = 0;
241   - while ($sql -> next_record()) {
242   -
243   - $aFields[$iCount]["id"] = $sql -> f("id");
244   - $aFields[$iCount]["name"] = $sql -> f("name");
245   - $iCount ++;
  169 + $oDocumentLink = & new DocumentLink($sql -> f("parent_document_id"), $sql -> f("parent_document_id"));
  170 + $oDocumentLink -> iId = $sql -> f("id");
  171 + return $oDocumentLink;
246 172 }
247   - return $aFields;
248   - }
249   - $_SESSION["errorMessage"] = $lang_err_database;
250   - return false;
251   - }
252   -
253   - /* Static function. Given a documenttype...will find all fields belongin to it
254   - *
255   - * @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"]
256   - */
257   - function getAllSpecificFields() {
258   - global $default, $lang_err_database;
259   - $aFields;
260   - settype($aFields, "array");
261   - $sql = $default -> db;
262   - $result = $sql -> query("SELECT id, name FROM ".$default -> owl_fields_table." Where is_generic = 0");
263   - if ($result) {
264   - $iCount = 0;
265   - while ($sql -> next_record()) {
266   -
267   - $aFields[$iCount]["id"] = $sql -> f("id");
268   - $aFields[$iCount]["name"] = $sql -> f("name");
269   - $iCount ++;
270   - }
271   - return $aFields;
272   - }
273   - $_SESSION["errorMessage"] = $lang_err_database;
274   - return false;
275   - }
276   -
277   - /* Static function. Given a documenttype...will find all fields belongin to it
278   - *
279   - * @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"]
280   - */
281   - function isFieldLinkedToType() {
282   - global $default, $lang_err_database;
283   - $sql = $default -> db;
284   - $query = "SELECT * FROM ".$default -> owl_document_type_fields_table." Where field_id = $this->iId";
285   - $sql -> query($query);
286   - $rows = $sql -> num_rows($sql);
287   -
288   - if ($rows > 0) {
289   - return true;
290   - } else {
  173 + $_SESSION["errorMessage"] = $lang_err_object_not_exist."id = ".$iDocumentLinkID." table = $default->owl_document_link_table";
291 174 return false;
292 175 }
293 176 $_SESSION["errorMessage"] = $lang_err_database;
294 177 return false;
295 178 }
296   -
297   - /* Static function. Given a documenttype...will find all fields belongin to it
298   - *
299   - * @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"]
300   - */
301   - function getAllDataTypes() {
302   - global $default, $lang_err_database;
303   - $aDataTypes;
304   - settype($aDataTypes, "array");
305   - $sql = $default -> db;
306   - $result = $sql -> query("SELECT id, name FROM ".$default -> owl_data_types_table);
307   - if ($result) {
308   - $iCount = 0;
309   - while ($sql -> next_record()) {
310   -
311   - $aDataTypes[$iCount]["id"] = $sql -> f("id");
312   - $aDataTypes[$iCount]["name"] = $sql -> f("name");
313   - $iCount ++;
314   - }
315   - return $aDataTypes;
316   - }
317   - $_SESSION["errorMessage"] = $lang_err_database;
318   - return false;
319   - }
320 179 }
321   -
322 180 ?>
323 181 \ No newline at end of file
... ...