Пример #1
0
 function handleCriteriaSet($aCriteriaSet, $iStartIndex, $sTitle = null, $bIsCondition = false)
 {
     if ($sTitle == null) {
         $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Advanced Search'));
         $sTitle = _kt('Search Results');
     } else {
         if ($bIsCondition) {
             $this->aBreadcrumbs[] = array('name' => _kt('Test Condition'));
             $this->oPage->setTitle(sprintf(_kt('Test Condition: %s'), $sTitle));
         } else {
             $this->aBreadcrumbs[] = array('name' => _kt('Saved Search'));
             $this->oPage->setTitle(sprintf(_kt('Saved Search: %s'), $sTitle));
         }
         $this->oPage->setBreadcrumbDetails($sTitle);
     }
     $this->browseType = "Folder";
     $searchable_text = KTUtil::arrayGet($_REQUEST, "fSearchableText");
     $sSearch = md5(serialize($aCriteriaSet));
     $_SESSION['boolean_search'][$sSearch] = $aCriteriaSet;
     $collection = new AdvancedCollection();
     $oColumnRegistry = KTColumnRegistry::getSingleton();
     $aColumns = $oColumnRegistry->getColumnsForView('ktcore.views.search');
     $collection->addColumns($aColumns);
     // get search parameters
     $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
     $aParams = array();
     $aJoins = array();
     $aJoins['main'] = $aCriteriaSet['join'] == 'AND' ? _kt('all') : _kt('any');
     foreach ($aCriteriaSet['subgroup'] as $k => $subgroup) {
         $aGroup = array();
         $aJoins[$k] = $subgroup['join'] == 'AND' ? _kt('all') : _kt('any');
         if (!empty($subgroup['values'])) {
             foreach ($subgroup['values'] as $value) {
                 $oCriterion =& $oCriteriaRegistry->getCriterion($value['type']);
                 if ($oCriterion == null || $oCriterion == "" || PEAR::isError($oCriterion)) {
                     $this->errorRedirectToMain('Criterion error');
                 }
                 $aGroup[] = $oCriterion->parameterDisplay($value['data']);
             }
         }
         $aParams[] = $aGroup;
     }
     // set a view option
     $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::addQueryStringSelf("action=performSearch&boolean_search_id=" . urlencode($sSearch));
     $aOptions['empty_message'] = _kt("No documents or folders match this query.");
     $aOptions['is_browse'] = true;
     $collection->setOptions($aOptions);
     $collection->setQueryObject(new BooleanSearchQuery($aCriteriaSet));
     //$a = new BooleanSearchQuery($aCriteriaSet);
     //var_dump($a->getDocumentCount()); exit(0);
     // form fields for saving the search
     $save_fields = array();
     $save_fields[] = new KTStringWidget(_kt('New search'), _kt('The name to save this search as'), 'name', null, $this->oPage, true);
     $aUserSearches = KTSavedSearch::getUserSearches($this->oUser->getId(), true);
     if (count($aUserSearches)) {
         $aVocab = array('' => ' ---- ');
         foreach ($aUserSearches as $oSearch) {
             $aVocab[$oSearch->getId()] = $oSearch->getName();
         }
         $aSelectOptions = array('vocab' => $aVocab);
         $save_fields[] = new KTLookupWidget(_kt('Existing search'), _kt('To save over one of your existing searches, select it here.'), 'fSearchId', null, $this->oPage, true, null, null, $aSelectOptions);
     }
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate("kt3/browse");
     $aTemplateData = array("context" => $this, "collection" => $collection, "custom_title" => $sTitle, "save_fields" => $save_fields, "params" => $aParams, "joins" => $aJoins, 'isEditable' => true, "boolean_search" => $sSearch, 'bulkactions' => KTBulkActionUtil::getAllBulkActions(), 'browseutil' => new KTBrowseUtil(), 'returnaction' => 'booleanSearch', 'returndata' => $sSearch);
     return $oTemplate->render($aTemplateData);
 }
Пример #2
0
 function do_main()
 {
     $oColumnRegistry =& KTColumnRegistry::getSingleton();
     $collection = new AdvancedCollection();
     $collection->addColumns($oColumnRegistry->getColumnsForView('ktcore.views.browse'));
     $aOptions = $collection->getEnvironOptions();
     // extract data from the environment
     $aOptions['result_url'] = $this->resultURL;
     $aOptions['is_browse'] = true;
     $collection->setOptions($aOptions);
     $collection->setQueryObject($this->oQuery);
     $collection->setColumnOptions('ktcore.columns.selection', array('rangename' => 'selection', 'show_folders' => true, 'show_documents' => true));
     // get bulk actions
     $aBulkActions = KTBulkActionUtil::getAllBulkActions();
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate('kt3/browse');
     $aTemplateData = array('context' => $this, 'collection' => $collection, 'browse_mode' => $this->browse_mode, 'isEditable' => $this->editable, 'bulkactions' => $aBulkActions, 'browseutil' => new KTBrowseUtil(), 'returnaction' => 'browse');
     if ($this->oFolder) {
         $aTemplateData['returndata'] = $this->oFolder->getId();
     }
     return $oTemplate->render($aTemplateData);
 }
Пример #3
0
 /**
  * Renders the search results.
  *
  * @return string
  */
 function do_searchResults()
 {
     if (array_key_exists('format', $_GET)) {
         switch ($_GET['format']) {
             case 'searchengine':
                 $_SESSION['search2resultFormat'] = 'searchengine';
                 break;
             case 'browseview':
                 $_SESSION['search2resultFormat'] = 'browseview';
                 break;
         }
     } else {
         if (!array_key_exists('search2resultFormat', $_SESSION)) {
             global $default;
             $_SESSION['search2resultFormat'] = $default->resultsDisplayFormat;
         }
     }
     if ($_SESSION['search2resultFormat'] == 'browseview') {
         $this->redirectTo('oldSearchResults');
     }
     $this->oPage->setBreadcrumbDetails(_kt("Search Results"));
     $this->oPage->title = _kt("Search Results");
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate("ktcore/search2/search_results");
     KTEntityUtil::_proxyCreate('KTDocumentContentVersion', 'KTDocumentContentVersionProxy');
     KTEntityUtil::_proxyCreate('KTDocumentCore', 'KTDocumentCoreProxy');
     KTEntityUtil::_proxyCreate('KTDocumentMetadataVersion', 'KTDocumentMetadataVersionProxy');
     $results = unserialize($_SESSION['search2_results']);
     // NOTE: sorting results (when it is implemented) might have to be done per section, as it is done with the browse view
     // Get the order of display - folders first / documents first
     // Get the display order of the results - documents / folders first
     $_SESSION['display_order'] = isset($_POST['display_order']) ? $_POST['display_order'] : $_SESSION['display_order'];
     $display_order = $_SESSION['display_order'];
     $selected_order = array('f' => '', 'd' => '', 's' => '');
     switch ($display_order) {
         case 's':
             $selected_order['s'] = 'selected';
             $resultArray = $results['shortfolders'];
             foreach ($results['shortdocs'] as $f) {
                 $resultArray[] = $f;
             }
             foreach ($results['folders'] as $d) {
                 $resultArray[] = $d;
             }
             foreach ($results['docs'] as $f) {
                 $resultArray[] = $f;
             }
             break;
         case 'd':
             $selected_order['d'] = 'selected';
             $resultArray = $results['docs'];
             foreach ($results['folders'] as $f) {
                 $resultArray[] = $f;
             }
             foreach ($results['shortdocs'] as $d) {
                 $resultArray[] = $d;
             }
             foreach ($results['shortfolders'] as $f) {
                 $resultArray[] = $f;
             }
             break;
         case 'f':
         default:
             $selected_order['f'] = 'selected';
             $resultArray = $results['folders'];
             foreach ($results['docs'] as $f) {
                 $resultArray[] = $f;
             }
             foreach ($results['shortfolders'] as $d) {
                 $resultArray[] = $d;
             }
             foreach ($results['shortdocs'] as $f) {
                 $resultArray[] = $f;
             }
     }
     $results = $resultArray;
     if (!is_array($results) || count($results) == 0) {
         $results = array();
     }
     $numRecs = count($results);
     $showall = $_GET['showAll'];
     if (is_numeric($showall)) {
         $showall = $showall + 0 > 0;
     } else {
         $showall = $showall == 'true';
     }
     $config = KTConfig::getSingleton();
     $resultsPerPage = $showall ? $numRecs : $config->get('search/resultsPerPage', SearchDispatcher::RESULTS_PER_PAGE);
     $maxPageMove = SearchDispatcher::MAX_PAGE_MOVEMENT;
     $pageOffset = 1;
     if (isset($_GET['pageOffset'])) {
         $pageOffset = $_GET['pageOffset'];
     }
     $maxPages = ceil($numRecs / $resultsPerPage);
     if ($pageOffset <= 0 || $pageOffset > $maxPages) {
         $pageOffset = 1;
     }
     $firstRec = ($pageOffset - 1) * $resultsPerPage;
     $lastRec = $firstRec + $resultsPerPage;
     if ($lastRec > $numRecs) {
         $lastRec = $numRecs;
     }
     $display = array_slice($results, $firstRec, $resultsPerPage);
     $startOffset = $pageOffset - $maxPageMove;
     if ($startOffset < 1) {
         $startOffset = 1;
     }
     $endOffset = $pageOffset + $maxPageMove;
     if ($endOffset > $maxPages) {
         $endOffset = $maxPages;
     }
     $pageMovement = array();
     for ($i = $startOffset; $i <= $endOffset; $i++) {
         $pageMovement[] = $i;
     }
     $aBulkActions = KTBulkActionUtil::getAllBulkActions();
     $aTemplateData = array("context" => $this, 'selected_order' => $selected_order, 'bulkactions' => $aBulkActions, 'firstRec' => $firstRec, 'lastRec' => $lastRec, 'showAll' => $showall, 'numResults' => count($results), 'pageOffset' => $pageOffset, 'resultsPerPage' => $resultsPerPage, 'maxPages' => $maxPages, 'results' => $display, 'pageMovement' => $pageMovement, 'startMovement' => $startOffset, 'endMovement' => $endOffset, 'txtQuery' => $_SESSION['search2_query'], 'iSavedID' => $_SESSION['search2_savedid'], 'txtSavedName' => $_SESSION['search2_savedname']);
     return $oTemplate->render($aTemplateData);
 }
Пример #4
0
 function do_main()
 {
     $aErrorOptions = array("message" => _kt("Please provide a search term"));
     $searchable_text = sanitizeForSQL(KTUtil::arrayGet($_REQUEST, "fSearchableText"));
     $this->oValidator->notEmpty($searchable_text, $aErrorOptions);
     $collection = new AdvancedCollection();
     $oColumnRegistry = KTColumnRegistry::getSingleton();
     $aColumns = $oColumnRegistry->getColumnsForView('ktcore.views.search');
     $collection->addColumns($aColumns);
     // set a view option
     $aTitleOptions = array('documenturl' => $GLOBALS['KTRootUrl'] . '/view.php', 'direct_folder' => true);
     $collection->setColumnOptions('ktcore.columns.title', $aTitleOptions);
     // set the selection options
     $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::addQueryStringSelf("fSearchableText=" . urlencode($searchable_text));
     $aOptions['empty_message'] = _kt("No documents or folders match this query.");
     $aOptions['is_browse'] = true;
     $collection->setOptions($aOptions);
     $collection->setQueryObject(new SimpleSearchQuery($searchable_text));
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate("kt3/browse");
     $aTemplateData = array("context" => $this, "collection" => $collection, 'isEditable' => true, 'bulkactions' => KTBulkActionUtil::getAllBulkActions(), 'browseutil' => new KTBrowseUtil(), 'returnaction' => 'simpleSearch', 'returndata' => $searchable_text);
     return $oTemplate->render($aTemplateData);
 }
Пример #5
0
 function do_search()
 {
     // Get the tag to search for and create search query
     $tag = isset($_REQUEST['tag']) ? $_REQUEST['tag'] : '';
     $decode = isset($_REQUEST['decode']) ? $_REQUEST['decode'] : '';
     if ($decode == 'true') {
         $tag = urldecode($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) {
             if ($tag == $item) {
                 continue;
             }
             $url = $base . '&tag=' . urlencode($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();
     $aColumns = $oColumnRegistry->getColumnsForView('ktcore.views.search');
     $collection->addColumns($aColumns);
     // set a view option
     $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
     $returnUrl = KTUtil::addQueryString('TagCloudRedirection&action=search&tag=' . urlencode($tag), false);
     $aOptions['return_url'] = $returnUrl;
     $aOptions['empty_message'] = _kt('No documents or folders match this query.');
     $aOptions['is_browse'] = true;
     $collection->setOptions($aOptions);
     $collection->setQueryObject(new TagQuery($oUser, $tag));
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate('kt3/browse');
     $aTemplateData = array('context' => $this, 'collection' => $collection, 'custom_title' => $sTitle, 'isEditable' => true, 'boolean_search' => $sSearch, 'bulkactions' => KTBulkActionUtil::getAllBulkActions(), 'browseutil' => new KTBrowseUtil(), 'returnaction' => $returnUrl);
     return $oTemplate->render($aTemplateData);
 }
Пример #6
0
 function getBulkActionsByNames($aNames, $slot = 'bulkaction', $oUser = null)
 {
     $aObjects = array();
     foreach (KTBulkActionUtil::getBulkActionInfo($slot) as $aAction) {
         list($sClassName, $sPath, $sName, $sPlugin) = $aAction;
         $oRegistry =& KTPluginRegistry::getSingleton();
         $oPlugin =& $oRegistry->getPlugin($sPlugin);
         if (!in_array($sName, $aNames)) {
             continue;
         }
         if (!empty($sPath)) {
             require_once $sPath;
         }
         $aObjects[] = new $sClassName(null, $oUser, $oPlugin);
     }
     return $aObjects;
 }