From 1459dba1011db15e2fad5520ad99375d20da113e Mon Sep 17 00:00:00 2001 From: Neil Blakey-Milner Date: Mon, 19 Sep 2005 20:10:35 +0000 Subject: [PATCH] Replace old store.inc/constructQuery metadata handling, and use the built-in handler in KTDocumentUtil::add --- presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php | 36 ++++++++++++++++-------------------- presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc | 80 +++++++++++++++++++++++++++++++++----------------------------------------------- 2 files changed, 49 insertions(+), 67 deletions(-) diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php index 9aa84b4..80c7ab7 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php @@ -148,24 +148,34 @@ if (!((strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0)) { exit(0); } -$aOptions = array( - 'contents' => new KTFSFileLike($_FILES['fFile']['tmp_name']), - 'documenttype' => DocumentType::get($fDocumentTypeID), -); - function localRenderError($oDocument) { print $oDocument->toString(); return; } DBUtil::startTransaction(); + +$matches = array(); +$aFields = array(); +foreach ($_REQUEST as $k => $v) { + if (preg_match('/^emd(\d+)$/', $k, $matches)) { + $aFields[] = array(DocumentField::get($matches[1]), $v); + } +} + +$aOptions = array( + 'contents' => new KTFSFileLike($_FILES['fFile']['tmp_name']), + 'documenttype' => DocumentType::get($fDocumentTypeID), + 'metadata' => $aFields, + 'description' => $fName, +); + $oUser =& User::get($_SESSION["userID"]); $oDocument =& KTDocumentUtil::add($oFolder, basename($_FILES['fFile']['name']), $oUser, $aOptions); if (PEAR::isError($oDocument)) { localRenderError($oDocument); exit(0); } -$oDocument->update(); //the document was created/uploaded due to a collaboration step in another //document and must be linked to that document @@ -196,20 +206,6 @@ if (isset($fDependantDocumentID)) { } } -// now handle meta data, pass new document id to queries -$aQueries = constructQuery(array_keys($_POST), array("document_id" =>$oDocument->getID())); -for ($i=0; $idb; - if ($sql->query($aQueries[$i])) { - $default->log->info("addDocumentBL.php query succeeded=" . $aQueries[$i]); - } else { - $default->log->error("addDocumentBL.php query failed=" . $aQueries[$i]); - } -} - -KTDocumentUtil::setComplete($oDocument, 'metadata'); -$oDocument->update(); - DBUtil::commit(); //redirect to the document details page controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID()); diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc index 83ea503..c225b17 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc @@ -25,6 +25,12 @@ * @package documentmanagement */ +require_once(KT_LIB_DIR . '/visualpatterns/PatternTableSqlQuery.inc'); +require_once(KT_LIB_DIR . '/visualpatterns/PatternMetaData.inc'); +require_once(KT_LIB_DIR . '/visualpatterns/PatternEditableTableSqlQuery.inc'); + +require_once(KT_LIB_DIR . '/documentmanagement/DocumentField.inc'); + function getDocumentType($iFolderID, $iDocumentTypeID, $iDependantDocumentID = null) { global $default; @@ -72,29 +78,14 @@ function getUploadDocument() { * Displays the generic meta data fields form */ function getGenericMetaDataForm() { - global $default; - /*ok*/ $sQuery = array("SELECT DISTINCT -1 AS document_id, DF.id AS document_field_id, DF.name AS field_name, -1 AS id " . - "FROM document_fields AS DF LEFT OUTER JOIN document_fields_link AS DFL ON DF.id = DFL.document_field_id " . - "WHERE DF.is_generic = ? ", array(true)); - - $aStoreColumnNames = array("document_id", "document_field_id", "value"); - $aDisplayColumnNames = array("document_id", "field_name", "value"); - $aMetaDataColumnNames = array(2=>"field_name"); - $aColumnsEditable = array(0,0,1); - $aColumnsVisible = array(0,1,1); - $aColumnDisplayTypes = array(1,1,4); - $aColumnDatabaseTypes = array(4,0,1); - - $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes); - $oPatternTableSqlQuery->setTableCaption(_("Generic Meta Data")); - $oPatternTableSqlQuery->setUniqueName("gmd"); - if ($default->genericMetaDataRequired === true) { - $oPatternTableSqlQuery->setRequiredColumnNames(array("value")); - } - $oPatternTableSqlQuery->setMetaDataFields($aMetaDataColumnNames); - $oPatternTableSqlQuery->setEmptyTableMessage(_("No Generic Meta Data")); - $oPatternTableSqlQuery->setRenderJavascriptValidation(false); - return $oPatternTableSqlQuery; + $oTemplating = KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata_fields/editable_metadata_fields"); + $aTemplateData = array( + 'caption' => _('Generic meta data'), + 'empty_message' => _("No Generic Meta Data"), + 'fields' => DocumentField::getList(array('is_generic = ?', array(true))), + ); + return $oTemplate->render($aTemplateData); } /** @@ -102,27 +93,25 @@ function getGenericMetaDataForm() { */ function getTypeSpecificMetaDataForm($iFolderID, $iDocumentTypeID) { global $default; - /*ok*/ $sQuery = array("SELECT DISTINCT -1 AS document_id, DF.id AS document_field_id, DF.name AS field_name, DTFL.is_mandatory AS is_mandatory, -1 AS id " . - "FROM document_type_fields_link AS DTFL INNER JOIN document_fields AS DF ON DTFL.field_id = DF.id " . - "LEFT OUTER JOIN document_fields_link AS DFL ON DFL.document_field_id = DTFL.field_id " . + /*ok*/ $sQuery = array("SELECT DF.id AS id " . + "FROM document_fields AS DF LEFT JOIN document_type_fields_link AS DTFL ON DTFL.field_id = DF.id " . "WHERE DF.is_generic = ? " . "AND DTFL.document_type_id = ?", array(false, $iDocumentTypeID)); - - $aStoreColumnNames = array("document_id", "document_field_id", "value"); - $aDisplayColumnNames = array("document_id", "field_name", "value"); - $aColumnsEditable = array(0,0,1); - $aColumnsVisible = array(0,1,1); - $aColumnDisplayTypes = array(1,1,4); - $aColumnDatabaseTypes = array(4,0,1); - $aMetaDataColumnNames = array(2=>"field_name"); - - $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes); - $oPatternTableSqlQuery->setTableCaption(_("Type specific meta data")); - $oPatternTableSqlQuery->setEmptyTableMessage(_("No Type Specific Meta Data")); - $oPatternTableSqlQuery->setUniqueName("tsmd"); - $oPatternTableSqlQuery->setMetaDataFields($aMetaDataColumnNames); - $oPatternTableSqlQuery->setRenderJavascriptValidation(false); - return $oPatternTableSqlQuery; + + $aIDs = DBUtil::getResultArray($sQuery); + + $aFields = array(); + foreach ($aIDs as $iID) { + $aFields[] =& call_user_func(array('DocumentField', 'get'), $iID); + } + $aTemplateData = array( + 'caption' => _('Type specific meta data'), + 'empty_message' => _("No Type Specific Meta Data"), + 'fields' => $aFields, + ); + $oTemplating = KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata_fields/editable_metadata_fields"); + return $oTemplate->render($aTemplateData); } function getMetaDataForm($iFolderID, $iDocumentTypeID) { @@ -130,8 +119,8 @@ function getMetaDataForm($iFolderID, $iDocumentTypeID) { $oTypeSpecificPattern = getTypeSpecificMetaDataForm($iFolderID, $iDocumentTypeID); $sToRender .= "\n"; $sToRender .= "\n"; - $sToRender .= ""; - $sToRender .= ""; + $sToRender .= ""; + $sToRender .= ""; $sToRender .= "
" . _("Document Meta Data") . "
" . $oGenericPattern->render() . "
" . $oTypeSpecificPattern->render() . "
" . $oGenericPattern . "
" . $oTypeSpecificPattern . "
"; // validation starts @@ -143,9 +132,6 @@ function getMetaDataForm($iFolderID, $iDocumentTypeID) { // filename $sToRender .= "\tif (!(validRequired(theForm.fFile, 'Document Filename'))) {\n"; $sToRender .= "\t\treturn false;\n\t}\n"; - // metadata - $sToRender .= $oGenericPattern->getValidationJavascript(); - $sToRender .= $oTypeSpecificPattern->getValidationJavascript(); $sToRender .= "return true;\n}\n"; $sToRender .= "//-->\n\n\n"; -- libgit2 0.21.4