Notifications
This articles details how to setup notifications in ArrowChat. These integrate with your site and do things such as notifying your users there is a new post on their profile.
Sections in this article
Setup and Understanding
First, you need to understand how notifications work and the basic process of installing them. You need to insert a database entry into ArrowChat whenever the action occurs. For example, if you want ArrowChat to notify users of a photo comment, you need to inset an entry into the arrowchat_notifications
table when a user comments on their photo.
Example
function add_photo_comment()
{
// Process the photo comment
if ($comment)
{
// Insert the photo comment
$msg = "Success! The comment was added to the user's photo";
// BEGIN ARROWCHAT NOTIFICATION
$sql = "INSERT INTO arrowchat_notifications (to_id, author_id, author_name, type, alert_time)
VALUES ('".$to_id."', '".$author_id."', '".$author_name."', '1', '".time()."')";
mysql_query($sql);
// END ARROWCHAT NOTIFICATION
}
else
{
$error = "You did not enter a comment";
}
}
The part that we need to insert is the SQL statement:
// BEGIN ARROWCHAT NOTIFICATION
$sql = "INSERT INTO arrowchat_notifications (to_id, author_id, author_name, type, alert_time)
VALUES ('".$to_id."', '".$author_id."', '".$author_name."', '1', '".time()."')";
mysql_query($sql);
// END ARROWCHAT NOTIFICATION
We'll go into more detail about the SQL in the next section.
Sample MySQL
All you need to do is add a row into the arrowchat_notifications
table to enable notifications. An example of the MySQL insert will be presented in this section. You do not have to use this exact code just as long as the database entry is added with the proper values.
Insert Values
Field Name | Field Type | Required? | Description |
---|---|---|---|
to_id | int | Yes | The user ID of the user that should receive the notification. |
author_id | int | No | The user ID of the user that sent the notification. Can be left blank if none. |
author_name | varchar | No | The name of the user that sent the notification. Can be left blank if none. |
type | int | Yes | The type of notification. You need to create a notification markup in the ArrowChat admin panel and then insert the number of that markup as the type. |
alert_time | int | Yes | The unix time of when the notification was sent. |
misc1 | varchar | No | A miscellaneous field that can be used for anything or left blank. |
misc2 | varchar | No | A miscellaneous field that can be used for anything or left blank. |
misc3 | varchar | No | A miscellaneous field that can be used for anything or left blank. |
Example Code
$sql = "INSERT INTO arrowchat_notifications (to_id, author_id, author_name, type, alert_time, misc1, misc2, misc3)
VALUES ('".$to_id."', '".$author_id."', '".$author_name."', '1', '".time()."', '', '', '')";
mysql_query($sql);
Creating a New Notification
In the ArrowChat admin panel under Manage > Notifications you can see a list of predefined notifications or create a new one. If you want to use an existing one, click Edit in order to get the Notification Number to be used as the type
in the SQL select statement.
If you create a new notification, you'll need to create your own custom HTML in the Notification Markup input box. This is the HTML that will be shown to the front-end user. You can look at other notification's markup to help you.
Variables that can be used in the Markup
{author_name} | The name of the user that sent the notification. |
{author_id} | The user ID of the user that sent the notification. |
{longago} | How long ago the notification was sent including the word. E.g. 4 seconds ago, 15 minutes ago, etc. |
{message_time} | The time the notification was sent. |
{misc1} | Outputs whatever you put into the misc1 field in the database. |
{misc2} | Outputs whatever you put into the misc2 field in the database. |
{misc3} | Outputs whatever you put into the misc3 field in the database. |