view.php.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 490 行 · 第 1/2 页
SVN-BASE
490 行
$content_class = 'view'; if (!empty($viewlet_data)) { $content_class = 'view withviewlets'; } $this->oPage->setContentClass($content_class); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/document/view'); $aTemplateData = array( 'context' => $this, 'sCheckoutUser' => $checkout_user, 'isCheckoutUser' => ($this->oUser->getId() == $oDocument->getCheckedOutUserId()), 'canCheckin' => $bCanCheckin, 'document_id' => $document_id, 'document' => $oDocument, 'documentName' => $oDocument->getName(), 'document_data' => $document_data, 'fieldsets' => $fieldsets, 'viewlet_data' => $viewlet_data, ); //return '<pre>' . print_r($aTemplateData, true) . '</pre>'; return $oTemplate->render($aTemplateData); } // FIXME refactor out the document-info creation into a single utility function. // this gets in: // fDocumentId (document to compare against) // fComparisonVersion (the metadata_version of the appropriate document) 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 do_error() { return ' '; // don't actually do anything. } function do_request($oDocument) { // Display form for sending a request through the the sys admin to unarchive the document // name, document, request, submit $oForm = new KTForm; $oForm->setOptions(array( 'label' => _kt('Request restoration of document'), 'submit_label' => _kt('Send request'), 'identifier' => '', 'cancel_url' => KTBrowseUtil::getUrlForFolder($oFolder), 'fail_action' => 'main', 'context' => $this, )); $oForm->addWidget( array('ktcore.widgets.text', array( 'label' => _kt('Reason'), 'name' => 'reason', 'required' => true, )) ); $data = isset($_REQUEST['data']) ? $_REQUEST['data'] : array(); $iFolderId = $oDocument->getFolderID(); $oFolder = Folder::get($iFolderId); $sFolderUrl = KTBrowseUtil::getUrlForFolder($oFolder); if(!empty($data)){ $res = $oForm->validate(); if (!empty($res['errors'])) { return $oForm->handleError('', $aError); } $aAdminGroups = Group::getAdministratorGroups(); if(!PEAR::isError($aAdminGroups) && !empty($aAdminGroups)){ foreach ($aAdminGroups as $oGroup) { $aGroupUsers = $oGroup->getMembers(); // ensure unique users foreach ($aGroupUsers as $oUser){ $aUsers[$oUser->getId()] = $oUser; } } $sSubject = _kt('Request for an archived document to be restored'); $sDetails = $data['reason']; // Send request foreach ($aUsers as $oU) { if (!PEAR::isError($oU)) { include_once(KT_DIR.'/plugins/ktcore/KTAssist.php'); KTAssistNotification::newNotificationForDocument($oDocument, $oU, $this->oUser, $sSubject, $sDetails); } } // Redirect to folder $this->addInfoMessage(_kt('The System Administrators have been notified of your request.')); redirect($sFolderUrl); exit(); } } return $oForm->renderPage(_kt('Archived document request') . ': '.$oDocument->getName()); } function getUserForId($iUserId) { $u = User::get($iUserId); if (PEAR::isError($u) || ($u == false)) { return _kt('User no longer exists'); } return $u->getName(); }}$oDispatcher = new ViewDocumentDispatcher;$oDispatcher->dispatch();?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?