From 279cd2aca2e9054afb13cbca0f62b1254e709850 Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 9 Jan 2003 15:36:58 +0000 Subject: [PATCH] Initial revision --- lib/documentmanagement/documentManager.inc | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/documentmanagement/documentTypeTest.php | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/visualpatterns/test.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 372 insertions(+), 0 deletions(-) create mode 100644 lib/documentmanagement/documentManager.inc create mode 100644 tests/documentmanagement/documentTypeTest.php create mode 100644 tests/visualpatterns/test.php diff --git a/lib/documentmanagement/documentManager.inc b/lib/documentmanagement/documentManager.inc new file mode 100644 index 0000000..7819bf7 --- /dev/null +++ b/lib/documentmanagement/documentManager.inc @@ -0,0 +1,237 @@ +owl_root_url/lib/owl.lib.php"); + +class DocumentManager { + + /** + * Create a new document type + * + * @param $sName Name of new document type + * + * @return true on successful creation, false otherwise and set $default->errorMessage + */ + function createDocumentType($sName) { + //escape all the necessary characters that may affect db query + $sName = addslashes($sName); + //Get hold of the global error string + global $default; + //if the document type doesn't exist + if (!($this->documentTypeExists($sName))) { + $sql = new Owl_DB(); + $result = $sql->query("INSERT INTO " . $default->owl_document_types_table . " (name) values ('" . $sName . "')"); + if (!$result) { + $default->errorMessage = "Database Error. Failed to insert document type " . $sName; + return false; + } + return true; + } + $default->errorMessage = "A document type with this name already exists"; + return false; + } + + /** + * Delete an existing document type + * + * @param $sName Name of document type to delete + * + * @return true on successful removal, false otherwise and set $default->errorMessage + */ + function deleteDocumentType($sName) { + //escape all the necessary characters that may affect db query + $sName = addslashes($sName); + //Get hold of the global error string + global $default; + //only remove the document type if it exists + if ($this->documentTypeExists($sName)) { + $sql = new Owl_DB(); + $result = $sql->query("DELETE FROM " . $default->owl_document_types_table . " WHERE name = '" . $sName . "'"); + if (!$result) { + $default->errorMessage = "Database Error. Failed to delete document type " . $sName; + return false; + } + return true; + } + $default->errorMessage = "There is no document type with this name"; + return false; + } + + /** + * Update a document type + * + * @param $iDocumentTypeID Primary key of document type to updatee + * @param $sName New document type name + * + * @return true on successful update, false otherwise and set $default->errorMessage + */ + function updateDocumentType($iDocumentTypeID, $sName) { + + } + + /** + * Checks to see if a document type with a given name + * already exists + * + * @param $sName Name of document type to check + * + * @return true if the document type exists, false otherwise + */ + function documentTypeExists($sName) { + //escape all the necessary characters that may affect db query + $sName = addslashes($sName); + //Get hold of the global error string + global $default; + $sql = new Owl_DB(); + $sql->query("SELECT * FROM " . $default->owl_document_types_table . " WHERE Name = '" . $sName . "'"); + return $sql->next_record(); + } + + /** + * Link a document type field with a specific document type + * + * @param $iDocumentTypeID Primary key of document type + * @param $iDocumentTypeFieldID Primary key of document field type + * @param $bIsMandatory Whether or not the field is mandatory + * + * @return true on successful creation, false otherwise and set $default->errorMessage + */ + function createDocumentTypeFieldLink($iDocumentTypeID, $iDocumentTypeFieldID, $bIsMandatory) { + //Get hold of the global error string + global $default; + //if the document field type is not associated with the document + if (!$this->documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID)) { + $sql = new Owl_DB(); + $result = $sql->query("INSERT INTO " . $default->document_type_fields_table . " (document_type_id, field_id, is_mandatory) VALUES (" . $iDocumentTypeID . ", " . $iDocumentTypeFieldID . ", " . $bIsMandatory . ")"); + if (!$result) { + $default->errorMessage = "Database Error. Failed to insert document field type with ID " . $iDocumentTypeFieldID; + return false; + } + return true; + } + $default->errorMessage = "This field type is already linked to this document type"; + return false; + } + + /** + * Delete the link between a document type field and a specific document type + * + * @param $iDocumentTypeID Primary key of document type + * @param $iDocumentTypeFieldID Primary key of document type field + */ + function deleteDocumentTypeFieldLink($iDocumentTypeID, $iDocumentTypeFieldID) { + //Get hold of the global error string + global $default; + if ($this->documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID)) { + $sql = new Owl_DB(); + $result = $sql->query("DELETE FROM " . $default->document_type_fields_table . " where document_type_id = " . $iDocumentTypeID . " AND field_id = " . $iDocumentTypeFieldID); + if (!result) { + $default->errorMessage = "Database Error. Failed to deleted document type field with document_type_id " . $iDocumentTypeID . " and field_id " . $iDocumentTypeFieldID; + return false; + } + return true; + } + $default->errorMessage = "A dcoument field type with document_type_id " . $iDocumentTypeID . " and a document_id " . $iDocumentTypeID . " does not exist"; + return false; + } + + + /** + * Checks to see if the given document type field is already linked to the given + * document type. + * + * @param $iDocumentTypeID Primary key of document type + * @param $iDocumentTypeFieldID Primary key of document field type + * + * @return true is the document field type is linked to the document type, false otherwise + */ + function documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID) { + $sql = new Owl_DB(); + $sql->query("SELECT * FROM " . $default->document_type_fields_table . " WHERE document_type_id = " . $iDocumentTypeID . " AND field_id = " . $iDocumentTypeFieldID); + return $sql->next_record(); + } + + /** + * Creates a document type field + * + * @param $sName Document type field name + * @param $sDataType Field data type + * + * @return true on successful insertion, false otherwise and sets $default->errorMessage + */ + function createDocumentTypeField($sName, $sDataType) { + //escape all the necessary characters that may affect db query + $sName = addslashes($sName); + $sDataType = addslashes($sDataType); + //Get hold of the global error string + global $default; + if (!$this->documentTypeFieldExists($sName)) { + $sql = new Owl_DB(); + $result = $sql->query("INSERT INTO " . $default->owl_fields_table . " (name, data_type) VALUES ('" . $sName . "', '" . $sDataType . "')"); + if (!$result) { + $default->errorMessage = "Database Error. Could not insert document field " . $sName . " with data type " . $sDataType . " into table " . $default->owl_fields_table; + return false; + } + return true; + } + $default->errorMessage = "A document type field with this name already exists"; + return false; + } + + /** + * Deletes a document type field + * + * @param $sName Name of document field type to delete + * + * @return true on successful deletion, false otherwise and set $default->errorMessage + */ + function deleteDocumentTypeField($sName) { + //escape any characters that may affect db query + $sName = addslashes($sName); + //Get hold of the global error string + global $default; + if ($this->documentTypeFieldExists($sName)) { + $sql = new Owl_DB(); + $result = $sql->query("DELETE FROM " . $default->owl_fields_table . " WHERE Name = '" . $sName . "'"); + if (!$result) { + $default->errorMessage = "Database Error. Could not delete document type field " . $sName . " from table " . $default->owl_field_table; + return false; + } + return true; + } + $default->errorMessage = "A document type field with the name " . $sName . " does not exist"; + return false; + } + + /** + * Checks whether a document type field exists + * + * @param $sName Document type field name to check + * + * @return true if document type field exists, false otherwise + */ + function documentTypeFieldExists($sName) { + global $default; + $sql = new Owl_DB(); + $sql->query("SELECT * FROM " . $default->owl_fields_table . " WHERE name = '" . $sName . "'"); + return $sql->next_record(); + } + + + +} + + +?> diff --git a/tests/documentmanagement/documentTypeTest.php b/tests/documentmanagement/documentTypeTest.php new file mode 100644 index 0000000..1e6bf9f --- /dev/null +++ b/tests/documentmanagement/documentTypeTest.php @@ -0,0 +1,93 @@ +owl_root_url/lib/owl.lib.php"); +require_once ("../../../lib/documentmanagement/documentManager.inc"); + +/** +* Database backend unit tests for: +* o Document type (document_types) +* o Field (fields) +* +* @author Rob Cherry, Jam Warehouse (Pty Ltd), South Africa +* @date 9 January 2003 +*/ + +//test creation of document type + +global $default; + +$docManager = new DocumentManager(); + +if ($docManager->createDocumentType("Test")) { + echo "Passed document type creation test
"; +} else { + echo "Failed 'document type creation' test: " . $default->errorMessage . "
"; +} + +//test creation of duplicate document types +if (!$docManager->createDocumentType("Test")) { + echo "Passed 'duplicate document type creation' test
"; +} else { + echo "Failed duplicate document type creation test
"; +} + +//test deletion of an existing document type +if ($docManager->deleteDocumentType("Test")) { + echo "Passed 'existing document type deletion' test
"; +} else { + echo "Failed existing document type deletion test
"; +} + +//test deletion of a document type that doesn't exist +if (!$docManager->deleteDocumentType("Does not exist")) { + echo "Passed 'deletion of non-existing document type' test
"; +} else { + echo "Failed 'deletion of non-existant document type' test
"; +} + +/** +* +* Field type tests +* +*/ + +//test creation of a field +if ($docManager->createDocumentTypeField("Test Field","VARCHAR")) { + echo "Passed 'creation of document type field' test
"; +} else { + echo "Failed 'creation of document type field' test
"; +} + +//test creation of duplicate field +if (!($docManager->createDocumentTypeField("Test Field","VARCHAR"))) { + echo "Passed 'creation of duplicate document type field ' test
"; +} else { + echo "Failed 'creation of duplicated document type field ' test
: $default->errorMessage"; +} + +//test deletion of a field +if ($docManager->deleteDocumentTypeField("Test Field")) { + echo "Passed 'deletion of document type field ' test
"; +} else { + echo "Failed 'deletion of document type field ' test<
"; +} + +//test deletion of a non-existant field +if (!$docManager->deleteDocumentTypeField("Test Field that doesn't exist")) { + echo "Passed 'deletion of non-existant document type field ' test
"; +} else { + echo "Failed 'deletion of non-existant document type field ' test<
"; +} + + + + + +?> diff --git a/tests/visualpatterns/test.php b/tests/visualpatterns/test.php new file mode 100644 index 0000000..ae48336 --- /dev/null +++ b/tests/visualpatterns/test.php @@ -0,0 +1,42 @@ +"www.google.com",1=>"www.yahoo.com",2=>"www.msn.com"); +$aTopMenuText = array(0=>"google",1=>"yahoo",2=>"msn"); +$oPatternTableLinks = new PatternTableLinks($aTopMenuLinks, $aTopMenuText, 3, 1); + +//build the central grid for paging through results +$aCentralPageColumns = array(0=>"name",1=>"parent",2=>"security"); +$aColumnTypes = array(0=>1,1=>2,2=>1); +$oTableSqlQuery = & new PatternTableSqlQuery("Folders", $aCentralPageColumns, $aColumnTypes); +($HTTP_GET_VARS["fStartIndex"]) ? $oTableSqlQuery->setStartIndex($HTTP_GET_VARS["fStartIndex"]) : $oTableSqlQuery->setStartIndex(0); +$oTableSqlQuery->setLinkType(1); + + + +//get a page +$tmp = new PatternMainPage(); + +//put the page together +$tmp->setNorthWestPayload($img); +$tmp->setNorthPayload($oPatternTableLinks); +$tmp->setCentralPayload($oTableSqlQuery); +$tmp->setFormAction("Navigate.inc"); +$tmp->render(); +*/ +?> -- libgit2 0.21.4