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 -------------------------------------------------- 46 public function __construct($Heading, $Fields, $ItemsPerPage, $BaseLink,
49 # normalize and save field info 52 $this->Fields = $Fields;
56 $this->Fields = array();
57 foreach ($Fields as $FieldId => $FieldInfo)
60 $this->Fields[$CanonicalId] = $FieldInfo;
64 # save other supplied settings for later use 65 $this->BaseLink = $BaseLink;
66 $this->Heading = $Heading;
67 $this->ItemsPerPage = $ItemsPerPage;
68 $this->SchemaId = $SchemaId;
70 # set up transport controls 71 foreach ($this->Fields as $FieldId => $FieldInfo)
73 if (isset($FieldInfo[
"DefaultSortField"]))
79 $this->SchemaId, $this->ItemsPerPage);
91 $this->Buttons[] = array(
110 if (strpos($Link, $VarName.
"=") !== FALSE)
112 $Link = preg_replace(
"/(&|&)".preg_quote($VarName).
"=[^&]*/",
115 $this->Buttons[] = array(
117 "Checked" => $Checked,
118 "VarName" => $VarName,
140 $Label, $Link, $Icon = NULL, $DisplayTestFunc = NULL,
141 $AdditionalAttributes = array())
143 $this->Actions[] = array(
147 "TestFunc" => $DisplayTestFunc,
148 "AddAttribs" => $AdditionalAttributes);
158 if ($NewValue !== NULL)
160 $this->NoItemsMsg = $NewValue;
162 return $this->NoItemsMsg;
171 return $this->TransportUI;
189 $StartingIndex = NULL, $TransportMsg = NULL)
191 # retrieve context values from transport controls 192 $StartingIndex = $this->
TransportUI->StartingIndex($StartingIndex);
194 $ReverseSort = $this->
TransportUI->ReverseSortFlag();
196 # display buttons above list 197 $this->DisplayTopButtons();
200 if ($this->Heading !== NULL)
202 if ($this->Heading == strip_tags($this->Heading))
204 print
"<h1>".$this->Heading.
"</h1>\n";
208 print $this->Heading.
"\n";
212 # display "no items" message and exit if no items 215 $this->DisplayNoItemsMessage();
220 print
'<table class="cw-table cw-table-sideheaders cw-table-fullsize 221 cw-table-padded cw-table-striped">';
227 foreach ($this->Fields as $FieldId => $FieldInfo)
229 # if header value supplied 230 if (isset($FieldInfo[
"Heading"]))
233 $Heading = $FieldInfo[
"Heading"];
235 # else if we can get header from schema 238 # use name of field (with any leading schema name stripped) 240 $Heading = preg_replace(
"/.+\: /",
"", $Heading);
242 # else if field ID appears like it may be a name 243 elseif (is_string($FieldId) && !is_numeric($FieldId))
249 $Heading =
"(NO HEADER SET)";
252 # if sorting is disabled for field 253 if (isset($FieldInfo[
"NoSorting"]))
256 print
"<th>".$Heading.
"</th>\n";
261 $SortLink = $this->BaseLink.
"&SF=".$FieldId
262 .$this->TransportUI->UrlParameterString(TRUE, array(
"SF",
"RS"));
264 # determine current sort direction 265 if (isset($FieldInfo[
"DefaultToDescendingSort"]))
267 $SortAscending = $ReverseSort ? TRUE : FALSE;
271 $SortAscending = $ReverseSort ? FALSE : TRUE;
274 # set sort direction indicator (if any) 275 if ($FieldId == $SortFieldId)
277 $DirIndicator = ($SortAscending) ?
"↑" :
"↓";
280 $SortLink .=
"&RS=1";
289 print
"<th><a href=\"".$SortLink.
"\">".$Heading.
"</a>" 290 .$DirIndicator.
"</th>\n";
294 # add action header if needed 295 if (is_array($this->Actions) && count($this->Actions))
297 print
"<th>Actions</th>\n";
301 print
"</tr></thead>\n";
305 foreach (
$Items as $ItemId => $Item)
311 foreach ($this->Fields as $FieldId => $FieldInfo)
313 # if there is value function defined for field 314 if (isset($FieldInfo[
"ValueFunction"]))
316 # call function for value 317 $Value = $FieldInfo[
"ValueFunction"]($Item, $FieldId);
321 # if item is associative array 324 # retrieve value for field (if any) from item 325 $Value = isset($Item[$FieldId])
326 ? $Item[$FieldId] :
"";
328 # else if field ID is item method 329 elseif (method_exists($Item, $FieldId))
331 # get field value via item method 332 $Value = $Item->$FieldId();
336 # get field value from item via Get() 337 $Values = $Item->Get($FieldId);
338 $Value = is_array($Values) ? array_shift($Values) : $Values;
341 # if max length specified for field 342 if (isset($FieldInfo[
"MaxLength"]))
345 $Value, $FieldInfo[
"MaxLength"]);
348 # encode any HTML-significant chars in value 349 if (!isset($FieldInfo[
"AllowHTML"]))
351 $Value = htmlspecialchars($Value);
355 # get link value (if any) 356 if (isset($FieldInfo[
"Link"]))
358 if (method_exists($Item,
"Id"))
360 $Link = preg_replace(
'/\$ID/', $Item->Id(),
365 $Link = preg_replace(
'/\$ID/', $ItemId,
368 $LinkStart =
'<a href="'.$Link.
'">';
371 elseif (isset($FieldInfo[
"LinkFunction"]))
373 $Link = $FieldInfo[
"LinkFunction"]($Item);
381 if (method_exists($Item,
"Id"))
383 $Link = preg_replace(
'/\$ID/', $Item->Id(),
388 $Link = preg_replace(
'/\$ID/', $ItemId,
391 $LinkStart =
'<a href="'.$Link.
'">';
401 # display cell with value 402 print
"<td>".$LinkStart.$Value.$LinkEnd.
"</td>\n";
406 if (is_array($this->Actions) && count($this->Actions))
409 $this->DisplayActionButtons($ItemId, $Item);
421 # if there are more items than are displayed 422 if ($TotalItemCount > count(
$Items))
424 # craft transport control message (if not supplied) 425 if ($TransportMsg === NULL)
429 $Item->Schema()->ResourceName())
431 $TransportMsg = $ItemsLabel
434 .min(($this->
TransportUI->StartingIndex() + $this->ItemsPerPage),
436 .
"</b> of <b>".$TotalItemCount.
"</b>";
439 # display transport controls 443 $this->SchemaId, $this->BaseLink, $TransportMsg);
448 # ---- PRIVATE INTERFACE ------------------------------------------------- 455 private $ItemsPerPage;
458 private $TransportUI;
463 private function DisplayTopButtons()
465 if (is_array($this->Buttons) && count($this->Buttons))
467 print
'<span style="float: right; padding-top: 1.5em;">';
468 foreach ($this->Buttons as $Info)
470 if (isset($Info[
"Icon"]) && strlen($Info[
"Icon"]))
472 $IconFile = $GLOBALS[
"AF"]->GUIFile($Info[
"Icon"]);
474 ?
'<img class="cw-button-icon" src="' 475 .$IconFile.
'" alt=""> ' 477 $IconButtonClass =
" cw-button-iconed";
482 $IconButtonClass =
"";
484 if (isset($Info[
"Checked"]))
486 $CheckboxState = $Info[
"Checked"] ?
"checked" :
"";
487 $OnChangeLinkBase = $Info[
"Link"].
"&".$Info[
"VarName"].
"=";
488 $OnChangeAction =
"if (this.checked) {" 489 .
" window.location = '".$OnChangeLinkBase.
"1';" 491 .
" window.location = '".$OnChangeLinkBase.
"0';" 493 ?> <input type=
"checkbox" name=
"<?= $Info["VarName
"] 494 ?>" <?= $CheckboxState
495 ?> onchange=
"<?= $OnChangeAction ?>">
496 <?= $Info[
"Label"] ?><?
PHP 500 ?> <a
class=
"cw-button cw-button-elegant cw-button-constrained<?= 502 href=
"<?= $Info["Link
"] ?>"><?= $IconTag ?><?=
503 htmlspecialchars($Info[
"Label"]) ?></a><?
PHP 513 private function DisplayNoItemsMessage()
515 print
"<span class=\"cw-itemlist-empty\">";
516 if (strlen($this->NoItemsMsg))
518 print $this->NoItemsMsg;
524 $Schema->ResourceName())).
" to display)";
528 print
"(no items to display)";
538 private function DisplayActionButtons($ItemId, $Item)
540 foreach ($this->Actions as $ActionInfo)
542 if ($ActionInfo[
"TestFunc"] !== NULL)
544 $DisplayButton = $ActionInfo[
"TestFunc"]($Item);
546 elseif (method_exists($Item,
"UserCanEdit"))
548 $DisplayButton = $Item->UserCanEdit($GLOBALS[
"G_User"]);
552 $DisplayButton = TRUE;
556 $ButtonClasses =
"cw-button cw-button-elegant" 557 .
" cw-button-constrained";
559 foreach ($ActionInfo[
"AddAttribs"]
560 as $AttribName => $AttribValue)
562 $AttribValue = htmlspecialchars($AttribValue);
563 if (strtolower($AttribName) ==
"class")
565 $ButtonClasses .=
" ".$AttribValue;
569 $ExtraAttribs .=
" ".$AttribName
570 .
'="'.$AttribValue.
'"';
573 if ($ActionInfo[
"Icon"])
575 $IconFile = $GLOBALS[
"AF"]->GUIFile($ActionInfo[
"Icon"]);
577 ?
'<img class="cw-button-icon" src="' 578 .$IconFile.
'" alt=""> ' 580 $ButtonClasses .=
" cw-button-iconed";
586 if (is_callable($ActionInfo[
"Link"]))
588 $Link = $ActionInfo[
"Link"]($Item);
590 elseif (method_exists($Item,
"Id"))
592 $Link = preg_replace(
'/\$ID/', $Item->Id(),
593 $ActionInfo[
"Link"]);
597 $Link = preg_replace(
'/\$ID/', $ItemId,
598 $ActionInfo[
"Link"]);
600 print
'<a class="'.$ButtonClasses.
'"'.$ExtraAttribs
601 .
' href="'.$Link.
'">'.$IconTag
602 .htmlspecialchars($ActionInfo[
"Label"]).
'</a>';
607 $GLOBALS[
"AF"]->SignalEvent(
"EVENT_HTML_INSERTION_POINT",
608 array($GLOBALS[
"AF"]->GetPageName(),
609 "Resource Summary Buttons", array(
610 "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.
__construct($Heading, $Fields, $ItemsPerPage, $BaseLink, $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.
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.
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.