Commit 1459dba1011db15e2fad5520ad99375d20da113e

Authored by Neil Blakey-Milner
1 parent d3664a12

Replace old store.inc/constructQuery metadata handling, and use the

built-in handler in KTDocumentUtil::add


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3619 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php
@@ -148,24 +148,34 @@ if (!((strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0)) { @@ -148,24 +148,34 @@ if (!((strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0)) {
148 exit(0); 148 exit(0);
149 } 149 }
150 150
151 -$aOptions = array(  
152 - 'contents' => new KTFSFileLike($_FILES['fFile']['tmp_name']),  
153 - 'documenttype' => DocumentType::get($fDocumentTypeID),  
154 -);  
155 -  
156 function localRenderError($oDocument) { 151 function localRenderError($oDocument) {
157 print $oDocument->toString(); 152 print $oDocument->toString();
158 return; 153 return;
159 } 154 }
160 155
161 DBUtil::startTransaction(); 156 DBUtil::startTransaction();
  157 +
  158 +$matches = array();
  159 +$aFields = array();
  160 +foreach ($_REQUEST as $k => $v) {
  161 + if (preg_match('/^emd(\d+)$/', $k, $matches)) {
  162 + $aFields[] = array(DocumentField::get($matches[1]), $v);
  163 + }
  164 +}
  165 +
  166 +$aOptions = array(
  167 + 'contents' => new KTFSFileLike($_FILES['fFile']['tmp_name']),
  168 + 'documenttype' => DocumentType::get($fDocumentTypeID),
  169 + 'metadata' => $aFields,
  170 + 'description' => $fName,
  171 +);
  172 +
162 $oUser =& User::get($_SESSION["userID"]); 173 $oUser =& User::get($_SESSION["userID"]);
163 $oDocument =& KTDocumentUtil::add($oFolder, basename($_FILES['fFile']['name']), $oUser, $aOptions); 174 $oDocument =& KTDocumentUtil::add($oFolder, basename($_FILES['fFile']['name']), $oUser, $aOptions);
164 if (PEAR::isError($oDocument)) { 175 if (PEAR::isError($oDocument)) {
165 localRenderError($oDocument); 176 localRenderError($oDocument);
166 exit(0); 177 exit(0);
167 } 178 }
168 -$oDocument->update();  
169 179
170 //the document was created/uploaded due to a collaboration step in another 180 //the document was created/uploaded due to a collaboration step in another
171 //document and must be linked to that document 181 //document and must be linked to that document
@@ -196,20 +206,6 @@ if (isset($fDependantDocumentID)) { @@ -196,20 +206,6 @@ if (isset($fDependantDocumentID)) {
196 } 206 }
197 } 207 }
198 208
199 -// now handle meta data, pass new document id to queries  
200 -$aQueries = constructQuery(array_keys($_POST), array("document_id" =>$oDocument->getID()));  
201 -for ($i=0; $i<count($aQueries); $i++) {  
202 - $sql = $default->db;  
203 - if ($sql->query($aQueries[$i])) {  
204 - $default->log->info("addDocumentBL.php query succeeded=" . $aQueries[$i]);  
205 - } else {  
206 - $default->log->error("addDocumentBL.php query failed=" . $aQueries[$i]);  
207 - }  
208 -}  
209 -  
210 -KTDocumentUtil::setComplete($oDocument, 'metadata');  
211 -$oDocument->update();  
212 -  
213 DBUtil::commit(); 209 DBUtil::commit();
214 //redirect to the document details page 210 //redirect to the document details page
215 controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID()); 211 controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID());
presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc
@@ -25,6 +25,12 @@ @@ -25,6 +25,12 @@
25 * @package documentmanagement 25 * @package documentmanagement
26 */ 26 */
27 27
  28 +require_once(KT_LIB_DIR . '/visualpatterns/PatternTableSqlQuery.inc');
  29 +require_once(KT_LIB_DIR . '/visualpatterns/PatternMetaData.inc');
  30 +require_once(KT_LIB_DIR . '/visualpatterns/PatternEditableTableSqlQuery.inc');
  31 +
  32 +require_once(KT_LIB_DIR . '/documentmanagement/DocumentField.inc');
  33 +
28 function getDocumentType($iFolderID, $iDocumentTypeID, $iDependantDocumentID = null) { 34 function getDocumentType($iFolderID, $iDocumentTypeID, $iDependantDocumentID = null) {
29 global $default; 35 global $default;
30 36
@@ -72,29 +78,14 @@ function getUploadDocument() { @@ -72,29 +78,14 @@ function getUploadDocument() {
72 * Displays the generic meta data fields form 78 * Displays the generic meta data fields form
73 */ 79 */
74 function getGenericMetaDataForm() { 80 function getGenericMetaDataForm() {
75 - global $default;  
76 - /*ok*/ $sQuery = array("SELECT DISTINCT -1 AS document_id, DF.id AS document_field_id, DF.name AS field_name, -1 AS id " .  
77 - "FROM document_fields AS DF LEFT OUTER JOIN document_fields_link AS DFL ON DF.id = DFL.document_field_id " .  
78 - "WHERE DF.is_generic = ? ", array(true));  
79 -  
80 - $aStoreColumnNames = array("document_id", "document_field_id", "value");  
81 - $aDisplayColumnNames = array("document_id", "field_name", "value");  
82 - $aMetaDataColumnNames = array(2=>"field_name");  
83 - $aColumnsEditable = array(0,0,1);  
84 - $aColumnsVisible = array(0,1,1);  
85 - $aColumnDisplayTypes = array(1,1,4);  
86 - $aColumnDatabaseTypes = array(4,0,1);  
87 -  
88 - $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes);  
89 - $oPatternTableSqlQuery->setTableCaption(_("Generic Meta Data"));  
90 - $oPatternTableSqlQuery->setUniqueName("gmd");  
91 - if ($default->genericMetaDataRequired === true) {  
92 - $oPatternTableSqlQuery->setRequiredColumnNames(array("value"));  
93 - }  
94 - $oPatternTableSqlQuery->setMetaDataFields($aMetaDataColumnNames);  
95 - $oPatternTableSqlQuery->setEmptyTableMessage(_("No Generic Meta Data"));  
96 - $oPatternTableSqlQuery->setRenderJavascriptValidation(false);  
97 - return $oPatternTableSqlQuery; 81 + $oTemplating = KTTemplating::getSingleton();
  82 + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata_fields/editable_metadata_fields");
  83 + $aTemplateData = array(
  84 + 'caption' => _('Generic meta data'),
  85 + 'empty_message' => _("No Generic Meta Data"),
  86 + 'fields' => DocumentField::getList(array('is_generic = ?', array(true))),
  87 + );
  88 + return $oTemplate->render($aTemplateData);
98 } 89 }
99 90
100 /** 91 /**
@@ -102,27 +93,25 @@ function getGenericMetaDataForm() { @@ -102,27 +93,25 @@ function getGenericMetaDataForm() {
102 */ 93 */
103 function getTypeSpecificMetaDataForm($iFolderID, $iDocumentTypeID) { 94 function getTypeSpecificMetaDataForm($iFolderID, $iDocumentTypeID) {
104 global $default; 95 global $default;
105 - /*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 " .  
106 - "FROM document_type_fields_link AS DTFL INNER JOIN document_fields AS DF ON DTFL.field_id = DF.id " .  
107 - "LEFT OUTER JOIN document_fields_link AS DFL ON DFL.document_field_id = DTFL.field_id " . 96 + /*ok*/ $sQuery = array("SELECT DF.id AS id " .
  97 + "FROM document_fields AS DF LEFT JOIN document_type_fields_link AS DTFL ON DTFL.field_id = DF.id " .
108 "WHERE DF.is_generic = ? " . 98 "WHERE DF.is_generic = ? " .
109 "AND DTFL.document_type_id = ?", array(false, $iDocumentTypeID)); 99 "AND DTFL.document_type_id = ?", array(false, $iDocumentTypeID));
110 -  
111 - $aStoreColumnNames = array("document_id", "document_field_id", "value");  
112 - $aDisplayColumnNames = array("document_id", "field_name", "value");  
113 - $aColumnsEditable = array(0,0,1);  
114 - $aColumnsVisible = array(0,1,1);  
115 - $aColumnDisplayTypes = array(1,1,4);  
116 - $aColumnDatabaseTypes = array(4,0,1);  
117 - $aMetaDataColumnNames = array(2=>"field_name");  
118 -  
119 - $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes);  
120 - $oPatternTableSqlQuery->setTableCaption(_("Type specific meta data"));  
121 - $oPatternTableSqlQuery->setEmptyTableMessage(_("No Type Specific Meta Data"));  
122 - $oPatternTableSqlQuery->setUniqueName("tsmd");  
123 - $oPatternTableSqlQuery->setMetaDataFields($aMetaDataColumnNames);  
124 - $oPatternTableSqlQuery->setRenderJavascriptValidation(false);  
125 - return $oPatternTableSqlQuery; 100 +
  101 + $aIDs = DBUtil::getResultArray($sQuery);
  102 +
  103 + $aFields = array();
  104 + foreach ($aIDs as $iID) {
  105 + $aFields[] =& call_user_func(array('DocumentField', 'get'), $iID);
  106 + }
  107 + $aTemplateData = array(
  108 + 'caption' => _('Type specific meta data'),
  109 + 'empty_message' => _("No Type Specific Meta Data"),
  110 + 'fields' => $aFields,
  111 + );
  112 + $oTemplating = KTTemplating::getSingleton();
  113 + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata_fields/editable_metadata_fields");
  114 + return $oTemplate->render($aTemplateData);
126 } 115 }
127 116
128 function getMetaDataForm($iFolderID, $iDocumentTypeID) { 117 function getMetaDataForm($iFolderID, $iDocumentTypeID) {
@@ -130,8 +119,8 @@ function getMetaDataForm($iFolderID, $iDocumentTypeID) { @@ -130,8 +119,8 @@ function getMetaDataForm($iFolderID, $iDocumentTypeID) {
130 $oTypeSpecificPattern = getTypeSpecificMetaDataForm($iFolderID, $iDocumentTypeID); 119 $oTypeSpecificPattern = getTypeSpecificMetaDataForm($iFolderID, $iDocumentTypeID);
131 $sToRender .= "<table border=\"0\" width=\"100%\">\n"; 120 $sToRender .= "<table border=\"0\" width=\"100%\">\n";
132 $sToRender .= "<tr><td><b>" . _("Document Meta Data") . "<b></td></tr>\n"; 121 $sToRender .= "<tr><td><b>" . _("Document Meta Data") . "<b></td></tr>\n";
133 - $sToRender .= "<tr><td valign=\"top\">" . $oGenericPattern->render() . "</td></tr>";  
134 - $sToRender .= "<tr><td valign=\"top\">" . $oTypeSpecificPattern->render() . "</td></tr>"; 122 + $sToRender .= "<tr><td valign=\"top\">" . $oGenericPattern . "</td></tr>";
  123 + $sToRender .= "<tr><td valign=\"top\">" . $oTypeSpecificPattern . "</td></tr>";
135 $sToRender .= "</table>"; 124 $sToRender .= "</table>";
136 125
137 // validation starts 126 // validation starts
@@ -143,9 +132,6 @@ function getMetaDataForm($iFolderID, $iDocumentTypeID) { @@ -143,9 +132,6 @@ function getMetaDataForm($iFolderID, $iDocumentTypeID) {
143 // filename 132 // filename
144 $sToRender .= "\tif (!(validRequired(theForm.fFile, 'Document Filename'))) {\n"; 133 $sToRender .= "\tif (!(validRequired(theForm.fFile, 'Document Filename'))) {\n";
145 $sToRender .= "\t\treturn false;\n\t}\n"; 134 $sToRender .= "\t\treturn false;\n\t}\n";
146 - // metadata  
147 - $sToRender .= $oGenericPattern->getValidationJavascript();  
148 - $sToRender .= $oTypeSpecificPattern->getValidationJavascript();  
149 $sToRender .= "return true;\n}\n"; 135 $sToRender .= "return true;\n}\n";
150 $sToRender .= "//-->\n</script>\n\n"; 136 $sToRender .= "//-->\n</script>\n\n";
151 137