From a24f1962e17a1a5998d171ee2a6e3fa56ee8a5e1 Mon Sep 17 00:00:00 2001 From: bshuttle Date: Wed, 30 Nov 2005 14:12:00 +0000 Subject: [PATCH] corrected version_history and metadata history. --- presentation/lookAndFeel/knowledgeTree/documentmanagement/editDocument.php | 18 ++++++++++++++++++ presentation/lookAndFeel/knowledgeTree/documentmanagement/view.php | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- templates/kt3/document/metadata_history.smarty | 32 ++++++++++++++++++++++++++++++++ templates/kt3/view_document_history.smarty | 5 +---- 4 files changed, 117 insertions(+), 20 deletions(-) create mode 100644 templates/kt3/document/metadata_history.smarty diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/editDocument.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/editDocument.php index 41fa0c9..2ebb44d 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/editDocument.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/editDocument.php @@ -246,8 +246,26 @@ class KTEditDocumentDispatcher extends KTStandardDispatcher { //return '
' . print_r($field_values, true) . '
'; $this->startTransaction(); + $res = KTDocumentUtil::createMetadataVersion($oDocument); + if (PEAR::isError($res)) { + $this->errorRedirectToMain('Unable to create a metadata version of the document.'); + } + + $oDocument->setLastModifiedDate(getCurrentDateTime()); + $oDocument->setModifiedUserId($this->oUser->getId()); + $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), 'update metadata.', UPDATE); + $res = $oDocumentTransaction->create(); + if (PEAR::isError($res)) { + $this->errorRedirectToMain('Failed to create transaction.'); + } + + $res = $oDocument->update(); + if (PEAR::isError($res)) { + $this->errorRedirectToMain('Failed to change basic details about the document..'); + } $res = KTDocumentUtil::saveMetadata($oDocument, $field_values); + if (PEAR::isError($res)) { $this->rollbackTransaction(); diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/view.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/view.php index 55d2302..d261d7c 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/view.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/view.php @@ -185,6 +185,45 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { } + function do_versionhistory() { + // this is the list of documents past. + $document_data = array(); + $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); + if ($document_id === null) { + $this->oPage->addError('No document was requested. Please browse for one.'); + return $this->do_error(); + } + $document_data["document_id"] = $document_id; + + // try get the document. + $oDocument =& Document::get($document_id); + if (PEAR::isError($oDocument)) { + $this->oPage->addError('The document you attempted to retrieve is invalid. Please browse for one.'); + return $this->do_error(); + } + // fixme check perms + + $this->oDocument =& $oDocument; + $this->aBreadcrumbs = array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($oDocument)); + $this->oPage->setBreadcrumbDetails("history"); + $this->addPortlets("History"); + + $aVersions = Document::getByLiveDocument($oDocument); + //var_dump($aVersions); + + // render pass. + $this->oPage->title = "Document History : " . $oDocument->getName(); + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("kt3/document/metadata_history"); + $aTemplateData = array( + "context" => $this, + "document_id" => $document_id, + "document" => $oDocument, + "versions" => $aVersions, + ); + return $oTemplate->render($aTemplateData); + } + // FIXME refactor out the document-info creation into a single utility function. // this gets in: // fDocumentId (document to compare against) @@ -219,17 +258,20 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { return $this->do_error(); } - // FIXME when transaction history accurately stores metadata_version, this is no longer required. - // FIXME detect that the metadata_version was "manufactured" - // - $oComparison =& $oDocument; - $comparison_data =& $document_data; // no copy. - - // - - + $oComparison =& Document::get($comparison_version); + if (PEAR::isError($oComparison)) { + $this->errorRedirectToMain('Invalid document to compare against.'); + } + $comparison_data = array(); + $comparison_data['document_id'] = $oComparison->getId(); + $document_data["document"] = $oDocument; + $comparison_data['document'] = $oComparison; + $document_data["document_type"] =& DocumentType::get($oDocument->getDocumentTypeID()); + $comparison_data["document_type"] =& DocumentType::get($oComparison->getDocumentTypeID()); + + // follow twice: once for normal, once for comparison. $is_valid_doctype = true; if (PEAR::isError($document_data["document_type"])) { @@ -247,9 +289,16 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { $document_data["field_values"] = $field_values; + $mdlist =& DocumentFieldLink::getList(array('document_id = ?', array($comparison_version))); + + $field_values = array(); + foreach ($mdlist as $oFieldLink) { + $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); + } + + $comparison_data["field_values"] = $field_values; + - // FIXME generate portlets - // FIXME generate breadcrumb // Fieldset generation. // @@ -281,11 +330,7 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { array_push($fieldsets, new $displayClass($oFieldset)); } } - - // - $document_data["is_manufactured"] = 1; - // - + // FIXME handle ad-hoc fieldsets. $oTemplating = new KTTemplating; @@ -308,6 +353,11 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { return ''; // allow normal rendering of errors. // FIXME show something useful / generic. } + + function getUserForId($iUserId) { + $u = User::get($iUserId); + return $u->getName(); + } } $oDispatcher = new ViewDocumentDispatcher; diff --git a/templates/kt3/document/metadata_history.smarty b/templates/kt3/document/metadata_history.smarty new file mode 100644 index 0000000..33e20f1 --- /dev/null +++ b/templates/kt3/document/metadata_history.smarty @@ -0,0 +1,32 @@ +

Metadata History: {$document->getName()}

+ +

This lists the older versions of the document, as the metadata about it has been changed.

+ + + + + + + + + + + + + + + + + + + + {foreach item=oVersion from=$versions} + + + + + + {/foreach} + + +
UserContent VersionCompare
{$context->getUserForId($document->getModifiedUserId())}{$document->getMajorVersionNumber()}.{$document->getMinorVersionNumber()}Current
{$context->getUserForId($oVersion->getModifiedUserId())}{$oVersion->getMajorVersionNumber()}.{$oVersion->getMinorVersionNumber()}compare with current
diff --git a/templates/kt3/view_document_history.smarty b/templates/kt3/view_document_history.smarty index b20af5c..76e67ab 100644 --- a/templates/kt3/view_document_history.smarty +++ b/templates/kt3/view_document_history.smarty @@ -11,7 +11,7 @@ Action Date Content version - Comment + Comment @@ -22,9 +22,6 @@ {$aTransactionRow.datetime} {$aTransactionRow.version} {$aTransactionRow.comment} - - Compare with current version - {/foreach} -- libgit2 0.21.4