Documentation

Board
in package
implements ArrayAccess, Routable uses BackwardCompatibility, ArrayAccessHelper

This class loads information about the current board, as well as other boards when needed. It also handles low-level tasks for managing boards, such as creating, deleting, and modifying them.

Implements the \ArrayAccess interface to ease backward compatibility with the deprecated global $board_info variable.

Table of Contents

Interfaces

ArrayAccess
Routable
Classes implementing this interface can build routes from URL query parameters and parse routes back into URL query parameters.

Properties

$board_id  : int
$cat  : object
$child_level  : int
$children  : array<string|int, mixed>
$count_posts  : bool
$cur_topic_approved  : bool
$cur_topic_starter  : int
$deny_groups  : array<string|int, mixed>
$description  : string
$error  : string
$id  : int
$info  : self
$last_msg  : int
$last_post  : array<string|int, mixed>
$link  : string
$link_children  : array<string|int, mixed>
$link_moderator_groups  : array<string|int, mixed>
$link_moderators  : array<string|int, mixed>
$loaded  : array<string|int, mixed>
$member_groups  : array<string|int, mixed>
$moderator_groups  : array<string|int, mixed>
$moderators  : array<string|int, mixed>
$msg_updated  : int
$name  : string
$new  : bool
$num_posts  : int
$num_topics  : int
$order  : int
$override_theme  : bool
$parent  : int
$parent_boards  : array<string|int, mixed>
$prev_board  : int
$profile  : int
$recycle  : bool
$redirect  : string
$theme  : int
$unapproved_posts  : int
$unapproved_topics  : int
$unapproved_user_topics  : int
$url  : string
$cache_props  : array<string|int, mixed>
$overridden_access_groups  : array<string|int, mixed>
$overridden_deny_groups  : array<string|int, mixed>
$parsed_descriptions  : array<string|int, mixed>
$prop_aliases  : array<string|int, mixed>
$backcompat  : array<string|int, mixed>

Methods

__set()  : void
Sets custom properties.
buildRoute()  : array<string|int, mixed>
Builds a routing path based on URL query parameters.
create()  : int
Create a new board and set its properties and position.
delete()  : void
Remove one or more boards.
exportStatic()  : void
Provides a way to export a class's public static properties and methods to global namespace.
fixChildren()  : void
Fixes the children of a board by setting their child_levels to new values.
getModeratorGroups()  : array<string|int, mixed>
Returns board's moderator groups with their names and link
getModerators()  : array<string|int, mixed>
Returns the given board's moderators, with their names and links
getMsgMemberID()  : int
Get the id_member associated with the specified message.
getParents()  : array<string|int, mixed>
Get all parent boards (requires first parent as parameter) It finds all the parents of id_parent, and that board itself.
init()  : object|null
Creates a new instance of this class if necessary, or updates an existing instance if one already exists for the given ID number. In either case, the instance will be returned.
isChildOf()  : bool
Returns whether the child board id is a child of the parent (recursive).
load()  : array<string|int, mixed>
Loads boards by ID number and/or by custom query.
markBoardsRead()  : void
Mark a board or multiple boards read.
modify()  : void
Modify the settings and position of a board.
move()  : array<string|int, mixed>
Changes this board's position in the overall board tree.
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.
parseDescription()  : void
Parses BBCode in $this->description and updates it with the result.
parseRoute()  : array<string|int, mixed>
Parses a route to get URL query parameters.
queryData()  : Generator<string|int, array<string|int, mixed>>
Generator that runs queries about board data and yields the result rows.
reorder()  : void
Put all boards in the right order and sorts the records of the boards table.
save()  : void
Saves this board to the database.
sort()  : void
Takes a board array and sorts it
unparseDescription()  : void
Restores $this->description to its unparsed value.
__construct()  : mixed
Constructor. Protected to force instantiation via Board::load().
blockOnError()  : void
Blocks access if an error occurred while loading the current board.
buildLinkTree()  : void
Builds the link tree path to the current board.
checkAccess()  : void
Checks whether the current user can access the current board.
loadBoardInfo()  : void
Loads information about the current board.

Properties

$board_id

public static int $board_id

ID number of the board being viewed.

As a general rule, code outside this class should use Board::$info->id rather than Board::$board_id. The only exception to this rule is in code executed before Board::load() has been called.

$cat

public object $cat

This board's category. An instance of SMF\Category.

$child_level

public int $child_level = 0

The hierarchy level of this board.

$children

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

Boards that are children of this board.

$count_posts

public bool $count_posts = true

Whether posts in this board count toward a user's total post count.

$cur_topic_approved

public bool $cur_topic_approved = false

Whether the current topic (if any) is approved.

$cur_topic_starter

public int $cur_topic_starter = 0

User who started the current topic (if any).

$deny_groups

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

Info about member groups forbidden from accessing this board.

$description

public string $description = ''

This board's description.

$error

public string $error

What error (if any) was encountered while loading this board.

$id

public int $id

This board's ID number.

$info

public static self $info

Instance of this class for board we are currently in.

$last_msg

public int $last_msg = 0

ID number of the latest message posted in this board.

$last_post

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

Info about the latest post in this board.

public string $link = ''

HTML anchor link for this board.

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

HTML anchor links for this board's children.

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

HTML anchor links for this board's moderator groups.

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

HTML anchor links for this board's moderators.

$loaded

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

All loaded instances of this class.

$member_groups

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

Info about member groups allowed to access this board.

$moderator_groups

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

Info about member groups allowed to moderate this board.

$moderators

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

Info about individual members allowed to moderate this board.

$msg_updated

public int $msg_updated = 0

ID number of the latest message in the forum at the time when this board was last updated.

$name

public string $name = ''

This board's name.

$new

public bool $new = false

Whether the board contains posts that the current user has not read.

$num_posts

public int $num_posts = 0

Number of posts in this board.

$num_topics

public int $num_topics = 0

Number of topics in this board.

$order

public int $order = 0

The positional order of this board.

$override_theme

public bool $override_theme = false

Whether this board's theme overrides the default.

$parent

public int $parent = 0

ID of this board's immediate ancestor.

$parent_boards

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

All of this board's ancestor boards.

$prev_board

public int $prev_board = 0

ID of the board previous to this one in positional order.

$profile

public int $profile = 1

The permission profile of this board.

$recycle

public bool $recycle = false

Whether this board is the recycle bin board.

$redirect

public string $redirect = ''

The redirection URL (if any) for this board.

$theme

public int $theme = 0

This board's theme.

$unapproved_posts

public int $unapproved_posts = 0

Number of unapproved posts in this board.

$unapproved_topics

public int $unapproved_topics = 0

Number of unapproved topics in this board.

$unapproved_user_topics

public int $unapproved_user_topics = 0

Number of unapproved topics in this board that were started by the current user.

$url

public string $url = ''

URL for this board.

$cache_props

protected static array<string|int, mixed> $cache_props = [ // When caching Board::$info 'info' => ['id', 'cat', 'name', 'description', 'moderators', 'moderator_groups', 'member_groups', 'deny_groups', 'num_posts', 'num_topics', 'unapproved_topics', 'unapproved_posts', 'parent_boards', 'parent', 'child_level', 'order', 'prev_board', 'theme', 'override_theme', 'profile', 'redirect', 'recycle', 'count_posts', 'cur_topic_approved', 'cur_topic_starter'], ]

Properties that should be cached in different situations.

$overridden_access_groups

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

IDs of groups that can access this board even though they are not explicitly granted access according to the database. Basically, this means any groups that have the manage_boards permission that aren't in the board's list of allowed groups.

$overridden_deny_groups

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

IDs of groups that can access this board even though they are supposedly denied access according to the database. Basically, this means any groups that have the manage_boards permission that are in the board's list of denied groups.

$parsed_descriptions

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

Holds parsed versions of board descriptions.

$prop_aliases

protected array<string|int, mixed> $prop_aliases = [ 'id_board' => 'id', 'board_name' => 'name', 'board_description' => 'description', 'groups' => 'member_groups', 'access_groups' => 'member_groups', 'deny_member_groups' => 'deny_groups', 'posts' => 'num_posts', 'topics' => 'num_topics', 'id_parent' => 'parent', 'level' => 'child_level', 'board_order' => 'order', 'id_theme' => 'theme', 'board_theme' => 'theme', 'id_profile' => 'profile', 'posts_count' => 'count_posts', 'href' => 'url', 'id_last_msg' => 'last_msg', 'id_msg_updated' => 'msg_updated', // Square brackets are parsed to find array elements. 'category' => 'cat[id]', 'id_cat' => 'cat[id]', // Initial exclamation mark means inverse of the property. 'is_read' => '!new', ]

Alternate names for some object properties.

$backcompat

private static array<string|int, mixed> $backcompat = ['prop_names' => ['board_id' => 'board', 'info' => 'board_info', 'loaded' => 'boards']]

BackwardCompatibility settings for this class.

Methods

__set()

Sets custom properties.

public __set(string $prop, mixed $value) : void
Parameters
$prop : string

The property name.

$value : mixed

The value to set.

buildRoute()

Builds a routing path based on URL query parameters.

public static buildRoute(array<string|int, mixed> $params) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

URL query parameters.

Return values
array<string|int, mixed>

Contains two elements: ['route' => [], 'params' => []]. The 'route' element contains the routing path. The 'params' element contains any $params that weren't incorporated into the route.

create()

Create a new board and set its properties and position.

public static create(array<string|int, mixed> $boardOptions) : int

Allows (almost) the same options as the modifyBoard() function. With the option inherit_permissions set, the parent board permissions will be inherited.

Parameters
$boardOptions : array<string|int, mixed>

An array of information for the new board

Return values
int

The ID of the new board

delete()

Remove one or more boards.

public static delete(array<string|int, mixed> $boards_to_remove[, int $moveChildrenTo = null ]) : void

Allows to move the children of the board before deleting it if moveChildrenTo is set to null, the child boards will be deleted. Deletes:

  • all topics that are on the given boards;
  • all information that's associated with the given boards; updates the statistics to reflect the new situation.
Parameters
$boards_to_remove : array<string|int, mixed>

The boards to remove

$moveChildrenTo : int = null

The ID of the board to move the child boards to (null to remove the child boards, 0 to make them a top-level board)

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'].

$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.

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

fixChildren()

Fixes the children of a board by setting their child_levels to new values.

public static fixChildren(int $parent, int $newLevel, int $newParent) : void

Used when a board is deleted or moved, to affect its children.

Parameters
$parent : int

The ID of the parent board

$newLevel : int

The new child level for each of the child boards

$newParent : int

The ID of the new parent board

getModeratorGroups()

Returns board's moderator groups with their names and link

public static getModeratorGroups(array<string|int, mixed> $boards) : array<string|int, mixed>
Parameters
$boards : array<string|int, mixed>

The boards to get moderator groups of

Return values
array<string|int, mixed>

An array containing information about the groups assigned to moderate each board

getModerators()

Returns the given board's moderators, with their names and links

public static getModerators(array<string|int, mixed> $boards) : array<string|int, mixed>
Parameters
$boards : array<string|int, mixed>

The boards to get moderators of

Return values
array<string|int, mixed>

An array containing information about the moderators of each board

getMsgMemberID()

Get the id_member associated with the specified message.

public static getMsgMemberID(int $messageID) : int
Parameters
$messageID : int

The ID of the message

Tags
todo

Move this? It's not really related to boards.

Return values
int

The ID of the member associated with that post

getParents()

Get all parent boards (requires first parent as parameter) It finds all the parents of id_parent, and that board itself.

public static getParents(int $id_parent) : array<string|int, mixed>

Additionally, it detects the moderators of said boards.

Parameters
$id_parent : int

The ID of the parent board

Return values
array<string|int, mixed>

An array of information about the boards found.

init()

Creates a new instance of this class if necessary, or updates an existing instance if one already exists for the given ID number. In either case, the instance will be returned.

public static init([int|null $id = null ][, array<string|int, mixed> $props = [] ]) : object|null

If $id is empty but self::$board_id isn't, $id is set to self::$board_id. If $id and self::$board_id are both empty, returns null.

If an instance already exists for the given ID number, then $props will simply be passed to the existing instance's set() method, and then the existing instance will be returned.

If an instance does not exist for the given ID number and $props is empty, a query will be performed to populate the properties with data from the boards table.

Parameters
$id : int|null = null

The ID number of a board, or null for current board. Default: null.

$props : array<string|int, mixed> = []

Properties to set for this board. Only used when $id is not null.

Return values
object|null

An instance of this class, or null on error.

isChildOf()

Returns whether the child board id is a child of the parent (recursive).

public static isChildOf(int $child, int $parent) : bool
Parameters
$child : int

The ID of the child board.

$parent : int

The ID of a parent board.

Return values
bool

Whether the specified child board is a child of the specified parent board.

load()

Loads boards by ID number and/or by custom query.

public static load([array<string|int, mixed>|int $ids = [] ][, array<string|int, mixed> $query_customizations = [] ]) : array<string|int, mixed>

If both arguments are empty, loads the board in self::$board_id.

Parameters
$ids : array<string|int, mixed>|int = []

The ID numbers of zero or more boards.

$query_customizations : array<string|int, mixed> = []

Customizations to the SQL query.

Return values
array<string|int, mixed>

Instances of this class for the loaded boards.

markBoardsRead()

Mark a board or multiple boards read.

public static markBoardsRead(int|array<string|int, mixed> $boards[, bool $unread = false ]) : void
Parameters
$boards : int|array<string|int, mixed>

The ID of a single board or an array of boards

$unread : bool = false

Whether we're marking them as unread

modify()

Modify the settings and position of a board.

public static modify(int $board_id, array<string|int, mixed> &$boardOptions) : void

Used by ManageBoards.php to change the settings of a board.

Parameters
$board_id : int

The ID of the board

$boardOptions : array<string|int, mixed>

An array of options related to the board

move()

Changes this board's position in the overall board tree.

public move(string $move_to[, int|null $target_category = null ][, int|null $target_board = null ][, bool $first_child = false ][, bool $save = true ]) : array<string|int, mixed>
Parameters
$move_to : string

Where to move the board. Value can be one of 'top', 'bottom', 'child', 'before', or 'after'.

$target_category : int|null = null

ID of the board's new category. Only applicable when $move_to is 'top' or 'bottom'.

$target_board : int|null = null

ID of another board that this board is being moved next to or is becoming a child of. Only applicable when $move_to is 'child', 'before,' or 'after'.

$first_child : bool = false

Whether this should be the first or last child of its new parent. Only applicable when $move_to is 'child'.

$save : bool = true

Whether to call the save() method for affected boards. If set to false, the caller is responsible for calling the save() method for each of the affected boards.

Return values
array<string|int, mixed>

IDs of all boards that were affected by this move.

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.

Return values
mixed

A reference to the property.

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.

parseDescription()

Parses BBCode in $this->description and updates it with the result.

public parseDescription() : void

parseRoute()

Parses a route to get URL query parameters.

public static parseRoute(array<string|int, mixed> $route[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>
Parameters
$route : array<string|int, mixed>

Array of routing path components.

$params : array<string|int, mixed> = []

Any existing URL query parameters.

Return values
array<string|int, mixed>

URL query parameters

queryData()

Generator that runs queries about board data and yields the result rows.

public static queryData(array<string|int, mixed> $selects[, array<string|int, mixed> $params = [] ][, array<string|int, mixed> $joins = [] ][, array<string|int, mixed> $where = [] ][, array<string|int, mixed> $order = [] ][, array<string|int, mixed> $group = [] ][, int $limit = 0 ]) : Generator<string|int, array<string|int, mixed>>
Parameters
$selects : array<string|int, mixed>

Table columns to select.

$params : array<string|int, mixed> = []

Parameters to substitute into query text.

$joins : array<string|int, mixed> = []

Zero or more complete JOIN clauses. E.g.: 'LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' Note that 'FROM {db_prefix}boards AS b' is always part of the query.

$where : array<string|int, mixed> = []

Zero or more conditions for the WHERE clause. Conditions will be placed in parentheses and concatenated with AND. If this is left empty, no WHERE clause will be used.

$order : array<string|int, mixed> = []

Zero or more conditions for the ORDER BY clause. If this is left empty, no ORDER BY clause will be used.

$group : array<string|int, mixed> = []

Zero or more conditions for the GROUP BY clause. If this is left empty, no GROUP BY clause will be used.

$limit : int = 0

Maximum number of results to retrieve. If this is left empty, all results will be retrieved.

Return values
Generator<string|int, array<string|int, mixed>>

Iterating over the result gives database rows.

reorder()

Put all boards in the right order and sorts the records of the boards table.

public static reorder() : void

Used by Board::modify(), Board::delete(), Category::modify(), and Category::delete()

save()

Saves this board to the database.

public save([array<string|int, mixed> $boardOptions = [] ]) : void
Parameters
$boardOptions : array<string|int, mixed> = []

An array of options related to the board.

sort()

Takes a board array and sorts it

public static sort(array<string|int, mixed> &$boards) : void
Parameters
$boards : array<string|int, mixed>

The boards

unparseDescription()

Restores $this->description to its unparsed value.

public unparseDescription() : void

__construct()

Constructor. Protected to force instantiation via Board::load().

protected __construct([int|null $id = null ][, array<string|int, mixed> $props = [] ]) : mixed

If $id is null, loads the current board:

  • Sets up the Board::$info object for current board information.
  • If cache is enabled, Board::$info is stored in cache.
  • Redirects to appropriate post if only a message ID was requested.
  • Is only used when inside a topic or board.
  • Determines the local moderators for the board and calls User::setModerators.
  • Prevents access if user is not in proper group nor a local moderator of the board.

If $id is an integer, creates an instance for that ID, sets any supplied properties in $props, and adds the instance to the Board::$loaded array.

If $id is an integer and $props is empty, a query will be performed to populate the properties with data from the boards table.

Parameters
$id : int|null = null

The ID number of a board, or null for current board. Default: null.

$props : array<string|int, mixed> = []

Properties to set for this board. Only used when $id is not null.

blockOnError()

Blocks access if an error occurred while loading the current board.

protected blockOnError() : void

buildLinkTree()

Builds the link tree path to the current board.

protected buildLinkTree() : void

checkAccess()

Checks whether the current user can access the current board.

protected checkAccess() : void

loadBoardInfo()

Loads information about the current board.

protected loadBoardInfo() : void

The loaded info is stored in the Board::$info instance of this class.


        
On this page

Search results