Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
|
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. | |
Comment is helper class to add/delete comments anywhere in moodle.
comment::__construct | ( | stdClass | $options | ) |
Construct function of comment class, initialise class members.
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 } |
moodle_database comment::add | ( | $content, | |
$format = FORMAT_MOODLE ) |
Add a new comment.
$DB
string | $content | |
int | $format |
stdClass |
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.
int | stdClass | $comment | The id of a comment, or a comment record. |
bool |
comment::can_post | ( | ) |
Returns true if the user can add comments against this comment description.
bool |
comment::can_view | ( | ) |
Returns true if the user is able to view comments.
bool |
moodle_database comment::count | ( | ) |
Returns the number of comments associated with the details of this object.
$DB
int |
comment::delete | ( | $comment | ) |
Delete a comment.
int | stdClass | $comment | The id of a comment, or a comment record. |
bool |
|
static |
delete by context, commentarea and itemid
stdClass | array | $param | { contextid => int the context in which the comments exist [required] commentarea => string the comment area [optional] itemid => int comment itemid [optional] } |
boolean |
comment::get_autostart | ( | ) |
Return autostart.
bool |
comment::get_cid | ( | ) |
Return the cid.
string |
comment::get_cm | ( | ) |
Returns the course module associated with the comment.
stdClass |
comment::get_commentarea | ( | ) |
Returns the comment area associated with the commentarea.
stdClass |
comment::get_comments | ( | $page = '', | |
$sortdirection = 'DESC' ) |
Return matched comments.
int | $page | |
str | $sortdirection | sort direction, ASC or DESC |
array |
comment::get_component | ( | ) |
Returns the component associated with the comment.
string |
|
protected |
Returns an SQL fragment and param for selecting on component.
string | $alias |
array |
comment::get_compontent | ( | ) |
Do not call! I am a deprecated method because of the typo in my name.
string |
comment::get_context | ( | ) |
Returns the context associated with the comment.
stdClass |
comment::get_courseid | ( | ) |
Returns the course id associated with the comment.
int |
comment::get_displaycancel | ( | ) |
Return display cancel.
bool |
comment::get_displaytotalcount | ( | ) |
Return display total count.
bool |
comment::get_fullwidth | ( | ) |
Return fullwidth.
bool |
comment::get_itemid | ( | ) |
Returns the item id associated with the comment.
int |
comment::get_linktext | ( | ) |
Return the link text.
string |
moodle_page comment::get_nojslink | ( | moodle_page | $page = null | ) |
Gets a link for this page that will work with JS disabled.
$PAGE
moodle_page | $page |
moodle_url |
comment::get_notoggle | ( | ) |
Return no toggle.
bool |
stdClass comment::get_pagination | ( | $page = 0 | ) |
Returns HTML to display a pagination bar.
$CFG @global core_renderer $OUTPUT
int | $page |
string |
comment::get_template | ( | ) |
Return the template.
string |
|
static |
Receive nonjs comment parameters.
moodle_page | $page | The page object to initialise comments within If not provided the global $PAGE is used |
comment::initialise_javascript | ( | moodle_page | $page | ) |
Initialises the JavaScript that enchances the comment API.
moodle_page | $page | The moodle page object that the JavaScript should be initialised for. |
comment::output | ( | $return = true | ) |
Prepare comment code in html.
boolean | $return |
string|void |
core_renderer comment::print_comment | ( | $cmt, | |
$nonjs = true ) |
Returns an array containing comments in HTML format.
$OUTPUT
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 |
array |
comment::print_comments | ( | $page = 0, | |
$return = true, | |||
$nonjs = true ) |
Print comments.
int | $page | |
bool | $return | return comments list string or print it out |
bool | $nonjs | print nonjs comments list or not? |
string|void |
|
static |
Delete page_comments in whole course, used by course reset.
stdClass | $context | course context |
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.
bool | $newvalue |
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.
coding_exception | if you try to change the component after it has been set. |
string | $component |
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.
bool | $newvalue |
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.
bool | $newvalue |
comment::set_fullwidth | ( | $fullwidth = true | ) |
Make the comments textarea fullwidth.
bool | $fullwidth |
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.
bool | $newvalue |
comment::set_post_permission | ( | $value | ) |
Determines if the user can post a comment.
bool | $value |
comment::set_view_permission | ( | $value | ) |
Determines if the user can view the comment.
bool | $value |
|
protected |
Revoke validate callbacks.
stdClass | $params | addtionall parameters need to add to callbacks |