/** * */ public function __call($ps_function, $pa_args) { $o_config = caGetBrowseConfig(); $o_search_config = caGetSearchConfig(); $pa_options = array_shift($pa_args); $vb_is_advanced = (bool) $this->request->getParameter('_advanced', pInteger); $vs_find_type = $vb_is_advanced ? $this->ops_find_type . '_advanced' : $this->ops_find_type; $this->view->setVar("config", $o_config); $ps_function = strtolower($ps_function); $ps_type = $this->request->getActionExtra(); $this->view->setVar("browse_type", $ps_function); if (!($va_browse_info = caGetInfoForBrowseType($ps_function))) { // invalid browse type – throw error die("Invalid browse type {$ps_function}"); } $vs_class = $va_browse_info['table']; $va_types = caGetOption('restrictToTypes', $va_browse_info, array(), array('castTo' => 'array')); $this->opo_result_context = new ResultContext($this->request, $va_browse_info['table'], $vs_find_type); $this->opo_result_context->setAsLastFind(); MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . _t("Search %1", $va_browse_info["displayName"]) . ": " . $this->opo_result_context->getSearchExpression()); if ($vb_is_advanced) { $this->opo_result_context->setSearchExpression(caGetQueryStringForHTMLFormInput($this->opo_result_context)); } $this->view->setVar('browseInfo', $va_browse_info); $this->view->setVar('options', caGetOption('options', $va_browse_info, array(), array('castTo' => 'array'))); $ps_view = caGetOption('view', $pa_options, $this->request->getParameter('view', pString)); $va_views = caGetOption('views', $va_browse_info, array(), array('castTo' => 'array')); if (!is_array($va_views) || sizeof($va_views) == 0) { $va_views = array('list' => array(), 'images' => array(), 'timeline' => array(), 'map' => array(), 'timelineData' => array(), 'pdf' => array()); } else { $va_views['pdf'] = array(); } if (!in_array($ps_view, array_keys($va_views))) { $ps_view = array_shift(array_keys($va_views)); } $vs_format = $ps_view == 'timelineData' ? 'json' : 'html'; #caAddPageCSSClasses(array($vs_class, $ps_function, $ps_view)); caAddPageCSSClasses(array($vs_class, $ps_function)); $this->view->setVar('isNav', (bool) $this->request->getParameter('isNav', pInteger)); // flag for browses that originate from nav bar $t_instance = $this->getAppDatamodel()->getInstanceByTableName($vs_class, true); $vn_type_id = $t_instance->getTypeIDForCode($ps_type); $this->view->setVar('t_instance', $t_instance); $this->view->setVar('table', $va_browse_info['table']); $this->view->setVar('primaryKey', $t_instance->primaryKey()); $this->view->setVar('browse', $o_browse = caGetBrowseInstance($vs_class)); $this->view->setVar('views', caGetOption('views', $va_browse_info, array(), array('castTo' => 'array'))); $this->view->setVar('view', $ps_view); $this->view->setVar('viewIcons', $o_config->getAssoc("views")); // // Load existing browse if key is specified // if ($ps_cache_key = $this->request->getParameter('key', pString)) { $o_browse->reload($ps_cache_key); } if (is_array($va_types) && sizeof($va_types)) { $o_browse->setTypeRestrictions($va_types); } // // Clear criteria if required // if ($vs_remove_criterion = $this->request->getParameter('removeCriterion', pString)) { $o_browse->removeCriteria($vs_remove_criterion, array($this->request->getParameter('removeID', pString))); } if ((bool) $this->request->getParameter('clear', pInteger)) { $o_browse->removeAllCriteria(); } if ($this->request->getParameter('getFacet', pInteger)) { $vs_facet = $this->request->getParameter('facet', pString); $this->view->setVar('facet_name', $vs_facet); $this->view->setVar('key', $o_browse->getBrowseID()); $va_facet_info = $o_browse->getInfoForFacet($vs_facet); $this->view->setVar('facet_info', $va_facet_info); # --- pull in different views based on format for facet - alphabetical, list, hierarchy switch ($va_facet_info["group_mode"]) { case "alphabetical": case "list": default: $this->view->setVar('facet_content', $o_browse->getFacetContent($vs_facet, array("checkAccess" => $this->opa_access_values))); $this->render("Browse/list_facet_html.php"); break; case "hierarchical": $this->render("Browse/hierarchy_facet_html.php"); break; } return; } // // Add criteria and execute // $vs_search_expression = $this->opo_result_context->getSearchExpression(); if ($vs_facet = $this->request->getParameter('facet', pString)) { $o_browse->addCriteria($vs_facet, array($this->request->getParameter('id', pString))); } else { if ($o_browse->numCriteria() == 0) { $o_browse->addCriteria("_search", array($vs_search_expression . ($o_search_config->get('matchOnStem') && !preg_match('!\\*$!', $vs_search_expression) && preg_match('![\\w]+$!', $vs_search_expression) ? '*' : ''))); } } // // Sorting // $vb_sort_changed = false; $o_block_result_context = null; if (!($ps_sort = $this->request->getParameter("sort", pString))) { // inherit sort setting from multisearch? (used when linking to full results from multisearch result) if ($this->request->getParameter("source", pString) === 'multisearch') { $o_block_result_context = new ResultContext($this->request, $va_browse_info['table'], 'multisearch', $ps_function); if ($ps_sort !== $o_block_result_context->getCurrentSort() && $o_block_result_context->getCurrentSort()) { $ps_sort = $o_block_result_context->getCurrentSort(); $vb_sort_changed = true; } } if (!$ps_sort && !($ps_sort = $this->opo_result_context->getCurrentSort())) { if (is_array($va_sorts = caGetOption('sortBy', $va_browse_info, null))) { $ps_sort = array_shift(array_keys($va_sorts)); $vb_sort_changed = true; } } } else { $vb_sort_changed = true; } if ($vb_sort_changed) { # --- set the default sortDirection if available $va_sort_direction = caGetOption('sortDirection', $va_browse_info, null); if ($ps_sort_direction = $va_sort_direction[$ps_sort]) { $this->opo_result_context->setCurrentSortDirection($ps_sort_direction); } } if (!($ps_sort_direction = $this->request->getParameter("direction", pString))) { if (!($ps_sort_direction = $this->opo_result_context->getCurrentSortDirection())) { $ps_sort_direction = 'asc'; } } $this->opo_result_context->setCurrentSort($ps_sort); $this->opo_result_context->setCurrentSortDirection($ps_sort_direction); $va_sort_by = caGetOption('sortBy', $va_browse_info, null); $this->view->setVar('sortBy', is_array($va_sort_by) ? $va_sort_by : null); $this->view->setVar('sortBySelect', $vs_sort_by_select = is_array($va_sort_by) ? caHTMLSelect("sort", $va_sort_by, array('id' => "sort"), array("value" => $ps_sort)) : ''); $this->view->setVar('sortControl', $vs_sort_by_select ? _t('Sort with %1', $vs_sort_by_select) : ''); $this->view->setVar('sort', $ps_sort); $this->view->setVar('sort_direction', $ps_sort_direction); $va_options = array('checkAccess' => $this->opa_access_values); if ($va_restrict_to_fields = caGetOption('restrictSearchToFields', $va_browse_info, null)) { $va_options['restrictSearchToFields'] = $va_restrict_to_fields; } if (caGetOption('dontShowChildren', $va_browse_info, false)) { $o_browse->addResultFilter('ca_objects.parent_id', 'is', 'null'); } $o_browse->execute($va_options); // // Facets // if ($vs_facet_group = caGetOption('facetGroup', $va_browse_info, null)) { $o_browse->setFacetGroup($vs_facet_group); } $va_available_facet_list = caGetOption('availableFacets', $va_browse_info, null); $va_facets = $o_browse->getInfoForAvailableFacets(); if (is_array($va_available_facet_list) && sizeof($va_available_facet_list)) { foreach ($va_facets as $vs_facet_name => $va_facet_info) { if (!in_array($vs_facet_name, $va_available_facet_list)) { unset($va_facets[$vs_facet_name]); } } } foreach ($va_facets as $vs_facet_name => $va_facet_info) { $va_facets[$vs_facet_name]['content'] = $o_browse->getFacetContent($vs_facet_name, array("checkAccess" => $this->opa_access_values)); } $this->view->setVar('facets', $va_facets); $this->view->setVar('key', $vs_key = $o_browse->getBrowseID()); $this->request->session->setVar($ps_function . '_last_browse_id', $vs_key); // // Current criteria // $va_criteria = $o_browse->getCriteriaWithLabels(); if (isset($va_criteria['_search']) && isset($va_criteria['_search']['*'])) { unset($va_criteria['_search']); } $va_criteria_for_display = array(); foreach ($va_criteria as $vs_facet_name => $va_criterion) { $va_facet_info = $o_browse->getInfoForFacet($vs_facet_name); foreach ($va_criterion as $vn_criterion_id => $vs_criterion) { $va_criteria_for_display[] = array('facet' => $va_facet_info['label_singular'], 'facet_name' => $vs_facet_name, 'value' => $vs_criterion, 'id' => $vn_criterion_id); } } $this->view->setVar('criteria', $va_criteria_for_display); // // Results // $qr_res = $o_browse->getResults(array('sort' => $va_sort_by[$ps_sort], 'sort_direction' => $ps_sort_direction)); $this->view->setVar('result', $qr_res); if (!($pn_hits_per_block = $this->request->getParameter("n", pString))) { if (!($pn_hits_per_block = $this->opo_result_context->getItemsPerPage())) { $pn_hits_per_block = $o_config->get("defaultHitsPerBlock"); } } $this->opo_result_context->getItemsPerPage($pn_hits_per_block); $this->view->setVar('hits_per_block', $pn_hits_per_block); $this->view->setVar('start', $vn_start = $this->request->getParameter('s', pInteger)); $this->opo_result_context->setParameter('key', $vs_key); if (($vn_key_start = $vn_start - 500) < 0) { $vn_key_start = 0; } $qr_res->seek($vn_key_start); $this->opo_result_context->setResultList($qr_res->getPrimaryKeyValues(1000)); if ($o_block_result_context) { $o_block_result_context->setResultList($qr_res->getPrimaryKeyValues(1000)); $o_block_result_context->saveContext(); } $qr_res->seek($vn_start); $this->opo_result_context->saveContext(); if ($vn_type_id) { if ($this->render("Browse/{$vs_class}_{$vs_type}_{$ps_view}_{$vs_format}.php")) { return; } } switch ($ps_view) { case 'pdf': $this->_genExport($qr_res, $this->request->getParameter("export_format", pString), $vs_search_expression, $vs_search_expression); break; case 'timelineData': $this->view->setVar('view', 'timeline'); $this->render("Browse/browse_results_timelineData_json.php"); break; default: $this->render("Browse/browse_results_html.php"); break; } }
/** * Responds to the two main List verbs, includes resumption and limiting. * * @param string $verb OAI-PMH verb for the request * @param string $metadataPrefix Metadata prefix * @param int $cursor Offset in response to begin output at * @param mixed $set Optional set argument * @param string $from Optional from date argument * @param string $until Optional until date argument * @uses createResumptionToken() */ private function listResponse($oaiData, $verb, $metadataPrefix, $cursor, $set, $from, $until) { $listLimit = $this->_listLimit; $o_dm = Datamodel::load(); // by this point, the mapping code was checked to be valid $t_instance = $o_dm->getInstanceByTableName($this->table, true); $vs_pk = $t_instance->primaryKey(); $va_access_values = caGetUserAccessValues($this->opo_request, $this->opa_provider_info); $vb_show_deleted = (bool) $this->opa_provider_info['show_deleted']; $vb_dont_enforce_access_settings = (bool) $this->opa_provider_info['dont_enforce_access_settings']; $vb_dont_cache = (bool) $this->opa_provider_info['dont_cache']; $vs_table = $t_instance->tableName(); if (!($o_search = caGetSearchInstance($vs_table))) { $this->throwError(self::OAI_ERR_BAD_ARGUMENT); return; } // Construct date range for from/until if defined $o_tep = new TimeExpressionParser(); $o_lang_settings = $o_tep->getLanguageSettings(); $vs_conj = array_shift($o_lang_settings->getList("rangeConjunctions")); $vs_range = $from && $until ? "{$from} {$vs_conj} {$until}" : ''; if ($set && $this->opa_provider_info['setFacet']) { $o_browse = caGetBrowseInstance($this->table); if (($vs_query = $this->opa_provider_info['query']) && $vs_query != "*") { $o_browse->addCriteria("_search", $vs_query); } $o_browse->addCriteria($this->opa_provider_info['setFacet'], $set); $o_browse->execute(array('showDeleted' => $vb_show_deleted, 'no_cache' => $vb_dont_cache, 'limitToModifiedOn' => $vs_range, 'checkAccess' => $vb_dont_enforce_access_settings ? null : $va_access_values)); $qr_res = $o_browse->getResults(); } else { $qr_res = $o_search->search(strlen($this->opa_provider_info['query']) ? $this->opa_provider_info['query'] : "*", array('no_cache' => $vb_dont_cache, 'limitToModifiedOn' => $vs_range, 'showDeleted' => $vb_show_deleted, 'checkAccess' => $vb_dont_enforce_access_settings ? null : $va_access_values)); } if (!$qr_res) { $this->throwError(self::OAI_ERR_NO_RECORDS_MATCH, _t('Query failed')); return; } $rows = $qr_res->numHits(); if (count($qr_res->numHits()) == 0) { $this->throwError(self::OAI_ERR_NO_RECORDS_MATCH, _t('No records match the given criteria')); } else { $verbElement = $oaiData->createElement($verb); $oaiData->documentElement->appendChild($verbElement); $t_change_log = new ApplicationChangeLog(); if ($vb_show_deleted) { // get list of deleted records $va_deleted_items = array(); $qr_res->seek($cursor); $vn_c = 0; $va_get_deleted_timestamps_for = array(); while ($qr_res->nextHit()) { if ((bool) $qr_res->get("{$vs_table}.deleted")) { $va_deleted_items[$vs_pk_val = (int) $qr_res->get("{$vs_table}.{$vs_pk}")] = true; $va_get_deleted_timestamps_for[$vs_pk_val] = true; } else { $vn_access = (int) $qr_res->get("{$vs_table}.access"); if (!in_array($vn_access, $va_access_values)) { $va_deleted_items[(int) $qr_res->get("{$vs_table}.{$vs_pk}")] = true; } } $vn_c++; if ($vn_c >= $listLimit) { break; } } $qr_res->seek(0); $va_deleted_timestamps = $t_change_log->getDeleteOnTimestampsForIDs($vs_table, array_keys($va_get_deleted_timestamps_for)); } // Export data using metadata mapping $va_items = ca_data_exporters::exportRecordsFromSearchResultToArray($this->getMappingCode(), $qr_res, array('start' => $cursor, 'limit' => $listLimit)); if (is_array($va_items) && sizeof($va_items)) { $va_timestamps = $t_change_log->getLastChangeTimestampsForIDs($vs_table, array_keys($va_items)); foreach ($va_items as $vn_id => $vs_item_xml) { if ($vb_show_deleted && $va_deleted_items[$vn_id]) { $headerData = array('identifier' => OaiIdentifier::itemToOaiId($vn_id), 'datestamp' => self::unixToUtc($va_deleted_timestamps[$vn_id]['timestamp'] ? $va_deleted_timestamps[$vn_id]['timestamp'] : $va_timestamps[$vn_id]['timestamp'])); if ($verb == 'ListIdentifiers') { $header = $this->createElementWithChildren($oaiData, $verbElement, 'header', $headerData); $header->setAttribute("status", "deleted"); } else { $recordElement = $verbElement->appendChild($oaiData->createElement('record')); $header = $this->createElementWithChildren($oaiData, $recordElement, 'header', $headerData); $header->setAttribute("status", "deleted"); } } else { $headerData = array('identifier' => OaiIdentifier::itemToOaiId($vn_id), 'datestamp' => self::unixToUtc($va_timestamps[$vn_id]['timestamp'])); if ($verb == 'ListIdentifiers') { $this->createElementWithChildren($oaiData, $verbElement, 'header', $headerData); } else { $recordElement = $verbElement->appendChild($oaiData->createElement('record')); $this->createElementWithChildren($oaiData, $recordElement, 'header', $headerData); $metadataElement = $oaiData->createElement('metadata'); $o_doc_src = DomDocument::loadXML($vs_item_xml); if ($o_doc_src) { // just in case the xml fails to load through DomDocument for some reason (e.g. a bad mapping or very weird characters) $metadataElement->appendChild($oaiData->importNode($o_doc_src->documentElement, true)); } $recordElement->appendChild($metadataElement); } } } } if ($rows > $cursor + $listLimit) { $token = $this->createResumptionToken($verb, $metadataPrefix, $cursor + $listLimit, $set, $from, $until); $tokenElement = $oaiData->createElement('resumptionToken', $token['key']); $tokenElement->setAttribute('expirationDate', self::unixToUtc($token['expiration'])); $tokenElement->setAttribute('completeListSize', $rows); $tokenElement->setAttribute('cursor', $cursor); $verbElement->appendChild($tokenElement); } else { if ($cursor != 0) { $tokenElement = $this->oaiData->createElement('resumptionToken'); $verbElement->appendChild($tokenElement); } } } }
/** * Given a item_id (request parameter 'id') returns a list of ancestors for use in the hierarchy browser * Returned data is JSON format */ public function getFacetHierarchyAncestorList() { $pn_id = $this->request->getParameter('id', pInteger); $va_access_values = caGetUserAccessValues($this->request); $ps_facet_name = $this->request->getParameter('facet', pString); $this->view->setVar("facet_name", $ps_facet_name); $this->view->setVar("key", $this->request->getParameter('key', pString)); $ps_browse_type = $this->request->getParameter('browseType', pString); if (!($va_browse_info = caGetInfoForBrowseType($ps_browse_type))) { // invalid browse type – throw error die("Invalid browse type"); } $this->view->setVar("browse_type", $ps_browse_type); $vs_class = $va_browse_info['table']; $o_browse = caGetBrowseInstance($vs_class); if (!is_array($va_facet_info = $o_browse->getInfoForFacet($ps_facet_name))) { return null; } if ($ps_cache_key = $this->request->getParameter('key', pString)) { $o_browse->reload($ps_cache_key); } $va_ancestors = array(); switch ($va_facet_info['type']) { case 'attribute': // is it a list attribute? $t_element = new ca_metadata_elements(); if ($t_element->load(array('element_code' => $va_facet_info['element_code']))) { if ($t_element->get('datatype') == 3) { // 3=list if (!$pn_id) { $t_list = new ca_lists(); $pn_id = $t_list->getRootListItemID($t_element->get('list_id')); } $t_item = new ca_list_items($pn_id); if ($t_item->getPrimaryKey()) { $vs_primary_key = $t_item->primaryKey(); $this->view->setVar("primary_key", $vs_primary_key); $vs_display_fld = $t_item->getLabelDisplayField(); $this->view->setVar("display_field", $vs_display_fld); $vs_label_table_name = $t_item->getLabelTableName(); $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'additionalTableToJoin' => $vs_label_table_name, 'additionalTableJoinType' => 'LEFT', 'additionalTableSelectFields' => array($vs_display_fld, 'locale_id'), 'additionalTableWheres' => array('(' . $vs_label_table_name . '.is_preferred = 1 OR ' . $vs_label_table_name . '.is_preferred IS NULL)')))); array_shift($va_ancestors); } } } break; case 'label': // label facet $va_facet_info['table'] = $this->ops_tablename; // fall through to default case // fall through to default case default: $t_item = $this->request->datamodel->getInstanceByTableName($va_facet_info['table']); $t_item->load($pn_id); if (method_exists($t_item, "getHierarchyList")) { $va_access_values = caGetUserAccessValues($this->request); $va_facet = $o_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values)); $va_hierarchy_list = $t_item->getHierarchyList(true); $vn_hierarchies_in_use = 0; foreach ($va_hierarchy_list as $vn_i => $va_item) { if (isset($va_facet[$va_item[$t_item->primaryKey()]])) { $vn_hierarchies_in_use++; if ($vn_hierarchies_in_use > 1) { break; } } } } if ($t_item->getPrimaryKey()) { $vs_primary_key = $t_item->primaryKey(); $this->view->setVar("primary_key", $vs_primary_key); $vs_display_fld = $t_item->getLabelDisplayField(); $this->view->setVar("display_field", $vs_display_fld); $vs_label_table_name = $t_item->getLabelTableName(); $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'additionalTableToJoin' => $vs_label_table_name, 'additionalTableJoinType' => 'LEFT', 'additionalTableSelectFields' => array($vs_display_fld, 'locale_id'), 'additionalTableWheres' => array('(' . $vs_label_table_name . '.is_preferred = 1 OR ' . $vs_label_table_name . '.is_preferred IS NULL)')))); } if ($vn_hierarchies_in_use <= 1) { array_shift($va_ancestors); } break; } $this->view->setVar('ancestors', $va_ancestors); switch ($this->request->getParameter('returnAs', pString)) { case "json": return $this->render('Browse/facet_hierarchy_ancestors_json.php'); break; # ------------------------------------------------ # ------------------------------------------------ case "html": default: return $this->render('Browse/facet_hierarchy_ancestors_html.php'); break; # ------------------------------------------------ } }
/** * * * @return (string) */ function caGetFacetForMenuBar($po_request, $vs_browse_type) { $vs_key = ''; //$po_request->session->getVar('objects_last_browse_id'); if (!($va_browse_info = caGetInfoForBrowseType($vs_browse_type))) { // invalid browse type – throw error return null; } $o_browse = caGetBrowseInstance($va_browse_info["table"]); if ($vs_key) { $o_browse->reload($vs_key); } $o_browse->execute(array('checkAccess' => caGetUserAccessValues($po_request), 'showAllForNoCriteriaBrowse' => true)); $va_facets = $o_browse->getInfoForAvailableFacets(); $vs_buf = ''; $vs_default_facet = null; foreach ($va_facets as $vs_facet_name => $va_facet_info) { if (!$vs_default_facet) { $vs_default_facet = $vs_facet_name; } $vs_buf .= "<li " . (!$vs_buf ? "class='active'" : "") . "><a href='#' onclick='jQuery(\".browseMenuFacet\").load(\"" . caNavUrl($po_request, '*', 'Browse', $vs_browse_type, array('facet' => $vs_facet_name, 'getFacet' => 1, 'key' => $vs_key, 'isNav' => 1)) . "\", function() { jQuery(this).parent().scrollTop(0); }); jQuery(this).parent().siblings().removeClass(\"active\"); jQuery(this).parent().addClass(\"active\"); return false;'>" . caUcFirstUTF8Safe($va_facet_info['label_plural']) . "</a></li>\n"; } if ($vs_default_facet) { $vs_buf .= "<script type='text/javascript'>jQuery(document).ready(function() { jQuery(\".browseMenuFacet\").load(\"" . caNavUrl($po_request, '*', 'Browse', $vs_browse_type, array('facet' => $vs_default_facet, 'getFacet' => 1, 'key' => $vs_key, 'isNav' => 1)) . "\"); });</script>\n"; } return $vs_buf; }
/** * */ public function __call($ps_function, $pa_args) { $o_config = caGetListingConfig(); $ps_function = strtolower($ps_function); $ps_type = $this->request->getActionExtra(); if (!($va_listing_info = caGetInfoForListingType($ps_function))) { // invalid listing type – throw error die("Invalid listing type"); } MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . $va_listing_info["displayName"]); $o_dm = Datamodel::load(); $ps_function = strtolower($ps_function); $vs_table = $va_listing_info['table']; $vs_search = caGetOption('search', $va_listing_info, '*'); $vs_segment_by = caGetOption('segmentBy', $va_listing_info, ''); $this->opo_result_context = new ResultContext($this->request, $vs_table, $this->ops_find_type); $this->opo_result_context->setAsLastFind(); if (!($t_instance = $o_dm->getInstanceByTableName($vs_table, true))) { die("Invalid table"); } if (!($o_browse = caGetBrowseInstance($vs_table))) { die("Invalid listing"); } // Set browse facet group if ($vs_facet_group = caGetOption('browseFacetGroup', $va_listing_info, null)) { $o_browse->setFacetGroup($vs_facet_group); } $va_types = caGetOption('restrictToTypes', $va_listing_info, array(), array('castTo' => 'array')); $va_type_list = $t_instance->getTypeList(); if (!is_array($va_types) || !sizeof($va_types)) { $va_types = array_keys($va_type_list); } else { $va_types = caMakeTypeIDList($vs_table, $va_types, array('dontIncludeSubtypesInTypeRestriction' => true)); } $o_browse->addCriteria("_search", array($vs_search)); $o_browse->setTypeRestrictions($va_types, array('dontExpandHierarchically' => true)); $o_browse->execute(array('checkAccess' => $this->opa_access_values)); // // Facets for search // $va_facets = $o_browse->getInfoForAvailableFacets(); foreach ($va_facets as $vs_facet_name => $va_facet_info) { $va_facets[$vs_facet_name]['content'] = $o_browse->getFacetContent($vs_facet_name, array('checkAccess' => $this->opa_access_values)); } $this->view->setVar('facets', $va_facets); // // Add criteria and execute // if ($vs_facet = $this->request->getParameter('facet', pString)) { $o_browse->addCriteria($vs_facet, array($vn_facet_id = $this->request->getParameter('id', pString))); $this->view->setVar('facet', $vs_facet); $this->view->setVar('facet_id', $vn_facet_id); } // // Sorting // $vb_sort_changed = false; if (!($ps_sort = $this->request->getParameter("sort", pString))) { if (!($ps_sort = $this->opo_result_context->getCurrentSort())) { if (is_array($va_sorts = caGetOption('sortBy', $va_listing_info, null))) { $ps_sort = array_shift(array_keys($va_sorts)); $vb_sort_changed = true; } } } else { $vb_sort_changed = true; } if ($vb_sort_changed) { # --- set the default sortDirection if available $va_sort_direction = caGetOption('sortDirection', $va_listing_info, null); if ($ps_sort_direction = $va_sort_direction[$ps_sort]) { $this->opo_result_context->setCurrentSortDirection($ps_sort_direction); } } if (!($ps_sort_direction = $this->request->getParameter("direction", pString))) { if (!($ps_sort_direction = $this->opo_result_context->getCurrentSortDirection())) { $ps_sort_direction = 'asc'; } } $this->opo_result_context->setCurrentSort($ps_sort); $this->opo_result_context->setCurrentSortDirection($ps_sort_direction); $va_sort_by = caGetOption('sortBy', $va_listing_info, null); $this->view->setVar('sortBy', is_array($va_sort_by) ? $va_sort_by : null); $this->view->setVar('sortBySelect', $vs_sort_by_select = is_array($va_sort_by) ? caHTMLSelect("sort", $va_sort_by, array('id' => "sort"), array("value" => $ps_sort)) : ''); $this->view->setVar('sortControl', $vs_sort_by_select ? _t('Sort with %1', $vs_sort_by_select) : ''); $this->view->setVar('sort', $ps_sort); $this->view->setVar('sort_direction', $ps_sort_direction); $va_lists = array(); $va_res_list = array(); $o_browse->execute(array('checkAccess' => $this->opa_access_values)); $qr_res = $o_browse->getResults(array('sort' => $va_sort_by[$ps_sort], 'sort_direction' => $ps_sort_direction)); while ($qr_res->nextHit()) { $vs_key = $qr_res->getWithTemplate($vs_segment_by); $va_lists[$vs_key][] = $va_res_list[] = $qr_res->getPrimaryKey(); } foreach ($va_lists as $vs_key => $va_ids) { $va_lists[$vs_key] = caMakeSearchResult($vs_table, $va_ids); } $this->view->setVar('table', $vs_table); $this->view->setVar('lists', $va_lists); $this->view->setVar('typeInfo', $va_type_list); $this->view->setVar('listingInfo', $va_listing_info); // // Current criteria // $va_criteria = $o_browse->getCriteriaWithLabels(); unset($va_criteria['_search']); $va_criteria_for_checking = array(); foreach ($va_criteria as $vs_facet_name => $va_criterion) { $va_facet_info = $o_browse->getInfoForFacet($vs_facet_name); foreach ($va_criterion as $vn_criterion_id => $vs_criterion) { $va_criteria_for_checking[$vs_facet_name] = $vn_criterion_id; } } $this->view->setVar('hasCriteria', sizeof($va_criteria_for_checking) > 0); $this->view->setVar('criteria', $va_criteria_for_checking); $this->opo_result_context->setResultList($va_res_list); $this->opo_result_context->saveContext(); $this->render("Listing/listing_html.php"); }
/** * */ public function __call($ps_function, $pa_args) { $o_config = caGetBrowseConfig(); $this->view->setVar("config", $o_config); $ps_function = strtolower($ps_function); $ps_type = $this->request->getActionExtra(); if (!($va_browse_info = caGetInfoForBrowseType($ps_function))) { // invalid browse type – throw error die("Invalid browse type"); } MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . _t("Browse %1", $va_browse_info["displayName"])); $this->view->setVar("browse_type", $ps_function); $vs_class = $va_browse_info['table']; $va_types = caGetOption('restrictToTypes', $va_browse_info, array(), array('castTo' => 'array')); $this->opo_result_context = new ResultContext($this->request, $va_browse_info['table'], $this->ops_find_type); // Don't set last find when loading facet, as some other controllers use this action and setting // last find will disrupt ResultContext navigation by setting it to "browse" when in fact a search (or some other // context) is still in effect. if (!$this->request->getParameter('getFacet', pInteger)) { $this->opo_result_context->setAsLastFind(); } $this->view->setVar('browseInfo', $va_browse_info); $this->view->setVar('paging', in_array(strtolower($va_browse_info['paging']), array('continous', 'nextprevious', 'letter')) ? strtolower($va_browse_info['paging']) : 'continous'); $this->view->setVar('name', $va_browse_info['displayName']); $this->view->setVar('options', caGetOption('options', $va_browse_info, array(), array('castTo' => 'array'))); $ps_view = $this->request->getParameter('view', pString); $va_views = caGetOption('views', $va_browse_info, array(), array('castTo' => 'array')); if (!is_array($va_views) || sizeof($va_views) == 0) { $va_views = array('list' => array(), 'images' => array(), 'timeline' => array(), 'map' => array(), 'timelineData' => array(), 'pdf' => array()); } else { $va_views['pdf'] = array(); $va_views['timelineData'] = array(); } if (!in_array($ps_view, array_keys($va_views))) { $ps_view = array_shift(array_keys($va_views)); } $vs_format = $ps_view == 'timelineData' ? 'json' : 'html'; caAddPageCSSClasses(array($vs_class, $ps_function)); $this->view->setVar('isNav', $vb_is_nav = (bool) $this->request->getParameter('isNav', pInteger)); // flag for browses that originate from nav bar $t_instance = $this->getAppDatamodel()->getInstanceByTableName($vs_class, true); $vn_type_id = $t_instance->getTypeIDForCode($ps_type); $this->view->setVar('t_instance', $t_instance); $this->view->setVar('table', $va_browse_info['table']); $this->view->setVar('primaryKey', $t_instance->primaryKey()); $this->view->setVar('browse', $o_browse = caGetBrowseInstance($vs_class)); $this->view->setVar('views', caGetOption('views', $va_browse_info, array(), array('castTo' => 'array'))); $this->view->setVar('view', $ps_view); $this->view->setVar('viewIcons', $o_config->getAssoc("views")); // // Load existing browse if key is specified // if ($ps_cache_key = $this->request->getParameter('key', pString)) { $o_browse->reload($ps_cache_key); } if (is_array($va_types) && sizeof($va_types)) { $o_browse->setTypeRestrictions($va_types, array('dontExpandHierarchically' => caGetOption('dontExpandTypesHierarchically', $va_browse_info, false))); } // // Clear criteria if required // if ($vs_remove_criterion = $this->request->getParameter('removeCriterion', pString)) { $o_browse->removeCriteria($vs_remove_criterion, array($this->request->getParameter('removeID', pString))); } if ((bool) $this->request->getParameter('clear', pInteger)) { $o_browse->removeAllCriteria(); } // // Return facet content // if ($this->request->getParameter('getFacet', pInteger)) { $vs_facet = $this->request->getParameter('facet', pString); $vn_s = $vb_is_nav ? $this->request->getParameter('s', pInteger) : 0; // start menu-based browse menu facet data at page boundary; all others get the full facet $this->view->setVar('start', $vn_s); $this->view->setVar('limit', $vn_limit = $vb_is_nav ? 500 : null); // break facet into pages for menu-based browse menu $this->view->setVar('facet_name', $vs_facet); $this->view->setVar('key', $o_browse->getBrowseID()); $this->view->setVar('facet_info', $va_facet_info = $o_browse->getInfoForFacet($vs_facet)); # --- pull in different views based on format for facet - alphabetical, list, hierarchy switch ($va_facet_info["group_mode"]) { case "alphabetical": case "list": default: $this->view->setVar('facet_content', $o_browse->getFacet($vs_facet, array("checkAccess" => $this->opa_access_values, 'start' => $vn_s, 'limit' => $vn_limit))); $this->render("Browse/list_facet_html.php"); break; case "hierarchical": $this->render("Browse/hierarchy_facet_html.php"); break; } return; } // // Add criteria and execute // // Get any preset-criteria $va_base_criteria = caGetOption('baseCriteria', $va_browse_info, null); if ($vs_facet = $this->request->getParameter('facet', pString)) { $o_browse->addCriteria($vs_facet, array($this->request->getParameter('id', pString))); } else { if ($o_browse->numCriteria() == 0) { if (is_array($va_base_criteria)) { foreach ($va_base_criteria as $vs_facet => $vs_value) { $o_browse->addCriteria($vs_facet, $vs_value); } } else { $o_browse->addCriteria("_search", array("*")); } } } // // Sorting // $vb_sort_changed = false; if (!($ps_sort = $this->request->getParameter("sort", pString))) { if (!($ps_sort = $this->opo_result_context->getCurrentSort())) { if (is_array($va_sorts = caGetOption('sortBy', $va_browse_info, null))) { $ps_sort = array_shift(array_keys($va_sorts)); $vb_sort_changed = true; } } } else { $vb_sort_changed = true; } if ($vb_sort_changed) { # --- set the default sortDirection if available $va_sort_direction = caGetOption('sortDirection', $va_browse_info, null); if ($ps_sort_direction = $va_sort_direction[$ps_sort]) { $this->opo_result_context->setCurrentSortDirection($ps_sort_direction); } } if (!($ps_sort_direction = $this->request->getParameter("direction", pString))) { if (!($ps_sort_direction = $this->opo_result_context->getCurrentSortDirection())) { $ps_sort_direction = 'asc'; } } $this->opo_result_context->setCurrentSort($ps_sort); $this->opo_result_context->setCurrentSortDirection($ps_sort_direction); $va_sort_by = caGetOption('sortBy', $va_browse_info, null); $this->view->setVar('sortBy', is_array($va_sort_by) ? $va_sort_by : null); $this->view->setVar('sortBySelect', $vs_sort_by_select = is_array($va_sort_by) ? caHTMLSelect("sort", $va_sort_by, array('id' => "sort"), array("value" => $ps_sort)) : ''); $this->view->setVar('sortControl', $vs_sort_by_select ? _t('Sort with %1', $vs_sort_by_select) : ''); $this->view->setVar('sort', $ps_sort); $this->view->setVar('sort_direction', $ps_sort_direction); if (caGetOption('dontShowChildren', $va_browse_info, false)) { $o_browse->addResultFilter('ca_objects.parent_id', 'is', 'null'); } // // Current criteria // $va_criteria = $o_browse->getCriteriaWithLabels(); if (isset($va_criteria['_search']) && isset($va_criteria['_search']['*'])) { unset($va_criteria['_search']); } $o_browse->execute(array('checkAccess' => $this->opa_access_values, 'showAllForNoCriteriaBrowse' => true)); // // Facets // if ($vs_facet_group = caGetOption('facetGroup', $va_browse_info, null)) { $o_browse->setFacetGroup($vs_facet_group); } $va_available_facet_list = caGetOption('availableFacets', $va_browse_info, null); $va_facets = $o_browse->getInfoForAvailableFacets(); foreach ($va_facets as $vs_facet_name => $va_facet_info) { if (isset($va_base_criteria[$vs_facet_name])) { continue; } // skip base criteria $va_facets[$vs_facet_name]['content'] = $o_browse->getFacet($vs_facet_name, array("checkAccess" => $this->opa_access_values, 'checkAvailabilityOnly' => caGetOption('deferred_load', $va_facet_info, false, array('castTo' => 'bool')))); } $this->view->setVar('facets', $va_facets); $this->view->setVar('key', $vs_key = $o_browse->getBrowseID()); $this->request->session->setVar($ps_function . '_last_browse_id', $vs_key); // remove base criteria from display list if (is_array($va_base_criteria)) { foreach ($va_base_criteria as $vs_base_facet => $vs_criteria_value) { unset($va_criteria[$vs_base_facet]); } } $va_criteria_for_display = array(); foreach ($va_criteria as $vs_facet_name => $va_criterion) { $va_facet_info = $o_browse->getInfoForFacet($vs_facet_name); foreach ($va_criterion as $vn_criterion_id => $vs_criterion) { $va_criteria_for_display[] = array('facet' => $va_facet_info['label_singular'], 'facet_name' => $vs_facet_name, 'value' => $vs_criterion, 'id' => $vn_criterion_id); } } $this->view->setVar('criteria', $va_criteria_for_display); // // Results // $qr_res = $o_browse->getResults(array('sort' => $va_sort_by[$ps_sort], 'sort_direction' => $ps_sort_direction)); if ($vs_letter_bar_field = caGetOption('showLetterBarFrom', $va_browse_info, null)) { // generate letter bar $va_letters = array(); while ($qr_res->nextHit()) { $va_letters[caRemoveAccents(mb_strtolower(mb_substr($qr_res->get($vs_letter_bar_field), 0, 1)))]++; } $this->view->setVar('letterBar', $va_letters); $qr_res->seek(0); } $this->view->setVar('showLetterBar', (bool) $vs_letter_bar_field); if ($vs_letter_bar_field && ($vs_l = mb_strtolower($this->request->getParameter('l', pString)))) { $va_filtered_ids = array(); while ($qr_res->nextHit()) { if (caRemoveAccents(mb_strtolower(mb_substr($qr_res->get($vs_letter_bar_field), 0, 1))) == $vs_l) { $va_filtered_ids[] = $qr_res->getPrimaryKey(); } } if (sizeof($va_filtered_ids) > 0) { $qr_res = caMakeSearchResult($vs_class, $va_filtered_ids); } } $this->view->setVar('letter', $vs_l); $this->view->setVar('result', $qr_res); if (!($pn_hits_per_block = $this->request->getParameter("n", pString))) { if (!($pn_hits_per_block = $this->opo_result_context->getItemsPerPage())) { $pn_hits_per_block = $o_config->get("defaultHitsPerBlock"); } } $this->opo_result_context->getItemsPerPage($pn_hits_per_block); $this->view->setVar('hits_per_block', $pn_hits_per_block); $this->view->setVar('start', $vn_start = $this->request->getParameter('s', pInteger)); $this->opo_result_context->setParameter('key', $vs_key); if (!$this->request->isAjax()) { if (($vn_key_start = $vn_start - 500) < 0) { $vn_key_start = 0; } $qr_res->seek($vn_key_start); $this->opo_result_context->setResultList($qr_res->getPrimaryKeyValues(500)); $qr_res->seek($vn_start); } $this->opo_result_context->saveContext(); if ($ps_type) { if ($this->render("Browse/{$vs_class}_{$ps_type}_{$ps_view}_{$vs_format}.php")) { return; } } switch ($ps_view) { case 'pdf': $this->_genExport($qr_res, $this->request->getParameter("export_format", pString), $vs_search_expression, $this->getCriteriaForDisplay($o_browse)); break; case 'timelineData': $this->view->setVar('view', 'timeline'); $this->render("Browse/browse_results_timelineData_json.php"); break; default: $this->opo_result_context->setCurrentView($ps_view); $this->render("Browse/browse_results_html.php"); break; } }
public function __construct(&$po_request, &$po_response, $pa_view_paths = null) { parent::__construct($po_request, $po_response, $pa_view_paths); // // Get browse target // $va_browse_targets = $this->request->config->getList('browse_targets'); if (!($vs_browse_target = $po_request->getParameter('target', pString)) || $vs_browse_target == 'null') { if (!($vs_browse_target = $po_request->session->getVar('pawtucket2_browse_target'))) { if (is_array($va_browse_targets)) { $vs_browse_target = array_shift($va_browse_targets); } } } $va_target_list = array(); foreach ($this->request->config->getList('browse_targets') as $vs_target) { $va_tmp = explode(":", $vs_target); $va_target_list[$vs_target] = caGetBrowseInstance($va_tmp[0]); if (sizeof($va_tmp) > 1) { $va_target_list[$vs_target]->setTypeRestrictions(array($va_tmp[1])); } if ($vs_facet_group = $po_request->config->get($va_tmp[0] . '_browse_facet_group')) { $va_target_list[$vs_target]->setFacetGroup($vs_facet_group); } } $this->view->setVar('targets', $va_target_list); // redirect user if not logged in if ($this->request->config->get('pawtucket_requires_login') && !$this->request->isLoggedIn() || $this->request->config->get('show_bristol_only') && !$this->request->isLoggedIn()) { $this->response->setRedirect(caNavUrl($this->request, "", "LoginReg", "form")); } elseif ($this->request->config->get('show_bristol_only') && $this->request->isLoggedIn()) { $this->response->setRedirect(caNavUrl($this->request, "bristol", "Show", "Index")); } // // Minimal view list (all targets have a "full" results view) // $this->opa_views = array('full' => _t('List')); $this->opa_views_options = array('full' => array("description" => _t("View results in a list"), "icon" => "icon_list.gif")); if ($this->request->config->get("dont_enforce_access_settings")) { $va_access_values = array(); } else { $va_access_values = caGetUserAccessValues($this->request); } $this->view->setVar('access_values', $va_access_values); // // Set up for browse target // $va_tmp = explode(":", $vs_browse_target); switch ($va_tmp[0]) { case 'ca_entities': $this->ops_tablename = 'ca_entities'; $this->opo_result_context = new ResultContext($po_request, $this->ops_tablename, $this->ops_find_type); $this->opo_browse = new EntityBrowse($this->opo_result_context->getSearchExpression(), 'pawtucket2'); // get configured result views, if specified if ($va_result_views_for_ca_entities = $po_request->config->getAssoc('result_views_for_ca_entities')) { $this->opa_views = $va_result_views_for_ca_entities; } // get configured result views options, if specified if ($va_result_views_options_for_ca_entities = $po_request->config->getAssoc('result_views_options_for_ca_entities')) { $this->opa_views_options = $va_result_views_options_for_ca_entities; } // get configured result sort options, if specified if ($va_sort_options_for_ca_entities = $po_request->config->getAssoc('result_sort_options_for_ca_entities')) { $this->opa_sorts = $va_sort_options_for_ca_entities; } else { $this->opa_sorts = array('ca_entity_labels.displayname' => _t('Name'), 'ca_entities.type_id' => _t('Type'), 'ca_entities.idno_sort' => _t('Idno')); } break; case 'ca_places': $this->ops_tablename = 'ca_places'; $this->opo_result_context = new ResultContext($po_request, $this->ops_tablename, $this->ops_find_type); $this->opo_browse = new PlaceBrowse($this->opo_result_context->getSearchExpression(), 'pawtucket2'); // get configured result views, if specified if ($va_result_views_for_ca_places = $po_request->config->getAssoc('result_views_for_ca_places')) { $this->opa_views = $va_result_views_for_ca_places; } // get configured result views options, if specified if ($va_result_views_options_for_ca_places = $po_request->config->getAssoc('result_views_options_for_ca_places')) { $this->opa_views_options = $va_result_views_options_for_ca_places; } // get configured result sort options, if specified if ($va_sort_options_for_ca_places = $po_request->config->getAssoc('result_sort_options_for_ca_places')) { $this->opa_sorts = $va_sort_options_for_ca_places; } else { $this->opa_sorts = array('ca_place_labels.name' => _t('Name'), 'ca_places.type_id' => _t('Type'), 'ca_places.idno_sort' => _t('Idno')); } break; case 'ca_occurrences': $this->ops_tablename = 'ca_occurrences'; $this->opo_result_context = new ResultContext($po_request, $this->ops_tablename, $this->ops_find_type); $this->opo_browse = new OccurrenceBrowse($this->opo_result_context->getSearchExpression(), 'pawtucket2'); // get configured result views, if specified if ($va_result_views_for_ca_occurrences = $po_request->config->getAssoc('result_views_for_ca_occurrences')) { $this->opa_views = $va_result_views_for_ca_occurrences; } // get configured result views options, if specified if ($va_result_views_options_for_ca_occurrences = $po_request->config->getAssoc('result_views_options_for_ca_occurrences')) { $this->opa_views_options = $va_result_views_options_for_ca_occurrences; } // get configured result sort options, if specified if ($va_sort_options_for_ca_occurrences = $po_request->config->getAssoc('result_sort_options_for_ca_occurrences')) { $this->opa_sorts = $va_sort_options_for_ca_occurrences; } else { $this->opa_sorts = array('ca_occurrence_labels.name' => _t('Title'), 'ca_occurrences.idno_sort' => _t('Idno')); } break; case 'ca_collections': $this->ops_tablename = 'ca_collections'; $this->opo_result_context = new ResultContext($po_request, $this->ops_tablename, $this->ops_find_type); $this->opo_browse = new CollectionBrowse($this->opo_result_context->getSearchExpression(), 'pawtucket2'); // get configured result views, if specified if ($va_result_views_for_ca_collections = $po_request->config->getAssoc('result_views_for_ca_collections')) { $this->opa_views = $va_result_views_for_ca_collections; } // get configured result views options, if specified if ($va_result_views_options_for_ca_collections = $po_request->config->getAssoc('result_views_options_for_ca_collections')) { $this->opa_views_options = $va_result_views_options_for_ca_collections; } // get configured result sort options, if specified if ($va_sort_options_for_ca_collections = $po_request->config->getAssoc('result_sort_options_for_ca_collections')) { $this->opa_sorts = $va_sort_options_for_ca_collections; } else { $this->opa_sorts = array('ca_collection_labels.name' => _t('Name'), 'ca_collections.type_id' => _t('Type'), 'ca_collections.idno_sort' => _t('Idno')); } break; default: $this->ops_tablename = 'ca_objects'; $this->opo_result_context = new ResultContext($po_request, $this->ops_tablename, $this->ops_find_type); $this->opo_browse = new ObjectBrowse($this->opo_result_context->getSearchExpression(), 'pawtucket2'); // get configured result views, if specified if ($va_result_views_for_ca_objects = $po_request->config->getAssoc('result_views_for_ca_objects')) { $this->opa_views = $va_result_views_for_ca_objects; } else { $this->opa_views = array('full' => _t('List'), 'thumbnail' => _t('Thumbnails')); } // get configured result views options, if specified if ($va_result_views_options_for_ca_objects = $po_request->config->getAssoc('result_views_options_for_ca_objects')) { $this->opa_views_options = $va_result_views_options_for_ca_objects; } else { $this->opa_views_options = array('thumbnail' => array("description" => _t("View thumbnails with brief captions"), "icon" => "icon_thumbnail.gif"), 'full' => array("description" => _t("View images with full captions"), "icon" => "icon_full.gif")); } // get configured result sort options, if specified if ($va_sort_options_for_ca_objects = $po_request->config->getAssoc('result_sort_options_for_ca_objects')) { $this->opa_sorts = $va_sort_options_for_ca_objects; } else { $this->opa_sorts = array('ca_object_labels.name' => _t('Title'), 'ca_objects.type_id' => _t('Type'), 'ca_objects.idno_sort' => _t('Idno')); } if ($po_request->config->get("show_map_object_search_results")) { JavascriptLoadManager::register('maps'); $this->opa_views['map'] = _t('Map'); if (!$this->opa_views_options['map']) { $this->opa_views_options['map'] = array("description" => _t("View results plotted on a map"), "icon" => "icon_map.gif"); } } break; } // if target changes we need clear out all browse criteria as they are no longer valid if ($vs_browse_target != $po_request->session->getVar('pawtucket2_browse_target')) { $this->opo_browse->removeAllCriteria(); } if ($va_tmp[1]) { // set type restriction off of target $this->opo_result_context->setTypeRestriction($va_tmp[1]); } // Set up target vars and controls $po_request->session->setVar('pawtucket2_browse_target', $vs_browse_target); if (sizeof($va_browse_targets = $this->request->config->getList('browse_targets')) > 1) { $va_browse_options = array(); foreach ($va_browse_targets as $vs_possible_browse_target) { if ($vs_browse_target_name = $this->opo_browse->getBrowseSubjectName($vs_possible_browse_target)) { $va_browse_options[$vs_browse_target_name] = $vs_possible_browse_target; } } $this->view->setVar('browse_selector', "<form action='#'>" . caHTMLSelect('target', $va_browse_options, array('id' => 'caBrowseTargetSelectorSelect', 'onchange' => 'window.location = \'' . caNavUrl($this->request, $this->request->getModulePath(), $this->request->getController(), 'Index', array('target' => '')) . '\' + jQuery(\'#caBrowseTargetSelectorSelect\').val();'), array('value' => $vs_browse_target, 'dontConvertAttributeQuotesToEntities' => true)) . "</form>\n"); } // get configured items per page options, if specified if ($va_items_per_page = $po_request->config->getList('items_per_page_options_for_' . $vs_browse_target . '_browse')) { $this->opa_items_per_page = $va_items_per_page; } if (($vn_items_per_page_default = (int) $po_request->config->get('items_per_page_default_for_' . $this->ops_tablename . '_browse')) > 0) { $this->opn_items_per_page_default = $vn_items_per_page_default; } else { $this->opn_items_per_page_default = $this->opa_items_per_page[0]; } // set current result view options so can check we are including a configured result view $this->view->setVar('result_views', $this->opa_views); $this->view->setVar('result_views_options', $this->opa_views_options); if ($this->opn_type_restriction_id = $this->opo_result_context->getTypeRestriction($pb_type_restriction_has_changed)) { $_GET['type_id'] = $this->opn_type_restriction_id; // push type_id into globals so breadcrumb trail can pick it up $this->opb_type_restriction_has_changed = $pb_type_restriction_has_changed; // get change status } }
function setDetail() { if (!$this->request->isLoggedIn()) { $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'loginForm')); return; } AssetLoadManager::register("mediaViewer"); $o_context = new ResultContext($this->request, 'ca_objects', 'sets', 'lightbox'); $o_context->setAsLastFind(); $this->view->setVar('browse', $o_browse = caGetBrowseInstance("ca_objects")); $this->view->setVar("browse_type", "caLightbox"); # --- this is only used when loading hierarchy facets and is a way to get around needing a browse type to pull the table in FindController $ps_view = $this->request->getParameter('view', pString); if (!in_array($ps_view, array('thumbnail', 'timeline', 'timelineData', 'pdf', 'list'))) { $ps_view = 'thumbnail'; } $this->view->setVar('view', $ps_view); $this->view->setVar('views', $this->opo_config->getAssoc("views")); if (!($t_set = $this->_getSet(__CA_SET_READ_ACCESS__))) { $this->Index(); } $vn_set_id = $t_set->get("set_id"); $this->view->setVar("set", $t_set); $va_comments = $t_set->getComments(); $this->view->setVar("comments", $va_comments); // // Load existing browse if key is specified // if ($ps_cache_key = $this->request->getParameter('key', pString)) { $o_browse->reload($ps_cache_key); } // // Clear criteria if required // if ($vs_remove_criterion = $this->request->getParameter('removeCriterion', pString)) { $o_browse->removeCriteria($vs_remove_criterion, array($this->request->getParameter('removeID', pString))); } if ((bool) $this->request->getParameter('clear', pInteger)) { // Clear all refine critera but *not* underlying _search criterion $va_criteria = $o_browse->getCriteria(); foreach ($va_criteria as $vs_criterion => $va_criterion_info) { if ($vs_criterion == '_search') { continue; } $o_browse->removeCriteria($vs_criterion, array_keys($va_criterion_info)); } } if ($this->request->getParameter('getFacet', pInteger)) { $vs_facet = $this->request->getParameter('facet', pString); $this->view->setVar('facet_name', $vs_facet); $this->view->setVar('key', $o_browse->getBrowseID()); $va_facet_info = $o_browse->getInfoForFacet($vs_facet); $this->view->setVar('facet_info', $va_facet_info); # --- pull in different views based on format for facet - alphabetical, list, hierarchy switch ($va_facet_info["group_mode"]) { case "alphabetical": case "list": default: $this->view->setVar('facet_content', $o_browse->getFacetContent($vs_facet, array("checkAccess" => $this->opa_access_values))); $this->render("Browse/list_facet_html.php"); break; case "hierarchical": $this->render("Browse/hierarchy_facet_html.php"); break; } return; } // // Add criteria and execute // $vs_search_expression = "ca_sets.set_id:{$vn_set_id}"; if ($o_browse->numCriteria() == 0 && $vs_search_expression) { $o_browse->addCriteria("_search", array($vs_search_expression)); } if ($vs_facet = $this->request->getParameter('facet', pString)) { $o_browse->addCriteria($vs_facet, array($this->request->getParameter('id', pString))); } // // Sorting // $vb_sort_changed = false; if (!($ps_secondary_sort = $this->request->getParameter("secondary_sort", pString))) { $ps_secondary_sort = $o_context->getCurrentSecondarySort(); } $va_config_sort = $this->opo_config->getAssoc("sortBy"); if (!is_array($va_config_sort)) { $va_config_sort = array(); } $va_sort_by = array_merge(array(_t('Set order') => "ca_set_items.rank/{$vn_set_id}"), $va_config_sort); if (!($ps_sort = urldecode($this->request->getParameter("sort", pString)))) { if (!$ps_sort && !($ps_sort = $o_context->getCurrentSort())) { if (is_array($va_sort_by)) { $ps_sort = array_shift(array_keys($va_sort_by)); $vb_sort_changed = true; } } } else { $vb_sort_changed = true; } if ($vb_sort_changed) { # --- set the default sortDirection if available $va_sort_direction = $this->opo_config->getAssoc("sortDirection"); if ($ps_sort_direction = $va_sort_direction[$ps_sort]) { $o_context->setCurrentSortDirection($ps_sort_direction); } $ps_secondary_sort = ""; } if (!($ps_sort_direction = $this->request->getParameter("direction", pString))) { if (!($ps_sort_direction = $o_context->getCurrentSortDirection())) { $ps_sort_direction = 'asc'; } } $o_context->setCurrentSort($ps_sort); $o_context->setCurrentSecondarySort($ps_secondary_sort); $o_context->setCurrentSortDirection($ps_sort_direction); $this->view->setVar('sortBy', is_array($va_sort_by) ? $va_sort_by : null); $this->view->setVar('sortBySelect', $vs_sort_by_select = is_array($va_sort_by) ? caHTMLSelect("sort", $va_sort_by, array('id' => "sort"), array("value" => $ps_sort)) : ''); $this->view->setVar('sort', $ps_sort); $va_secondary_sort_by = $this->opo_config->getAssoc("secondarySortBy"); $this->view->setVar('secondarySortBy', is_array($va_secondary_sort_by) ? $va_secondary_sort_by : null); $this->view->setVar('secondarySortBySelect', $vs_secondary_sort_by_select = is_array($va_secondary_sort_by) ? caHTMLSelect("secondary_sort", $va_secondary_sort_by, array('id' => "secondary_sort"), array("value" => $ps_secondary_sort)) : ''); $this->view->setVar('secondarySort', $ps_secondary_sort); $this->view->setVar('sortDirection', $ps_sort_direction); $va_options = array('checkAccess' => $this->opa_access_values, 'no_cache' => true); $o_browse->execute(array_merge($va_options, array('strictPhraseSearching' => true))); // // Facets // if ($vs_facet_group = $this->opo_config->get("set_facet_group")) { $o_browse->setFacetGroup($vs_facet_group); } $va_available_facet_list = $this->opo_config->get("availableFacets"); $va_facets = $o_browse->getInfoForAvailableFacets(); if (is_array($va_available_facet_list) && sizeof($va_available_facet_list)) { foreach ($va_facets as $vs_facet_name => $va_facet_info) { if (!in_array($vs_facet_name, $va_available_facet_list)) { unset($va_facets[$vs_facet_name]); } } } foreach ($va_facets as $vs_facet_name => $va_facet_info) { $va_facets[$vs_facet_name]['content'] = $o_browse->getFacetContent($vs_facet_name, array("checkAccess" => $this->opa_access_values)); } $this->view->setVar('facets', $va_facets); $this->view->setVar('key', $vs_key = $o_browse->getBrowseID()); $this->request->session->setVar('lightbox_last_browse_id', $vs_key); // // Current criteria // $va_criteria = $o_browse->getCriteriaWithLabels(); if (isset($va_criteria['_search']) && isset($va_criteria['_search']['*'])) { unset($va_criteria['_search']); } $va_criteria_for_display = array(); foreach ($va_criteria as $vs_facet_name => $va_criterion) { $va_facet_info = $o_browse->getInfoForFacet($vs_facet_name); foreach ($va_criterion as $vn_criterion_id => $vs_criterion) { $va_criteria_for_display[] = array('facet' => $va_facet_info['label_singular'], 'facet_name' => $vs_facet_name, 'value' => $vs_criterion, 'id' => $vn_criterion_id); } } $this->view->setVar('criteria', $va_criteria_for_display); // // Results // $vs_combined_sort = $va_sort_by[$ps_sort]; if ($ps_secondary_sort) { $vs_combined_sort .= ";" . $va_secondary_sort_by[$ps_secondary_sort]; } $qr_res = $o_browse->getResults(array('sort' => $vs_combined_sort, 'sort_direction' => $ps_sort_direction)); $this->view->setVar('result', $qr_res); if (!($pn_hits_per_block = $this->request->getParameter("n", pString))) { if (!($pn_hits_per_block = $o_context->getItemsPerPage())) { $pn_hits_per_block = $this->opo_config->get("defaultHitsPerBlock") ? $this->opo_config->get("defaultHitsPerBlock") : 36; } } $o_context->getItemsPerPage($pn_hits_per_block); $this->view->setVar('hits_per_block', $pn_hits_per_block); $this->view->setVar('start', $vn_start = $this->request->getParameter('s', pInteger)); $o_context->setParameter('key', $vs_key); if (($vn_key_start = $vn_start - 500) < 0) { $vn_key_start = 0; } $qr_res->seek($vn_key_start); $o_context->setResultList($qr_res->getPrimaryKeyValues(1000)); if ($o_block_result_context) { $o_block_result_context->setResultList($qr_res->getPrimaryKeyValues(1000)); $o_block_result_context->saveContext(); } $qr_res->seek($vn_start); $o_context->saveContext(); MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . ucfirst($this->ops_lightbox_display_name) . ": " . $t_set->getLabelForDisplay()); switch ($ps_view) { case 'pdf': $this->_genExport($qr_res, $this->request->getParameter("export_format", pString), $vs_label = $t_set->get('ca_sets.preferred_labels'), $vs_label); case 'timelineData': $this->view->setVar('view', 'timeline'); $this->render("Sets/set_detail_timelineData_json.php"); break; default: $this->render("Sets/set_detail_html.php"); break; } }