From 8035779b31822ae57fa16eea95eddc41d3bfbfaa Mon Sep 17 00:00:00 2001 From: Megan Watson Date: Thu, 10 Apr 2008 13:53:36 +0000 Subject: [PATCH] KTS-3175 "Add "browse by tag" feature" Fixed. Created a portlet that displays next to the search results and can be used to filter down through the results. --- plugins/ktcore/KTPortlets.php | 58 +++++++++++++++++++++++++++++++++------------------------- plugins/tagcloud/TagCloudDashlet.php | 44 +++++++++++++++++++++----------------------- plugins/tagcloud/TagCloudPlugin.php | 56 +++++++++++++++++++++++++++++--------------------------- plugins/tagcloud/TagCloudPortlet.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/tagcloud/TagCloudRedirectPage.php | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------ plugins/tagcloud/TagCloudUtil.inc.php | 249 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/tagcloud/templates/TagCloud/portlet.smarty | 29 +++++++++++++++++++++++++++++ 7 files changed, 537 insertions(+), 153 deletions(-) create mode 100644 plugins/tagcloud/TagCloudPortlet.php create mode 100644 plugins/tagcloud/TagCloudUtil.inc.php create mode 100644 plugins/tagcloud/templates/TagCloud/portlet.smarty diff --git a/plugins/ktcore/KTPortlets.php b/plugins/ktcore/KTPortlets.php index 889e34f..376323c 100644 --- a/plugins/ktcore/KTPortlets.php +++ b/plugins/ktcore/KTPortlets.php @@ -5,32 +5,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ @@ -48,7 +48,7 @@ class KTSearchPortlet extends KTPortlet { $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("kt3/portlets/search_portlet"); - + $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', 1); $iDocumentId = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); if (!$iFolderId && !$iDocumentId) { @@ -59,10 +59,10 @@ class KTSearchPortlet extends KTPortlet { $aSearches = KTSavedSearch::getUserSearches($iUserId); // empty on error. - if (PEAR::isError($aSearches)) { - $aSearches = array(); + if (PEAR::isError($aSearches)) { + $aSearches = array(); } - + $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', 1); $aTemplateData = array( "context" => $this, @@ -87,16 +87,24 @@ class KTBrowseModePortlet extends KTPortlet { parent::KTPortlet($sTitle); } - function render() { + function render() { // this is unfortunate, but such is life. $current_action = KTUtil::arrayGet($_REQUEST, 'fBrowseMode', null); $modes = array( - 'folder' => array('name' => _kt('Folder'), 'target' => "main"), + 'folder' => array('name' => _kt('Folder'), 'target' => "main"), 'document_type' => array('name' => _kt('Document Type'), 'target' => 'selectType'), 'lookup_value' => array('name' => _kt('Lookup Value'), 'target' => 'selectField'), - ); - - $oTemplating =& KTTemplating::getSingleton(); + ); + + // Browse by tag + $oRegistry =& KTPluginRegistry::getSingleton(); + $oPlugin =& $oRegistry->getPlugin('ktcore.tagcloud.plugin'); + if(!PEAR::isError($oPlugin) && !empty($oPlugin)){ + $tagUrl = $oPlugin->getPagePath('TagCloudRedirection'); + $modes['tag'] = array('name' => ''._kt('Tag').''); + } + + $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("kt3/portlets/browsemodes_portlet"); $aTemplateData = array( "context" => $this, @@ -104,7 +112,7 @@ class KTBrowseModePortlet extends KTPortlet { "modes" => $modes, ); - return $oTemplate->render($aTemplateData); + return $oTemplate->render($aTemplateData); } } @@ -161,21 +169,21 @@ class KTAdminSectionNavigation extends KTPortlet { function KTAdminSectionNavigation() { parent::KTPortlet(_kt("Administration")); } - + function render() { require_once(KT_LIB_DIR . "/plugins/KTAdminNavigation.php"); - + $oRegistry =& KTAdminNavigationRegistry::getSingleton(); - $categories = $oRegistry->getCategories(); - + $categories = $oRegistry->getCategories(); + // we need to investigate sub_url solutions. - + $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("kt3/portlets/admin_categories"); $aTemplateData = array( "context" => $this, "categories" => $categories, ); - return $oTemplate->render($aTemplateData); + return $oTemplate->render($aTemplateData); } } diff --git a/plugins/tagcloud/TagCloudDashlet.php b/plugins/tagcloud/TagCloudDashlet.php index cdf5b94..bc5c316 100644 --- a/plugins/tagcloud/TagCloudDashlet.php +++ b/plugins/tagcloud/TagCloudDashlet.php @@ -6,32 +6,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ @@ -44,7 +44,7 @@ require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); class TagCloudDashlet extends KTBaseDashlet { var $oUser; var $sClass = 'ktBlock'; - + /** * Constructor method * @@ -53,7 +53,7 @@ class TagCloudDashlet extends KTBaseDashlet { function TagCloudDashlet(){ $this->sTitle = _kt('Tag Cloud'); } - + /** * Check to see if user is active * @@ -74,9 +74,7 @@ class TagCloudDashlet extends KTBaseDashlet { $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('TagCloud/dashlet'); - $aTags = & $this->get_relevant_tags(); - if($aTags) - $aTags = & $this->get_tag_weightings($aTags); + $aTags = $this->get_tag_weightings($aTags); $oRegistry =& KTPluginRegistry::getSingleton(); $oPlugin =& $oRegistry->getPlugin('ktcore.tagcloud.plugin'); @@ -88,14 +86,14 @@ class TagCloudDashlet extends KTBaseDashlet { ); return $oTemplate->render($aTemplateData); } - + /** * Builds the weightings for tags based on their frequency * * @param array $aTags * @return array */ - function & get_tag_weightings(&$aTags) + function get_tag_weightings($aTags) { $aTags = $this->get_relevant_tags(); @@ -121,23 +119,23 @@ class TagCloudDashlet extends KTBaseDashlet { return $aTags; } - + /** * Returns the relevant tags for the current user * * @return array */ - function & get_relevant_tags() + function get_relevant_tags() { $aUserPermissions = KTSearchUtil::permissionToSQL($this->oUser, null); if(PEAR::isError($aUserPermissions)) { return false; } - list($where, $params, $joins) = KTSearchUtil::permissionToSQL($this->oUser, null); + list($where, $params, $joins) = $aUserPermissions; $sql = " - SELECT - TW.tag, count(*) as freq - FROM + SELECT + TW.tag, count(*) as freq + FROM document_tags DT INNER JOIN tag_words TW ON DT.tag_id=TW.id WHERE DT.document_id in (SELECT D.id FROM documents D $joins WHERE $where AND D.status_id = '1') GROUP BY TW.tag"; @@ -155,6 +153,6 @@ class TagCloudDashlet extends KTBaseDashlet { return $aTags; } - + } ?> diff --git a/plugins/tagcloud/TagCloudPlugin.php b/plugins/tagcloud/TagCloudPlugin.php index a83324c..00ed567 100644 --- a/plugins/tagcloud/TagCloudPlugin.php +++ b/plugins/tagcloud/TagCloudPlugin.php @@ -6,36 +6,36 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ - + require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); require_once('TagCloudRedirectPage.php'); @@ -48,7 +48,8 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); class TagCloudPlugin extends KTPlugin{ var $sNamespace = 'ktcore.tagcloud.plugin'; - + var $iVersion = 1; + /** * Constructor method for plugin * @@ -60,7 +61,7 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); $this->sFriendlyName = _kt('Tag Cloud Plugin'); return $res; } - + /** * Setup function for plugin * @@ -69,8 +70,9 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); // Register plugin components $this->registerCriterion('TagCloudCriterion', 'ktcore.criteria.tagcloud', KT_LIB_DIR . '/browse/Criteria.inc'); $this->registerDashlet('TagCloudDashlet', 'ktcore.tagcloud.feed.dashlet', 'TagCloudDashlet.php'); - $this->registerPage('TagCloudRedirection', 'TagCloudRedirectPage', __FILE__); - + $this->registerPage('TagCloudRedirection', 'TagCloudRedirectPage', __FILE__); + $this->registerPortlet(array(), 'TagCloudPortlet', 'tagcloud.portlet', 'TagCloudPortlet.php'); + // Check if the tagcloud fielset entry exists, if not, create it if(!TagCloudPlugin::tagFieldsetExists()){ @@ -85,7 +87,7 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); }else{ // if the entry exists, make the fieldset id viewable anyway $iFieldsetId = TagCloudPlugin::tagFieldsetExists(); } - + // Check if the tagcloud document field entry exists, if not, create it if(!TagCloudPlugin::tagFieldExists()){ $oField = TagCloudPlugin::createDocumentField($iFieldsetId); @@ -93,18 +95,18 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); return false; } } - + $oTemplating =& KTTemplating::getSingleton(); $oTemplating->addLocation('Tag Cloud Plugin', '/plugins/tagcloud/templates'); } - + /** * function to add fieldset entry to fieldsets table * * @return unknown */ function createFieldset(){ - // create the fieldsets entry + // create the fieldsets entry $oFieldset = KTFieldset::createFromArray(array( 'name' => 'Tag Cloud', 'description' => 'Tag Cloud', @@ -114,12 +116,12 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); 'isGeneric' => true, 'isComplete' => false, 'isComplex' => false, - 'isSystem' => false, + 'isSystem' => false, )); - + return $oFieldset; } - + /** * function to add the tagcloud entry to the document_fields table * @@ -127,7 +129,7 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); * @return int $id */ function createDocumentField($parentId){ - // create the document_field entry + // create the document_field entry $id = DocumentField::createFromArray(array( 'Name' => 'Tag', 'Description' => 'Tag Words', @@ -136,12 +138,12 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); 'HasLookup' => false, 'HasLookupTree' => false, 'ParentFieldset' => $parentId, - 'IsMandatory' => false, + 'IsMandatory' => false, )); return $id; } - + /** * function to check if the Tag field exists in the document_fields table * @@ -155,7 +157,7 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); if (PEAR::isError($sTag)) { // XXX: log error return false; - + } if(!is_null($sTag)){ return $sTag; @@ -163,7 +165,7 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); return false; } } - + /** * function to check if the fieldset exists in the database * @@ -177,7 +179,7 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); if (PEAR::isError($iFieldset)) { // XXX: log error return false; - + } if(!is_null($iFieldset)){ return $iFieldset; diff --git a/plugins/tagcloud/TagCloudPortlet.php b/plugins/tagcloud/TagCloudPortlet.php new file mode 100644 index 0000000..a0d780a --- /dev/null +++ b/plugins/tagcloud/TagCloudPortlet.php @@ -0,0 +1,78 @@ +. + * + * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, + * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "Powered by + * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. + * Contributor( s): ______________________________________ + * + */ + +require_once(KT_LIB_DIR . '/widgets/portlet.inc.php'); +require_once('TagCloudUtil.inc.php'); + +class TagCloudPortlet extends KTPortlet { + var $bActive = true; + var $oUser = ''; + var $sTag = ''; + + function TagCloudPortlet($oUser = NULL, $sTag = NULL) { + if(empty($oUser)){ + $iUserId = $_SESSION['userID']; + $oUser = User::get($iUserId); + } + $this->oUser = $oUser; + $this->sTag = $sTag; + $title = _kt('Tag Cloud'); + parent::KTPortlet($title); + } + + function render() { + $oRegistry =& KTPluginRegistry::getSingleton(); + $oPlugin =& $oRegistry->getPlugin('ktcore.tagcloud.plugin'); + $url = $oPlugin->getPagePath('TagCloudRedirection'); + $url .= '&action=search'; + + $aTags = get_relevant_tags($this->oUser, $this->sTag); + $aTags = get_tag_weightings($aTags); + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('TagCloud/portlet'); + $aTemplateData = array( + 'tags' => $aTags, + 'url' => $url + ); + return $oTemplate->render($aTemplateData); + } + +} + +?> \ No newline at end of file diff --git a/plugins/tagcloud/TagCloudRedirectPage.php b/plugins/tagcloud/TagCloudRedirectPage.php index f1179be..ea38de5 100644 --- a/plugins/tagcloud/TagCloudRedirectPage.php +++ b/plugins/tagcloud/TagCloudRedirectPage.php @@ -1,39 +1,39 @@ . - * - * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, - * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * - * The interactive user interfaces in modified source and object code versions - * of this program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. - * Contributor( s): ______________________________________ - * - */ +* $Id$ +* +* KnowledgeTree Open Source Edition +* Document Management Made Simple +* Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 3 as published by the +* Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +* details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, +* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. +* +* The interactive user interfaces in modified source and object code versions +* of this program must display Appropriate Legal Notices, as required under +* Section 5 of the GNU General Public License version 3. +* +* In accordance with Section 7(b) of the GNU General Public License version 3, +* these Appropriate Legal Notices must retain the display of the "Powered by +* KnowledgeTree" logo and retain the original copyright notice. If the display of the +* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices +* must display the words "Powered by KnowledgeTree" and retain the original +* copyright notice. +* Contributor( s): ______________________________________ +* +*/ require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); @@ -52,46 +52,71 @@ require_once(KT_LIB_DIR . '/browse/PartialQuery.inc.php'); require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); require_once(KT_LIB_DIR . '/actions/bulkaction.php'); +require_once(KT_DIR . '/plugins/tagcloud/TagCloudPortlet.php'); + class TagCloudRedirectPage extends KTStandardDispatcher { - /** + /** * Dispatcher main method * * @return unknown */ - function do_main() { - $searchable_text = KTUtil::arrayGet($_REQUEST, 'tag'); - // set breadcrumbs - $this->aBreadcrumbs[] = array('url' => 'dashboard.php', 'name' => _kt('Dashboard')); - $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'].'&tag='.htmlentities($searchable_text,ENT_QUOTES,'UTF-8'), 'name' => _kt('Tag Cloud Search')); - // set page title - $sTitle = _kt('Search Results'); - - $this->oPage->setBreadcrumbDetails($sTitle); - - // build criteria set - $aCriteriaSet = array( - 'join'=>'AND', - 'subgroup'=>array( - 0=>array( - 'join'=>'AND', - 'values'=>array( - 1=>array( - 'data'=>array( - 'ktcore.criteria.tagcloud'=>$searchable_text, - 'ktcore.criteria.tagcloud_not'=>0 - ), - 'type'=>'ktcore.criteria.tagcloud' - ) - ) - ) - ) - ); - - - $this->browseType = 'Folder'; - $sSearch = md5(serialize($aCriteriaSet)); - $_SESSION['boolean_search'][$sSearch] = $aCriteriaSet; + function do_main() { + // Clear the session for a new search + $url = isset($_REQUEST['tag']) ? 'tag='.$_REQUEST['tag'] : ''; + $_SESSION['tagList'] = array(); + $this->redirectTo('search', $url); + } + + /** + * Recall a previous tag search and remove the tags that were selected after it. + */ + function do_recall() { + $tag = $_REQUEST['tag']; + $pos = $_REQUEST['pos']; + + // Delete all tags after and including the selected tag + $tagList = $_SESSION['tagList']; + $tagList = array_slice($tagList, 0, $pos); + + $_SESSION['tagList'] = $tagList; + + $this->redirectTo('search', 'tag='.$tag); + } + + function do_search() { + // Get the tag to search for and create search query + $tag = isset($_REQUEST['tag']) ? $_REQUEST['tag'] : ''; + + $iUserId = $_SESSION['userID']; + $oUser = User::get($iUserId); + + // set breadcrumbs + $this->aBreadcrumbs[] = array('url' => 'dashboard.php', 'name' => _kt('Dashboard')); + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Tag Cloud Search')); + + $tagList = $_SESSION['tagList']; + if(!empty($tagList)){ + $aPrevTag = end($tagList); + $aTagTree = $aPrevTag['tagTree']; + + $base = KTUtil::addQueryString('TagCloudRedirection&action=recall', null); + foreach($aTagTree as $key => $item){ + $url = $base.'&tag='.$item.'&pos='.$key; + $this->aBreadcrumbs[] = array('url' => $url, 'name' => $item); + } + } + if(!empty($tag)){ + $this->aBreadcrumbs[] = array('url' => '', 'name' => $tag); + } + + // set page title + $sTitle = _kt('Search Results'); + $this->oPage->setBreadcrumbDetails($sTitle); + + // Set tag cloud portlet + $portlet = new TagCloudPortlet($oUser, $tag); + $this->oPage->addPortlet($portlet); $collection = new AdvancedCollection; $oColumnRegistry = KTColumnRegistry::getSingleton(); @@ -99,25 +124,22 @@ class TagCloudRedirectPage extends KTStandardDispatcher { $collection->addColumns($aColumns); // set a view option - $aTitleOptions = array( - 'documenturl' => $GLOBALS['KTRootUrl'] . '/view.php', - ); + $aTitleOptions = array('documenturl' => $GLOBALS['KTRootUrl'] . '/view.php',); $collection->setColumnOptions('ktcore.columns.title', $aTitleOptions); $collection->setColumnOptions('ktcore.columns.selection', array( 'rangename' => 'selection', 'show_folders' => true, 'show_documents' => true, - )); + )); $aOptions = $collection->getEnvironOptions(); // extract data from the environment - //$aOptions['return_url'] = KTUtil::addQueryString('dashboard.php', false); - $aOptions['return_url'] = KTUtil::addQueryString('TagCloudRedirection&tag='. $searchable_text, false ); + $aOptions['return_url'] = KTUtil::addQueryString('TagCloudRedirection&action=search&tag='. $tag, false ); $aOptions['empty_message'] = _kt('No documents or folders match this query.'); $aOptions['is_browse'] = true; $collection->setOptions($aOptions); - $collection->setQueryObject(new BooleanSearchQuery($aCriteriaSet)); + $collection->setQueryObject(new TagQuery($oUser, $tag)); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('kt3/browse'); @@ -131,10 +153,8 @@ class TagCloudRedirectPage extends KTStandardDispatcher { 'browseutil' => new KTBrowseUtil(), 'returnaction' => 'booleanSearch', 'returndata' => $sSearch, - ); return $oTemplate->render($aTemplateData); - - } + } } ?> diff --git a/plugins/tagcloud/TagCloudUtil.inc.php b/plugins/tagcloud/TagCloudUtil.inc.php new file mode 100644 index 0000000..d0c1c8b --- /dev/null +++ b/plugins/tagcloud/TagCloudUtil.inc.php @@ -0,0 +1,249 @@ +. + * + * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, + * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "Powered by + * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. + * Contributor( s): ______________________________________ + * + */ + + +/** +* Builds the weightings for tags based on their frequency +* +* @param array $aTags +* @return array +*/ +function get_tag_weightings($aTags) +{ + if (empty($aTags)){ + return array(); + }else{ + $min_freq = min(array_values($aTags)); + $max_freq = max(array_values($aTags)); + } + $min_size = 10; + $max_size = 20; + + $distrib = $max_freq - $min_freq; + if ($distrib == 0){ + $distrib=1; + } + + $step = ($max_size - $min_size)/($distrib); + + foreach($aTags as $tag => $freq) + { + $size = ceil($min_size + (($freq - $min_freq) * $step)); + $aTags[$tag] = $size; + } + + return $aTags; +} + +/** +* Returns the relevant tags for the current user +* +* @return array +*/ +function get_relevant_tags($oUser, $sTag) +{ + $aTagList = isset($_SESSION['tagList']) ? $_SESSION['tagList'] : array(); + $tagTree = array(); + $documentList = ''; + + // Get the previous tag info: + // the list of documents that contain the tag to search within + // the tags that have already been filtered so they aren't displayed again + if(!empty($aTagList)){ + $aPrevTag = end($aTagList); + $sPrevTag = $aPrevTag['tag']; + $documentList = $aPrevTag['docs']; + $tagTree = $aPrevTag['tagTree']; + } + + if(empty($sTag)){ + // If there is no tag specified then get all tags. + $aUserPermissions = KTSearchUtil::permissionToSQL($oUser, 'ktcore.permissions.read'); + if(PEAR::isError($aUserPermissions)) { + return array(); + } + // ensure the user has read permission on the documents + list($sWhere, $aParams, $sJoins) = $aUserPermissions; + + $sql = "SELECT TW.tag, count(*) as freq + FROM document_tags DT + INNER JOIN tag_words TW ON DT.tag_id=TW.id + WHERE DT.document_id in (SELECT D.id FROM documents D $sJoins WHERE $sWhere AND D.status_id = '1') + GROUP BY TW.tag"; + + $tags = DBUtil::getResultArray(array($sql, $aParams)); + }else{ + // Create a new tag query to get the document id's associated with the tag + $oQuery = new TagQuery($oUser, $sTag); + $aOptions = array(); + $aOptions['select'] = 'DISTINCT DTS.document_id'; + + $aQuery = $oQuery->getQuery($aOptions); + $sInnerQuery = $aQuery[0]; + $aParams = $aQuery[1]; + + $aDocIds = DBUtil::getResultArrayKey($aQuery, 'document_id'); + $sDocs = implode(',', $aDocIds); + + // Don't display tags that have already been selected. + $tagTree[] = $sTag; + $cnt = count($tagTree); + $sIgnoreTags = '?'; + for($i = 1; $i < $cnt; $i++){ + $sIgnoreTags .= ',?'; + } + + // Get the tags within the documents that haven't been selected before + $sQuery = "SELECT TW.tag, count(*) as freq + FROM document_tags DT INNER JOIN tag_words TW ON DT.tag_id=TW.id + WHERE DT.document_id in ($sDocs) AND TW.tag NOT IN ($sIgnoreTags) + GROUP BY TW.tag"; + + $tags = DBUtil::getResultArray(array($sQuery, $tagTree), null); + + // Add new tag to the session + if($sPrevTag != $sTag){ + $aTagList[] = array('tag' => $sTag, 'docs' => $sDocs, 'tagTree' => $tagTree); + $_SESSION['tagList'] = $aTagList; + } + } + + // Create tag / frequency array + $aTags = array(); + foreach($tags as $tag) + { + $word=$tag['tag']; + $freq=$tag['freq']; + $aTags[$word] = $freq; + } + + return $aTags; + +} + +class TagQuery extends PartialQuery +{ + var $oUser; + var $sTag; + + function TagQuery($oUser, $sTag = '') + { + $this->sTag = $sTag; + $this->oUser = $oUser; + } + + function getDocumentCount() + { + $aOptions = array( + 'select' => 'count(DISTINCT DTS.document_id) AS cnt', + ); + $aQuery = $this->getQuery($aOptions); + if (PEAR::isError($aQuery)) { return 0; } + $iRet = DBUtil::getOneResultKey($aQuery, 'cnt'); + return $iRet; + } + + function getBaseQuery($aOptions) + { + $aCriteriaSet = array( + 'join'=>'AND', + 'subgroup'=>array( + 0=>array( + 'join'=>'AND', + 'values'=>array( + 1=>array( + 'data'=>array( + 'ktcore.criteria.tagcloud' => $this->sTag, + 'ktcore.criteria.tagcloud_not'=>0 + ), + 'type'=>'ktcore.criteria.tagcloud' + ) + ), + ) + ) + ); + + $aQuery = KTSearchUtil::criteriaToQuery($aCriteriaSet, $this->oUser, 'ktcore.permissions.read', $aOptions); + return $aQuery; + } + + function getQuery($aOptions = null) + { + $aTagList = isset($_SESSION['tagList']) ? $_SESSION['tagList'] : array(); + if(!empty($aTagList)){ + $aPrevTag = end($aTagList); + $documentList = $aPrevTag['docs']; + } + + // If the document list is empty then create internal query with read permissions for the user and the first tag + $aQuery = $this->getBaseQuery($aOptions); + if(empty($documentList)){ + return $aQuery; + } + + $sQuery = $aQuery[0]; + + $sQuery .= " AND DTS.document_id IN ($documentList) "; + $aQuery[0] = $sQuery; + + return $aQuery; + } + + function getDocuments($iBatchSize, $iBatchStart, $sSortColumn, $sSortOrder, $sJoinClause = null, $aJoinParams = null) + { + $aOptions = array( + 'select' => 'DISTINCT DTS.document_id AS id' + ); + $res = $this->getQuery($aOptions); + if (PEAR::isError($res)) { return array(); } + list($sQuery, $aParams) = $res; + $sQuery .= ' ORDER BY ' . $sSortColumn . ' ' . $sSortOrder . ' '; + $sQuery .= ' LIMIT ?, ?'; + + $aParams[] = $iBatchStart; + $aParams[] = $iBatchSize; + + $q = array($sQuery, $aParams); + $res = DBUtil::getResultArray($q); + + return $res; + } +} + + +?> \ No newline at end of file diff --git a/plugins/tagcloud/templates/TagCloud/portlet.smarty b/plugins/tagcloud/templates/TagCloud/portlet.smarty new file mode 100644 index 0000000..13ec9c0 --- /dev/null +++ b/plugins/tagcloud/templates/TagCloud/portlet.smarty @@ -0,0 +1,29 @@ +{literal} + +{/literal} + +{if empty($tags)} +

+ {i18n}There are no tags defined or accessible.{/i18n} +

+ +{else} +
+{foreach from=$tags key=tag item=size} + + {$tag|sanitize}  + +{/foreach} +
+{/if} + +
+
\ No newline at end of file -- libgit2 0.21.4