/** * */ public function advanced() { $o_config = caGetSearchConfig(); $ps_function = strtolower($this->request->getActionExtra()); if (!($va_search_info = caGetInfoForAdvancedSearchType($ps_function))) { // invalid advanced search type – throw error die("Invalid advanced search type"); } $vs_class = $va_search_info['table']; $va_types = caGetOption('restrictToTypes', $va_search_info, array(), array('castTo' => 'array')); $this->opo_result_context = new ResultContext($this->request, $va_search_info['table'], $this->ops_find_type . '_advanced'); $this->opo_result_context->setAsLastFind(); MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . _t("Search %1", $va_search_info["displayName"])); $this->view->setVar('searchInfo', $va_search_info); $this->view->setVar('options', caGetOption('options', $va_search_info, array(), array('castTo' => 'array'))); $va_default_form_values = $this->opo_result_context->getParameter("pawtucketAdvancedSearchFormContent_{$ps_function}"); $va_default_form_booleans = $this->opo_result_context->getParameter("pawtucketAdvancedSearchFormBooleans_{$ps_function}"); $va_tags = $this->view->getTagList($va_search_info['view']); $t_subject = $this->request->datamodel->getInstanceByTableName($va_search_info['table'], true); $va_form_elements = array(); $vs_script = null; foreach ($va_tags as $vs_tag) { $va_parse = caParseTagOptions($vs_tag); $vs_tag_proc = $va_parse['tag']; $va_opts = $va_parse['options']; if (($vs_default_value = caGetOption('default', $va_opts, null)) || ($vs_default_value = caGetOption($vs_tag_proc, $va_default_form_values, null))) { $va_default_form_values[$vs_tag_proc] = $vs_default_value; unset($va_opts['default']); } $vs_tag_val = null; switch (strtolower($vs_tag_proc)) { case 'submit': $this->view->setVar($vs_tag, "<a href='#' class='caAdvancedSearchFormSubmit'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Submit')) . "</a>"); break; case 'reset': $this->view->setVar($vs_tag, "<a href='#' class='caAdvancedSearchFormReset'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Reset')) . "</a>"); $vs_script = "<script type='text/javascript'>\n\tjQuery('.caAdvancedSearchFormSubmit').bind('click', function() {\n\t\tjQuery('#caAdvancedSearch').submit();\n\t\treturn false;\n\t});\n\tjQuery('.caAdvancedSearchFormReset').bind('click', function() {\n\t\tjQuery('#caAdvancedSearch').find('input[type!=\"hidden\"],textarea').val('');\n\t\tjQuery('#caAdvancedSearch').find('select.caAdvancedSearchBoolean').val('AND');\n\t\tjQuery('#caAdvancedSearch').find('select').prop('selectedIndex', 0);\n\t\treturn false;\n\t});\n\tjQuery(document).ready(function() {\n\t\tvar f, defaultValues = " . json_encode($va_default_form_values) . ", defaultBooleans = " . json_encode($va_default_form_booleans) . ";\n\t\tfor (f in defaultValues) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('input[name=\"' + f_proc+ '\"], textarea[name=\"' + f_proc+ '\"], select[name=\"' + f_proc+ '\"]').each(function(k, v) {\n\t\t\t\tif (defaultValues[f][k]) { jQuery(v).val(defaultValues[f][k]); } \n\t\t\t});\n\t\t}\n\t\tfor (f in defaultBooleans) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('select[name=\"' + f_proc+ '\"].caAdvancedSearchBoolean').each(function(k, v) {\n\t\t\t\tif (defaultBooleans[f][k]) { jQuery(v).val(defaultBooleans[f][k]); }\n\t\t\t});\n\t\t}\n\t});\n</script>\n"; break; default: if (preg_match("!^(.*):label\$!", $vs_tag_proc, $va_matches)) { $this->view->setVar($vs_tag, $vs_tag_val = $t_subject->getDisplayLabel($va_matches[1])); } elseif (preg_match("!^(.*):boolean\$!", $vs_tag_proc, $va_matches)) { $this->view->setVar($vs_tag, caHTMLSelect($vs_tag_proc . '[]', array(_t('AND') => 'AND', _t('OR') => 'OR', 'AND NOT' => 'AND NOT'), array('class' => 'caAdvancedSearchBoolean'))); } else { $va_opts['asArrayElement'] = true; if (isset($va_opts['restrictToTypes']) && $va_opts['restrictToTypes'] && !is_array($va_opts['restrictToTypes'])) { $va_opts['restrictToTypes'] = explode(";", $va_opts['restrictToTypes']); } if ($vs_tag_val = $t_subject->htmlFormElementForSearch($this->request, $vs_tag_proc, $va_opts)) { $this->view->setVar($vs_tag, $vs_tag_val); } $va_tmp = explode('.', $vs_tag_proc); if (($t_element = ca_metadata_elements::getInstance($va_tmp[1])) && $t_element->get('datatype') == 0) { if (is_array($va_elements = $t_element->getElementsInSet())) { foreach ($va_elements as $va_element) { if ($va_element['datatype'] > 0) { $va_form_elements[] = $va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code']; } } } break; } } if ($vs_tag_val) { $va_form_elements[] = $vs_tag_proc; } break; } } $this->view->setVar("form", caFormTag($this->request, "{$ps_function}", 'caAdvancedSearch', null, 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true, 'submitOnReturn' => true))); $this->view->setVar("/form", $vs_script . caHTMLHiddenInput("_advancedFormName", array("value" => $ps_function)) . caHTMLHiddenInput("_formElements", array("value" => join(';', $va_form_elements))) . caHTMLHiddenInput("_advanced", array("value" => 1)) . "</form>"); $this->render($va_search_info['view']); }
/** * Given a item_id (request parameter 'id') returns a list of direct children for use in the hierarchy browser * Returned data is JSON format */ public function Get($pa_additional_query_params = null, $pa_options = null) { $ps_query = $this->request->getParameter('term', pString); $pb_exact = $this->request->getParameter('exact', pInteger); $ps_exclude = $this->request->getParameter('exclude', pString); $va_excludes = explode(";", $ps_exclude); $ps_type = $this->request->getParameter('type', pString); $ps_types = $this->request->getParameter('types', pString); $pb_no_subtypes = (bool) $this->request->getParameter('noSubtypes', pInteger); $pb_quickadd = (bool) $this->request->getParameter('quickadd', pInteger); $pb_no_inline = (bool) $this->request->getParameter('noInline', pInteger); $t_object = new ca_objects(); $t_collection = new ca_collections(); if (!($pn_limit = $this->request->getParameter('limit', pInteger))) { $pn_limit = 100; } $va_items = array(); if (($vn_str_len = mb_strlen($ps_query)) > 0) { if ($vn_str_len < 3) { $pb_exact = true; } // force short strings to be an exact match (using a very short string as a stem would perform badly and return too many matches in most cases) $o_object_search = new ObjectSearch(); $o_collection_search = new CollectionSearch(); $pa_types = array(); if ($ps_types) { $pa_types = explode(';', $ps_types); } else { if ($ps_type) { $pa_types = array($ps_type); } } // Get type_ids $vs_type_query = ''; $va_ids = array(); if (sizeof($pa_types)) { $va_types = $this->opo_item_instance->getTypeList(); $va_types_proc = array(); foreach ($va_types as $vn_type_id => $va_type) { $va_types_proc[$vn_type_id] = $va_types_proc[$va_type['idno']] = $vn_type_id; } foreach ($pa_types as $ps_type) { if (isset($va_types_proc[$ps_type])) { $va_ids[$va_types_proc[$ps_type]] = true; } } $va_ids = array_keys($va_ids); if (sizeof($va_ids) > 0) { $t_list = new ca_lists(); if (!$pb_no_subtypes) { foreach ($va_ids as $vn_id) { $va_children = $t_list->getItemsForList($this->opo_item_instance->getTypeListCode(), array('item_id' => $vn_id, 'idsOnly' => true)); $va_ids = array_merge($va_ids, $va_children); } $va_ids = array_flip(array_flip($va_ids)); } $o_object_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $this->opo_item_instance->getTypeFieldName(), 'IN', join(",", $va_ids)); } } else { $va_ids = null; } // add any additional search elements $vs_additional_query_params = ''; if (is_array($pa_additional_query_params) && sizeof($pa_additional_query_params)) { $vs_additional_query_params = ' AND (' . join(' AND ', $pa_additional_query_params) . ')'; } // add filters if (isset($pa_options['filters']) && is_array($pa_options['filters']) && sizeof($pa_options['filters'])) { foreach ($pa_options['filters'] as $va_filter) { $o_object_search->addResultFilter($va_filter[0], $va_filter[1], $va_filter[2]); } } // do search $va_opts = array('exclude' => $va_excludes, 'limit' => $pn_limit); if ($vn_restrict_to_hier_id = $this->request->getParameter('currentHierarchyOnly', pInteger)) { $o_object_search->addResultFilter('ca_objects.hier_object_id', '=', (int) $vn_restrict_to_hier_id); } if (!$pb_exact) { $o_search_config = caGetSearchConfig(); $ps_query = trim(preg_replace("![" . str_replace("!", "\\!", $o_search_config->get('search_tokenizer_regex')) . "]+!", " ", $ps_query)); } $qr_res = $o_object_search->search('(' . $ps_query . (intval($pb_exact) ? '' : '*') . ')' . $vs_type_query . $vs_additional_query_params, array('search_source' => 'Lookup', 'no_cache' => false, 'sort' => 'ca_objects.idno_sort')); $qr_res->setOption('prefetch', $pn_limit); $qr_res->setOption('dontPrefetchAttributes', true); if (is_array($va_objects = caProcessRelationshipLookupLabel($qr_res, new ca_objects(), $va_opts))) { foreach ($va_objects as $vn_object_id => $va_object) { $va_objects[$vn_object_id]['id'] = 'ca_objects-' . $va_objects[$vn_object_id]['id']; } } //if ($vs_hier_fld && ($vn_restrict_to_hier_id = $this->request->getParameter('currentHierarchyOnly', pInteger))) { //$o_collection_search->addResultFilter('ca_collections.hier_collection_id', '=', (int)$vn_restrict_to_hier_id); // How to restrict objects? //} $qr_res = $o_collection_search->search('(' . $ps_query . (intval($pb_exact) ? '' : '*') . ')' . $vs_type_query . $vs_additional_query_params, array('search_source' => 'Lookup', 'no_cache' => false, 'sort' => 'ca_collections.idno_sort')); $qr_res->setOption('prefetch', $pn_limit); $qr_res->setOption('dontPrefetchAttributes', true); if (is_array($va_collections = caProcessRelationshipLookupLabel($qr_res, new ca_collections(), $va_opts))) { foreach ($va_collections as $vn_collection_id => $va_collection) { $va_collections[$vn_collection_id]['id'] = 'ca_collections-' . $va_collections[$vn_collection_id]['id']; } } } if (!is_array($va_objects)) { $va_objects = array(); } if (!is_array($va_collections)) { $va_collections = array(); } if (!sizeof($va_objects) && !sizeof($va_collections)) { $va_objects[-1] = _t('No matches found for <em>%1</em>', $ps_query); } $this->view->setVar('object_list', $va_objects); $this->view->setVar('collection_list', $va_collections); return $this->render(str_replace(' ', '_', 'ajax_object_collection_list_html.php')); }
* the "license.txt" file for details, or visit the CollectiveAccess web site at * http://www.CollectiveAccess.org * * ---------------------------------------------------------------------- */ $qr_results = $this->getVar('result'); $va_block_info = $this->getVar('blockInfo'); $vs_block = $this->getVar('block'); $vn_start = (int) $this->getVar('start'); // offset to seek to before outputting results $vn_hits_per_block = (int) $this->getVar('itemsPerPage'); $vb_has_more = (bool) $this->getVar('hasMore'); $vs_search = (string) $this->getVar('search'); $vn_init_with_start = (int) $this->getVar('initializeWithStart'); $va_access_values = caGetUserAccessValues($this->request); $o_config = caGetSearchConfig(); $o_browse_config = caGetBrowseConfig(); $va_browse_types = array_keys($o_browse_config->get("browseTypes")); if (!($vs_placeholder = $o_config->get("placeholder_media_icon"))) { $vs_placeholder = "<i class='fa fa-picture-o fa-2x'></i>"; } $vs_placeholder_tag = "<div class='multisearchImgPlaceholder'>" . $vs_placeholder . "</div>"; if ($qr_results->numHits() > 0) { if (!$this->request->isAjax()) { ?> <small class="pull-right"> <?php if (in_array($vs_block, $va_browse_types)) { ?> <span class='multisearchFullResults'><?php print caNavLink($this->request, '<span class="glyphicon glyphicon-list"></span> ' . _t('Full results'), '', '', 'Search', '{{{block}}}', array('search' => $vs_search));
public function Get($pa_additional_query_params = null, $pa_options = null) { header("Content-type: application/json"); $o_config = Configuration::load(); $o_search_config = caGetSearchConfig(); if (!$this->ops_search_class) { return null; } $ps_query = $this->request->getParameter('term', pString); $pb_exact = $this->request->getParameter('exact', pInteger); $ps_exclude = $this->request->getParameter('exclude', pString); $va_excludes = explode(";", $ps_exclude); $ps_type = $this->request->getParameter('type', pString); $ps_types = $this->request->getParameter('types', pString); $ps_restrict_to_search = trim($this->request->getParameter('restrictToSearch', pString)); $pb_no_subtypes = (bool) $this->request->getParameter('noSubtypes', pInteger); $pb_quickadd = (bool) $this->request->getParameter('quickadd', pInteger); $pb_no_inline = (bool) $this->request->getParameter('noInline', pInteger); if (!($pn_limit = $this->request->getParameter('limit', pInteger))) { $pn_limit = 100; } $va_items = array(); if (($vn_str_len = mb_strlen($ps_query)) > 0) { if ($vn_str_len < 3) { $pb_exact = true; } // force short strings to be an exact match (using a very short string as a stem would perform badly and return too many matches in most cases) $o_search = new $this->ops_search_class(); $pa_types = array(); if ($ps_types) { $pa_types = explode(';', $ps_types); } else { if ($ps_type) { $pa_types = array($ps_type); } } // Get type_ids $va_ids = array(); if (sizeof($pa_types)) { $va_types = $this->opo_item_instance->getTypeList(); $va_types_proc = array(); foreach ($va_types as $vn_type_id => $va_type) { $va_types_proc[$vn_type_id] = $va_types_proc[$va_type['idno']] = $vn_type_id; } foreach ($pa_types as $ps_type) { if (isset($va_types_proc[$ps_type])) { $va_ids[$va_types_proc[$ps_type]] = true; } } $va_ids = array_keys($va_ids); if (sizeof($va_ids) > 0) { $t_list = new ca_lists(); if (!$pb_no_subtypes) { foreach ($va_ids as $vn_id) { $va_children = $t_list->getItemsForList($this->opo_item_instance->getTypeListCode(), array('item_id' => $vn_id, 'idsOnly' => true)); $va_ids = array_merge($va_ids, $va_children); } $va_ids = array_flip(array_flip($va_ids)); } $o_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $this->opo_item_instance->getTypeFieldName(), 'IN', join(",", $va_ids)); } } // add any additional search elements $vs_additional_query_params = ''; if (is_array($pa_additional_query_params) && sizeof($pa_additional_query_params)) { $vs_additional_query_params = ' AND (' . join(' AND ', $pa_additional_query_params) . ')'; } $vs_restrict_to_search = ''; if (strlen($ps_restrict_to_search) > 0) { $vs_restrict_to_search .= ' AND (' . $ps_restrict_to_search . ')'; } // get sort field $vs_sort = $this->request->getAppConfig()->get($this->opo_item_instance->tableName() . '_lookup_sort'); if (!$vs_sort) { $vs_sort = '_natural'; } $vs_hier_parent_id_fld = $this->opo_item_instance->getProperty('HIERARCHY_PARENT_ID_FLD'); $vs_hier_fld = $this->opo_item_instance->getProperty('HIERARCHY_ID_FLD'); if ($vs_hier_fld && ($vn_restrict_to_hier_id = $this->request->getParameter('currentHierarchyOnly', pInteger))) { $o_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $vs_hier_fld, '=', (int) $vn_restrict_to_hier_id); } // add filters if (isset($pa_options['filters']) && is_array($pa_options['filters']) && sizeof($pa_options['filters'])) { foreach ($pa_options['filters'] as $va_filter) { $o_search->addResultFilter($va_filter[0], $va_filter[1], $va_filter[2]); } } if (!$pb_exact) { $ps_query = trim(preg_replace("![" . str_replace("!", "\\!", $o_search_config->get('search_tokenizer_regex')) . "]+!", " ", $ps_query)); } // do search if ($vs_additional_query_params || $vs_restrict_to_search) { $vs_search = '(' . trim($ps_query) . (intval($pb_exact) ? '' : '*') . ')' . $vs_additional_query_params . $vs_restrict_to_search; } else { $vs_search = trim($ps_query) . (intval($pb_exact) ? '' : '*'); } $qr_res = $o_search->search($vs_search); $qr_res->setOption('prefetch', $pn_limit); $qr_res->setOption('dontPrefetchAttributes', true); $va_opts = array('exclude' => $va_excludes, 'limit' => $pn_limit); if (!$pb_no_inline && ($pb_quickadd || !strlen($pb_quickadd) && $this->request->user && $this->request->user->canDoAction('can_quickadd_' . $this->opo_item_instance->tableName()) && !(bool) $o_config->get($this->opo_item_instance->tableName() . '_disable_quickadd'))) { // if the lookup was restricted by search, try the lookup without the restriction // so that we can notify the user that he might be about to create a duplicate if (strlen($ps_restrict_to_search) > 0) { $o_no_filter_result = $o_search->search(trim($ps_query) . (intval($pb_exact) ? '' : '*') . $vs_type_query . $vs_additional_query_params, array('search_source' => 'Lookup', 'no_cache' => false, 'sort' => $vs_sort)); if ($o_no_filter_result->numHits() != $qr_res->numHits()) { $va_opts['inlineCreateMessageDoesNotExist'] = _t("<em>%1</em> doesn't exist with this filter but %2 record(s) match overall. Create <em>%1</em>?", $ps_query, $o_no_filter_result->numHits()); $va_opts['inlineCreateMessage'] = _t('<em>%1</em> matches %2 more record(s) without the current filter. Create <em>%1</em>?', $ps_query, $o_no_filter_result->numHits() - $qr_res->numHits()); } } if (!isset($va_opts['inlineCreateMessageDoesNotExist'])) { $va_opts['inlineCreateMessageDoesNotExist'] = _t('<em>%1</em> does not exist. Create?', $ps_query); } if (!isset($va_opts['inlineCreateMessage'])) { $va_opts['inlineCreateMessage'] = _t('Create <em>%1</em>?', $ps_query); } $va_opts['inlineCreateQuery'] = $ps_query; } else { $va_opts['emptyResultQuery'] = $ps_query; $va_opts['emptyResultMessage'] = _t('No matches found for <em>%1</em>', $ps_query); } $va_items = caProcessRelationshipLookupLabel($qr_res, $this->opo_item_instance, $va_opts); } if (!is_array($va_items)) { $va_items = array(); } // Optional output simple list of labels instead of full data format if ((bool) $this->request->getParameter('simple', pInteger)) { $va_items = caExtractValuesFromArrayList($va_items, 'label', array('preserveKeys' => false)); } $this->view->setVar(str_replace(' ', '_', $this->ops_name_singular) . '_list', array_values($va_items)); return $this->render(str_replace(' ', '_', 'ajax_' . $this->ops_name_singular . '_list_html.php')); }
/** * * * @return array */ function caGetInfoForAdvancedSearchType($ps_search_type) { $o_search_config = caGetSearchConfig(); $va_search_types = $o_search_config->getAssoc('advancedSearchTypes'); $ps_search_type = strtolower($ps_search_type); if (isset($va_search_types[$ps_search_type])) { return $va_search_types[$ps_search_type]; } return null; }