Documentation

Topic
in package
implements ArrayAccess, Routable uses BackwardCompatibility, ArrayAccessHelper

Represents a topic.

This class's static methods also takes care of certain actions on topics: lock/unlock a topic, sticky/unsticky it, etc.

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

$id  : int
$id_board  : int
$id_first_msg  : int
$id_last_msg  : int
$id_member_started  : int
$id_poll  : int
$id_previous_board  : int
$id_previous_topic  : int
$id_redirect_topic  : int
$info  : Topic
$is_approved  : bool
$is_locked  : bool
$is_poll  : bool
$is_sticky  : bool
$loaded  : array<string|int, mixed>
$new_from  : int
$notify_prefs  : array<string|int, mixed>
$num_replies  : int
$num_views  : int
$permissions  : array<string|int, mixed>
$real_num_replies  : int
$started_name  : string
$started_time  : string
$started_timestamp  : int
$subject  : string
$topic_id  : int
$total_visible_posts  : int
$unapproved_posts  : int
$unwatched  : int
$updated_name  : string
$updated_timestamp  : int
$anyown_permissions  : array<string|int, mixed>
$common_permissions  : array<string|int, mixed>
$events  : array<string|int, mixed>
$prop_aliases  : array<string|int, mixed>
$backcompat  : array<string|int, mixed>

Methods

__construct()  : object
Constructor.
__set()  : void
Sets custom properties.
approve()  : bool
Approves or unapproves topics.
buildRoute()  : array<string|int, mixed>
Builds a routing path based on URL query parameters.
doPermissions()  : array<string|int, mixed>
Determines the current user's permissions in this topic.
exportStatic()  : void
Provides a way to export a class's public static properties and methods to global namespace.
getLikedMsgs()  : array<string|int, mixed>
Gets the IDs of messages in this topic that the current user likes.
getLinkedEvents()  : array<string|int, mixed>
Returns any calendar events that are linked to this topic.
getNotificationPrefs()  : array<string|int, mixed>
Gets the current user's notification preferences for this topic.
load()  : self
Loads information about a topic.
lock()  : array<string|int, mixed>
Sets the locked state for one or more topics.
move()  : void
Moves one or more topics to a specific board.
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.
parseRoute()  : array<string|int, mixed>
Parses a route to get URL query parameters.
remove()  : void
Removes the passed id_topic's. (permissions are NOT checked here!).
sticky()  : array<string|int, mixed>
Sets the sticky state for one or more topics.
loadTopicInfo()  : void
Loads primary information about this topic.

Properties

$id

public int $id

This topic's ID number.

$id_board

public int $id_board

The board that contains this topic.

$id_first_msg

public int $id_first_msg

ID number of the first message in this topic.

$id_last_msg

public int $id_last_msg

ID number of the latest message in this topic.

$id_member_started

public int $id_member_started

ID number of the user who started this topic. This will be 0 for topics started by guests.

$id_poll

public int $id_poll

ID number of a poll associated with this topic (if any).

$id_previous_board

public int $id_previous_board

For topics in the recycle board, the ID number of the board that this topic used to be in.

$id_previous_topic

public int $id_previous_topic

For topics in the recycle board, the ID number of the topic that the messages in this topic used to be in.

$id_redirect_topic

public int $id_redirect_topic

ID number of a topic that this topic redirects to (if any).

$info

public static Topic $info

Instance of this class for the requested topic.

$is_approved

public bool $is_approved

Whether this topic has been approved by a moderator.

$is_locked

public bool $is_locked

Whether this topic is locked.

$is_poll

public bool $is_poll

Whether there is a visible poll associated with this topic.

If polls are disabled, this will be false even if $id_poll is not empty.

$is_sticky

public bool $is_sticky

Whether this topic is stickied.

$loaded

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

All loaded instances of this class.

$new_from

public int $new_from

ID number of the first message in this topic that the current user has not previously read.

$notify_prefs

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

The current user's notification preferences regarding this topic.

$num_replies

public int $num_replies

The number of visible replies to this topic.

This will be different that $real_num_replies if some replies have not yet been approved by a moderator.

$num_views

public int $num_views

The number of times this topic has been viewed.

$permissions

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

Contextual permissions that the current user has in this topic.

"Contextual" here means "suitable for use in Utils::$context." Examples include can_move, can_lock, etc.

$real_num_replies

public int $real_num_replies

The true number of replies to this topic, including both approved and unapproved ones.

$started_name

public string $started_name

Name of the user who started this topic.

For topics started by guests, this will be the value of the poster_name field of the first post in the topic.

For topics started by members, this will the real_name of the member who started the topic.

$started_time

public string $started_time

Formatted time string corresponding to $started_timestamp.

$started_timestamp

public int $started_timestamp

Unix timestamp when the first message in this topic was submitted.

$subject

public string $subject

Subject line of this topic's first message.

$topic_id

public static int $topic_id

ID number of the requested topic.

$total_visible_posts

public int $total_visible_posts

The number of visible messages in this topic.

$unapproved_posts

public int $unapproved_posts

The number of unapproved messages in this topic.

$unwatched

public int $unwatched

True if the current user does not want notifications about replies to this topic.

$updated_name

public string $updated_name

Name of the user who most recently replied to this topic.

For replies by guests, this will be the value of the poster_name field of the last post in the topic.

For replies by members, this will the real_name of the member who most recently replied to the topic.

$updated_timestamp

public int $updated_timestamp

Unix timestamp when the latest message in this topic was submitted or modified.

$anyown_permissions

protected static array<string|int, mixed> $anyown_permissions = ['can_move' => 'move', 'can_lock' => 'lock', 'can_delete' => 'remove', 'can_add_poll' => 'poll_add', 'can_remove_poll' => 'poll_remove', 'can_reply' => 'post_reply', 'can_reply_unapproved' => 'post_unapproved_replies']

Permissions with _any/_own versions. $context[YYY] => ZZZ_any/_own. Used by Topic::doPermissions();

$common_permissions

protected static array<string|int, mixed> $common_permissions = ['can_approve' => 'approve_posts', 'can_ban' => 'manage_bans', 'can_sticky' => 'make_sticky', 'can_merge' => 'merge_any', 'can_split' => 'split_any', 'calendar_post' => 'calendar_post', 'can_send_pm' => 'pm_send', 'can_report_moderator' => 'report_any', 'can_moderate_forum' => 'moderate_forum', 'can_issue_warning' => 'issue_warning', 'can_restore_topic' => 'move_any', 'can_restore_msg' => 'move_any', 'can_like' => 'likes_like']

Common permissions to check for this topic. Used by Topic::doPermissions();

$events

protected array<string|int, mixed> $events

IDs of any events that are linked to this topic.

$prop_aliases

protected array<string|int, mixed> $prop_aliases = ['id_topic' => 'id', 'locked' => 'is_locked', 'approved' => 'is_approved', 'topic_started_name' => 'started_name', 'topic_started_time' => 'started_time']

Alternate names for some object properties.

$backcompat

private static array<string|int, mixed> $backcompat = ['prop_names' => ['topic_id' => 'topic']]

BackwardCompatibility settings for this class.

Methods

__construct()

Constructor.

public __construct(int $id[, array<string|int, mixed> $props = [] ]) : object
Parameters
$id : int

The ID number of the topic.

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

Properties to set for this topic.

Return values
object

An instance of this class.

__set()

Sets custom properties.

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

The property name.

$value : mixed

The value to set.

approve()

Approves or unapproves topics.

public static approve(array<string|int, mixed>|int $topics[, bool $approve = true ]) : bool

Doesn't check permissions.

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

Array of topic ids.

$approve : bool = true

Whether to approve the topics. If false, unapproves them instead.

Return values
bool

Whether the operation was successful.

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.

doPermissions()

Determines the current user's permissions in this topic.

public doPermissions() : array<string|int, mixed>

Permission values are stored in $this->permissions and also returned.

Return values
array<string|int, mixed>

Contextual permissions info.

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.

getLikedMsgs()

Gets the IDs of messages in this topic that the current user likes.

public getLikedMsgs() : array<string|int, mixed>
Return values
array<string|int, mixed>

IDs of messages in this topic that the current user likes.

getLinkedEvents()

Returns any calendar events that are linked to this topic.

public getLinkedEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>

getNotificationPrefs()

Gets the current user's notification preferences for this topic.

public getNotificationPrefs() : array<string|int, mixed>

Values are stored in $this->notify_prefs and also returned.

Return values
array<string|int, mixed>

Notification preferences.

load()

Loads information about a topic.

public static load([int|null $id = null ]) : self
Parameters
$id : int|null = null

The ID number of a topic, or null for the current topic.

Return values
self

An instance of this class.

lock()

Sets the locked state for one or more topics.

public static lock(array<string|int, mixed>|int $topics, int $level) : array<string|int, mixed>

Doesn't check permissions. Logs the action and sends notifications.

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

Array of topic IDs.

$level : int

0 = unlocked, 1 = user locked, 2 = moderator locked.

Return values
array<string|int, mixed>

IDs of topics that were changed.

move()

Moves one or more topics to a specific board.

public static move(array<string|int, mixed>|int $topics, int $toBoard) : void

Doesn't check permissions. Determines the source boards for the supplied topics. Handles the moving of mark_read data. Updates the posts count of the affected boards.

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

The ID of a single topic to move or an array containing the IDs of multiple topics to move.

$toBoard : int

The ID of the board to move the topics to.

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.

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

remove()

Removes the passed id_topic's. (permissions are NOT checked here!).

public static remove(array<string|int, mixed>|int $topics[, bool $decreasePostCount = true ][, bool $ignoreRecycling = false ][, bool $updateBoardCount = true ]) : void
Parameters
$topics : array<string|int, mixed>|int

The topics to remove (can be an id or an array of ids).

$decreasePostCount : bool = true

Whether to decrease the users' post counts

$ignoreRecycling : bool = false

Whether to ignore recycling board settings

$updateBoardCount : bool = true

Whether to adjust topic counts for the boards

sticky()

Sets the sticky state for one or more topics.

public static sticky(array<string|int, mixed>|int $topics, bool $sticky_state) : array<string|int, mixed>

Doesn't check permissions. Logs the action and sends notifications.

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

Array of topic IDs.

$sticky_state : bool

True to sticky or false to unsticky.

Return values
array<string|int, mixed>

IDs of topics that were changed.

loadTopicInfo()

Loads primary information about this topic.

protected loadTopicInfo() : void

        
On this page

Search results