function do_viewComparison() { $document_data = array(); $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); if ($document_id === null) { $this->oPage->addError(sprintf(_kt("No document was requested. Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl())); return $this->do_error(); } $document_data['document_id'] = $document_id; $base_version = KTUtil::arrayGet($_REQUEST, 'fBaseVersion'); // try get the document. $oDocument =& Document::get($document_id, $base_version); if (PEAR::isError($oDocument)) { $this->oPage->addError(sprintf(_kt("The base document you attempted to retrieve is invalid. Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl())); return $this->do_error(); } if (!Permission::userHasDocumentReadPermission($oDocument)) { // FIXME inconsistent. $this->oPage->addError(_kt('You are not allowed to view this document')); return $this->permissionDenied(); } $this->oDocument =& $oDocument; $this->oPage->setSecondaryTitle($oDocument->getName()); $aOptions = array('documentaction' => 'viewDocument', 'folderaction' => 'browse'); $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($oDocument, $aOptions)); $this->oPage->setBreadcrumbDetails(_kt('compare versions')); $comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion'); if ($comparison_version === null) { $this->oPage->addError(sprintf(_kt("No comparison version was requested. Please <a href=\"%s\">select a version</a>."), KTUtil::addQueryStringSelf('action=history&fDocumentId=' . $document_id))); return $this->do_error(); } $oComparison =& Document::get($oDocument->getId(), $comparison_version); if (PEAR::isError($oComparison)) { $this->errorRedirectToMain(_kt('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'])) { $this->oPage->addError(_kt('The document you requested has an invalid <strong>document type</strong>. Unfortunately, this means that we cannot effectively display it.')); $is_valid_doctype = false; } // we want to grab all the md for this doc, since its faster that way. $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($base_version))); $field_values = array(); foreach ($mdlist as $oFieldLink) { $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); } $document_data['field_values'] = $field_values; $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($comparison_version))); $field_values = array(); foreach ($mdlist as $oFieldLink) { $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); } $comparison_data['field_values'] = $field_values; // Fieldset generation. // // we need to create a set of FieldsetDisplay objects // that adapt the Fieldsets associated with this lot // to the view (i.e. ZX3). Unfortunately, we don't have // any of the plumbing to do it, so we handle this here. $fieldsets = array(); // we always have a generic. array_push($fieldsets, new GenericFieldsetDisplay()); // FIXME can we key this on fieldset namespace? or can we have duplicates? // now we get the other fieldsets, IF there is a valid doctype. if ($is_valid_doctype) { // these are the _actual_ fieldsets. $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton(); // and the generics $activesets = KTFieldset::getGenericFieldsets(); foreach ($activesets as $oFieldset) { $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); array_push($fieldsets, new $displayClass($oFieldset)); } $activesets = KTFieldset::getForDocumentType($oDocument->getDocumentTypeID()); foreach ($activesets as $oFieldset) { $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); array_push($fieldsets, new $displayClass($oFieldset)); } } // FIXME handle ad-hoc fieldsets. $this->addPortlets(); $oTemplate = $this->oValidator->validateTemplate('ktcore/document/compare'); $aTemplateData = array('context' => $this, 'document_id' => $document_id, 'document' => $oDocument, 'document_data' => $document_data, 'comparison_data' => $comparison_data, 'comparison_document' => $oComparison, 'fieldsets' => $fieldsets); //var_dump($aTemplateData['comparison_data']); return $oTemplate->render($aTemplateData); }
function getCrumbStringForDocument($params, &$smarty) { $aBreadcrumbs = KTBrowseUtil::breadcrumbsForDocument($params['document'], array('final' => true)); if (PEAR::isError($aBreadcrumbs)) { return _kt('No breadcrumbs available'); } $aCrumbs = array(); foreach ($aBreadcrumbs as $aBreadcrumb) { $aCrumbs[] = $aBreadcrumb['name']; } return implode('/', $aCrumbs); }
function check() { $this->oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']); if (!$this->_show()) { return false; } $aOptions = array('final' => false, 'documentaction' => 'viewDocument', 'folderaction' => 'browse'); $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($this->oDocument, $aOptions)); $actions = KTDocumentActionUtil::getDocumentActionsForDocument($this->oDocument, $this->oUser, 'documentinfo'); $oPortlet = new KTActionPortlet(sprintf(_kt('Document info'))); $oPortlet->setActions($actions, $this->sName); $this->oPage->addPortlet($oPortlet); $actions = KTDocumentActionUtil::getDocumentActionsForDocument($this->oDocument, $this->oUser); $oPortlet = new KTActionPortlet(sprintf(_kt('Document actions'))); $oPortlet->setActions($actions, $this->sName); $this->oPage->addPortlet($oPortlet); $this->oPage->setSecondaryTitle($this->oDocument->getName()); return true; }
function testBreadcrumbsForDocument() { $oFolder =& KTFolderUtil::add($this->oFolder, 'testBreadcrumbsForDocument', $this->oUser); $oDocument =& KTDocumentUtil::add($oFolder, 'testBreadcrumbsForDocument.txt', $this->oUser, array()); $aBreadcrumbs =& KTBrowseUtil::breadcrumbsForDocument($oDocument, array('final' => true)); $this->assertEqual($this->_getId($aBreadcrumbs[0]['url']), 1); $this->assertEqual($aBreadcrumbs[0]['name'], 'Folders'); $this->assertEqual($this->_getId($aBreadcrumbs[1]['url']), $this->oFolder->getId()); $this->assertEqual($aBreadcrumbs[1]['name'], $this->oFolder->getName()); $this->assertEqual($this->_getId($aBreadcrumbs[2]['url']), $oFolder->getId()); $this->assertEqual($aBreadcrumbs[2]['name'], $oFolder->getName()); $this->assertNull($aBreadcrumbs[3]['url']); $this->assertEqual($aBreadcrumbs[3]['name'], $oDocument->getName()); $aBreadcrumbs =& KTBrowseUtil::breadcrumbsForDocument($oDocument, array('final' => false)); $this->assertEqual($this->_getId($aBreadcrumbs[0]['url']), 1); $this->assertEqual($aBreadcrumbs[0]['name'], 'Folders'); $this->assertEqual($this->_getId($aBreadcrumbs[1]['url']), $this->oFolder->getId()); $this->assertEqual($aBreadcrumbs[1]['name'], $this->oFolder->getName()); $this->assertEqual($this->_getId($aBreadcrumbs[2]['url']), $oFolder->getId()); $this->assertEqual($aBreadcrumbs[2]['name'], $oFolder->getName()); $this->assertEqual($this->_getId($aBreadcrumbs[3]['url']), $oDocument->getId()); $this->assertEqual($aBreadcrumbs[3]['name'], $oDocument->getName()); }