Commit 6bd6939af9239575f187ba4fbad5654d3067e424
1 parent
82f923ae
KTS-1730
"An advanced search function to search by metadata" Implemented. Reviewed By: Conrad git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6319 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
6 changed files
with
305 additions
and
0 deletions
lib/browse/Criteria.inc
| ... | ... | @@ -651,6 +651,48 @@ class GenericMetadataCriterion extends BrowseCriterion { |
| 651 | 651 | } |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | +class GeneralMetadataCriterion extends BrowseCriterion { | |
| 655 | + var $aLookup = array( | |
| 656 | + "table" => "document_fields_link", | |
| 657 | + "field" => "value", | |
| 658 | + "joinColumn" => "document_id", | |
| 659 | + ); | |
| 660 | + var $bString = true; | |
| 661 | + var $sDocumentField = 'value'; | |
| 662 | + var $sSortField = null; | |
| 663 | + var $bContains = true; | |
| 664 | + var $sNamespace = 'ktcore.criteria.generalmetadata'; | |
| 665 | + var $sSearchTable = "DFL" ; | |
| 666 | + var $bHandleNot = false; | |
| 667 | + function GeneralMetadataCriterion() | |
| 668 | + { | |
| 669 | + $this->sDisplay = _kt('General Metadata'); | |
| 670 | + } | |
| 671 | + | |
| 672 | + function documentDisplay ($oDocument) { | |
| 673 | + | |
| 674 | + return 'General Metadata'; | |
| 675 | + } | |
| 676 | + | |
| 677 | + | |
| 678 | + function getSearchField () { | |
| 679 | + return $this->aLookup['field']; | |
| 680 | + } | |
| 681 | + | |
| 682 | + | |
| 683 | + function searchSQL ($aRequest) { | |
| 684 | + $val = array('('.$this->getSearchTable() . "." . $this->getSearchField() . " LIKE '%!%' or dm.name LIKE '%!%' )", | |
| 685 | + array(DBUtil::escapeSimple($aRequest[$this->getWidgetBase()]),DBUtil::escapeSimple($aRequest[$this->getWidgetBase()]))); | |
| 686 | + | |
| 687 | + return $val; | |
| 688 | + } | |
| 689 | + | |
| 690 | + function searchJoinSQL () { | |
| 691 | + global $default; | |
| 692 | + return "LEFT JOIN $default->document_fields_link_table AS $this->sSearchTable ON $this->sSearchTable.metadata_version_id = D.metadata_version_id"; | |
| 693 | + } | |
| 694 | +} | |
| 695 | + | |
| 654 | 696 | class DateModifiedCriterion extends DateCreatedCriterion { |
| 655 | 697 | var $sDocumentField = 'modified'; |
| 656 | 698 | var $sSortField = 'modified'; | ... | ... |
plugins/generalmetadata/GeneralMetadataDashlet.php
0 โ 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * $Id: GeneralMetadataDashlet.php,v 1.1 2006/02/28 16:53:49 nbm Exp $ | |
| 5 | + * | |
| 6 | + * Copyright (c) 2007 Jam Warehouse http://www.jamwarehouse.com | |
| 7 | + * | |
| 8 | + * This program is free software; you can redistribute it and/or modify | |
| 9 | + * it under the terms of the GNU General Public License as published by | |
| 10 | + * the Free Software Foundation; using version 2 of the License. | |
| 11 | + * | |
| 12 | + * This program is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | + * GNU General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License | |
| 18 | + * along with this program; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 | + * | |
| 21 | + * ------------------------------------------------------------------------- | |
| 22 | + * | |
| 23 | + * You can contact the copyright owner regarding licensing via the contact | |
| 24 | + * details that can be found on the KnowledgeTree web site: | |
| 25 | + * | |
| 26 | + * http://www.knowledgetree.com/ | |
| 27 | + */ | |
| 28 | + | |
| 29 | + | |
| 30 | +require_once(KT_LIB_DIR . '/browse/browseutil.inc.php'); | |
| 31 | +require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); | |
| 32 | +require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); | |
| 33 | + | |
| 34 | +class GeneralMetadataDashlet extends KTBaseDashlet { | |
| 35 | + var $oUser; | |
| 36 | + var $sClass = 'ktBlock'; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * Constructor method | |
| 40 | + * | |
| 41 | + * @return GeneralMetadataDashlet | |
| 42 | + */ | |
| 43 | + function GeneralMetadataDashlet(){ | |
| 44 | + $this->sTitle = _kt('General Metadata Search'); | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Check to see if user is active | |
| 49 | + * | |
| 50 | + * @param object $oUser | |
| 51 | + * @return boolean | |
| 52 | + */ | |
| 53 | + function is_active($oUser) { | |
| 54 | + $this->oUser = $oUser; | |
| 55 | + return true; | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Render function for template | |
| 60 | + * | |
| 61 | + * @return unknown | |
| 62 | + */ | |
| 63 | + function render() { | |
| 64 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 65 | + $oTemplate = $oTemplating->loadTemplate('GeneralMetadata/dashlet'); | |
| 66 | + | |
| 67 | + $oRegistry =& KTPluginRegistry::getSingleton(); | |
| 68 | + $oPlugin =& $oRegistry->getPlugin('ktcore.generalmetadata.plugin'); | |
| 69 | + $url = $oPlugin->getPagePath('GeneralMetadataPage'); | |
| 70 | + | |
| 71 | + $aTemplateData = array( | |
| 72 | + 'context' => $this, | |
| 73 | + 'url' => $url, | |
| 74 | + ); | |
| 75 | + return $oTemplate->render($aTemplateData); | |
| 76 | + } | |
| 77 | +} | |
| 78 | +?> | ... | ... |
plugins/generalmetadata/GeneralMetadataPage.php
0 โ 100644
| 1 | +<?php | |
| 2 | +require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); | |
| 3 | +require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); | |
| 4 | +require_once(KT_LIB_DIR . "/templating/templating.inc.php"); | |
| 5 | +require_once(KT_LIB_DIR . "/database/dbutil.inc"); | |
| 6 | +require_once(KT_LIB_DIR . "/util/ktutil.inc"); | |
| 7 | +require_once(KT_LIB_DIR . "/dispatcher.inc.php"); | |
| 8 | +require_once(KT_LIB_DIR . "/browse/Criteria.inc"); | |
| 9 | +require_once(KT_LIB_DIR . "/search/savedsearch.inc.php"); | |
| 10 | +require_once(KT_LIB_DIR . "/search/searchutil.inc.php"); | |
| 11 | + | |
| 12 | +require_once(KT_LIB_DIR . "/browse/DocumentCollection.inc.php"); | |
| 13 | +require_once(KT_LIB_DIR . "/browse/BrowseColumns.inc.php"); | |
| 14 | +require_once(KT_LIB_DIR . "/browse/PartialQuery.inc.php"); | |
| 15 | + | |
| 16 | +require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); | |
| 17 | +require_once(KT_LIB_DIR . '/actions/bulkaction.php'); | |
| 18 | + | |
| 19 | +class GeneralMetadataPage extends KTStandardDispatcher { | |
| 20 | + | |
| 21 | + function do_main() { | |
| 22 | + $searchable_text = KTUtil::arrayGet($_POST, "fSearchableText"); | |
| 23 | + | |
| 24 | + // set breadcrumbs | |
| 25 | + $this->aBreadcrumbs[] = array('url' => 'dashboard.php', 'name' => _kt('Dashboard')); | |
| 26 | + $this->aBreadcrumbs[] = array('name' => _kt('General Metadata Search')); | |
| 27 | + | |
| 28 | + $sTitle = _kt('Search Results'); | |
| 29 | + $this->oPage->setBreadcrumbDetails($sTitle); | |
| 30 | + | |
| 31 | + | |
| 32 | + $aCriteriaSet = array( | |
| 33 | + 'join'=>'AND', | |
| 34 | + 'subgroup'=>array( | |
| 35 | + 0=>array( | |
| 36 | + 'join'=>'AND', | |
| 37 | + 'values'=>array( | |
| 38 | + 1=>array( | |
| 39 | + 'data'=>array( | |
| 40 | + 'ktcore.criteria.generalmetadata'=>$searchable_text, | |
| 41 | + 'ktcore.criteria.generalmetadata_not'=>0 | |
| 42 | + ), | |
| 43 | + 'type'=>'ktcore.criteria.generalmetadata' | |
| 44 | + ) | |
| 45 | + ) | |
| 46 | + ) | |
| 47 | + ) | |
| 48 | + ); | |
| 49 | + | |
| 50 | + | |
| 51 | + $this->browseType = "Folder"; | |
| 52 | + $sSearch = md5(serialize($aCriteriaSet)); | |
| 53 | + $_SESSION['boolean_search'][$sSearch] = $aCriteriaSet; | |
| 54 | + | |
| 55 | + $collection = new AdvancedCollection; | |
| 56 | + $oColumnRegistry = KTColumnRegistry::getSingleton(); | |
| 57 | + $aColumns = $oColumnRegistry->getColumnsForView('ktcore.views.search'); | |
| 58 | + $collection->addColumns($aColumns); | |
| 59 | + | |
| 60 | + // set a view option | |
| 61 | + $aTitleOptions = array( | |
| 62 | + 'documenturl' => $GLOBALS['KTRootUrl'] . '/view.php', | |
| 63 | + ); | |
| 64 | + $collection->setColumnOptions('ktcore.columns.title', $aTitleOptions); | |
| 65 | + $collection->setColumnOptions('ktcore.columns.selection', array( | |
| 66 | + 'rangename' => 'selection', | |
| 67 | + 'show_folders' => true, | |
| 68 | + 'show_documents' => true, | |
| 69 | + )); | |
| 70 | + | |
| 71 | + $aOptions = $collection->getEnvironOptions(); // extract data from the environment | |
| 72 | + | |
| 73 | + $aOptions['return_url'] = KTUtil::addQueryStringSelf("action=performSearch&boolean_search_id=" . urlencode($sSearch)); | |
| 74 | + $aOptions['empty_message'] = _kt("No documents or folders match this query."); | |
| 75 | + $aOptions['is_browse'] = true; | |
| 76 | + | |
| 77 | + $collection->setOptions($aOptions); | |
| 78 | + $collection->setQueryObject(new BooleanSearchQuery($aCriteriaSet)); | |
| 79 | + | |
| 80 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 81 | + $oTemplate = $oTemplating->loadTemplate("kt3/browse"); | |
| 82 | + $aTemplateData = array( | |
| 83 | + "context" => $this, | |
| 84 | + "collection" => $collection, | |
| 85 | + "custom_title" => $sTitle, | |
| 86 | + "params" => $aParams, | |
| 87 | + "joins" => $aJoins, | |
| 88 | + 'isEditable' => true, | |
| 89 | + "boolean_search" => $sSearch, | |
| 90 | + 'bulkactions' => KTBulkActionUtil::getAllBulkActions(), | |
| 91 | + 'browseutil' => new KTBrowseUtil(), | |
| 92 | + 'returnaction' => 'booleanSearch', | |
| 93 | + 'returndata' => $sSearch, | |
| 94 | + | |
| 95 | + ); | |
| 96 | + return $oTemplate->render($aTemplateData); | |
| 97 | + } | |
| 98 | +} | |
| 99 | +?> | |
| 0 | 100 | \ No newline at end of file | ... | ... |
plugins/generalmetadata/GeneralMetadataPlugin.php
0 โ 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * $Id: GeneralMetadataPlugin.php,v 1.1 2006/02/28 16:53:49 nbm Exp $ | |
| 5 | + * | |
| 6 | + * Copyright (c) 2006 Jam Warehouse http://www.jamwarehouse.com | |
| 7 | + * | |
| 8 | + * This program is free software; you can redistribute it and/or modify | |
| 9 | + * it under the terms of the GNU General Public License as published by | |
| 10 | + * the Free Software Foundation; using version 2 of the License. | |
| 11 | + * | |
| 12 | + * This program is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | + * GNU General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License | |
| 18 | + * along with this program; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 | + * | |
| 21 | + * ------------------------------------------------------------------------- | |
| 22 | + * | |
| 23 | + * You can contact the copyright owner regarding licensing via the contact | |
| 24 | + * details that can be found on the KnowledgeTree web site: | |
| 25 | + * | |
| 26 | + * http://www.ktdms.com/ | |
| 27 | + */ | |
| 28 | + | |
| 29 | +require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); | |
| 30 | +require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); | |
| 31 | +require_once('GeneralMetadataPage.php'); | |
| 32 | +require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * Tag Cloud Plugin class | |
| 36 | + * | |
| 37 | + */ | |
| 38 | + class GeneralMetadataPlugin extends KTPlugin{ | |
| 39 | + | |
| 40 | + var $sNamespace = 'ktcore.generalmetadata.plugin'; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Constructor method for plugin | |
| 44 | + * | |
| 45 | + * @param string $sFilename | |
| 46 | + * @return GeneralMetadataPlugin | |
| 47 | + */ | |
| 48 | + function GeneralMetadataPlugin($sFilename = null) { | |
| 49 | + $res = parent::KTPlugin($sFilename); | |
| 50 | + $this->sFriendlyName = _kt('General Metadata Search Plugin'); | |
| 51 | + return $res; | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Setup function for plugin | |
| 56 | + * | |
| 57 | + */ | |
| 58 | + function setup() { | |
| 59 | + // Register plugin components | |
| 60 | + $this->registerCriterion('GeneralMetadataCriterion', 'ktcore.criteria.generalmetadata', KT_LIB_DIR . '/browse/Criteria.inc'); | |
| 61 | + $this->registerDashlet('GeneralMetadataDashlet', 'ktcore.generalmetadata.dashlet', 'GeneralMetadataDashlet.php'); | |
| 62 | + $this->registerPage('GeneralMetadataPage', 'GeneralMetadataPage', __FILE__); | |
| 63 | + | |
| 64 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 65 | + $oTemplating->addLocation('General Metadata Search', '/plugins/generalmetadata/templates'); | |
| 66 | + } | |
| 67 | + } | |
| 68 | +$oPluginRegistry =& KTPluginRegistry::getSingleton(); | |
| 69 | +$oPluginRegistry->registerPlugin('GeneralMetadataPlugin', 'ktcore.generalmetadata.plugin', __FILE__); | |
| 0 | 70 | \ No newline at end of file | ... | ... |
plugins/generalmetadata/templates/GeneralMetadata/dashlet.smarty
0 โ 100644
| 1 | +<form action="{$url}" method="POST"> | |
| 2 | +<input onclick="this.focus()" type="text" name="fSearchableText" id="dashlet-search-text" | |
| 3 | +size="15" /><input type="submit" value="{i18n}search{/i18n}" | |
| 4 | +class="searchbutton frontpage" /> | |
| 5 | +</form> | |
| 6 | +{if (!empty($saved_searches))} | |
| 7 | +<hr /> | |
| 8 | +<h3>{i18n}Saved Searches{/i18n}</h3> | |
| 9 | +{foreach item=oSearch from=$saved_searches} | |
| 10 | +<span class="descriptiveText">{i18n}Saved Search{/i18n}: </span><a | |
| 11 | +href="{"booleanSearch"|generateControllerUrl}&qs[action]=performSearch&qs[fSavedSearchId]={$oSearch->getId()}">{$oSearch->getName()}</a><br /> | |
| 12 | +{/foreach} | |
| 13 | + | |
| 14 | + | |
| 15 | +{/if} | |
| 0 | 16 | \ No newline at end of file | ... | ... |
plugins/ktcore/KTCorePlugin.php
| ... | ... | @@ -181,6 +181,8 @@ class KTCorePlugin extends KTPlugin { |
| 181 | 181 | $this->registerCriterion('TransactionTextCriterion', 'ktcore.criteria.transactiontext', KT_LIB_DIR . '/browse/Criteria.inc'); |
| 182 | 182 | $this->registerCriterion('DateCreatedDeltaCriterion', 'ktcore.criteria.datecreateddelta', KT_LIB_DIR . '/browse/Criteria.inc'); |
| 183 | 183 | $this->registerCriterion('DateModifiedDeltaCriterion', 'ktcore.criteria.datemodifieddelta', KT_LIB_DIR . '/browse/Criteria.inc'); |
| 184 | + $this->registerCriterion('GeneralMetadataCriterion', 'ktcore.criteria.generalmetadata', KT_LIB_DIR . '/browse/Criteria.inc'); | |
| 185 | + | |
| 184 | 186 | |
| 185 | 187 | $this->setupAdmin(); |
| 186 | 188 | } | ... | ... |