3 # FILE: TransportControlsUI_Base.php 5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2015-2016 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 20 # ---- PUBLIC INTERFACE -------------------------------------------------- 37 # normalize and store item types 47 # normalize and store items per page 50 # retrieve current position (if any) from URL 51 $this->
StartingIndex(isset($_GET[static::PNAME_STARTINGINDEX])
52 ? $_GET[static::PNAME_STARTINGINDEX] : array());
54 # retrieve sort fields (if any) from URL 55 $this->
SortField(isset($_GET[static::PNAME_SORTFIELD])
56 ? $_GET[static::PNAME_SORTFIELD] : array());
58 ? $_GET[static::PNAME_REVERSESORT] : array());
60 # retrieve active tab (if any) from URL 61 if (isset($_GET[static::PNAME_ACTIVETAB]))
63 $this->
ActiveTab($_GET[static::PNAME_ACTIVETAB]);
79 if ($NewValue !== NULL)
81 if (is_array($NewValue))
84 if (count($this->
ItemsPerPage) != count($this->ItemTypes))
86 throw new InvalidArgumentException(
"Count of items per page (" 88 .
") does not match count of item types (" 89 .count($this->ItemTypes).
").");
94 foreach ($this->ItemTypes as $ItemType)
117 # make sure incoming data makes sense based on known item types 119 && (is_array(
$ItemCounts) && count($this->ItemCounts) > 1))
121 throw new InvalidArgumentException(
"Single item count supplied" 122 .
" when multiple item types were supplied to constructor.");
125 # normalize and store item counts 126 foreach ($this->ItemTypes as $ItemType)
132 $this->ItemCounts[$ItemType] =
139 $this->ItemCounts[$ItemType] = 0;
148 # determine index of first item on the first and last page 149 foreach ($this->ItemTypes as $ItemType)
151 $this->LastPageStartIndexes[$ItemType] = $this->ItemCounts[$ItemType]
152 - ($this->ItemCounts[$ItemType] % $this->
ItemsPerPage[$ItemType]);
155 # make sure starting indexes are within bounds 156 foreach ($this->ItemTypes as $ItemType)
158 if ($this->StartingIndexes[$ItemType]
159 > $this->LastPageStartIndexes[$ItemType])
161 $this->StartingIndexes[$ItemType] =
162 $this->LastPageStartIndexes[$ItemType];
166 # if active tab not already specified 169 # if there are item counts available 170 if (count($this->ItemCounts))
172 # set active tab based on item type with the highest count 174 arsort($SortedCounts);
175 reset($SortedCounts);
196 # if new starting index supplied 197 if ($NewValue !== NULL)
199 # start with empty (all default value) indexes 200 $this->StartingIndexes = array();
203 foreach ($this->ItemTypes as $ItemType)
205 if (is_array($NewValue))
207 $this->StartingIndexes[$ItemType] =
208 isset($NewValue[$ItemType])
209 ? $NewValue[$ItemType]
214 $this->StartingIndexes[$ItemType] = $NewValue;
217 # make sure starting index is within bounds 218 if (isset($this->LastPageStartIndexes[$ItemType]))
220 if ($this->StartingIndexes[$ItemType]
221 > $this->LastPageStartIndexes[$ItemType])
223 $this->StartingIndexes[$ItemType] =
224 $this->LastPageStartIndexes[$ItemType];
230 # return array of values or single value to caller, depending on 231 # whether we are using multiple item types 232 return (count($this->ItemTypes) > 1)
233 ? $this->StartingIndexes
234 : reset($this->StartingIndexes);
248 # if new sort field supplied 249 if ($NewValue !== NULL)
251 # start with empty (all default) sort field list 252 $this->SortFields = array();
255 foreach ($this->ItemTypes as $ItemType)
257 # if multiple new values supplied 258 if (is_array($NewValue))
260 # if valid value supplied for this item type 261 if (isset($NewValue[$ItemType])
262 && $this->
IsValidField($NewValue[$ItemType], $ItemType))
265 $this->SortFields[$ItemType] = $NewValue[$ItemType];
270 $this->SortFields[$ItemType] = self::$DefaultSortField;
275 # if supplied value looks valid 278 # set value for item type to this value 279 $this->SortFields[$ItemType] = $NewValue;
284 $this->SortFields[$ItemType] = self::$DefaultSortField;
290 # return array of values or single value to caller, depending on 291 # whether we are using multiple item types 292 return (count($this->ItemTypes) > 1)
294 : reset($this->SortFields);
304 if ($NewValue !== NULL)
306 self::$DefaultSortField = $NewValue;
308 return self::$DefaultSortField;
319 if ($NewValue !== NULL)
325 : self::$DefaultActiveTab;
335 if ($NewValue !== NULL)
337 self::$DefaultActiveTab = $NewValue;
339 return self::$DefaultActiveTab;
353 # if new value(s) supplied 354 if ($NewValue !== NULL)
356 # start with empty (all default value) 357 $this->ReverseSortFlags = array();
360 foreach ($this->ItemTypes as $ItemType)
362 # if multiple new values supplied 363 if (is_array($NewValue))
365 # if value supplied for this item type 366 if (isset($NewValue[$ItemType]))
369 $this->ReverseSortFlags[$ItemType] =
370 ($NewValue[$ItemType] ? TRUE : FALSE);
374 # assume no reverse sort for item type 375 $this->ReverseSortFlags[$ItemType] = FALSE;
380 # set value for item type to supplied value 381 $this->ReverseSortFlags[$ItemType] =
382 ($NewValue ? TRUE : FALSE);
387 # return array of values or single value to caller, depending on 388 # whether we are using multiple item types 389 return (count($this->ItemTypes) > 1)
390 ? $this->ReverseSortFlags
391 : reset($this->ReverseSortFlags);
404 $EncodeSeparators = TRUE, $ExcludeParameters = NULL)
406 # add any non-default starting indexes to query data 407 foreach ($this->StartingIndexes as $ItemType => $Index)
411 $QData[static::PNAME_STARTINGINDEX][$ItemType] = $Index;
415 # add any non-default sort fields to query data 416 foreach ($this->SortFields as $ItemType => $Field)
418 if ($Field != self::$DefaultSortField)
420 $QData[static::PNAME_SORTFIELD][$ItemType] = $Field;
424 # add any non-default sort directions to query data 425 foreach ($this->ReverseSortFlags as $ItemType => $Flag)
429 $QData[static::PNAME_REVERSESORT][$ItemType] = 1;
433 # add active tab to query data if set and meaningful 434 if (isset($this->
ActiveTab) && (count($this->ItemTypes) > 1))
439 # remove any requested exclusions 442 if ($ExcludeParameters)
444 foreach ($ExcludeParameters as $Param)
446 if (isset($QData[$Param]))
448 unset($QData[$Param]);
454 # collapse down parameters if only one item type 455 if (count($this->ItemTypes) == 1)
457 $Params = array(static::PNAME_STARTINGINDEX,
458 static::PNAME_SORTFIELD,
459 static::PNAME_REVERSESORT);
460 foreach ($Params as $Param)
462 if (isset($QData[$Param]))
464 $QData[$Param] = reset($QData[$Param]);
469 # if no non-default transport parameters 470 if (!isset($QData) || !count($QData))
472 # return empty string 477 # build parameter string and return it to caller 478 $Sep = $EncodeSeparators ?
"&" :
"&";
479 return $Sep.http_build_query($QData,
"", $Sep);
499 # ---- TEST/LINK METHODS ------------------------------------------------ 500 # (useful if constructing your own interface rather than using PrintControls() 508 $this->CurrentItemType = $ItemType;
517 $this->CurrentBaseLink = $BaseLink;
529 return (($this->StartingIndexes[$this->CurrentItemType]
531 < ($this->LastPageStartIndexes[$this->CurrentItemType] + 1))
544 return ($this->StartingIndexes[$this->CurrentItemType] > 0)
556 return ($this->StartingIndexes[$this->CurrentItemType]
557 < ($this->LastPageStartIndexes[$this->CurrentItemType]
570 return (($this->StartingIndexes[$this->CurrentItemType] + 1)
585 && (($this->StartingIndexes[$this->CurrentItemType]
587 < $this->LastPageStartIndexes[$this->CurrentItemType]))
601 && ($this->StartingIndexes[$this->CurrentItemType]
613 min($this->LastPageStartIndexes[$this->CurrentItemType],
614 ($this->StartingIndexes[$this->CurrentItemType]
625 max(0, ($this->StartingIndexes[$this->CurrentItemType]
636 min($this->LastPageStartIndexes[$this->CurrentItemType],
637 ($this->StartingIndexes[$this->CurrentItemType]
648 max(0, ($this->StartingIndexes[$this->CurrentItemType]
659 $this->LastPageStartIndexes[$this->CurrentItemType]);
672 # ---- PRIVATE INTERFACE ------------------------------------------------- 695 return floor($this->ItemCounts[$this->CurrentItemType] / 5)
696 - (floor($this->ItemCounts[$this->CurrentItemType] / 5)
707 # temporarily swap in supplied starting index 711 # get link with parameters 712 $Link = $this->CurrentBaseLink.$this->UrlParameterString();
714 # restore starting index 717 # return link to caller 729 # default field is assumed to always be valid 730 if ($Field === self::$DefaultSortField)
735 # fields are assumed to be always valid for no item type 736 if ($ItemType === self::NO_ITEM_TYPE)
741 # load metadata schema to check against (if not already loaded) 743 if (!isset($Schemas[$ItemType]))
748 # report to caller whether field exists for this schema 749 return $Schemas[$ItemType]->FieldExists($Field);
ReverseLink()
Get link for reverse button.
ForwardLink()
Get link for forward button.
ItemsPerPage($NewValue=NULL)
Get/set maximum number of items per page.
ActiveTab($NewValue=NULL)
Get/set the active tab value (usually an item type).
ShowForwardButton()
Report whether forward button should be displayed.
FastReverseLink()
Get link for fast reverse button.
FastDistance()
Get distance to jump for fast forward/reverse.
static DefaultSortField($NewValue=NULL)
Get/set default sort field value.
GoToStartLink()
Get link for button to go to start.
ReverseSortFlag($NewValue=NULL)
Get/set whether to reverse the sort order from normal.
GoToEndLink()
Get link for button to go to end.
static DefaultActiveTab($NewValue=NULL)
Get/set the default active tab value (usually an item type).
ShowAnyForwardButtons()
Report whether any forward buttons should be displayed.
__construct($ItemTypes, $ItemsPerPage=10)
Class constructor.
Class to provide support for transport controls (used for paging back and forth through a list) in th...
ShowReverseButton()
Report whether reverse button should be displayed.
UrlParameterString($EncodeSeparators=TRUE, $ExcludeParameters=NULL)
Get string containing URL parameters, ready for inclusion in URL.
FastForwardLink()
Get link for fast forward button.
ShowAnyReverseButtons()
Report whether any reverse buttons should be displayed.
GetLinkWithStartingIndex($StartingIndex)
Generate link with specified modified starting index.
SortField($NewValue=NULL)
Get/set ID of field(s) currently used for sorting.
ShowFastReverseButton()
Report whether fast reverse button should be displayed.
IsValidField($Field, $ItemType)
Check whether specified field looks valid for specified item type.
ItemTypeNames($Names=NULL)
Get/set printable names for item types.
SetBaseLink($BaseLink)
Set current base link for Link methods.
const NO_ITEM_TYPE
Constant to use when no item types available.
ShowFastForwardButton()
Report whether fast forward button should be displayed.
ItemCount($ItemCounts=NULL)
Get/set count of items in search results.
SetItemType($ItemType)
Set current item type for Show or Link methods.
StartingIndex($NewValue=NULL)
Get/set current starting index values.