5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2016 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 16 # ---- PUBLIC INTERFACE -------------------------------------------------- 44 # normalize and save field info 47 $this->Fields = $Fields;
51 $this->Fields = array();
52 foreach ($Fields as $FieldId => $FieldInfo)
55 $this->Fields[$CanonicalId] = $FieldInfo;
59 # set default base link 60 $this->
BaseLink =
"index.php?P=".$GLOBALS[
"AF"]->GetPageName();
62 # save schema ID for later use 63 $this->SchemaId = $SchemaId;
65 # set up transport controls 66 foreach ($this->Fields as $FieldId => $FieldInfo)
68 if (isset($FieldInfo[
"DefaultSortField"]))
86 if ($NewValue !== NULL)
90 return $this->BaseLink;
101 if ($NewValue !== NULL)
105 return $this->VariablesToPreserve;
114 $Link = $this->BaseLink;
117 if (isset($_GET[$VarName]))
119 $Link .=
"&".$VarName.
"=".urlencode($_GET[$VarName]);
132 if ($NewValue !== NULL)
136 return $this->Heading;
146 if ($NewValue !== NULL)
151 return $this->ItemsPerPage;
163 $this->Buttons[] = array(
182 if (strpos($Link, $VarName.
"=") !== FALSE)
184 $Link = preg_replace(
"/(&|&)".preg_quote($VarName).
"=[^&]*/",
187 $this->Buttons[] = array(
189 "Checked" => $Checked,
190 "VarName" => $VarName,
212 $Label, $Link, $Icon = NULL, $DisplayTestFunc = NULL,
213 $AdditionalAttributes = array())
215 $this->Actions[] = array(
219 "TestFunc" => $DisplayTestFunc,
220 "AddAttribs" => $AdditionalAttributes);
230 if ($NewValue !== NULL)
232 $this->NoItemsMsg = $NewValue;
234 return $this->NoItemsMsg;
243 return $this->TransportUI;
261 $StartingIndex = NULL, $TransportMsg = NULL)
263 # retrieve context values from transport controls 264 $StartingIndex = $this->
TransportUI->StartingIndex($StartingIndex);
266 $ReverseSort = $this->
TransportUI->ReverseSortFlag();
268 # display buttons above list 269 $this->DisplayTopButtons();
276 print
"<h1>".$this->Heading.
"</h1>\n";
284 # display "no items" message and exit if no items 287 $this->DisplayNoItemsMessage();
292 print
'<table class="cw-table cw-table-sideheaders cw-table-fullsize 293 cw-table-padded cw-table-striped">';
299 foreach ($this->Fields as $FieldId => $FieldInfo)
301 # if header value supplied 302 if (isset($FieldInfo[
"Heading"]))
305 $Heading = $FieldInfo[
"Heading"];
307 # else if we can get header from schema 310 # use name of field (with any leading schema name stripped) 312 $Heading = preg_replace(
"/.+\: /",
"", $Heading);
314 # else if field ID appears like it may be a name 315 elseif (is_string($FieldId) && !is_numeric($FieldId))
321 $Heading =
"(NO HEADER SET)";
324 # if sorting is disabled for field 325 if (isset($FieldInfo[
"NoSorting"]))
328 print
"<th>".$Heading.
"</th>\n";
334 .$this->TransportUI->UrlParameterString(TRUE, array(
"SF",
"RS"));
336 # determine current sort direction 337 if (isset($FieldInfo[
"DefaultToDescendingSort"]))
339 $SortAscending = $ReverseSort ? TRUE : FALSE;
343 $SortAscending = $ReverseSort ? FALSE : TRUE;
346 # set sort direction indicator (if any) 347 if ($FieldId == $SortFieldId)
349 $DirIndicator = ($SortAscending) ?
"↑" :
"↓";
352 $SortLink .=
"&RS=1";
361 print
"<th><a href=\"".$SortLink.
"\">".$Heading.
"</a>" 362 .$DirIndicator.
"</th>\n";
366 # add action header if needed 367 if (is_array($this->Actions) && count($this->Actions))
369 print
"<th>Actions</th>\n";
373 print
"</tr></thead>\n";
377 foreach (
$Items as $ItemId => $Item)
383 foreach ($this->Fields as $FieldId => $FieldInfo)
385 # if there is value function defined for field 386 if (isset($FieldInfo[
"ValueFunction"]))
388 # call function for value 389 $Value = $FieldInfo[
"ValueFunction"]($Item, $FieldId);
393 # if item is associative array 396 # retrieve value for field (if any) from item 397 $Value = isset($Item[$FieldId])
398 ? $Item[$FieldId] :
"";
400 # else if field ID is item method 401 elseif (method_exists($Item, $FieldId))
403 # get field value via item method 404 $Value = $Item->$FieldId();
408 # get field value from item via Get() 409 $Values = $Item->Get($FieldId);
410 $Value = is_array($Values) ? array_shift($Values) : $Values;
413 # if max length specified for field 414 if (isset($FieldInfo[
"MaxLength"]))
417 $Value, $FieldInfo[
"MaxLength"]);
420 # encode any HTML-significant chars in value 421 if (!isset($FieldInfo[
"AllowHTML"]))
423 $Value = htmlspecialchars($Value);
427 # get link value (if any) 428 if (isset($FieldInfo[
"Link"]))
430 if (method_exists($Item,
"Id"))
432 $Link = preg_replace(
'/\$ID/', $Item->Id(),
437 $Link = preg_replace(
'/\$ID/', $ItemId,
440 $LinkStart =
'<a href="'.$Link.
'">';
443 elseif (isset($FieldInfo[
"LinkFunction"]))
445 $Link = $FieldInfo[
"LinkFunction"]($Item);
453 if (method_exists($Item,
"Id"))
455 $Link = preg_replace(
'/\$ID/', $Item->Id(),
460 $Link = preg_replace(
'/\$ID/', $ItemId,
463 $LinkStart =
'<a href="'.$Link.
'">';
473 # display cell with value 474 print
"<td>".$LinkStart.$Value.$LinkEnd.
"</td>\n";
478 if (is_array($this->Actions) && count($this->Actions))
481 $this->DisplayActionButtons($ItemId, $Item);
493 # if there are more items than are displayed 494 if ($TotalItemCount > count(
$Items))
496 # craft transport control message (if not supplied) 497 if ($TransportMsg === NULL)
501 $Item->Schema()->ResourceName())
503 $TransportMsg = $ItemsLabel
506 .min(($this->
TransportUI->StartingIndex() + $this->ItemsPerPage),
508 .
"</b> of <b>".$TotalItemCount.
"</b>";
511 # display transport controls 520 # ---- PRIVATE INTERFACE ------------------------------------------------- 527 private $ItemsPerPage = 25;
530 private $TransportUI;
531 private $VariablesToPreserve = array();
536 private function DisplayTopButtons()
538 if (is_array($this->Buttons) && count($this->Buttons))
540 print
'<span style="float: right; padding-top: 1.5em;">';
541 foreach ($this->Buttons as $Info)
543 if (isset($Info[
"Icon"]) && strlen($Info[
"Icon"]))
545 $IconFile = $GLOBALS[
"AF"]->GUIFile($Info[
"Icon"]);
547 ?
'<img class="cw-button-icon" src="' 548 .$IconFile.
'" alt=""> ' 550 $IconButtonClass =
" cw-button-iconed";
555 $IconButtonClass =
"";
557 if (isset($Info[
"Checked"]))
559 $CheckboxState = $Info[
"Checked"] ?
"checked" :
"";
560 $OnChangeLinkBase = $Info[
"Link"].
"&".$Info[
"VarName"].
"=";
561 $OnChangeAction =
"if (this.checked) {" 562 .
" window.location = '".$OnChangeLinkBase.
"1';" 564 .
" window.location = '".$OnChangeLinkBase.
"0';" 566 ?> <input type=
"checkbox" name=
"<?= $Info["VarName
"] 567 ?>" <?= $CheckboxState
568 ?> onchange=
"<?= $OnChangeAction ?>">
569 <?= $Info[
"Label"] ?><?
PHP 573 ?> <a
class=
"cw-button cw-button-elegant cw-button-constrained<?= 575 href=
"<?= $Info["Link
"] ?>"><?= $IconTag ?><?=
576 htmlspecialchars($Info[
"Label"]) ?></a><?
PHP 586 private function DisplayNoItemsMessage()
588 print
"<span class=\"cw-itemlist-empty\">";
589 if (strlen($this->NoItemsMsg))
591 print $this->NoItemsMsg;
597 $Schema->ResourceName())).
" to display)";
601 print
"(no items to display)";
611 private function DisplayActionButtons($ItemId, $Item)
613 foreach ($this->Actions as $ActionInfo)
615 if ($ActionInfo[
"TestFunc"] !== NULL)
617 $DisplayButton = $ActionInfo[
"TestFunc"]($Item);
619 elseif (method_exists($Item,
"UserCanEdit"))
621 $DisplayButton = $Item->UserCanEdit($GLOBALS[
"G_User"]);
625 $DisplayButton = TRUE;
629 $ButtonClasses =
"cw-button cw-button-elegant" 630 .
" cw-button-constrained";
632 foreach ($ActionInfo[
"AddAttribs"]
633 as $AttribName => $AttribValue)
635 $AttribValue = htmlspecialchars($AttribValue);
636 if (strtolower($AttribName) ==
"class")
638 $ButtonClasses .=
" ".$AttribValue;
642 $ExtraAttribs .=
" ".$AttribName
643 .
'="'.$AttribValue.
'"';
646 if ($ActionInfo[
"Icon"])
648 $IconFile = $GLOBALS[
"AF"]->GUIFile($ActionInfo[
"Icon"]);
650 ?
'<img class="cw-button-icon" src="' 651 .$IconFile.
'" alt=""> ' 653 $ButtonClasses .=
" cw-button-iconed";
659 if (is_callable($ActionInfo[
"Link"]))
661 $Link = $ActionInfo[
"Link"]($Item);
663 elseif (method_exists($Item,
"Id"))
665 $Link = preg_replace(
'/\$ID/', $Item->Id(),
666 $ActionInfo[
"Link"]);
670 $Link = preg_replace(
'/\$ID/', $ItemId,
671 $ActionInfo[
"Link"]);
673 print
'<a class="'.$ButtonClasses.
'"'.$ExtraAttribs
674 .
' href="'.$Link.
'">'.$IconTag
675 .htmlspecialchars($ActionInfo[
"Label"]).
'</a>';
680 $GLOBALS[
"AF"]->SignalEvent(
"EVENT_HTML_INSERTION_POINT",
681 array($GLOBALS[
"AF"]->GetPageName(),
682 "Resource Summary Buttons", array(
683 "Resource" => $Item)));
Class to provide a user interface for displaying a list of items.
static DefaultSortField($NewValue=NULL)
Get/set default sort field value.
& TransportUI()
Get the transport controls UI component used by the item list.
BaseLink($NewValue=NULL)
Get/set base URL for current page, for any links that need to be constructed.
__construct($Fields, $SchemaId=TransportControlsUI::NO_ITEM_TYPE)
Constructor for item list UI class.
static Pluralize($Word)
Pluralize an English word.
AddTopCheckbox($Label, $Checked, $VarName, $Link)
Add "checkbox" above list.
Display($Items, $TotalItemCount=NULL, $StartingIndex=NULL, $TransportMsg=NULL)
Print list HTML with specified items.
Heading($NewValue=NULL)
Get/set heading text to be printed above list.
ItemsPerPage($NewValue=NULL)
Get/set maximum number of items per page.
Class to provide support for transport controls (used for paging back and forth through a list) in th...
AddTopButton($Label, $Link, $Icon=NULL)
Add "button" above list.
static NeatlyTruncateString($String, $MaxLength, $BreakAnywhere=FALSE)
Attempt to truncate a string as neatly as possible with respect to word breaks, punctuation, and HTML tags.
VariablesToPreserve($NewValue=NULL)
Get/set list of $_GET variables to preserve by adding them to base link whenever it is used...
AddActionButton($Label, $Link, $Icon=NULL, $DisplayTestFunc=NULL, $AdditionalAttributes=array())
Add action "button" to each item in list.
const NO_ITEM_TYPE
Constant to use when no item types available.
NoItemsMessage($NewValue=NULL)
Get/set message to display when there are no items to list.
GetFullBaseLink()
Get full base link, including any variables to preserve.