DraftPM
extends Draft
in package
Represents a personal message draft.
This class extends SMF\Draft for the special case of personal message drafts.
Table of Contents
Properties
- $board : int
- $body : string
- $icon : string
- $id : int
- $locked : bool
- $member : int
- $poster_time : int
- $recipients : array<string|int, mixed>
- $reply_to : int
- $smileys_enabled : bool
- $sticky : bool
- $subject : string
- $topic : int
- $type : int
- $enabled_setting : string
- $permission : string
Methods
- __construct() : mixed
- Constructor.
- delete() : bool
- Deletes one or more drafts from the database.
- prepare() : void
- Prepares the draft data for use in the personal message editor.
- save() : bool
- Saves a draft in the user_drafts table.
- showInEditor() : bool
- Loads a group of personal message drafts for the given user.
- showInProfile() : void
- Show all personal message drafts that belong to the given user.
- read() : array<string|int, mixed>
- Retrieves this drafts' data from the user_drafts table.
- saveToDatabase() : bool
- Saves this draft to the database.
- setProperties() : void
- Sets draft properties based on submitted form data.
- xml() : void
- Returns an XML response to an autosave AJAX request.
Properties
$board
public
int
$board
= 0
ID of the board that this draft is intended to be posted in. Only applies to post drafts.
$body
public
string
$body
= ''
The body of this draft.
$icon
public
string
$icon
= 'xx'
The icon of this draft. Only applies to post drafts.
$id
public
int
$id
= 0
The ID number of this draft.
$locked
public
bool
$locked
= false
Whether this draft post is intended to be locked when posted. Only applies to post drafts.
$member
public
int
$member
= 0
ID of the author of this draft.
$poster_time
public
int
$poster_time
= 0
When this draft was created.
$recipients
public
array<string|int, mixed>
$recipients
= ['to' => [], 'bcc' => []]
Intended recipients for this draft. Only applies to personal message drafts.
$reply_to
public
int
$reply_to
= 0
ID of the personal message that this draft is replying to. Only applies to personal message drafts.
$smileys_enabled
public
bool
$smileys_enabled
= true
Whether smileys are enabled in this draft.
$sticky
public
bool
$sticky
= false
Whether this draft post is intended to be stickied when posted. Only applies to post drafts.
$subject
public
string
$subject
= ''
The subject of this draft.
$topic
public
int
$topic
= 0
ID of the topic that this draft is intended to be posted in. Only applies to post drafts.
$type
public
int
$type
= 1
The type of this draft. 0 = post; 1 = personal message.
$enabled_setting
protected
string
$enabled_setting
= 'drafts_pm_enabled'
Config::$modSettings setting that enables/disables this type of draft.
$permission
protected
string
$permission
= 'pm_draft'
Permission that allows the user to save this type of draft.
Methods
__construct()
Constructor.
public
__construct([int $id_draft = 0 ][, bool $check = true ][, array<string|int, mixed> $recipientList = [] ]) : mixed
Parameters
- $id_draft : int = 0
-
ID of the draft to load.
- $check : bool = true
-
Validate that this draft belongs to the current user.
- $recipientList : array<string|int, mixed> = []
-
Only used by the DraftPM class.
delete()
Deletes one or more drafts from the database.
public
static delete(int|array<string|int, mixed> $drafts[, bool $check = true ]) : bool
Optionally validates that the drafts belong to the current user.
Parameters
- $drafts : int|array<string|int, mixed>
-
The IDs of one or more drafts to delete.
- $check : bool = true
-
Whether or not to check that the drafts belong to the current user.
Return values
bool —Whether the drafts were deleted.
prepare()
Prepares the draft data for use in the personal message editor.
public
prepare() : void
save()
Saves a draft in the user_drafts table.
public
save(array<string|int, mixed> &$post_errors) : bool
Does nothing if this type of draft (i.e. post or PM) is disabled.
If this is a new draft, creates a new database entry for it. If this is an existing draft, updates the current database entry.
If necessary, updates $post_errors for display in the template.
Parameters
- $post_errors : array<string|int, mixed>
-
Any errors encountered trying to save this draft.
Return values
bool —Whether the draft was saved successfully.
showInEditor()
Loads a group of personal message drafts for the given user.
public
static showInEditor(int $member_id[, bool|int $reply_to = false ]) : bool
Used in the posting screens to allow draft selection.
Parameters
- $member_id : int
-
ID of the member to show drafts for
- $reply_to : bool|int = false
-
ID of the PM that is being replied to.
Return values
bool —Whether the drafts (if any) were loaded.
showInProfile()
Show all personal message drafts that belong to the given user.
public
static showInProfile([int $memID = -1 ]) : void
Uses the showdraft template. The UI allows for deleting and loading/editing of drafts.
Parameters
- $memID : int = -1
-
ID of the user whose drafts should be loaded.
read()
Retrieves this drafts' data from the user_drafts table.
protected
read([bool $check = true ]) : array<string|int, mixed>
Optionally validates that this draft belongs to the current user.
Parameters
- $check : bool = true
-
Validate that this draft belongs to this user. Default: true.
Return values
array<string|int, mixed> —Data about the draft. Empty if draft was not found.
saveToDatabase()
Saves this draft to the database.
protected
saveToDatabase() : bool
Return values
bool —Whether the save operation was successful.
setProperties()
Sets draft properties based on submitted form data.
protected
setProperties([array<string|int, mixed> $recipientList = [] ]) : void
Parameters
- $recipientList : array<string|int, mixed> = []
-
ID numbers of members the PM will be sent to, grouped into 'to' and 'bcc' sub-arrays. Only applies to PM drafts.
xml()
Returns an XML response to an autosave AJAX request.
protected
static xml(int $id_draft) : void
Provides the ID of the draft saved and the time it was saved.
Parameters
- $id_draft : int