Documentation

Topic
in package
implements ArrayAccess 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

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>
$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.
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.
getNotificationPrefs()  : array<string|int, mixed>
Gets the current user's notification preferences for this topic.
load()  : object
Loads information about a topic.
lock()  : void
Locks a topic... either by way of a moderator or the topic starter.
move()  : mixed
Moves one or more topics to a specific board. (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
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.
prepareLikesContext()  : array<string|int, mixed>
Backward compatibility wrapper for the getLikedMsgs method.
remove()  : mixed
Removes the passed id_topic's. (permissions are NOT checked here!).
sticky()  : void
Sticky a topic.
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();

$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 = ['func_names' => ['lock' => 'LockTopic', 'sticky' => 'Sticky', 'approve' => 'approveTopics', 'move' => 'moveTopics', 'remove' => 'removeTopics', 'prepareLikesContext' => 'prepareLikesContext'], '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> $topics[, bool $approve = true ]) : bool
Parameters
$topics : array<string|int, mixed>

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.

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

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.

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 ]) : object
Parameters
$id : int|null = null

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

Return values
object

An instance of this class.

lock()

Locks a topic... either by way of a moderator or the topic starter.

public static lock() : void

What this does:

  • locks a topic, toggles between locked/unlocked/admin locked.
  • only admins can unlock topics locked by other admins.
  • requires the lock_own or lock_any permission.
  • logs the action to the moderator log.
  • returns to the topic after it is done.
  • it is accessed via ?action=lock.

move()

Moves one or more topics to a specific board. (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

public static move(array<string|int, mixed>|int $topics, int $toBoard) : mixed
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.

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.

prepareLikesContext()

Backward compatibility wrapper for the getLikedMsgs method.

public static prepareLikesContext(int $topic) : array<string|int, mixed>
Parameters
$topic : int

The topic ID to fetch the info from.

Return values
array<string|int, mixed>

An array of IDs of messages in the specified topic that the current user likes

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 ]) : mixed
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()

Sticky a topic.

public static sticky() : void

Can't be done by topic starters - that would be annoying! What this does:

  • stickies a topic - toggles between sticky and normal.
  • requires the make_sticky permission.
  • adds an entry to the moderator log.
  • when done, sends the user back to the topic.
  • accessed via ?action=sticky.

loadTopicInfo()

Loads primary information about this topic.

protected loadTopicInfo() : void

        
On this page

Search results