/** * Options: * appendToSearch = optional text to be AND'ed wuth current search expression * output_format = determines format out search result output. "PDF" and "HTML" are currently supported; "HTML" is the default * view = view with path relative to controller to use overriding default ("search/<table_name>_search_basic_html.php") * vars = associative array with key value pairs to assign to the view * * Callbacks: * hookBeforeNewSearch() is called just before executing a new search. The first parameter is the BrowseEngine object containing the search. */ public function Index($pa_options = null) { $po_search = isset($pa_options['search']) ? $pa_options['search'] : null; if (isset($pa_options['saved_search']) && $pa_options['saved_search']) { $this->opo_result_context->setSearchExpression($pa_options['saved_search']['search']); $this->opo_result_context->isNewSearch(true); } parent::Index($pa_options); AssetLoadManager::register('hierBrowser'); AssetLoadManager::register('browsable'); // need this to support browse panel when filtering/refining search results $t_model = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true); $va_access_values = caGetUserAccessValues($this->request); // Get elements of result context $vn_page_num = $this->opo_result_context->getCurrentResultsPageNumber(); $vs_search = $this->opo_result_context->getSearchExpression(); $vb_is_new_search = $this->opo_result_context->isNewSearch(); if ((bool) $this->request->getParameter('reset', pString) && $this->request->getParameter('reset', pString) != 'save') { $vs_search = ''; $vb_is_new_search = true; } if (!($vn_items_per_page = $this->opo_result_context->getItemsPerPage())) { $vn_items_per_page = $this->opn_items_per_page_default; $this->opo_result_context->setItemsPerPage($vn_items_per_page); } if (!($vs_view = $this->opo_result_context->getCurrentView())) { $va_tmp = array_keys($this->opa_views); $vs_view = $this->ops_view_default ? $this->ops_view_default : array_shift($va_tmp); $this->opo_result_context->setCurrentView($vs_view); } if (!isset($this->opa_views[$vs_view])) { $va_tmp = array_keys($this->opa_views); $vs_view = array_shift($va_tmp); } if (!($vs_sort = $this->opo_result_context->getCurrentSort())) { $va_tmp = array_keys($this->opa_sorts); $vs_sort = array_shift($va_tmp); } $vs_sort_direction = $this->opo_result_context->getCurrentSortDirection(); $vb_sort_has_changed = $this->opo_result_context->sortHasChanged(); if (!$this->opn_type_restriction_id) { $this->opn_type_restriction_id = ''; } $this->view->setVar('type_id', $this->opn_type_restriction_id); MetaTagManager::setWindowTitle(_t('%1 search', $this->searchName('plural'))); // Get attribute sorts $va_sortable_elements = ca_metadata_elements::getSortableElements($this->ops_tablename, $this->opn_type_restriction_id); if (!is_array($this->opa_sorts)) { $this->opa_sorts = array(); } foreach ($va_sortable_elements as $va_sortable_element) { $this->opa_sorts[$this->ops_tablename . '.' . $va_sortable_element['element_code']] = $va_sortable_element['display_label']; } if ($pa_options['appendToSearch']) { $vs_append_to_search .= " AND (" . $pa_options['appendToSearch'] . ")"; } // // Execute the search // if ($vs_search && $vs_search != "") { /* any request? */ $va_search_opts = array('sort' => $vs_sort, 'sort_direction' => $vs_sort_direction, 'appendToSearch' => $vs_append_to_search, 'checkAccess' => $va_access_values, 'no_cache' => $vb_is_new_search, 'dontCheckFacetAvailability' => true, 'filterNonPrimaryRepresentations' => true); if ($vb_is_new_search || isset($pa_options['saved_search']) || is_subclass_of($po_search, "BrowseEngine") && !$po_search->numCriteria()) { $vs_browse_classname = get_class($po_search); $po_search = new $vs_browse_classname(); if (is_subclass_of($po_search, "BrowseEngine")) { $po_search->addCriteria('_search', $vs_search); if (method_exists($this, "hookBeforeNewSearch")) { $this->hookBeforeNewSearch($po_search); } } $this->opo_result_context->setParameter('show_type_id', null); } if ($this->opn_type_restriction_id) { $po_search->setTypeRestrictions(array($this->opn_type_restriction_id), array('includeSubtypes' => false)); } $vb_criteria_have_changed = false; if (is_subclass_of($po_search, "BrowseEngine")) { // // Restrict facets to specific group for main browse landing page (if set in app.conf config) // if ($vs_facet_group = $this->request->config->get($this->ops_tablename . '_search_refine_facet_group')) { $po_search->setFacetGroup($vs_facet_group); } $vb_criteria_have_changed = $po_search->criteriaHaveChanged(); $po_search->execute($va_search_opts); $this->opo_result_context->setParameter('browse_id', $po_search->getBrowseID()); if ($vs_group_name = $this->request->config->get('browse_facet_group_for_' . $this->ops_tablename)) { $po_search->setFacetGroup($vs_group_name); } $vo_result = $po_search->getResults($va_search_opts); } else { $vo_result = $po_search->search($vs_search, $va_search_opts); } $vo_result = isset($pa_options['result']) ? $pa_options['result'] : $vo_result; $this->opo_result_context->validateCache(); // Only prefetch what we need $vo_result->setOption('prefetch', $vn_items_per_page); // // Handle details of partitioning search results by type, if required // if ((bool) $this->request->config->get('search_results_partition_by_type')) { $va_type_counts = $vo_result->getResultCountForFieldValues(array('ca_objects.type_id')); $va_type_counts_obj_type = $va_type_counts['ca_objects.type_id']; ksort($va_type_counts_obj_type); $this->view->setVar('counts_by_type', $va_type_counts_obj_type); $vn_show_type_id = $this->opo_result_context->getParameter('show_type_id'); if (!isset($va_type_counts_obj_type[$vn_show_type_id])) { $va_tmp = array_keys($va_type_counts_obj_type); $vn_show_type_id = array_shift($va_tmp); } $this->view->setVar('show_type_id', $vn_show_type_id); $vo_result->filterResult('ca_objects.type_id', $vn_show_type_id); } if ($vb_is_new_search || $vb_criteria_have_changed || $vb_sort_has_changed) { $this->opo_result_context->setResultList($vo_result->getPrimaryKeyValues()); $this->opo_result_context->setParameter('availableVisualizationChecked', 0); if ($this->opo_result_context->searchExpressionHasChanged()) { $vn_page_num = 1; } } $this->view->setVar('num_hits', $vo_result->numHits()); $this->view->setVar('num_pages', $vn_num_pages = ceil($vo_result->numHits() / $vn_items_per_page)); if ($vn_page_num > $vn_num_pages) { $vn_page_num = 1; } $vo_result->seek(($vn_page_num - 1) * $vn_items_per_page); $this->view->setVar('page', $vn_page_num); $this->view->setVar('search', $vs_search); $this->view->setVar('result', $vo_result); } // // Set up view for display of results // $t_model = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true); $this->view->setVar('views', $this->opa_views); // pass view list to view for rendering $this->view->setVar('current_view', $vs_view); $this->view->setVar('sorts', $this->opa_sorts); // pass sort list to view for rendering $this->view->setVar('current_sort', $vs_sort); $this->view->setVar('current_sort_direction', $vs_sort_direction); $this->view->setVar('current_items_per_page', $vn_items_per_page); $this->view->setVar('items_per_page', $this->opa_items_per_page); $this->view->setVar('t_subject', $t_model); $this->view->setVar('mode_name', _t('search')); $this->view->setVar('mode', 'search'); $this->view->setVar('mode_type_singular', $this->searchName('singular')); $this->view->setVar('mode_type_plural', $this->searchName('plural')); $this->view->setVar('search_history', $this->opo_result_context->getSearchHistory()); $this->view->setVar('result_context', $this->opo_result_context); $this->view->setVar('uses_hierarchy_browser', $this->usesHierarchyBrowser()); $this->view->setVar('access_values', $va_access_values); $this->view->setVar('browse', $po_search); $t_display = $this->view->getVar('t_display'); if (!is_array($va_display_list = $this->view->getVar('display_list'))) { $va_display_list = array(); } if ($vs_view == 'editable') { $va_initial_data = array(); $va_row_headers = array(); $vn_item_count = 0; if ($vo_result) { $vs_pk = $vo_result->primaryKey(); while ($vn_item_count < 100 && $vo_result->nextHit()) { $va_result = array('item_id' => $vn_id = $vo_result->get($vs_pk)); foreach ($va_display_list as $vn_placement_id => $va_bundle_info) { $va_result[str_replace(".", "-", $va_bundle_info['bundle_name'])] = $t_display->getDisplayValue($vo_result, $vn_placement_id, array('request' => $this->request)); } $va_initial_data[] = $va_result; $vn_item_count++; $va_row_headers[] = $vn_item_count . " " . caEditorLink($this->request, caNavIcon($this->request, __CA_NAV_BUTTON_EDIT__), 'caResultsEditorEditLink', $this->ops_tablename, $vn_id); } } $this->view->setVar('initialData', $va_initial_data); $this->view->setVar('rowHeaders', $va_row_headers); } // // Bottom line // $va_bottom_line = array(); $vb_bottom_line_is_set = false; foreach ($va_display_list as $vn_placement_id => $va_placement) { if (isset($va_placement['settings']['bottom_line']) && $va_placement['settings']['bottom_line']) { $va_bottom_line[$vn_placement_id] = caProcessBottomLineTemplate($this->request, $va_placement, $vo_result, array('pageStart' => ($vn_page_num - 1) * $vn_items_per_page, 'pageEnd' => ($vn_page_num - 1) * $vn_items_per_page + $vn_items_per_page)); $vb_bottom_line_is_set = true; } else { $va_bottom_line[$vn_placement_id] = ''; } } $this->view->setVar('bottom_line', $vb_bottom_line_is_set ? $va_bottom_line : null); switch ($pa_options['output_format']) { # ------------------------------------ case 'LABELS': $this->_genLabels($vo_result, $this->request->getParameter("label_form", pString), $vs_search, $vs_search); break; # ------------------------------------ # ------------------------------------ case 'EXPORT': $this->_genExport($vo_result, $this->request->getParameter("export_format", pString), $vs_search, $vs_search); break; # ------------------------------------ # ------------------------------------ case 'HTML': default: // generate type menu and type value list if (method_exists($t_model, "getTypeList")) { $this->view->setVar('type_list', $t_model->getTypeList()); } if ($this->opb_uses_hierarchy_browser) { AssetLoadManager::register('hierBrowser'); // only for interfaces that use the hierarchy browser $t_list = new ca_lists(); if ($vs_type_list_code = $t_model->getTypeListCode()) { $this->view->setVar('num_types', $t_list->numItemsInList($vs_type_list_code)); $this->view->setVar('type_menu', $t_list->getListAsHTMLFormElement($vs_type_list_code, 'type_id', array('id' => 'hierTypeList'))); } // set last browse id for hierarchy browser $this->view->setVar('browse_last_id', intval($this->request->session->getVar($this->ops_tablename . '_browse_last_id'))); } $this->opo_result_context->setAsLastFind(); $this->opo_result_context->saveContext(); if (isset($pa_options['vars']) && is_array($pa_options['vars'])) { foreach ($pa_options['vars'] as $vs_key => $vs_val) { $this->view->setVar($vs_key, $vs_val); } } if (isset($pa_options['view']) && $pa_options['view']) { $this->render($pa_options['view']); } else { $this->render('Search/' . $this->ops_tablename . '_search_basic_html.php'); } break; # ------------------------------------ } }
public function Index($pa_options = null) { $po_search = isset($pa_options['search']) && $pa_options['search'] ? $pa_options['search'] : null; parent::Index($pa_options); AssetLoadManager::register('browsable'); // need this to support browse panel when filtering/refining search results $t_model = $this->opo_datamodel->getTableInstance($this->ops_tablename, true); // Get elements of result context $vn_page_num = $this->opo_result_context->getCurrentResultsPageNumber(); $vs_search = $this->opo_result_context->getSearchExpression(); if (!($vn_items_per_page = $this->opo_result_context->getItemsPerPage())) { $vn_items_per_page = $this->opa_items_per_page[0]; } if (!($vs_view = $this->opo_result_context->getCurrentView())) { $va_tmp = array_keys($this->opa_views); $vs_view = array_shift($va_tmp); } if (!($vs_sort = $this->opo_result_context->getCurrentSort())) { $va_tmp = array_keys($this->opa_sorts); $vs_sort = array_shift($va_tmp); } $vs_sort_direction = $this->opo_result_context->getCurrentSortDirection(); $vn_display_id = $this->opo_result_context->getCurrentBundleDisplay(); if (!$this->opn_type_restriction_id) { $this->opn_type_restriction_id = ''; } $this->view->setVar('type_id', $this->opn_type_restriction_id); MetaTagManager::setWindowTitle(_t('%1 advanced search', $this->searchName('plural'))); $t_form = new ca_search_forms(); if (!($vn_form_id = isset($pa_options['form_id']) ? $pa_options['form_id'] : null)) { if (!($vn_form_id = $this->opo_result_context->getParameter('form_id'))) { if (sizeof($va_forms = $t_form->getForms(array('table' => $this->ops_tablename, 'user_id' => $this->request->getUserID(), 'access' => __CA_SEARCH_FORM_READ_ACCESS__)))) { $va_tmp = array_keys($va_forms); $vn_form_id = array_shift($va_tmp); } } } $t_form->load($vn_form_id); $this->view->setVar('t_form', $t_form); $this->view->setVar('form_id', $vn_form_id); if ($pa_options['appendToSearch']) { $vs_append_to_search .= " AND (" . $pa_options['appendToSearch'] . ")"; } // // Execute the search // if (isset($pa_options['saved_search']) && $pa_options['saved_search']) { // Is this a saved search? If so, reused the canned params $va_form_data = $pa_options['saved_search']; foreach ($pa_options['saved_search'] as $vs_fld => $vs_val) { $vs_proc_fld = str_replace(".", "_", $vs_fld); $va_proc_form_data[$vs_proc_fld] = $vs_val; } $vs_search = $t_form->getLuceneQueryStringForHTMLFormInput($va_proc_form_data); $vb_is_new_search = true; } else { if (!($vs_search = $t_form->getLuceneQueryStringForHTMLFormInput($_REQUEST))) { // try to get search off of request $vs_search = $this->opo_result_context->getSearchExpression(); // get the search out of the result context $va_form_data = $this->opo_result_context->getParameter('form_data'); $vb_is_new_search = !$this->opo_result_context->cacheIsValid(); } else { $va_form_data = $t_form->extractFormValuesFromArray($_REQUEST); // ah ok, its an incoming request, so get the form values out for interpretation/processing/whatever $vb_is_new_search = true; } } if ($this->request->getParameter('reset', pString) == 'clear') { $vs_search = ''; $vb_is_new_search = true; } if ($vs_search && $vs_search != "") { /* any request? */ $va_search_opts = array('sort' => $vs_sort, 'sort_direction' => $vs_sort_direction, 'appendToSearch' => $vs_append_to_search, 'getCountsByField' => 'type_id', 'checkAccess' => $va_access_values, 'no_cache' => $vb_is_new_search); if ($vb_is_new_search || isset($pa_options['saved_search']) || is_subclass_of($po_search, "BrowseEngine") && !$po_search->numCriteria()) { $vs_browse_classname = get_class($po_search); $this->opo_browse = $po_search = new $vs_browse_classname(); $po_search->addCriteria('_search', $vs_search); } if ($this->opn_type_restriction_id) { $po_search->setTypeRestrictions(array($this->opn_type_restriction_id)); } $vb_criteria_have_changed = false; if (is_subclass_of($po_search, "BrowseEngine")) { $vb_criteria_have_changed = $po_search->criteriaHaveChanged(); $po_search->execute($va_search_opts); $this->opo_result_context->setParameter('browse_id', $po_search->getBrowseID()); $vo_result = $po_search->getResults($va_search_opts); } else { $vo_result = $po_search->search($vs_search, $va_search_opts); } $this->opo_result_context->validateCache(); // Only prefetch what we need $vo_result->setOption('prefetch', $vn_items_per_page); $this->opo_result_context->setParameter('form_data', $va_form_data); $this->opo_result_context->setSearchExpression($vs_search); if ($vb_is_new_search || $vb_criteria_have_changed) { $this->opo_result_context->setResultList($vo_result->getPrimaryKeyValues()); $vn_page_num = 1; } $vo_result->seek(($vn_page_num - 1) * $vn_items_per_page); $this->view->setVar('num_hits', $vo_result->numHits()); $this->view->setVar('num_pages', $vn_num_pages = ceil($vo_result->numHits() / $vn_items_per_page)); if ($vn_page_num > $vn_num_pages) { $vn_page_num = 1; } $this->view->setVar('page', $vn_page_num); $this->view->setVar('search', $vs_search); $this->view->setVar('result', $vo_result); } // // Set up view for display of results // $t_model = $this->opo_datamodel->getTableInstance($this->ops_tablename); $this->view->setVar('views', $this->opa_views); // pass view list to view for rendering $this->view->setVar('current_view', $vs_view); $this->view->setVar('sorts', $this->opa_sorts); // pass sort list to view for rendering $this->view->setVar('current_sort', $vs_sort); $this->view->setVar('current_sort_direction', $vs_sort_direction); $this->view->setVar('current_items_per_page', $vn_items_per_page); $this->view->setVar('items_per_page', $this->opa_items_per_page); $this->view->setVar('t_subject', $t_model); $this->view->setVar('mode_name', _t('search')); $this->view->setVar('mode', 'search'); $this->view->setVar('mode_type_singular', $this->searchName('singular')); $this->view->setVar('mode_type_plural', $this->searchName('plural')); $this->view->setVar('search_history', $this->opo_result_context->getSearchHistory()); $this->view->setVar('result_context', $this->opo_result_context); $this->view->setVar('browse', $po_search); switch ($pa_options['output_format']) { # ------------------------------------ case 'PDF': $this->_genPDF($vo_result, $this->request->getParameter("label_form", pString), $vs_search); break; # ------------------------------------ # ------------------------------------ case 'EXPORT': $this->_genExport($vo_result, $this->request->getParameter("export_format", pString), $vs_search, $vs_search); break; # ------------------------------------ # ------------------------------------ case 'HTML': default: // generate type menu and type value list if (method_exists($t_model, "getTypeList")) { $this->view->setVar('type_list', $t_model->getTypeList()); } // Call advanced search form generator directly to set view vars in the current view // This lets our view in this action render Search/search_advanced_form_html.php directly // to avoid the annoying flicker that occurs if we load the initial search form via AJAX $this->getAdvancedSearchForm(false); $this->opo_result_context->setAsLastFind(); $this->opo_result_context->saveContext(); $this->render('Search/' . $this->ops_tablename . '_search_advanced_html.php'); break; # ------------------------------------ } }