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]);
87 # make sure incoming data makes sense based on known item types 89 && (count($this->ItemCounts) > 1))
91 throw InvalidArgumentException(
"Single item count supplied" 92 .
" when multiple item types were supplied to constructor.");
95 # normalize and store item counts 96 foreach ($this->ItemTypes as $ItemType)
102 $this->ItemCounts[$ItemType] =
109 $this->ItemCounts[$ItemType] = 0;
118 # determine index of first item on the first and last page 119 foreach ($this->ItemTypes as $ItemType)
121 $this->LastPageStartIndexes[$ItemType] = $this->ItemCounts[$ItemType]
122 - ($this->ItemCounts[$ItemType] % $this->ItemsPerPage[$ItemType]);
125 # make sure starting indexes are within bounds 126 foreach ($this->ItemTypes as $ItemType)
128 if ($this->StartingIndexes[$ItemType]
129 > $this->LastPageStartIndexes[$ItemType])
131 $this->StartingIndexes[$ItemType] =
132 $this->LastPageStartIndexes[$ItemType];
136 # if active tab not already specified 139 # if there are item counts available 140 if (count($this->ItemCounts))
142 # set active tab based on item type with the highest count 144 arsort($SortedCounts);
145 reset($SortedCounts);
163 # if new starting index supplied 164 if ($NewValue !== NULL)
166 # start with empty (all default value) indexes 167 $this->StartingIndexes = array();
170 foreach ($this->ItemTypes as $ItemType)
172 if (is_array($NewValue))
174 $this->StartingIndexes[$ItemType] =
175 isset($NewValue[$ItemType])
176 ? $NewValue[$ItemType]
181 $this->StartingIndexes[$ItemType] = $NewValue;
184 # make sure starting index is within bounds 185 if (isset($this->LastPageStartIndexes[$ItemType]))
187 if ($this->StartingIndexes[$ItemType]
188 > $this->LastPageStartIndexes[$ItemType])
190 $this->StartingIndexes[$ItemType] =
191 $this->LastPageStartIndexes[$ItemType];
197 # return array of values or single value to caller, depending on 198 # whether we are using multiple item types 199 return (count($this->ItemTypes) > 1)
200 ? $this->StartingIndexes
201 : reset($this->StartingIndexes);
215 # if new sort field supplied 216 if ($NewValue !== NULL)
218 # start with empty (all default) sort field list 219 $this->SortFields = array();
222 foreach ($this->ItemTypes as $ItemType)
224 # if multiple new values supplied 225 if (is_array($NewValue))
227 # if valid value supplied for this item type 228 if (isset($NewValue[$ItemType])
229 && $this->
IsValidField($NewValue[$ItemType], $ItemType))
232 $this->SortFields[$ItemType] = $NewValue[$ItemType];
237 $this->SortFields[$ItemType] = self::$DefaultSortField;
242 # if supplied value looks valid 245 # set value for item type to this value 246 $this->SortFields[$ItemType] = $NewValue;
251 $this->SortFields[$ItemType] = self::$DefaultSortField;
257 # return array of values or single value to caller, depending on 258 # whether we are using multiple item types 259 return (count($this->ItemTypes) > 1)
261 : reset($this->SortFields);
271 if ($NewValue !== NULL)
273 self::$DefaultSortField = $NewValue;
275 return self::$DefaultSortField;
286 if ($NewValue !== NULL)
292 : self::$DefaultActiveTab;
302 if ($NewValue !== NULL)
304 self::$DefaultActiveTab = $NewValue;
306 return self::$DefaultActiveTab;
320 # if new value(s) supplied 321 if ($NewValue !== NULL)
323 # start with empty (all default value) 324 $this->ReverseSortFlags = array();
327 foreach ($this->ItemTypes as $ItemType)
329 # if multiple new values supplied 330 if (is_array($NewValue))
332 # if value supplied for this item type 333 if (isset($NewValue[$ItemType]))
336 $this->ReverseSortFlags[$ItemType] =
337 ($NewValue[$ItemType] ? TRUE : FALSE);
341 # assume no reverse sort for item type 342 $this->ReverseSortFlags[$ItemType] = FALSE;
347 # set value for item type to supplied value 348 $this->ReverseSortFlags[$ItemType] =
349 ($NewValue ? TRUE : FALSE);
354 # return array of values or single value to caller, depending on 355 # whether we are using multiple item types 356 return (count($this->ItemTypes) > 1)
357 ? $this->ReverseSortFlags
358 : reset($this->ReverseSortFlags);
371 $EncodeSeparators = TRUE, $ExcludeParameters = NULL)
373 # add any non-default starting indexes to query data 374 foreach ($this->StartingIndexes as $ItemType => $Index)
378 $QData[static::PNAME_STARTINGINDEX][$ItemType] = $Index;
382 # add any non-default sort fields to query data 383 foreach ($this->SortFields as $ItemType => $Field)
385 if ($Field != self::$DefaultSortField)
387 $QData[static::PNAME_SORTFIELD][$ItemType] = $Field;
391 # add any non-default sort directions to query data 392 foreach ($this->ReverseSortFlags as $ItemType => $Flag)
396 $QData[static::PNAME_REVERSESORT][$ItemType] = 1;
400 # add active tab to query data if set and meaningful 401 if (isset($this->
ActiveTab) && (count($this->ItemTypes) > 1))
406 # remove any requested exclusions 409 if ($ExcludeParameters)
411 foreach ($ExcludeParameters as $Param)
413 if (isset($QData[$Param]))
415 unset($QData[$Param]);
421 # collapse down parameters if only one item type 422 if (count($this->ItemTypes) == 1)
424 $Params = array(static::PNAME_STARTINGINDEX,
425 static::PNAME_SORTFIELD,
426 static::PNAME_REVERSESORT);
427 foreach ($Params as $Param)
429 if (isset($QData[$Param]))
431 $QData[$Param] = reset($QData[$Param]);
436 # if no non-default transport parameters 437 if (!isset($QData) || !count($QData))
439 # return empty string 444 # build parameter string and return it to caller 445 $Sep = $EncodeSeparators ?
"&" :
"&";
446 return $Sep.http_build_query($QData,
"", $Sep);
450 # ---- TEST/LINK METHODS ------------------------------------------------ 451 # (useful if constructing your own interface rather than using PrintControls() 459 $this->CurrentItemType = $ItemType;
468 $this->CurrentBaseLink = $BaseLink;
480 return (($this->StartingIndexes[$this->CurrentItemType]
481 + $this->ItemsPerPage[$this->CurrentItemType])
482 < ($this->LastPageStartIndexes[$this->CurrentItemType] + 1))
495 return ($this->StartingIndexes[$this->CurrentItemType] > 0)
507 return ($this->StartingIndexes[$this->CurrentItemType]
508 < ($this->LastPageStartIndexes[$this->CurrentItemType]
509 - $this->ItemsPerPage[$this->CurrentItemType]))
521 return (($this->StartingIndexes[$this->CurrentItemType] + 1)
522 >= ($this->ItemsPerPage[$this->CurrentItemType] * 2))
535 return (($this->
FastDistance() > $this->ItemsPerPage[$this->CurrentItemType])
536 && (($this->StartingIndexes[$this->CurrentItemType]
538 < $this->LastPageStartIndexes[$this->CurrentItemType]))
551 return (($this->
FastDistance() > $this->ItemsPerPage[$this->CurrentItemType])
552 && ($this->StartingIndexes[$this->CurrentItemType]
564 min($this->LastPageStartIndexes[$this->CurrentItemType],
565 ($this->StartingIndexes[$this->CurrentItemType]
566 + $this->ItemsPerPage[$this->CurrentItemType])));
576 max(0, ($this->StartingIndexes[$this->CurrentItemType]
577 - $this->ItemsPerPage[$this->CurrentItemType])));
587 min($this->LastPageStartIndexes[$this->CurrentItemType],
588 ($this->StartingIndexes[$this->CurrentItemType]
599 max(0, ($this->StartingIndexes[$this->CurrentItemType]
610 $this->LastPageStartIndexes[$this->CurrentItemType]);
623 # ---- PRIVATE INTERFACE ------------------------------------------------- 645 return floor($this->ItemCounts[$this->CurrentItemType] / 5)
646 - (floor($this->ItemCounts[$this->CurrentItemType] / 5)
657 # temporarily swap in supplied starting index 661 # get link with parameters 662 $Link = $this->CurrentBaseLink.$this->UrlParameterString();
664 # restore starting index 667 # return link to caller 679 # default field is assumed to always be valid 680 if ($Field === self::$DefaultSortField)
685 # fields are assumed to be always valid for no item type 686 if ($ItemType === self::NO_ITEM_TYPE)
691 # load metadata schema to check against (if not already loaded) 693 if (!isset($Schemas[$ItemType]))
698 # report to caller whether field exists for this schema 699 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.
ItemCount($ItemCounts)
Get/set count of items in search results.
ShowFastReverseButton()
Report whether fast reverse button should be displayed.
IsValidField($Field, $ItemType)
Check whether specified field looks valid for specified item type.
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.
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.