TextDescription(FALSE), 120));
# ----- LOCAL FUNCTIONS ------------------------------------------------------
/**
* Process an array of search facets, generating the necessary HTML for
* each.
* @param array $Facets Search facets to display. This is keyed by
* FieldId. If there are no sub-selections, then the value is an
* array of hrefs for URLs that will modify the search. If there
* are subselection, then the value is an array that contains a
* single array where the last element is a link to remove the
* current selection and the other elements are suggestions.
* @param array $FieldsOpenByDefault List of fields to be initially open.
* @param bool $DisplayCounts If TRUE, resource counts will be added
* to the list item if available.
*/
function PrintSearchFacets($Facets, $FieldsOpenByDefault, $DisplayCounts)
{
# ShrinkCounter counts the number of shrinkable facet spans so
# that each can have a unique class name
static $ShrinkCounter = 0;
# if we have any facets
if (count($Facets) > 0)
{
# iterate over each
foreach ($Facets as $Key => $Values)
{
# if this facet should be open, display it as such, otherwise
# display a closed facet (the HTML below differs in which
# elements get the "display: none" initially applied)
$ToggleClass = "DD_Toggle".$ShrinkCounter;
if (isset($FieldsOpenByDefault[$Key]))
{
print "
"
."["
."+"
."–"
."] ".$Key.""
."
\n"
."
\n";
}
else
{
print "
"
."["
."+"
."–"
."] ".$Key.""
."
\n"
."
\n";
}
# foreach value in this facet, generate a list item
foreach ($Values as $Value)
{
# check if this facet is a tree, which encodes
# suggestions arrays
if (!isset($Value["Name"]))
{
# current selection in the tree is always the last element
$TopLevel = array_pop($Value);
# display current selection
$ListItem = GenerateFacetListItem($TopLevel, $DisplayCounts);
print $ListItem."
\n";
# then list the children of the current selection in a sublist
foreach ($Value as $ValueChild)
{
print GenerateFacetListItem($ValueChild, $DisplayCounts);
}
print "
\n";
$ShrinkCounter++;
}
}
}
/**
* Generate list item HTML for facet.
* @param array $Info List item info, with "Name" and either "AddLink"
* or "RemoveLink" entries, and optionally a "Count" entry.
* @param bool $DisplayCounts If TRUE, resource counts will be added
* to the list item if available.
* @return string Generated item string.
*/
function GenerateFacetListItem($Info, $DisplayCounts)
{
# if this is a removal item
if (isset($Info["RemoveLink"]))
{
$Item = '
\n";
}
# return generated item to caller
return $Item;
}
/**
* Get the controls for sorting and ordering.
* @param int $ItemType Type of item handled by sort controls.
* @param mixed $SortField The field to sort by.
* @param bool $SortDescending Set to TRUE to indicate that sorting is in
* descending order.
* @param array $SortableFields Array of sortable fields.
* @param string $UrlParameterString String with all URL parameters.
* @param SearchParameterSet $SearchParams Search parameters for this search
* @param int $NumSearchResults Number of search results
* @return Returns the sort controls HTML as a string.
*/
function GetSortControls($ItemType, $SortField, $SortDescending,
$SortableFields, $UrlParameterString, $SearchParams, $NumSearchResults)
{
# split out URL parameters to build hidden tags for sort field and direction
parse_str($UrlParameterString, $UrlParameters);
$SortFieldHiddenTags = "";
$SortDirectionHiddenTags = "";
# for each URL parameter
foreach ($UrlParameters as $Param => $Values)
{
# if multiple values were (or may be) provided
if (is_array($Values))
{
# for each value
foreach ($Values as $Index => $Value)
{
# build hidden tag
$Tag = "\n";
# if not sort field or starting index parameter for this item type
if ((($Param != TransportControlsUI::PNAME_SORTFIELD)
&& ($Param != TransportControlsUI::PNAME_STARTINGINDEX))
|| ($Index != $ItemType))
{
# add tag to sort field tags
$SortFieldHiddenTags .= $Tag;
}
# if not reverse sort parameter for this item type
if (($Param != TransportControlsUI::PNAME_REVERSESORT)
|| ($Index != $ItemType))
{
# add tag to sort direction tags
$SortDirectionHiddenTags .= $Tag;
}
}
}
else
{
# build hidden tag
$Tag = "\n";
# add tag to sort field and sort direction tags
$SortFieldHiddenTags .= $Tag;
$SortDirectionHiddenTags .= $Tag;
}
}
# retrieve specifications for sort direction button
list($AscOrderInfo, $DescOrderInfo) = GetSortOrderButton($SortField);
# grab unique ID for use in the JavaScript below
$SafeUniqId = defaulthtmlentities(uniqid());
$SafeSortFieldId = NULL;
ob_start();
?>