|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00025 defined('MOODLE_INTERNAL') || die(); 00026 00027 class comment { 00033 private $cid; 00039 private $commentarea; 00044 private $itemid; 00050 private $template; 00055 private $contextid; 00060 private $context; 00065 private $courseid; 00071 private $cm; 00076 private $component; 00081 private $pluginname; 00086 private $plugintype; 00091 private $viewcap = false; 00096 private $postcap = false; 00101 private $linktext; 00107 protected $notoggle = false; 00113 protected $autostart = false; 00118 protected $displaytotalcount = false; 00123 protected $displaycancel = false; 00128 protected $totalcommentcount = null; 00129 00133 private static $nonjs = false; 00134 private static $comment_itemid = null; 00135 private static $comment_context = null; 00136 private static $comment_area = null; 00137 private static $comment_page = null; 00138 private static $comment_component = null; 00160 public function __construct(stdClass $options) { 00161 $this->viewcap = false; 00162 $this->postcap = false; 00163 00164 // setup client_id 00165 if (!empty($options->client_id)) { 00166 $this->cid = $options->client_id; 00167 } else { 00168 $this->cid = uniqid(); 00169 } 00170 00171 // setup context 00172 if (!empty($options->context)) { 00173 $this->context = $options->context; 00174 $this->contextid = $this->context->id; 00175 } else if(!empty($options->contextid)) { 00176 $this->contextid = $options->contextid; 00177 $this->context = get_context_instance_by_id($this->contextid); 00178 } else { 00179 print_error('invalidcontext'); 00180 } 00181 00182 if (!empty($options->component)) { 00183 // set and validate component 00184 $this->set_component($options->component); 00185 } else { 00186 // component cannot be empty 00187 throw new comment_exception('invalidcomponent'); 00188 } 00189 00190 // setup course 00191 // course will be used to generate user profile link 00192 if (!empty($options->course)) { 00193 $this->courseid = $options->course->id; 00194 } else if (!empty($options->courseid)) { 00195 $this->courseid = $options->courseid; 00196 } else { 00197 $this->courseid = SITEID; 00198 } 00199 00200 // setup coursemodule 00201 if (!empty($options->cm)) { 00202 $this->cm = $options->cm; 00203 } else { 00204 $this->cm = null; 00205 } 00206 00207 // setup commentarea 00208 if (!empty($options->area)) { 00209 $this->commentarea = $options->area; 00210 } 00211 00212 // setup itemid 00213 if (!empty($options->itemid)) { 00214 $this->itemid = $options->itemid; 00215 } else { 00216 $this->itemid = 0; 00217 } 00218 00219 // setup customized linktext 00220 if (!empty($options->linktext)) { 00221 $this->linktext = $options->linktext; 00222 } else { 00223 $this->linktext = get_string('comments'); 00224 } 00225 00226 // setup options for callback functions 00227 $this->comment_param = new stdClass(); 00228 $this->comment_param->context = $this->context; 00229 $this->comment_param->courseid = $this->courseid; 00230 $this->comment_param->cm = $this->cm; 00231 $this->comment_param->commentarea = $this->commentarea; 00232 $this->comment_param->itemid = $this->itemid; 00233 00234 // setup notoggle 00235 if (!empty($options->notoggle)) { 00236 $this->set_notoggle($options->notoggle); 00237 } 00238 00239 // setup notoggle 00240 if (!empty($options->autostart)) { 00241 $this->set_autostart($options->autostart); 00242 } 00243 00244 // setup displaycancel 00245 if (!empty($options->displaycancel)) { 00246 $this->set_displaycancel($options->displaycancel); 00247 } 00248 00249 // setup displaytotalcount 00250 if (!empty($options->showcount)) { 00251 $this->set_displaytotalcount($options->showcount); 00252 } 00253 00254 // setting post and view permissions 00255 $this->check_permissions(); 00256 00257 // load template 00258 $this->template = html_writer::tag('div', '___picture___', array('class' => 'comment-userpicture')); 00259 $this->template .= html_writer::start_tag('div', array('class' => 'comment-content')); 00260 $this->template .= '___name___ - '; 00261 $this->template .= html_writer::tag('span', '___time___'); 00262 $this->template .= html_writer::tag('div', '___content___'); 00263 $this->template .= html_writer::end_tag('div'); // .comment-content 00264 if (!empty($this->plugintype)) { 00265 $this->template = plugin_callback($this->plugintype, $this->pluginname, 'comment', 'template', array($this->comment_param), $this->template); 00266 } 00267 00268 unset($options); 00269 } 00270 00277 public static function init(moodle_page $page = null) { 00278 global $PAGE; 00279 00280 if (empty($page)) { 00281 $page = $PAGE; 00282 } 00283 // setup variables for non-js interface 00284 self::$nonjs = optional_param('nonjscomment', '', PARAM_ALPHANUM); 00285 self::$comment_itemid = optional_param('comment_itemid', '', PARAM_INT); 00286 self::$comment_context = optional_param('comment_context', '', PARAM_INT); 00287 self::$comment_page = optional_param('comment_page', '', PARAM_INT); 00288 self::$comment_area = optional_param('comment_area', '', PARAM_AREA); 00289 00290 $page->requires->string_for_js('addcomment', 'moodle'); 00291 $page->requires->string_for_js('deletecomment', 'moodle'); 00292 $page->requires->string_for_js('comments', 'moodle'); 00293 $page->requires->string_for_js('commentsrequirelogin', 'moodle'); 00294 } 00295 00306 public function set_component($component) { 00307 if (!empty($this->component) && $this->component !== $component) { 00308 throw new coding_exception('You cannot change the component of a comment once it has been set'); 00309 } 00310 $this->component = $component; 00311 list($this->plugintype, $this->pluginname) = normalize_component($component); 00312 } 00313 00319 public function set_view_permission($value) { 00320 $this->viewcap = (bool)$value; 00321 } 00322 00328 public function set_post_permission($value) { 00329 $this->postcap = (bool)$value; 00330 } 00331 00338 private function check_permissions() { 00339 $this->postcap = has_capability('moodle/comment:post', $this->context); 00340 $this->viewcap = has_capability('moodle/comment:view', $this->context); 00341 if (!empty($this->plugintype)) { 00342 $permissions = plugin_callback($this->plugintype, $this->pluginname, 'comment', 'permissions', array($this->comment_param), array('post'=>false, 'view'=>false)); 00343 $this->postcap = $this->postcap && $permissions['post']; 00344 $this->viewcap = $this->viewcap && $permissions['view']; 00345 } 00346 } 00347 00355 public function get_nojslink(moodle_page $page = null) { 00356 if ($page === null) { 00357 global $PAGE; 00358 $page = $PAGE; 00359 } 00360 00361 $link = new moodle_url($page->url, array( 00362 'nonjscomment' => true, 00363 'comment_itemid' => $this->itemid, 00364 'comment_context' => $this->context->id, 00365 'comment_area' => $this->commentarea, 00366 )); 00367 $link->remove_params(array('comment_page')); 00368 return $link; 00369 } 00370 00379 public function set_notoggle($newvalue = true) { 00380 $this->notoggle = (bool)$newvalue; 00381 } 00382 00391 public function set_autostart($newvalue = true) { 00392 $this->autostart = (bool)$newvalue; 00393 } 00394 00403 public function set_displaycancel($newvalue = true) { 00404 $this->displaycancel = (bool)$newvalue; 00405 } 00406 00415 public function set_displaytotalcount($newvalue = true) { 00416 $this->displaytotalcount = (bool)$newvalue; 00417 } 00418 00425 public function initialise_javascript(moodle_page $page) { 00426 00427 $options = new stdClass; 00428 $options->client_id = $this->cid; 00429 $options->commentarea = $this->commentarea; 00430 $options->itemid = $this->itemid; 00431 $options->page = 0; 00432 $options->courseid = $this->courseid; 00433 $options->contextid = $this->contextid; 00434 $options->component = $this->component; 00435 $options->notoggle = $this->notoggle; 00436 $options->autostart = $this->autostart; 00437 00438 $page->requires->js_init_call('M.core_comment.init', array($options), true); 00439 00440 return true; 00441 } 00442 00448 public function output($return = true) { 00449 global $PAGE, $OUTPUT; 00450 static $template_printed; 00451 00452 $this->initialise_javascript($PAGE); 00453 00454 if (!empty(self::$nonjs)) { 00455 // return non js comments interface 00456 return $this->print_comments(self::$comment_page, $return, true); 00457 } 00458 00459 $html = ''; 00460 00461 // print html template 00462 // Javascript will use the template to render new comments 00463 if (empty($template_printed) && $this->can_view()) { 00464 $html .= html_writer::tag('div', $this->template, array('style' => 'display:none', 'id' => 'cmt-tmpl')); 00465 $template_printed = true; 00466 } 00467 00468 if ($this->can_view()) { 00469 // print commenting icon and tooltip 00470 $html .= html_writer::start_tag('div', array('class' => 'mdl-left')); 00471 $html .= html_writer::link($this->get_nojslink($PAGE), get_string('showcommentsnonjs'), array('class' => 'showcommentsnonjs')); 00472 00473 if (!$this->notoggle) { 00474 // If toggling is enabled (notoggle=false) then print the controls to toggle 00475 // comments open and closed 00476 $countstring = ''; 00477 if ($this->displaytotalcount) { 00478 $countstring = '('.$this->count().')'; 00479 } 00480 $html .= html_writer::start_tag('a', array('class' => 'comment-link', 'id' => 'comment-link-'.$this->cid, 'href' => '#')); 00481 $html .= html_writer::empty_tag('img', array('id' => 'comment-img-'.$this->cid, 'src' => $OUTPUT->pix_url('t/collapsed'), 'alt' => $this->linktext, 'title' => $this->linktext)); 00482 $html .= html_writer::tag('span', $this->linktext.' '.$countstring, array('id' => 'comment-link-text-'.$this->cid)); 00483 $html .= html_writer::end_tag('a'); 00484 } 00485 00486 $html .= html_writer::start_tag('div', array('id' => 'comment-ctrl-'.$this->cid, 'class' => 'comment-ctrl')); 00487 00488 if ($this->autostart) { 00489 // If autostart has been enabled print the comments list immediatly 00490 $html .= html_writer::start_tag('ul', array('id' => 'comment-list-'.$this->cid, 'class' => 'comment-list comments-loaded')); 00491 $html .= html_writer::tag('li', '', array('class' => 'first')); 00492 $html .= $this->print_comments(0, true, false); 00493 $html .= html_writer::end_tag('ul'); // .comment-list 00494 $html .= $this->get_pagination(0); 00495 } else { 00496 $html .= html_writer::start_tag('ul', array('id' => 'comment-list-'.$this->cid, 'class' => 'comment-list')); 00497 $html .= html_writer::tag('li', '', array('class' => 'first')); 00498 $html .= html_writer::end_tag('ul'); // .comment-list 00499 $html .= html_writer::tag('div', '', array('id' => 'comment-pagination-'.$this->cid, 'class' => 'comment-pagination')); 00500 } 00501 00502 if ($this->can_post()) { 00503 // print posting textarea 00504 $html .= html_writer::start_tag('div', array('class' => 'comment-area')); 00505 $html .= html_writer::start_tag('div', array('class' => 'db')); 00506 $html .= html_writer::tag('textarea', '', array('name' => 'content', 'rows' => 2, 'cols' => 20, 'id' => 'dlg-content-'.$this->cid)); 00507 $html .= html_writer::end_tag('div'); // .db 00508 00509 $html .= html_writer::start_tag('div', array('class' => 'fd', 'id' => 'comment-action-'.$this->cid)); 00510 $html .= html_writer::link('#', get_string('savecomment'), array('id' => 'comment-action-post-'.$this->cid)); 00511 00512 if ($this->displaycancel) { 00513 $html .= html_writer::tag('span', ' | '); 00514 $html .= html_writer::link('#', get_string('cancel'), array('id' => 'comment-action-cancel-'.$this->cid)); 00515 } 00516 00517 $html .= html_writer::end_tag('div'); // .fd 00518 $html .= html_writer::end_tag('div'); // .comment-area 00519 $html .= html_writer::tag('div', '', array('class' => 'clearer')); 00520 } 00521 00522 $html .= html_writer::end_tag('div'); // .comment-ctrl 00523 $html .= html_writer::end_tag('div'); // .mdl-left 00524 } else { 00525 $html = ''; 00526 } 00527 00528 if ($return) { 00529 return $html; 00530 } else { 00531 echo $html; 00532 } 00533 } 00534 00541 public function get_comments($page = '') { 00542 global $DB, $CFG, $USER, $OUTPUT; 00543 if (!$this->can_view()) { 00544 return false; 00545 } 00546 if (!is_numeric($page)) { 00547 $page = 0; 00548 } 00549 $params = array(); 00550 $perpage = (!empty($CFG->commentsperpage))?$CFG->commentsperpage:15; 00551 $start = $page * $perpage; 00552 $ufields = user_picture::fields('u'); 00553 $sql = "SELECT $ufields, c.id AS cid, c.content AS ccontent, c.format AS cformat, c.timecreated AS ctimecreated 00554 FROM {comments} c 00555 JOIN {user} u ON u.id = c.userid 00556 WHERE c.contextid = :contextid AND c.commentarea = :commentarea AND c.itemid = :itemid 00557 ORDER BY c.timecreated DESC"; 00558 $params['contextid'] = $this->contextid; 00559 $params['commentarea'] = $this->commentarea; 00560 $params['itemid'] = $this->itemid; 00561 00562 $comments = array(); 00563 $formatoptions = array('overflowdiv' => true); 00564 $rs = $DB->get_recordset_sql($sql, $params, $start, $perpage); 00565 foreach ($rs as $u) { 00566 $c = new stdClass(); 00567 $c->id = $u->cid; 00568 $c->content = $u->ccontent; 00569 $c->format = $u->cformat; 00570 $c->timecreated = $u->ctimecreated; 00571 $url = new moodle_url('/user/view.php', array('id'=>$u->id, 'course'=>$this->courseid)); 00572 $c->profileurl = $url->out(); 00573 $c->fullname = fullname($u); 00574 $c->time = userdate($c->timecreated, get_string('strftimerecent', 'langconfig')); 00575 $c->content = format_text($c->content, $c->format, $formatoptions); 00576 $c->avatar = $OUTPUT->user_picture($u, array('size'=>18)); 00577 00578 $candelete = $this->can_delete($c->id); 00579 if (($USER->id == $u->id) || !empty($candelete)) { 00580 $c->delete = true; 00581 } 00582 $comments[] = $c; 00583 } 00584 $rs->close(); 00585 00586 if (!empty($this->plugintype)) { 00587 // moodle module will filter comments 00588 $comments = plugin_callback($this->plugintype, $this->pluginname, 'comment', 'display', array($comments, $this->comment_param), $comments); 00589 } 00590 00591 return $comments; 00592 } 00593 00600 public function count() { 00601 global $DB; 00602 if ($this->totalcommentcount === null) { 00603 $this->totalcommentcount = $DB->count_records('comments', array('itemid' => $this->itemid, 'commentarea' => $this->commentarea, 'contextid' => $this->context->id)); 00604 } 00605 return $this->totalcommentcount; 00606 } 00607 00616 public function get_pagination($page = 0) { 00617 global $CFG, $OUTPUT; 00618 $count = $this->count(); 00619 $perpage = (!empty($CFG->commentsperpage))?$CFG->commentsperpage:15; 00620 $pages = (int)ceil($count/$perpage); 00621 if ($pages == 1 || $pages == 0) { 00622 return html_writer::tag('div', '', array('id' => 'comment-pagination-'.$this->cid, 'class' => 'comment-pagination')); 00623 } 00624 if (!empty(self::$nonjs)) { 00625 // used in non-js interface 00626 return $OUTPUT->paging_bar($count, $page, $perpage, $this->get_nojslink(), 'comment_page'); 00627 } else { 00628 // return ajax paging bar 00629 $str = ''; 00630 $str .= '<div class="comment-paging" id="comment-pagination-'.$this->cid.'">'; 00631 for ($p=0; $p<$pages; $p++) { 00632 if ($p == $page) { 00633 $class = 'curpage'; 00634 } else { 00635 $class = 'pageno'; 00636 } 00637 $str .= '<a href="#" class="'.$class.'" id="comment-page-'.$this->cid.'-'.$p.'">'.($p+1).'</a> '; 00638 } 00639 $str .= '</div>'; 00640 } 00641 return $str; 00642 } 00643 00651 public function add($content, $format = FORMAT_MOODLE) { 00652 global $CFG, $DB, $USER, $OUTPUT; 00653 if (!$this->can_post()) { 00654 throw new comment_exception('nopermissiontocomment'); 00655 } 00656 $now = time(); 00657 $newcmt = new stdClass; 00658 $newcmt->contextid = $this->contextid; 00659 $newcmt->commentarea = $this->commentarea; 00660 $newcmt->itemid = $this->itemid; 00661 $newcmt->content = $content; 00662 $newcmt->format = $format; 00663 $newcmt->userid = $USER->id; 00664 $newcmt->timecreated = $now; 00665 00666 // This callback allow module to modify the content of comment, such as filter or replacement 00667 plugin_callback($this->plugintype, $this->pluginname, 'comment', 'add', array(&$newcmt, $this->comment_param)); 00668 00669 $cmt_id = $DB->insert_record('comments', $newcmt); 00670 if (!empty($cmt_id)) { 00671 $newcmt->id = $cmt_id; 00672 $newcmt->time = userdate($now, get_string('strftimerecent', 'langconfig')); 00673 $newcmt->fullname = fullname($USER); 00674 $url = new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $this->courseid)); 00675 $newcmt->profileurl = $url->out(); 00676 $newcmt->content = format_text($newcmt->content, $format, array('overflowdiv'=>true)); 00677 $newcmt->avatar = $OUTPUT->user_picture($USER, array('size'=>16)); 00678 return $newcmt; 00679 } else { 00680 throw new comment_exception('dbupdatefailed'); 00681 } 00682 } 00683 00693 public function delete_comments($param) { 00694 global $DB; 00695 $param = (array)$param; 00696 if (empty($param['contextid'])) { 00697 return false; 00698 } 00699 $DB->delete_records('comments', $param); 00700 return true; 00701 } 00702 00708 public function reset_course_page_comments($context) { 00709 global $DB; 00710 $contexts = array(); 00711 $contexts[] = $context->id; 00712 $children = get_child_contexts($context); 00713 foreach ($children as $c) { 00714 $contexts[] = $c->id; 00715 } 00716 list($ids, $params) = $DB->get_in_or_equal($contexts); 00717 $DB->delete_records_select('comments', "commentarea='page_comments' AND contextid $ids", $params); 00718 } 00719 00726 public function delete($commentid) { 00727 global $DB, $USER; 00728 $candelete = has_capability('moodle/comment:delete', $this->context); 00729 if (!$comment = $DB->get_record('comments', array('id'=>$commentid))) { 00730 throw new comment_exception('dbupdatefailed'); 00731 } 00732 if (!($USER->id == $comment->userid || !empty($candelete))) { 00733 throw new comment_exception('nopermissiontocomment'); 00734 } 00735 $DB->delete_records('comments', array('id'=>$commentid)); 00736 return true; 00737 } 00738 00747 public function print_comments($page = 0, $return = true, $nonjs = true) { 00748 global $DB, $CFG, $PAGE; 00749 00750 if (!$this->can_view()) { 00751 return ''; 00752 } 00753 00754 $html = ''; 00755 if (!(self::$comment_itemid == $this->itemid && 00756 self::$comment_context == $this->context->id && 00757 self::$comment_area == $this->commentarea)) { 00758 $page = 0; 00759 } 00760 $comments = $this->get_comments($page); 00761 00762 $html = ''; 00763 if ($nonjs) { 00764 $html .= html_writer::tag('h3', get_string('comments')); 00765 $html .= html_writer::start_tag('ul', array('id' => 'comment-list-'.$this->cid, 'class' => 'comment-list')); 00766 } 00767 // Reverse the comments array to display them in the correct direction 00768 foreach (array_reverse($comments) as $cmt) { 00769 $html .= html_writer::tag('li', $this->print_comment($cmt, $nonjs), array('id' => 'comment-'.$cmt->id.'-'.$this->cid)); 00770 } 00771 if ($nonjs) { 00772 $html .= html_writer::end_tag('ul'); 00773 $html .= $this->get_pagination($page); 00774 } 00775 if ($nonjs && $this->can_post()) { 00776 // Form to add comments 00777 $html .= html_writer::start_tag('form', array('method' => 'post', 'action' => new moodle_url('/comment/comment_post.php'))); 00778 // Comment parameters 00779 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'contextid', 'value' => $this->contextid)); 00780 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'add')); 00781 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'area', 'value' => $this->commentarea)); 00782 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'component', 'value' => $this->component)); 00783 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'itemid', 'value' => $this->itemid)); 00784 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'courseid', 'value' => $this->courseid)); 00785 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); 00786 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'returnurl', 'value' => $PAGE->url)); 00787 // Textarea for the actual comment 00788 $html .= html_writer::tag('textarea', '', array('name' => 'content', 'rows' => 2)); 00789 // Submit button to add the comment 00790 $html .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('submit'))); 00791 $html .= html_writer::end_tag('form'); 00792 } 00793 if ($return) { 00794 return $html; 00795 } else { 00796 echo $html; 00797 } 00798 } 00799 00817 public function print_comment($cmt, $nonjs = true) { 00818 global $OUTPUT; 00819 $patterns = array(); 00820 $replacements = array(); 00821 00822 if (!empty($cmt->delete) && empty($nonjs)) { 00823 $deletelink = html_writer::start_tag('div', array('class'=>'comment-delete')); 00824 $deletelink .= html_writer::start_tag('a', array('href' => '#', 'id' => 'comment-delete-'.$this->cid.'-'.$cmt->id)); 00825 $deletelink .= $OUTPUT->pix_icon('t/delete', get_string('delete')); 00826 $deletelink .= html_writer::end_tag('a'); 00827 $deletelink .= html_writer::end_tag('div'); 00828 $cmt->content = $deletelink . $cmt->content; 00829 } 00830 $patterns[] = '___picture___'; 00831 $patterns[] = '___name___'; 00832 $patterns[] = '___content___'; 00833 $patterns[] = '___time___'; 00834 $replacements[] = $cmt->avatar; 00835 $replacements[] = html_writer::link($cmt->profileurl, $cmt->fullname); 00836 $replacements[] = $cmt->content; 00837 $replacements[] = userdate($cmt->timecreated, get_string('strftimerecent', 'langconfig')); 00838 00839 // use html template to format a single comment. 00840 return str_replace($patterns, $replacements, $this->template); 00841 } 00842 00848 protected function validate($params=array()) { 00849 foreach ($params as $key=>$value) { 00850 $this->comment_param->$key = $value; 00851 } 00852 $validation = plugin_callback($this->plugintype, $this->pluginname, 'comment', 'validate', array($this->comment_param), false); 00853 if (!$validation) { 00854 throw new comment_exception('invalidcommentparam'); 00855 } 00856 } 00857 00862 public function can_view() { 00863 $this->validate(); 00864 return !empty($this->viewcap); 00865 } 00866 00871 public function can_post() { 00872 $this->validate(); 00873 return isloggedin() && !empty($this->postcap); 00874 } 00875 00881 public function can_delete($commentid) { 00882 $this->validate(array('commentid'=>$commentid)); 00883 return has_capability('moodle/comment:delete', $this->context); 00884 } 00885 00890 public function get_compontent() { 00891 return $this->component; 00892 } 00893 00898 public function get_context() { 00899 return $this->context; 00900 } 00901 00906 public function get_courseid() { 00907 return $this->courseid; 00908 } 00909 00915 public function get_cm() { 00916 return $this->cm; 00917 } 00918 00924 public function get_itemid() { 00925 return $this->itemid; 00926 } 00927 00933 public function get_commentarea() { 00934 return $this->commentarea; 00935 } 00936 } 00937 00938 class comment_exception extends moodle_exception { 00939 }