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;
78 $this->Buttons[] = array(
102 $Label, $Link, $Icon = NULL, $DisplayTestFunc = NULL,
103 $AdditionalAttributes = array())
105 $this->Actions[] = array(
109 "TestFunc" => $DisplayTestFunc,
110 "AddAttribs" => $AdditionalAttributes);
120 if ($NewValue !== NULL)
122 $this->NoItemsMsg = $NewValue;
124 return $this->NoItemsMsg;
142 $StartingIndex = NULL, $TransportMsg = NULL)
144 # set up transport controls (doing it early to retrieve sort info) 145 foreach ($this->Fields as $FieldId => $FieldInfo)
147 if (isset($FieldInfo[
"DefaultSortField"]))
153 $StartingIndex = $TransportUI->StartingIndex($StartingIndex);
154 $SortFieldId = $TransportUI->SortField();
155 $ReverseSort = $TransportUI->ReverseSortFlag();
157 # display buttons above list 158 if (count($this->Buttons))
160 print
'<span style="float: right; padding-top: 1.5em;">';
161 foreach ($this->Buttons as $Info)
165 $IconFile = $GLOBALS[
"AF"]->GUIFile($Info[
"Icon"]);
167 ?
'<img class="cw-button-icon" src="' 168 .$IconFile.
'" alt=""> ' 170 $IconButtonClass =
" cw-button-iconed";
175 $IconButtonClass =
"";
177 ?><a
class=
"cw-button cw-button-elegant cw-button-constrained<?= 179 href=
"<?= $Info["Link
"] ?>"><?= $IconTag ?><?=
180 htmlspecialchars($Info[
"Label"]) ?></a><?
PHP 186 if ($this->Heading !== NULL)
188 if ($this->Heading == strip_tags($this->Heading))
190 print
"<h1>".$this->Heading.
"</h1>\n";
194 print $this->Heading.
"\n";
198 # display "no items" message and exit if no items 201 print
"<span class=\"cw-itemlist-empty\">";
202 if (strlen($this->NoItemsMsg))
204 print $this->NoItemsMsg;
210 $Schema->ResourceName())).
" to display)";
214 print
"(no items to display)";
221 print
'<table class="cw-table cw-table-sideheaders cw-table-fullsize 222 cw-table-padded cw-table-striped">';
228 foreach ($this->Fields as $FieldId => $FieldInfo)
230 # if header value supplied 231 if (isset($FieldInfo[
"Heading"]))
234 $Heading = $FieldInfo[
"Heading"];
236 # else if we can get header from schema 239 # use name of field (with any leading schema name stripped) 241 $Heading = preg_replace(
"/.+\: /",
"", $Heading);
243 # else if field ID appears like it may be a name 244 elseif (is_string($FieldId) && !is_numeric($FieldId))
250 $Heading =
"(NO HEADER SET)";
253 # if sorting is disabled for field 254 if (isset($FieldInfo[
"NoSorting"]))
257 print
"<th>".$Heading.
"</th>\n";
262 $SortLink = $this->BaseLink.
"&SF=".$FieldId
263 .$TransportUI->UrlParameterString(TRUE, array(
"SF",
"RS"));
265 # determine current sort direction 266 if (isset($FieldInfo[
"DefaultToDescendingSort"]))
268 $SortAscending = $ReverseSort ? TRUE : FALSE;
272 $SortAscending = $ReverseSort ? FALSE : TRUE;
275 # set sort direction indicator (if any) 276 if ($FieldId == $SortFieldId)
278 $DirIndicator = ($SortAscending) ?
"↑" :
"↓";
281 $SortLink .=
"&RS=1";
290 print
"<th><a href=\"".$SortLink.
"\">".$Heading.
"</a>" 291 .$DirIndicator.
"</th>\n";
295 # add action header if needed 296 if (count($this->Actions))
298 print
"<th>Actions</th>\n";
302 print
"</tr></thead>\n";
306 foreach (
$Items as $ItemId => $Item)
312 foreach ($this->Fields as $FieldId => $FieldInfo)
314 # if there is value function defined for field 315 if (isset($FieldInfo[
"ValueFunction"]))
317 # call function for value 318 $Value = $FieldInfo[
"ValueFunction"]($Item, $FieldId);
322 # if item is associative array 325 # retrieve value for field (if any) from item 326 $Value = isset($Item[$FieldId])
327 ? $Item[$FieldId] :
"";
329 # else if field ID is item method 330 elseif (method_exists($Item, $FieldId))
332 # get field value via item method 333 $Value = $Item->$FieldId();
337 # get field value from item via Get() 338 $Values = $Item->Get($FieldId);
339 $Value = is_array($Values) ? array_shift($Values) : $Values;
342 # if max length specified for field 343 if (isset($FieldInfo[
"MaxLength"]))
345 $Value = NeatlyTruncateString(
346 $Value, $FieldInfo[
"MaxLength"]);
349 # encode any HTML-significant chars in value 350 if (!isset($FieldInfo[
"AllowHTML"]))
352 $Value = htmlspecialchars($Value);
356 # get link value (if any) 357 if (isset($FieldInfo[
"Link"]))
359 if (method_exists($Item,
"Id"))
361 $Link = preg_replace(
'/\$ID/', $Item->Id(),
366 $Link = preg_replace(
'/\$ID/', $ItemId,
369 $LinkStart =
'<a href="'.$Link.
'">';
378 # display cell with value 379 print
"<td>".$LinkStart.$Value.$LinkEnd.
"</td>\n";
383 if (count($this->Actions))
386 foreach ($this->Actions as $ActionInfo)
388 if ($ActionInfo[
"TestFunc"] !== NULL)
390 $DisplayButton = $ActionInfo[
"TestFunc"]($Item);
392 elseif (method_exists($Item,
"UserCanEdit"))
394 $DisplayButton = $Item->UserCanEdit($GLOBALS[
"G_User"]);
398 $DisplayButton = TRUE;
402 $ButtonClasses =
"cw-button cw-button-elegant" 403 .
" cw-button-constrained";
405 foreach ($ActionInfo[
"AddAttribs"]
406 as $AttribName => $AttribValue)
408 $AttribValue = htmlspecialchars($AttribValue);
409 if (strtolower($AttribName) ==
"class")
411 $ButtonClasses .=
" ".$AttribValue;
415 $ExtraAttribs .=
" ".$AttribName
416 .
'="'.$AttribValue.
'"';
419 if ($ActionInfo[
"Icon"])
421 $IconFile = $GLOBALS[
"AF"]->GUIFile($ActionInfo[
"Icon"]);
423 ?
'<img class="cw-button-icon" src="' 424 .$IconFile.
'" alt=""> ' 426 $ButtonClasses .=
" cw-button-iconed";
432 if (is_callable($ActionInfo[
"Link"]))
434 $Link = $ActionInfo[
"Link"]($Item);
436 elseif (method_exists($Item,
"Id"))
438 $Link = preg_replace(
'/\$ID/', $Item->Id(),
439 $ActionInfo[
"Link"]);
443 $Link = preg_replace(
'/\$ID/', $ItemId,
444 $ActionInfo[
"Link"]);
446 print
'<a class="'.$ButtonClasses.
'"'.$ExtraAttribs
447 .
' href="'.$Link.
'">'.$IconTag
448 .htmlspecialchars($ActionInfo[
"Label"]).
'</a>';
453 $GLOBALS[
"AF"]->SignalEvent(
"EVENT_HTML_INSERTION_POINT",
454 array($GLOBALS[
"AF"]->GetPageName(),
455 "Resource Summary Buttons", array(
456 "Resource" => $Item)));
469 # if there are more items than are displayed 470 if ($TotalItemCount > count(
$Items))
472 # craft transport control message (if not supplied) 473 if ($TransportMsg === NULL)
477 $Item->Schema()->ResourceName())
479 $TransportMsg = $ItemsLabel
480 .
" <b>".($TransportUI->StartingIndex() + 1)
482 .min(($TransportUI->StartingIndex() + $this->ItemsPerPage),
484 .
"</b> of <b>".$TotalItemCount.
"</b>";
487 # display transport controls 488 $TransportUI->StartingIndex($StartingIndex);
489 $TransportUI->ItemCount($TotalItemCount);
490 $TransportUI->PrintControls(
491 $this->SchemaId, $this->BaseLink, $TransportMsg);
496 # ---- PRIVATE INTERFACE ------------------------------------------------- 503 private $ItemsPerPage;
Class to provide a user interface for displaying a list of items.
static DefaultSortField($NewValue=NULL)
Get/set default sort field value.
__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.