Skip to main content
The Forum model represents a forum section in ForkBB. It extends DataModel and provides properties and methods for managing forums, subforums, moderators, and forum-specific permissions.

Location

app/Models/Forum/Forum.php

Properties

id
int
Unique forum identifier
forum_name
string
Forum display name
parent_forum_id
int|null
Parent forum ID (null for top-level forums)
num_topics
int
Total number of topics in the forum
num_posts
int
Total number of posts in the forum
last_post
int
Timestamp of the last post
last_post_id
int
ID of the last post
last_poster
string
Username of the last poster
last_topic
string
Title of the last topic with activity
post_topics
int|null
Permission to create topics (1=allowed, null=use group default)
post_replies
int|null
Permission to reply to topics (1=allowed, null=use group default)
redirect_url
string|null
Redirect URL if forum is a redirect link
sort_by
int
Topic sorting method (0=last post desc, 1=posted desc, 2=subject, etc.)
page
int
Current page number

Computed Properties

parent
Forum|null
Parent forum object. Returns null for root forum (id=0).
name
string
Forum name (alias for forum_name)
friendly
string
URL-friendly forum name for links
subforums
array
Array of direct subforum objects indexed by forum ID
descendants
array
Array of all descendant forums (including nested subforums)
moderators
array
Array of moderator data with name and link for each moderator
tree
Forum
Aggregated statistics for this forum and all descendants
numPages
int
Total number of pages based on topic count and user display settings
pagination
array
Pagination array for forum pages

Permission Properties

canCreateTopic
bool
Returns true if current user can create topics in this forum
canMarkRead
bool
Returns true if current user can mark all topics as read
canSubscription
bool
Returns true if current user can subscribe to forum updates
URL to the forum page
URL to search for new posts in this forum
URL to the last post in the forum
URL to create a new topic
URL to mark all topics as read
URL to subscribe to forum updates
URL to unsubscribe from forum updates

Methods

modAdd()

Adds one or more users as moderators to the forum.
public function modAdd(User ...$users): void
users
User...
Variable number of User objects to add as moderators
Example:
$forum = $container->forums->get(5);
$user1 = $container->users->load(123);
$user2 = $container->users->load(456);

$forum->modAdd($user1, $user2);
// Save changes
$container->forums->update($forum);

modDelete()

Removes one or more users from the forum’s moderator list.
public function modDelete(User ...$users): void
users
User...
Variable number of User objects to remove as moderators
Example:
$forum = $container->forums->get(5);
$user = $container->users->load(123);

$forum->modDelete($user);
$container->forums->update($forum);

hasPage()

Checks if the current page number is valid for this forum.
public function hasPage(): bool
Returns: bool - true if page is valid Example:
$forum = $container->forums->get(5);
$forum->page = 3;

if ($forum->hasPage()) {
    $topics = $forum->pageData();
} else {
    // Invalid page number
}

pageData()

Returns an array of topics for the current page.
public function pageData(): array
Returns: Array of topic objects Throws: InvalidArgumentException if page number is invalid Example:
$forum = $container->forums->get(5);
$forum->page = 1;

$topics = $forum->pageData();
foreach ($topics as $topic) {
    echo "{$topic->name}\n";
}

calcPage()

Calculates which page a specific topic is on within the forum.
public function calcPage(int $tid): void
tid
int
Topic ID to find
Example:
$forum = $container->forums->get(5);
$forum->calcPage(789); // Calculate page for topic 789

if ($forum->page !== null) {
    echo "Topic is on page {$forum->page}";
}

Usage Example

// Load a forum
$forum = $container->forums->get(10);

// Display forum info
echo "<h2>{$forum->name}</h2>";
echo "<p>Topics: {$forum->num_topics}, Posts: {$forum->num_posts}</p>";

// Check permissions
if ($forum->canCreateTopic) {
    echo "<a href=\"{$forum->linkCreateTopic}\">New Topic</a>";
}

// Display subforums
foreach ($forum->subforums as $subforum) {
    echo "<a href=\"{$subforum->link}\">{$subforum->name}</a><br>";
}

// Get topics for page 1
$forum->page = 1;
if ($forum->hasPage()) {
    $topics = $forum->pageData();
    foreach ($topics as $topic) {
        echo "<div>{$topic->name}</div>";
    }
}

// Display moderators
if (!empty($forum->moderators)) {
    echo "Moderators: ";
    foreach ($forum->moderators as $mod) {
        if ($mod['link']) {
            echo "<a href=\"{$mod['link']}\">{$mod['name']}</a> ";
        } else {
            echo "{$mod['name']} ";
        }
    }
}

// Get tree statistics (including descendants)
$stats = $forum->tree;
echo "Total posts (including subforums): {$stats->num_posts}";

Sorting Options

The sort_by property controls topic sorting:
  • 0 - Last post DESC (default)
  • 1 - Posted DESC
  • 2 - Subject ASC
  • 4 - Last post ASC
  • 5 - Posted ASC
  • 6 - Subject DESC