Inheritance chain
Your comment model extends several classes. In turn, these are:
-
\IPS\Content\Comment
Provides the features of Comments. The rest of the guides in this section cover implementing these features. -
\IPS\Content
Provides a small number of features which are common to both Content Item models and Content Comment models such as getting the author and working with $databaseColumnMap. -
\IPS\Patterns\ActiveRecord
Provides the functionality to load items from the database, work with their properties, save and delete them. See the Active Records guide for more information on this class.
Basic skeleton
namespace IPS\yourApp; class _Comment extends \IPS\Content\Comment { /** * @brief [ActiveRecord] Multiton Store */ protected static $multitons; /** * @brief Default Values */ protected static $defaultValues = NULL; /** * @brief [Content\Comment] Item Class */ public static $itemClass = 'IPS\yourApp\YourClass'; /** * @brief [ActiveRecord] Database Table */ public static $databaseTable = 'yourapp_comments'; /** * @brief [ActiveRecord] Database Prefix */ public static $databasePrefix = 'comment_'; /** * @brief Title */ public static $title = ‘thing_comments’; /** * @brief Database Column Map */ public static $databaseColumnMap = array( 'item' => 'fid', 'author' => 'mid', 'author_name' => 'author', 'content' => 'text', 'date' => 'date', 'ip_address' => 'ip_address' ); }
Specifying your class properties
Comment models require a few static properties to configure their behavior, most of which are identical to the Content Item model. Many come from the Active Record class.
Required. The application key that the comment belongs to.
Required. The module key that the comment belongs to.
public static $defaultValues = NULL;
Required. Inherited from \IPS\Patterns\ActiveRecord.
These two properties are requirements of \IPS\Patterns\ActiveRecord. They don't need a value assigned; they simply need to be defined.
Required. Inherited from \IPS\Patterns\ActiveRecord.
The name of the database table that stores these comments.
Optional. Inherited from \IPS\Patterns\ActiveRecord.
Specifies the field prefix this table uses.
Required. Features provided by the higher classes your model extends will examine this array to find out what columns certain things are stored as in your database. The following elements are required, and in all cases the value is with the $databasePrefix omitted:
-
item
Required. Should contain the column name that holds the ID value of the content item this comment belongs to. -
author
Required. Should contain the column name that holds the ID number of the member who posted the content. -
content
Required. Should contain the column name that holds the actual comment text. -
date
Required. Should contain the column name that holds a unix timestamp of when the comment was posted. -
ip_address
Required. Should contain the column name that holds the IP address of the user who posted the comment. -
author_name
Optional. Can contain the column name that holds the username of the member who posted the comment. -
first
Optional. Can contain the column name that holds a boolean value indicating if this is the first comment on the item.
Optional. Specifies the template to be used when displaying the comment (see the html() method below). For example:
array( array( 'global', 'core', 'front' ), 'commentContainer' );
Optional. Specifies the template to be used to display the comment form. For example:
array( array( 'forms', 'core', 'front' ), 'commentTemplate' );
Optional. Specifies a prefix to add to language strings used by the model, allowing you to create custom language strings for your purpose.
Available methods on the Comment model
In addition to those provided by \IPS\Patterns\ActiveRecord (which work exactly the same as for content item models), a number of additional methods are available.
Returns the URL to the comment, automatically calculating the the correct page number and including an anchor to the correct page location. This method is already defined for you.
-
$action (string, optional)
If passed, will add a 'do=value' parameter to the URL.
Returns the content item that this comment belongs to.
Returns the \IPS\Member object for the user that posted the content item. For example:
$comment = YourClass::load( 1 ); $user = $comment->author(); echo $comment->name;
Returns the content in a format suitable for use with the data-ipsTruncate widget.
-
$oneLine (boolean, optional, default FALSE)
By default, paragraphs are turned into line break. If this parameter is TRUE, paragraphs are replaced with spaces instead of line breaks, making the truncated content suitable for a one-line display.
Returns a boolean value indicating if the provided member can edit the content item.
-
$member (\IPS\Member, optional)
If provided, uses this member's permissions when performing the check. By default, the currently-logged in member will be used.
Returns a boolean value indicating if the provided member can delete the content item
-
$member (\IPS\Member, optional)
If provided, uses this member's permissions when performing the check. By default, the currently-logged in member will be used.
Returns a boolean value indicating if the provided member has permission to perform the action specified by the $type param in the specified $container (if provided)
-
$type (string, required)
The type of permission being checked. Acceptable values are:- edit
- delete
- move
- hide (if Hiding/Approving is enabled)
- unhide (if Hiding/Approving is enabled)
- view_hidden (if Hiding/Approving is enabled)
-
$member (\IPS\Member, optional)
If provided, uses this member's permissions when performing the check. By default, the currently-logged in member will be used. -
$container (\IPS\Node\Model, optional)
If provided, checks the permission specifically in this container node.
Performs the specified moderation action. Throws OutOfRangeException if the member does not have permission to perform this action.
-
$type (string, required)
The type of moderation action being performed. Consult the list in the previous method for acceptable values. -
$member (\IPS\Member, optional)
If provided, uses this member's permissions when performing the check. By default, the currently-logged in member will be used. -
$reason (string, optional)
Used only for hide/unhide actions; specifies the reason the action is being taken.
Returns true or false indicating whether this is the first comment on the content item.
Indicates whether the member is ignoring the author of the comment.
-
$member (\IPS\Member, optional)
If provided, uses this members ignore preference when checking for ignore status. By default, the currently-logged in member will be used.
Returns a string that can be used in templates to show when the comment was posted, e.g. "Posted 2 hours ago".
Returns the HTML to display the comment, wrapped in its comment template.
Report Document