/** * Delete a comment * * @param int $commentid * @return bool */ public function delete($commentid) { global $DB, $USER; $candelete = has_capability('moodle/comment:delete', $this->context); if (!($comment = $DB->get_record('comments', array('id' => $commentid)))) { throw new comment_exception('dbupdatefailed'); } if (!($USER->id == $comment->userid || !empty($candelete))) { throw new comment_exception('nopermissiontocomment'); } $DB->delete_records('comments', array('id' => $commentid)); // Trigger comment delete event. if (core_component::is_core_subsystem($this->component)) { $eventclassname = '\\core\\event\\' . $this->component . '_comment_deleted'; } else { $eventclassname = '\\' . $this->component . '\\event\\comment_deleted'; } if (class_exists($eventclassname)) { $event = $eventclassname::create(array('context' => $this->context, 'objectid' => $commentid, 'other' => array('itemid' => $this->itemid))); $event->add_record_snapshot('comments', $comment); $event->trigger(); } return true; }