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 public function __construct($Heading, $Fields, $ItemsPerPage, $BaseLink,
47 # normalize and save field info 50 $this->Fields = $Fields;
54 $this->Fields = array();
55 foreach ($Fields as $FieldId => $FieldInfo)
58 $this->Fields[$CanonicalId] = $FieldInfo;
62 # save other supplied settings for later use 63 $this->BaseLink = $BaseLink;
64 $this->Heading = $Heading;
65 $this->ItemsPerPage = $ItemsPerPage;
66 $this->SchemaId = $SchemaId;
68 # set up transport controls 69 foreach ($this->Fields as $FieldId => $FieldInfo)
71 if (isset($FieldInfo[
"DefaultSortField"]))
77 $this->SchemaId, $this->ItemsPerPage);
89 $this->Buttons[] = array(
113 $Label, $Link, $Icon = NULL, $DisplayTestFunc = NULL,
114 $AdditionalAttributes = array())
116 $this->Actions[] = array(
120 "TestFunc" => $DisplayTestFunc,
121 "AddAttribs" => $AdditionalAttributes);
131 if ($NewValue !== NULL)
133 $this->NoItemsMsg = $NewValue;
135 return $this->NoItemsMsg;
144 return $this->TransportUI;
162 $StartingIndex = NULL, $TransportMsg = NULL)
164 # retrieve context values from transport controls 165 $StartingIndex = $this->
TransportUI->StartingIndex($StartingIndex);
167 $ReverseSort = $this->
TransportUI->ReverseSortFlag();
169 # display buttons above list 170 if (count($this->Buttons))
172 print
'<span style="float: right; padding-top: 1.5em;">';
173 foreach ($this->Buttons as $Info)
177 $IconFile = $GLOBALS[
"AF"]->GUIFile($Info[
"Icon"]);
179 ?
'<img class="cw-button-icon" src="' 180 .$IconFile.
'" alt=""> ' 182 $IconButtonClass =
" cw-button-iconed";
187 $IconButtonClass =
"";
189 ?><a
class=
"cw-button cw-button-elegant cw-button-constrained<?= 191 href=
"<?= $Info["Link
"] ?>"><?= $IconTag ?><?=
192 htmlspecialchars($Info[
"Label"]) ?></a><?
PHP 198 if ($this->Heading !== NULL)
200 if ($this->Heading == strip_tags($this->Heading))
202 print
"<h1>".$this->Heading.
"</h1>\n";
206 print $this->Heading.
"\n";
210 # display "no items" message and exit if no items 213 print
"<span class=\"cw-itemlist-empty\">";
214 if (strlen($this->NoItemsMsg))
216 print $this->NoItemsMsg;
222 $Schema->ResourceName())).
" to display)";
226 print
"(no items to display)";
233 print
'<table class="cw-table cw-table-sideheaders cw-table-fullsize 234 cw-table-padded cw-table-striped">';
240 foreach ($this->Fields as $FieldId => $FieldInfo)
242 # if header value supplied 243 if (isset($FieldInfo[
"Heading"]))
246 $Heading = $FieldInfo[
"Heading"];
248 # else if we can get header from schema 251 # use name of field (with any leading schema name stripped) 253 $Heading = preg_replace(
"/.+\: /",
"", $Heading);
255 # else if field ID appears like it may be a name 256 elseif (is_string($FieldId) && !is_numeric($FieldId))
262 $Heading =
"(NO HEADER SET)";
265 # if sorting is disabled for field 266 if (isset($FieldInfo[
"NoSorting"]))
269 print
"<th>".$Heading.
"</th>\n";
274 $SortLink = $this->BaseLink.
"&SF=".$FieldId
275 .$this->TransportUI->UrlParameterString(TRUE, array(
"SF",
"RS"));
277 # determine current sort direction 278 if (isset($FieldInfo[
"DefaultToDescendingSort"]))
280 $SortAscending = $ReverseSort ? TRUE : FALSE;
284 $SortAscending = $ReverseSort ? FALSE : TRUE;
287 # set sort direction indicator (if any) 288 if ($FieldId == $SortFieldId)
290 $DirIndicator = ($SortAscending) ?
"↑" :
"↓";
293 $SortLink .=
"&RS=1";
302 print
"<th><a href=\"".$SortLink.
"\">".$Heading.
"</a>" 303 .$DirIndicator.
"</th>\n";
307 # add action header if needed 308 if (count($this->Actions))
310 print
"<th>Actions</th>\n";
314 print
"</tr></thead>\n";
318 foreach (
$Items as $ItemId => $Item)
324 foreach ($this->Fields as $FieldId => $FieldInfo)
326 # if there is value function defined for field 327 if (isset($FieldInfo[
"ValueFunction"]))
329 # call function for value 330 $Value = $FieldInfo[
"ValueFunction"]($Item, $FieldId);
334 # if item is associative array 337 # retrieve value for field (if any) from item 338 $Value = isset($Item[$FieldId])
339 ? $Item[$FieldId] :
"";
341 # else if field ID is item method 342 elseif (method_exists($Item, $FieldId))
344 # get field value via item method 345 $Value = $Item->$FieldId();
349 # get field value from item via Get() 350 $Values = $Item->Get($FieldId);
351 $Value = is_array($Values) ? array_shift($Values) : $Values;
354 # if max length specified for field 355 if (isset($FieldInfo[
"MaxLength"]))
357 $Value = NeatlyTruncateString(
358 $Value, $FieldInfo[
"MaxLength"]);
361 # encode any HTML-significant chars in value 362 if (!isset($FieldInfo[
"AllowHTML"]))
364 $Value = htmlspecialchars($Value);
368 # get link value (if any) 369 if (isset($FieldInfo[
"Link"]))
371 if (method_exists($Item,
"Id"))
373 $Link = preg_replace(
'/\$ID/', $Item->Id(),
378 $Link = preg_replace(
'/\$ID/', $ItemId,
381 $LinkStart =
'<a href="'.$Link.
'">';
390 # display cell with value 391 print
"<td>".$LinkStart.$Value.$LinkEnd.
"</td>\n";
395 if (count($this->Actions))
398 foreach ($this->Actions as $ActionInfo)
400 if ($ActionInfo[
"TestFunc"] !== NULL)
402 $DisplayButton = $ActionInfo[
"TestFunc"]($Item);
404 elseif (method_exists($Item,
"UserCanEdit"))
406 $DisplayButton = $Item->UserCanEdit($GLOBALS[
"G_User"]);
410 $DisplayButton = TRUE;
414 $ButtonClasses =
"cw-button cw-button-elegant" 415 .
" cw-button-constrained";
417 foreach ($ActionInfo[
"AddAttribs"]
418 as $AttribName => $AttribValue)
420 $AttribValue = htmlspecialchars($AttribValue);
421 if (strtolower($AttribName) ==
"class")
423 $ButtonClasses .=
" ".$AttribValue;
427 $ExtraAttribs .=
" ".$AttribName
428 .
'="'.$AttribValue.
'"';
431 if ($ActionInfo[
"Icon"])
433 $IconFile = $GLOBALS[
"AF"]->GUIFile($ActionInfo[
"Icon"]);
435 ?
'<img class="cw-button-icon" src="' 436 .$IconFile.
'" alt=""> ' 438 $ButtonClasses .=
" cw-button-iconed";
444 if (is_callable($ActionInfo[
"Link"]))
446 $Link = $ActionInfo[
"Link"]($Item);
448 elseif (method_exists($Item,
"Id"))
450 $Link = preg_replace(
'/\$ID/', $Item->Id(),
451 $ActionInfo[
"Link"]);
455 $Link = preg_replace(
'/\$ID/', $ItemId,
456 $ActionInfo[
"Link"]);
458 print
'<a class="'.$ButtonClasses.
'"'.$ExtraAttribs
459 .
' href="'.$Link.
'">'.$IconTag
460 .htmlspecialchars($ActionInfo[
"Label"]).
'</a>';
465 $GLOBALS[
"AF"]->SignalEvent(
"EVENT_HTML_INSERTION_POINT",
466 array($GLOBALS[
"AF"]->GetPageName(),
467 "Resource Summary Buttons", array(
468 "Resource" => $Item)));
481 # if there are more items than are displayed 482 if ($TotalItemCount > count(
$Items))
484 # craft transport control message (if not supplied) 485 if ($TransportMsg === NULL)
489 $Item->Schema()->ResourceName())
491 $TransportMsg = $ItemsLabel
494 .min(($this->
TransportUI->StartingIndex() + $this->ItemsPerPage),
496 .
"</b> of <b>".$TotalItemCount.
"</b>";
499 # display transport controls 503 $this->SchemaId, $this->BaseLink, $TransportMsg);
508 # ---- PRIVATE INTERFACE ------------------------------------------------- 515 private $ItemsPerPage;
518 private $TransportUI;
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.
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.
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.