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 54 foreach ($this->ItemTypes as $ItemType)
60 # retrieve current position (if any) from URL 61 $this->
StartingIndex(isset($_GET[static::PNAME_STARTINGINDEX])
62 ? $_GET[static::PNAME_STARTINGINDEX] : array());
64 # retrieve sort fields (if any) from URL 65 $this->
SortField(isset($_GET[static::PNAME_SORTFIELD])
66 ? $_GET[static::PNAME_SORTFIELD] : array());
68 ? $_GET[static::PNAME_REVERSESORT] : array());
70 # retrieve active tab (if any) from URL 71 if (isset($_GET[static::PNAME_ACTIVETAB]))
73 $this->
ActiveTab($_GET[static::PNAME_ACTIVETAB]);
91 # make sure incoming data makes sense based on known item types 93 && (is_array(
$ItemCounts) && count($this->ItemCounts) > 1))
95 throw new InvalidArgumentException(
"Single item count supplied" 96 .
" when multiple item types were supplied to constructor.");
99 # normalize and store item counts 100 foreach ($this->ItemTypes as $ItemType)
106 $this->ItemCounts[$ItemType] =
113 $this->ItemCounts[$ItemType] = 0;
122 # determine index of first item on the first and last page 123 foreach ($this->ItemTypes as $ItemType)
125 $this->LastPageStartIndexes[$ItemType] = $this->ItemCounts[$ItemType]
126 - ($this->ItemCounts[$ItemType] % $this->ItemsPerPage[$ItemType]);
129 # make sure starting indexes are within bounds 130 foreach ($this->ItemTypes as $ItemType)
132 if ($this->StartingIndexes[$ItemType]
133 > $this->LastPageStartIndexes[$ItemType])
135 $this->StartingIndexes[$ItemType] =
136 $this->LastPageStartIndexes[$ItemType];
140 # if active tab not already specified 143 # if there are item counts available 144 if (count($this->ItemCounts))
146 # set active tab based on item type with the highest count 148 arsort($SortedCounts);
149 reset($SortedCounts);
170 # if new starting index supplied 171 if ($NewValue !== NULL)
173 # start with empty (all default value) indexes 174 $this->StartingIndexes = array();
177 foreach ($this->ItemTypes as $ItemType)
179 if (is_array($NewValue))
181 $this->StartingIndexes[$ItemType] =
182 isset($NewValue[$ItemType])
183 ? $NewValue[$ItemType]
188 $this->StartingIndexes[$ItemType] = $NewValue;
191 # make sure starting index is within bounds 192 if (isset($this->LastPageStartIndexes[$ItemType]))
194 if ($this->StartingIndexes[$ItemType]
195 > $this->LastPageStartIndexes[$ItemType])
197 $this->StartingIndexes[$ItemType] =
198 $this->LastPageStartIndexes[$ItemType];
204 # return array of values or single value to caller, depending on 205 # whether we are using multiple item types 206 return (count($this->ItemTypes) > 1)
207 ? $this->StartingIndexes
208 : reset($this->StartingIndexes);
222 # if new sort field supplied 223 if ($NewValue !== NULL)
225 # start with empty (all default) sort field list 226 $this->SortFields = array();
229 foreach ($this->ItemTypes as $ItemType)
231 # if multiple new values supplied 232 if (is_array($NewValue))
234 # if valid value supplied for this item type 235 if (isset($NewValue[$ItemType])
236 && $this->
IsValidField($NewValue[$ItemType], $ItemType))
239 $this->SortFields[$ItemType] = $NewValue[$ItemType];
244 $this->SortFields[$ItemType] = self::$DefaultSortField;
249 # if supplied value looks valid 252 # set value for item type to this value 253 $this->SortFields[$ItemType] = $NewValue;
258 $this->SortFields[$ItemType] = self::$DefaultSortField;
264 # return array of values or single value to caller, depending on 265 # whether we are using multiple item types 266 return (count($this->ItemTypes) > 1)
268 : reset($this->SortFields);
278 if ($NewValue !== NULL)
280 self::$DefaultSortField = $NewValue;
282 return self::$DefaultSortField;
293 if ($NewValue !== NULL)
299 : self::$DefaultActiveTab;
309 if ($NewValue !== NULL)
311 self::$DefaultActiveTab = $NewValue;
313 return self::$DefaultActiveTab;
327 # if new value(s) supplied 328 if ($NewValue !== NULL)
330 # start with empty (all default value) 331 $this->ReverseSortFlags = array();
334 foreach ($this->ItemTypes as $ItemType)
336 # if multiple new values supplied 337 if (is_array($NewValue))
339 # if value supplied for this item type 340 if (isset($NewValue[$ItemType]))
343 $this->ReverseSortFlags[$ItemType] =
344 ($NewValue[$ItemType] ? TRUE : FALSE);
348 # assume no reverse sort for item type 349 $this->ReverseSortFlags[$ItemType] = FALSE;
354 # set value for item type to supplied value 355 $this->ReverseSortFlags[$ItemType] =
356 ($NewValue ? TRUE : FALSE);
361 # return array of values or single value to caller, depending on 362 # whether we are using multiple item types 363 return (count($this->ItemTypes) > 1)
364 ? $this->ReverseSortFlags
365 : reset($this->ReverseSortFlags);
378 $EncodeSeparators = TRUE, $ExcludeParameters = NULL)
380 # add any non-default starting indexes to query data 381 foreach ($this->StartingIndexes as $ItemType => $Index)
385 $QData[static::PNAME_STARTINGINDEX][$ItemType] = $Index;
389 # add any non-default sort fields to query data 390 foreach ($this->SortFields as $ItemType => $Field)
392 if ($Field != self::$DefaultSortField)
394 $QData[static::PNAME_SORTFIELD][$ItemType] = $Field;
398 # add any non-default sort directions to query data 399 foreach ($this->ReverseSortFlags as $ItemType => $Flag)
403 $QData[static::PNAME_REVERSESORT][$ItemType] = 1;
407 # add active tab to query data if set and meaningful 408 if (isset($this->
ActiveTab) && (count($this->ItemTypes) > 1))
413 # remove any requested exclusions 416 if ($ExcludeParameters)
418 foreach ($ExcludeParameters as $Param)
420 if (isset($QData[$Param]))
422 unset($QData[$Param]);
428 # collapse down parameters if only one item type 429 if (count($this->ItemTypes) == 1)
431 $Params = array(static::PNAME_STARTINGINDEX,
432 static::PNAME_SORTFIELD,
433 static::PNAME_REVERSESORT);
434 foreach ($Params as $Param)
436 if (isset($QData[$Param]))
438 $QData[$Param] = reset($QData[$Param]);
443 # if no non-default transport parameters 444 if (!isset($QData) || !count($QData))
446 # return empty string 451 # build parameter string and return it to caller 452 $Sep = $EncodeSeparators ?
"&" :
"&";
453 return $Sep.http_build_query($QData,
"", $Sep);
473 # ---- TEST/LINK METHODS ------------------------------------------------ 474 # (useful if constructing your own interface rather than using PrintControls() 482 $this->CurrentItemType = $ItemType;
491 $this->CurrentBaseLink = $BaseLink;
503 return (($this->StartingIndexes[$this->CurrentItemType]
504 + $this->ItemsPerPage[$this->CurrentItemType])
505 < ($this->LastPageStartIndexes[$this->CurrentItemType] + 1))
518 return ($this->StartingIndexes[$this->CurrentItemType] > 0)
530 return ($this->StartingIndexes[$this->CurrentItemType]
531 < ($this->LastPageStartIndexes[$this->CurrentItemType]
532 - $this->ItemsPerPage[$this->CurrentItemType]))
544 return (($this->StartingIndexes[$this->CurrentItemType] + 1)
545 >= ($this->ItemsPerPage[$this->CurrentItemType] * 2))
558 return (($this->
FastDistance() > $this->ItemsPerPage[$this->CurrentItemType])
559 && (($this->StartingIndexes[$this->CurrentItemType]
561 < $this->LastPageStartIndexes[$this->CurrentItemType]))
574 return (($this->
FastDistance() > $this->ItemsPerPage[$this->CurrentItemType])
575 && ($this->StartingIndexes[$this->CurrentItemType]
587 min($this->LastPageStartIndexes[$this->CurrentItemType],
588 ($this->StartingIndexes[$this->CurrentItemType]
589 + $this->ItemsPerPage[$this->CurrentItemType])));
599 max(0, ($this->StartingIndexes[$this->CurrentItemType]
600 - $this->ItemsPerPage[$this->CurrentItemType])));
610 min($this->LastPageStartIndexes[$this->CurrentItemType],
611 ($this->StartingIndexes[$this->CurrentItemType]
622 max(0, ($this->StartingIndexes[$this->CurrentItemType]
633 $this->LastPageStartIndexes[$this->CurrentItemType]);
646 # ---- PRIVATE INTERFACE ------------------------------------------------- 669 return floor($this->ItemCounts[$this->CurrentItemType] / 5)
670 - (floor($this->ItemCounts[$this->CurrentItemType] / 5)
681 # temporarily swap in supplied starting index 685 # get link with parameters 686 $Link = $this->CurrentBaseLink.$this->UrlParameterString();
688 # restore starting index 691 # return link to caller 703 # default field is assumed to always be valid 704 if ($Field === self::$DefaultSortField)
709 # fields are assumed to be always valid for no item type 710 if ($ItemType === self::NO_ITEM_TYPE)
715 # load metadata schema to check against (if not already loaded) 717 if (!isset($Schemas[$ItemType]))
722 # report to caller whether field exists for this schema 723 return $Schemas[$ItemType]->FieldExists($Field);
ReverseLink()
Get link for reverse button.
ForwardLink()
Get link for forward button.
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.
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.
__construct($ItemTypes, $ItemsPerPage)
Class constructor.
StartingIndex($NewValue=NULL)
Get/set current starting index values.