DraftPM
extends Draft
in package
Uses
BackwardCompatibility
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
- $backcompat : array<string|int, mixed>
Methods
- __construct() : mixed
- Constructor.
- delete() : bool
- Deletes one or more drafts from the database.
- exportStatic() : void
- Provides a way to export a class's public static properties and methods to global namespace.
- 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.
$backcompat
private
static array<string|int, mixed>
$backcompat
= ['func_names' => ['showInEditor' => 'showInEditor', 'showInProfile' => 'showPMDrafts']]
BackwardCompatibility settings for this class.
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.
exportStatic()
Provides a way to export a class's public static properties and methods to global namespace.
public
static exportStatic() : void
To do so:
- Use this trait in the class.
- 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.
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