ci_pm  0.9
CodeIgniter Private Messaging Plugin
 All Data Structures Functions
Public Member Functions | Data Fields
Pm_model Class Reference

Pm Model. More...

Inheritance diagram for Pm_model:

Public Member Functions

 __construct ($dateformat="Y.m.d - H:i:s", $enforce_field_types=TRUE)
 Pm_model constructor. More...
 
 initialize ($dateformat="d.m.Y - H:i", $enforce_field_types=TRUE)
 initialize More...
 
 get_messages ($type=MSG_NONDELETED)
 Get messages. More...
 
 get_message ($msg_id)
 Get message. More...
 
 get_recipients ($msg_id)
 Get recipients. More...
 
 get_author ($msg_id)
 Get author. More...
 
 flag_read ($msg_id, $allow_notify=TRUE)
 Flag read. More...
 
 flag_deleted ($msg_id, $status=1)
 Flag message deleted. More...
 
 flag_undeleted ($msg_id)
 Flag message undeleted. More...
 
 send_message ($recipients, $subject, $body, $notify=TRUE)
 Send message. More...
 

Data Fields

 $messages = array()
 
 $recipients = array()
 

Detailed Description

Pm Model.

The model works using two tables: table1 contains the messages, table2 the referencing between the messages and the recipients - by message and user IDs.

NOTE: All operations are performed for the current user, given by user id. This id is gotten from the User_model which contains a dummy method always returning the first user id found. Replace this method with a more meaningful own method.

The class can be initialized by calling initialize which will allow changing dateformat and enforce_field_types vars. It makes use of the Table_model class to read, write and update table data.

Copyright (c) 2015 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author
Balint Morvai
Version
0.9

Constructor & Destructor Documentation

__construct (   $dateformat = "Y.m.d - H:i:s",
  $enforce_field_types = TRUE 
)

Pm_model constructor.

Pm_model constructor.

Parameters
dateformatstring: format to display dates in
enforce_field_typesbool: setting whether to enforce field types in PHP by cast
Returns
void

Member Function Documentation

flag_deleted (   $msg_id,
  $status = 1 
)

Flag message deleted.

Flag a message (by id) as deleted. Note: depending on whether the user was recipient or author the message will be flaged deleted in table2 or table1, i.e. it will be determined automatically if the msg is to be deleted from sent-folder or inbox of the user. Optionally through 2nd param a costum value can be supplied to update the "deleted" field to, while the default is 1. This also can be used to restore the msg instead of deleting it, by e.g. passing NULL. NOTE: The "DDATE" will be set to "NOW" regardeless of the "status" value passed. Returns TRUE if successful, FALSE otherwise.

Parameters
msg_idinteger: db message id of the message to flag as deleted
statusinteger: optional value to update "deleted" field to, default 1
Returns
bool
flag_read (   $msg_id,
  $allow_notify = TRUE 
)

Flag read.

Flag a message (by id) as read. If optional 2nd param is set FALSE, the sender will not get to know that msg was read. Returns TRUE if successful, FALSE otherwise.

Parameters
msg_idinteger: db message id of the message to flag as read
allow_notifybool: boolean indicating whether author may be notified if requested
Returns
bool
flag_undeleted (   $msg_id)

Flag message undeleted.

Flag a message (by id) as NOT deleted. Note: This method is just using the flag_deleted method with "NULL" as 2nd param. This will make the DDATE be the "restored date". Returns TRUE if successful, FALSE otherwise.

Parameters
msg_idinteger: db message id of the message to flag as deleted
Returns
bool
get_author (   $msg_id)

Get author.

Get user id of author of a specific message given by msg id. Do that for any message, not just the ones authored by the logged in user. Returns user id directly if msg found or -1 otherwise.

Parameters
msg_idinteger: message id of the message to get author for
Returns
int
get_message (   $msg_id)

Get message.

Get a specific message by message id to or from the logged in user and return CI results array.

Parameters
msg_idinteger: message id of the message to get
Returns
array
get_messages (   $type = MSG_NONDELETED)

Get messages.

Get messages to or from the logged in user and return CI results array. Get messages of the given type, see below. Order results by date created, descending.

Parameters
typeinteger: message type to get. Use one of the following: MSG_NONDELETED: received by user, not deleted (default); MSG_DELETED: received or sent by user, deleted; MSG_UNREAD: received by user, not deleted, not read; MSG_SENT: sent by user, not deleted; type < 0: get ALL messages, deleted or not, sent to or by this user
Returns
array
get_recipients (   $msg_id)

Get recipients.

Get user ids of all recipients of a specific message given by msg id. Do that for any message, not just the ones authored by the logged in user. Returns CI result array with recipient ids or empty array.

Parameters
msg_idinteger: message id of the message to get recipients for
Returns
array
initialize (   $dateformat = "d.m.Y - H:i",
  $enforce_field_types = TRUE 
)

initialize

Initializes values for this class.

Parameters
dateformatstring: format to display dates in
enforce_field_typesbool: setting whether to enforce field types in PHP by cast
Returns
void
send_message (   $recipients,
  $subject,
  $body,
  $notify = TRUE 
)

Send message.

Add a new personal message to table1 and recipients to table2. Note: sending messages to oneself is not allowed and this should stay this way, since it would cause problems with deleting & restoring messages. Returns TRUE if successful, returns FALSE otherwise.

Parameters
recipientsinteger: array of one or more user ids of the recipients (can be array or single var) of the message to add.
subjectstring: subject of the message
bodystring: message text
notifybool: notify flag, whether to notify sender upon read, default TRUE
Returns
bool

The documentation for this class was generated from the following file: