Documentation

ItemList
in package
implements ArrayAccess Uses BackwardCompatibility, ArrayAccessHelper

This class provides a standard way of displaying lists for SMF.

Table of Contents

Interfaces

ArrayAccess

Properties

$additional_rows  : array<string|int, mixed>
$form  : array<string|int, mixed>
$headers  : array<string|int, mixed>
$id  : string
$items_per_page  : int
$javascript  : string
$no_items_align  : string
$no_items_label  : string
$num_columns  : int
$page_index  : string
$rows  : array<string|int, mixed>
$sort  : array<string|int, mixed>
$start  : int
$start_var_name  : string
$title  : string
$total_num_items  : int
$width  : string
$db_sort  : string
$items  : array<string|int, mixed>
$options  : array<string|int, mixed>
$backcompat  : array<string|int, mixed>

Methods

__construct()  : mixed
Create a new list.
exportStatic()  : void
Provides a way to export a class's public static properties and methods to global namespace.
load()  : object
Static wrapper for constructor.
offsetExists()  : bool
Checks whether a property has been set when object is accessed as an array.
offsetGet()  : mixed
Gets properties when object is accessed as an array.
offsetSet()  : void
Sets properties when object is accessed as an array.
offsetUnset()  : void
Unsets properties when object is accessed as an array.
buildAdditionalRows()  : void
A list can sometimes need a few extra rows above and below.
buildForm()  : void
In case there's a form, share it with the template context.
buildHeaders()  : void
Builds the table headers for this list.
buildPageIndex()  : void
Creates the page index, if necessary.
buildRows()  : void
Builds the table rows for the list items.
checkOptions()  : bool
Checks whether $options provides enough data to make a list.
getItems()  : void
Gets the list items from the database.
setBasics()  : void
Handles some list properties that can be set directly from the options.
setSort()  : void
Figure out the sort.
setStartAndItemsPerPage()  : void
Figures out $this->start and $this->items_per_page.

Properties

$additional_rows

public array<string|int, mixed> $additional_rows = []

Additional rows to wrap around this lis.

$form

public array<string|int, mixed> $form

Info about the HTML form for this list.

$headers

public array<string|int, mixed> $headers = []

Table headers.

$id

public string $id

The list's identifier string.

$items_per_page

public int $items_per_page = 0

How many items to put on each page of the list.

$javascript

public string $javascript

Any JavaScript to add for this list.

$no_items_align

public string $no_items_align

CSS class for the empty list message. E.g.: 'centertext', 'lefttext', etc.

$no_items_label

public string $no_items_label

Message to show when the list is empty.

$num_columns

public int $num_columns

The number of columns in this list.

$page_index

public string $page_index

The page index for navigating this list.

$rows

public array<string|int, mixed> $rows = []

Table rows for the items in the list.

$sort

public array<string|int, mixed> $sort = []

Info about how this list is sorted.

$start

public int $start = 0

Where the current page of the list begins.

$start_var_name

public string $start_var_name = 'start'

URL parameter that indicates where to start current page of the list.

$title

public string $title

The title of this list. Optional.

$total_num_items

public int $total_num_items

How many items are in the entire list.

$width

public string $width

CSS width for the table. Optional.

$db_sort

protected string $db_sort = '1=1'

Value for the ORDER BY clause.

$items

protected array<string|int, mixed> $items = []

The items retrieved from the database.

$options

protected array<string|int, mixed> $options = []

The list options passed to the constructor.

$backcompat

private static array<string|int, mixed> $backcompat = ['func_names' => ['load' => 'createList']]

BackwardCompatibility settings for this class.

Methods

__construct()

Create a new list.

public __construct(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>

An array of options for the list - 'id', 'columns', 'items_per_page', 'get_count', etc.

exportStatic()

Provides a way to export a class's public static properties and methods to global namespace.

public static exportStatic() : void

To do so:

  1. Use this trait in the class.
  2. At the END of the class's file, call its exportStatic() method.

Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.

Regarding the $backcompat items:

A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].

$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.

$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.

Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.

load()

Static wrapper for constructor.

public static load(array<string|int, mixed> $options) : object
Parameters
$options : array<string|int, mixed>

Same as for the constructor.

Return values
object

An instance of this class.

offsetExists()

Checks whether a property has been set when object is accessed as an array.

public offsetExists(mixed $prop) : bool
Parameters
$prop : mixed

The property name.

Return values
bool

offsetGet()

Gets properties when object is accessed as an array.

public offsetGet(mixed $prop) : mixed
Parameters
$prop : mixed

The property name.

offsetSet()

Sets properties when object is accessed as an array.

public offsetSet(mixed $prop, mixed $value) : void
Parameters
$prop : mixed

The property name.

$value : mixed

The value to set.

offsetUnset()

Unsets properties when object is accessed as an array.

public offsetUnset(mixed $prop) : void
Parameters
$prop : mixed

The property name.

buildAdditionalRows()

A list can sometimes need a few extra rows above and below.

protected buildAdditionalRows() : void

buildForm()

In case there's a form, share it with the template context.

protected buildForm() : void

buildHeaders()

Builds the table headers for this list.

protected buildHeaders() : void

buildPageIndex()

Creates the page index, if necessary.

protected buildPageIndex() : void

buildRows()

Builds the table rows for the list items.

protected buildRows() : void

checkOptions()

Checks whether $options provides enough data to make a list.

protected checkOptions(array<string|int, mixed> $options) : bool
Parameters
$options : array<string|int, mixed>

Same as for the constructor.

Return values
bool

Whether we can build a list with this data.

getItems()

Gets the list items from the database.

protected getItems() : void

setBasics()

Handles some list properties that can be set directly from the options.

protected setBasics() : void

setSort()

Figure out the sort.

protected setSort() : void

setStartAndItemsPerPage()

Figures out $this->start and $this->items_per_page.

protected setStartAndItemsPerPage() : void

If $this->items_per_page > 0, also figures out $this->total_num_items.


        
On this page

Search results