diff --git a/plugins/ktcore/KTCorePlugin.php b/plugins/ktcore/KTCorePlugin.php index d1a1c6c..423799a 100644 --- a/plugins/ktcore/KTCorePlugin.php +++ b/plugins/ktcore/KTCorePlugin.php @@ -217,10 +217,6 @@ class KTCorePlugin extends KTPlugin { _kt('Document Fieldsets'), _kt('Manage the different types of information that can be associated with classes of documents.'), 'admin/documentFieldsv2.php', null); - $this->registerAdminPage("linkmanagement", 'KTDocLinkAdminDispatcher', 'documents', - _kt('Link Type Management'), - _kt('Manage the different ways documents can be associated with one another.'), - 'admin/documentLinks.php', null); $this->registerAdminPage("workflows", 'KTWorkflowDispatcher', 'documents', _kt('Workflows'), _kt('Configure the process documents go through.'), 'admin/workflows.php', null); diff --git a/plugins/ktstandard/KTDocumentLinks.php b/plugins/ktstandard/KTDocumentLinks.php index 4c79bb3..11219de 100644 --- a/plugins/ktstandard/KTDocumentLinks.php +++ b/plugins/ktstandard/KTDocumentLinks.php @@ -23,7 +23,7 @@ * All Rights Reserved. * */ - +require_once(KT_LIB_DIR . "/actions/documentviewlet.inc.php"); require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); require_once(KT_LIB_DIR . '/documentmanagement/DocumentLink.inc'); require_once(KT_LIB_DIR . '/documentmanagement/LinkType.inc'); @@ -47,6 +47,7 @@ class KTDocumentLinks extends KTPlugin { function setup() { $this->registerAction('documentaction', 'KTDocumentLinkAction', 'ktcore.actions.document.link'); + $this->registerAction('documentviewlet', 'KTDocumentLinkViewlet', 'ktcore.viewlets.document.link'); $this->registerColumn(_kt('Link Title'), 'ktdocumentlinks.columns.title', 'KTDocumentLinkTitle', dirname(__FILE__) . '/KTDocumentLinksColumns.php'); $this->registerAdminPage("linkmanagement", 'KTDocLinkAdminDispatcher', 'documents', @@ -56,6 +57,74 @@ class KTDocumentLinks extends KTPlugin { } } + + +class KTDocumentLinkViewlet extends KTDocumentViewlet { + var $sName = 'ktcore.viewlets.document.link'; + + function display_viewlet() { + $oKTTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oKTTemplating->loadTemplate("ktstandard/links/links_viewlet"); + if (is_null($oTemplate)) { return ""; } + + $temp_links_from = DocumentLink::getLinksFromDocument($this->oDocument->getId()); + $temp_links_to = DocumentLink::getLinksToDocument($this->oDocument->getId()); + + $links_to = array(); + $links_from = array(); + + foreach ($temp_links_from as $link) { + $oDoc = $link->getChildDocument(); + if (PEAR::isError($oDoc)) { + continue; + } + + if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, 'ktcore.permissions.read', $oDoc)) { + $type = $link->getLinkType(); + $aInfo = array( + 'url' => KTBrowseUtil::getUrlForDocument($oDoc), + 'name' => $oDoc->getName(), + 'type' => $type->getName(), + 'description' => $type->getDescription(), + ); + + $links_from[] = $aInfo; + } + } + + foreach ($temp_links_to as $link) { + $oDoc = $link->getParentDocument(); + if (PEAR::isError($oDoc)) { + continue; + } + + if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, 'ktcore.permissions.read', $oDoc)) { + $type = $link->getLinkType(); + $aInfo = array( + 'url' => KTBrowseUtil::getUrlForDocument($oDoc), + 'name' => $oDoc->getName(), + 'type' => $type->getName(), + 'description' => $type->getDescription(), + ); + + $links_to[] = $aInfo; + } + } + + if (empty($links_from) && empty($links_to)) { + return ""; + } + + $oTemplate->setData(array( + 'context' => $this, + 'links_from' => $links_from, + 'links_to' => $links_to, + )); + return $oTemplate->render(); + } + +} + class KTDocumentLinkAction extends KTDocumentAction { var $sName = 'ktcore.actions.document.link'; diff --git a/templates/ktcore/document/view.smarty b/templates/ktcore/document/view.smarty index 4097ab5..04065d7 100644 --- a/templates/ktcore/document/view.smarty +++ b/templates/ktcore/document/view.smarty @@ -45,9 +45,7 @@ these tasks, use the Request Assistance action.{/i18n}
-{foreach from=$viewlets item=oViewlet} - {$oViewlet->display_viewlet()} -{/foreach} +{$sviewlet_data}
{/if} diff --git a/templates/ktstandard/links/links_viewlet.smarty b/templates/ktstandard/links/links_viewlet.smarty new file mode 100644 index 0000000..a1ca945 --- /dev/null +++ b/templates/ktstandard/links/links_viewlet.smarty @@ -0,0 +1,20 @@ +
+ {if $links_from} +

Links from this document

+ + {/if} + + {if $links_to} +

Links to this document

+ + {/if} + +
diff --git a/view.php b/view.php index 4cfbb57..59712b7 100755 --- a/view.php +++ b/view.php @@ -207,13 +207,15 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { $aInfo = $oAction->getInfo(); if ($aInfo !== null) { - $aViewlets[] = $oAction; // use the action, since we display_viewlet() later. + $aViewlets[] = $oAction->display_viewlet(); // use the action, since we display_viewlet() later. } } + $viewlet_data = implode(" ", $aViewlets); + $viewlet_data = trim($viewlet_data); $content_class = 'view'; - if (!empty($aViewlets)) { + if (!empty($viewlet_data)) { $content_class = 'view withviewlets'; } $this->oPage->setContentClass($content_class); @@ -231,7 +233,7 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { "document" => $oDocument, "document_data" => $document_data, "fieldsets" => $fieldsets, - 'viewlets' => $aViewlets, + 'viewlet_data' => $viewlet_data, ); //return '
' . print_r($aTemplateData, true) . '
'; return $oTemplate->render($aTemplateData);