Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
comment Class Reference

Comment is helper class to add/delete comments anywhere in moodle. More...

Public Member Functions

 __construct (stdClass $options)
 Construct function of comment class, initialise class members.
 
moodle_database add ($content, $format=FORMAT_MOODLE)
 Add a new comment.
 
 can_delete ($comment)
 Returns true if the user can delete this comment.
 
 can_post ()
 Returns true if the user can add comments against this comment description.
 
 can_view ()
 Returns true if the user is able to view comments.
 
moodle_database count ()
 Returns the number of comments associated with the details of this object.
 
 delete ($comment)
 Delete a comment.
 
 get_autostart ()
 Return autostart.
 
 get_cid ()
 Return the cid.
 
 get_cm ()
 Returns the course module associated with the comment.
 
 get_commentarea ()
 Returns the comment area associated with the commentarea.
 
 get_comments ($page='', $sortdirection='DESC')
 Return matched comments.
 
 get_component ()
 Returns the component associated with the comment.
 
 get_compontent ()
 Do not call! I am a deprecated method because of the typo in my name.
 
 get_context ()
 Returns the context associated with the comment.
 
 get_courseid ()
 Returns the course id associated with the comment.
 
 get_displaycancel ()
 Return display cancel.
 
 get_displaytotalcount ()
 Return display total count.
 
 get_fullwidth ()
 Return fullwidth.
 
 get_itemid ()
 Returns the item id associated with the comment.
 
 get_linktext ()
 Return the link text.
 
moodle_page get_nojslink (moodle_page $page=null)
 Gets a link for this page that will work with JS disabled.
 
 get_notoggle ()
 Return no toggle.
 
stdClass get_pagination ($page=0)
 Returns HTML to display a pagination bar.
 
 get_template ()
 Return the template.
 
 initialise_javascript (moodle_page $page)
 Initialises the JavaScript that enchances the comment API.
 
 output ($return=true)
 Prepare comment code in html.
 
core_renderer print_comment ($cmt, $nonjs=true)
 Returns an array containing comments in HTML format.
 
 print_comments ($page=0, $return=true, $nonjs=true)
 Print comments.
 
 set_autostart ($newvalue=true)
 Sets the value of the autostart option.
 
 set_component ($component)
 Sets the component.
 
 set_displaycancel ($newvalue=true)
 Sets the displaycancel option.
 
 set_displaytotalcount ($newvalue=true)
 Sets the displaytotalcount option.
 
 set_fullwidth ($fullwidth=true)
 Make the comments textarea fullwidth.
 
 set_notoggle ($newvalue=true)
 Sets the value of the notoggle option.
 
 set_post_permission ($value)
 Determines if the user can post a comment.
 
 set_view_permission ($value)
 Determines if the user can view the comment.
 

Static Public Member Functions

static delete_comments ($param)
 delete by context, commentarea and itemid
 
static init (moodle_page $page=null)
 Receive nonjs comment parameters.
 
static reset_course_page_comments ($context)
 Delete page_comments in whole course, used by course reset.
 

Protected Member Functions

 get_component_select_sql ($alias='')
 Returns an SQL fragment and param for selecting on component.
 
 validate ($params=array())
 Revoke validate callbacks.
 

Protected Attributes

bool $autostart = false
 If set to true comments are automatically loaded as soon as the page loads.
 
stdClass $comment_param
 comment paramaters for callback.
 
bool $displaycancel = false
 If set to true a cancel button will be shown on the form used to submit comments.
 
bool $displaytotalcount = false
 If set to true the total count of comments is displayed when displaying comments.
 
bool $fullwidth = false
 Set to true to remove the col attribute from the textarea making it full width.
 
bool $notoggle = false
 If set to true then comment sections won't be able to be opened and closed instead they will always be visible.
 
int $totalcommentcount = null
 The number of comments associated with this comments params.
 

Detailed Description

Comment is helper class to add/delete comments anywhere in moodle.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

comment::__construct ( stdClass $options)

Construct function of comment class, initialise class members.

Parameters
stdClass$options{ context => context context to use for the comment [required] component => string which plugin will comment being added to [required] itemid => int the id of the associated item (forum post, glossary item etc) [required] area => string comment area cm => stdClass course module course => course course object client_id => string an unique id to identify comment area autostart => boolean automatically expend comments showcount => boolean display the number of comments displaycancel => boolean display cancel button notoggle => boolean don't show/hide button linktext => string title of show/hide button }

Member Function Documentation

◆ add()

moodle_database comment::add ( $content,
$format = FORMAT_MOODLE )

Add a new comment.

$DB

Parameters
string$content
int$format
Return values
stdClass

◆ can_delete()

comment::can_delete ( $comment)

Returns true if the user can delete this comment.

The user can delete comments if it is one they posted and they can still make posts, or they have the capability to delete comments.

A database call is avoided if a comment record is passed.

Parameters
int | stdClass$commentThe id of a comment, or a comment record.
Return values
bool

◆ can_post()

comment::can_post ( )

Returns true if the user can add comments against this comment description.

Return values
bool

◆ can_view()

comment::can_view ( )

Returns true if the user is able to view comments.

Return values
bool

◆ count()

moodle_database comment::count ( )

Returns the number of comments associated with the details of this object.

$DB

Return values
int

◆ delete()

comment::delete ( $comment)

Delete a comment.

Parameters
int | stdClass$commentThe id of a comment, or a comment record.
Return values
bool

◆ delete_comments()

static comment::delete_comments ( $param)
static

delete by context, commentarea and itemid

Parameters
stdClass | array$param{ contextid => int the context in which the comments exist [required] commentarea => string the comment area [optional] itemid => int comment itemid [optional] }
Return values
boolean

◆ get_autostart()

comment::get_autostart ( )

Return autostart.

Since
3.1
Return values
bool

◆ get_cid()

comment::get_cid ( )

Return the cid.

Since
3.1
Return values
string

◆ get_cm()

comment::get_cm ( )

Returns the course module associated with the comment.

Return values
stdClass

◆ get_commentarea()

comment::get_commentarea ( )

Returns the comment area associated with the commentarea.

Return values
stdClass

◆ get_comments()

comment::get_comments ( $page = '',
$sortdirection = 'DESC' )

Return matched comments.

Parameters
int$page
str$sortdirectionsort direction, ASC or DESC
Return values
array

◆ get_component()

comment::get_component ( )

Returns the component associated with the comment.

Return values
string

◆ get_component_select_sql()

comment::get_component_select_sql ( $alias = '')
protected

Returns an SQL fragment and param for selecting on component.

Parameters
string$alias
Return values
array

◆ get_compontent()

comment::get_compontent ( )

Do not call! I am a deprecated method because of the typo in my name.

Deprecated
since 2.9
See also
comment\get_component()
Return values
string

◆ get_context()

comment::get_context ( )

Returns the context associated with the comment.

Return values
stdClass

◆ get_courseid()

comment::get_courseid ( )

Returns the course id associated with the comment.

Return values
int

◆ get_displaycancel()

comment::get_displaycancel ( )

Return display cancel.

Since
3.1
Return values
bool

◆ get_displaytotalcount()

comment::get_displaytotalcount ( )

Return display total count.

Since
3.1
Return values
bool

◆ get_fullwidth()

comment::get_fullwidth ( )

Return fullwidth.

Since
3.1
Return values
bool

◆ get_itemid()

comment::get_itemid ( )

Returns the item id associated with the comment.

Return values
int

◆ get_linktext()

comment::get_linktext ( )

Return the link text.

Since
3.1
Return values
string

◆ get_nojslink()

moodle_page comment::get_nojslink ( moodle_page $page = null)

Gets a link for this page that will work with JS disabled.

$PAGE

Parameters
moodle_page$page
Return values
moodle_url

◆ get_notoggle()

comment::get_notoggle ( )

Return no toggle.

Since
3.1
Return values
bool

◆ get_pagination()

stdClass comment::get_pagination ( $page = 0)

Returns HTML to display a pagination bar.

$CFG @global core_renderer $OUTPUT

Parameters
int$page
Return values
string

◆ get_template()

comment::get_template ( )

Return the template.

Since
3.1
Return values
string

◆ init()

static comment::init ( moodle_page $page = null)
static

Receive nonjs comment parameters.

Parameters
moodle_page$pageThe page object to initialise comments within If not provided the global $PAGE is used

◆ initialise_javascript()

comment::initialise_javascript ( moodle_page $page)

Initialises the JavaScript that enchances the comment API.

Parameters
moodle_page$pageThe moodle page object that the JavaScript should be initialised for.

◆ output()

comment::output ( $return = true)

Prepare comment code in html.

Parameters
boolean$return
Return values
string|void

◆ print_comment()

core_renderer comment::print_comment ( $cmt,
$nonjs = true )

Returns an array containing comments in HTML format.

$OUTPUT

Parameters
stdClass$cmt{ id => int comment id content => string comment content format => int comment text format timecreated => int comment's timecreated profileurl => string link to user profile fullname => comment author's full name avatar => string user's avatar delete => boolean does user have permission to delete comment? }
bool$nonjs
Return values
array

◆ print_comments()

comment::print_comments ( $page = 0,
$return = true,
$nonjs = true )

Print comments.

Parameters
int$page
bool$returnreturn comments list string or print it out
bool$nonjsprint nonjs comments list or not?
Return values
string|void

◆ reset_course_page_comments()

static comment::reset_course_page_comments ( $context)
static

Delete page_comments in whole course, used by course reset.

Parameters
stdClass$contextcourse context

◆ set_autostart()

comment::set_autostart ( $newvalue = true)

Sets the value of the autostart option.

If set to true then the comments will be loaded during page load. Normally this happens only once the user expands the comment section.

Parameters
bool$newvalue

◆ set_component()

comment::set_component ( $component)

Sets the component.

This method shouldn't be public, changing the component once it has been set potentially invalidates permission checks. A coding_error is now thrown if code attempts to change the component.

Exceptions
coding_exceptionif you try to change the component after it has been set.
Parameters
string$component

◆ set_displaycancel()

comment::set_displaycancel ( $newvalue = true)

Sets the displaycancel option.

If set to true then a cancel button will be shown when using the form to post comments.

Parameters
bool$newvalue

◆ set_displaytotalcount()

comment::set_displaytotalcount ( $newvalue = true)

Sets the displaytotalcount option.

If set to true then the total number of comments will be displayed when printing comments.

Parameters
bool$newvalue

◆ set_fullwidth()

comment::set_fullwidth ( $fullwidth = true)

Make the comments textarea fullwidth.

Since
2.8.1 + 2.7.4
Parameters
bool$fullwidth

◆ set_notoggle()

comment::set_notoggle ( $newvalue = true)

Sets the value of the notoggle option.

If set to true then the user will not be able to expand and collase the comment section.

Parameters
bool$newvalue

◆ set_post_permission()

comment::set_post_permission ( $value)

Determines if the user can post a comment.

Parameters
bool$value

◆ set_view_permission()

comment::set_view_permission ( $value)

Determines if the user can view the comment.

Parameters
bool$value

◆ validate()

comment::validate ( $params = array())
protected

Revoke validate callbacks.

Parameters
stdClass$paramsaddtionall parameters need to add to callbacks

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