Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

Post class.

Copyright: 2019 Ryan Wyllie <ryan@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 357 lines (10 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: post  - X-Ref

Post class.

__construct(int $id,int $discussionid,int $parentid,int $authorid,int $timecreated,int $timemodified,bool $mailed,string $subject,string $message,int $messageformat,bool $messagetrust,bool $hasattachments,int $totalscore,bool $mailnow,bool $deleted,int $privatereplyto,?int $wordcount,?int $charcount)   X-Ref
Constructor.

param: int $id ID
param: int $discussionid The id of the discussion this post belongs to
param: int $parentid The id of the post that this post is replying to. Zero if it isn't a reply.
param: int $authorid The id of user who authored the post
param: int $timecreated Timestamp for when the post was created
param: int $timemodified Timestamp for when the post last modified
param: bool $mailed If the post has been mailed
param: string $subject Post subject
param: string $message Post message
param: int $messageformat Format of the post message
param: bool $messagetrust Is this a trusted message, i.e. created by a trusted user.
param: bool $hasattachments Does the post have attachments
param: int $totalscore Total score
param: bool $mailnow Should this post be mailed immediately
param: bool $deleted Is the post deleted
param: int $privatereplyto Which user this reply is intended for in a private reply situation

get_id()   X-Ref
Get the post id.

return: int

get_discussion_id()   X-Ref
Get the discussion id.

return: int

get_parent_id()   X-Ref
Get the id of the parent post. Returns zero if this post is not a reply.

return: int

has_parent()   X-Ref
Does this post have a parent? I.e. is it a reply?

return: bool

get_author_id()   X-Ref
Get the id of the user that authored the post.

return: int

get_time_created()   X-Ref
Get the timestamp for when this post was created.

return: int

get_time_modified()   X-Ref
Get the timestamp for when this post was last modified.

return: int

has_been_mailed()   X-Ref
Has this post been mailed?

return: bool

get_subject()   X-Ref
Get the post subject.

return: string

get_message()   X-Ref
Get the post message.

return: string

get_message_format()   X-Ref
Get the post message format.

return: int

is_message_trusted()   X-Ref
Is this a trusted message? I.e. was it authored by a trusted user?

return: bool

has_attachments()   X-Ref
Does this post have attachments?

return: bool

get_total_score()   X-Ref
Get the total score.

return: int

should_mail_now()   X-Ref
Should this post be mailed now?

return: bool

is_deleted()   X-Ref
Is this post deleted?

return: bool

is_private_reply()   X-Ref
Is this post private?

return: bool

get_private_reply_recipient_id()   X-Ref
Get the id of the user that this post was intended for.

return: int

get_age()   X-Ref
Get the post's age in seconds.

return: int

is_owned_by_user(stdClass $user)   X-Ref
Check if the given user authored this post.

param: stdClass $user The user to check.
return: bool

is_private_reply_intended_for_user(stdClass $user)   X-Ref
Check if the given post is a private reply intended for the given user.

param: stdClass $user The user to check.
return: bool

get_wordcount()   X-Ref
Returns the word count.

return: int|null

get_charcount()   X-Ref
Returns the char count.

return: int|null

add_message_counts(\stdClass $record)   X-Ref
This methods adds/updates forum posts' word count and char count attributes based on $data->message.

param: \stdClass $record A record ready to be inserted / updated in DB.
return: void.