本文整理汇总了PHP中comment::add方法的典型用法代码示例。如果您正苦于以下问题:PHP comment::add方法的具体用法?PHP comment::add怎么用?PHP comment::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comment
的用法示例。
在下文中一共展示了comment::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_comment
function add_comment()
{
safe('comment');
global $global, $smarty, $lang;
$channel = post('channel');
$com_page_id = post('page_id');
$com_username = post('username');
$com_email = post('email');
$com_rank = post('rank');
$com_text = post('text');
if ($channel == '' || $com_page_id == '' || $com_username == '' || $com_email == '' || $com_rank == '' || $com_text == '') {
$info_text = $lang['submit_error_info'];
} else {
$com_channel_id = get_id('channel', 'cha_code', $channel);
$com_add_time = time();
$obj = new comment();
$obj->set_value('com_channel_id', $com_channel_id);
$obj->set_value('com_page_id', $com_page_id);
$obj->set_value('com_username', $com_username);
$obj->set_value('com_email', $com_email);
$obj->set_value('com_rank', $com_rank);
$obj->set_value('com_text', $com_text);
$obj->set_value('com_add_time', $com_add_time);
$obj->set_value('com_show', 0);
$obj->set_value('com_lang', S_LANG);
$obj->add();
if (intval(get_varia('sentmail'))) {
$email_title = '您的网站有了新的评论';
$str = get_data($channel, $com_page_id, substr($channel, 0, 3) . '_title');
$email_text = '评论:《' . $str . '》<br />' . $com_text;
call_send_email($email_title, $email_text, $com_username, $com_email);
}
$info_text = $lang['submit_comment'];
}
$smarty->assign('info_text', $info_text);
$smarty->assign('link_text', $lang['go_back']);
$smarty->assign('link_href', url(array('channel' => $channel, 'id' => $com_page_id)));
}
示例2: wiki_add_comment
/**
* Add comments ro database
*
* @param object $context. Current context
* @param int $pageid. Current pageid
* @param string $content. Content of the comment
* @param string editor. Version of editor we are using.
**/
function wiki_add_comment($context, $pageid, $content, $editor)
{
global $CFG;
require_once $CFG->dirroot . '/comment/lib.php';
list($context, $course, $cm) = get_context_info_array($context->id);
$cmt = new stdclass();
$cmt->context = $context;
$cmt->itemid = $pageid;
$cmt->area = 'wiki_page';
$cmt->course = $course;
$cmt->component = 'mod_wiki';
$manager = new comment($cmt);
if ($editor == 'creole') {
$manager->add($content, FORMAT_CREOLE);
} else {
if ($editor == 'html') {
$manager->add($content, FORMAT_HTML);
} else {
if ($editor == 'nwiki') {
$manager->add($content, FORMAT_NWIKI);
}
}
}
}
示例3: stdClass
$args = new stdClass();
$args->context = $context;
$args->course = $course;
$args->cm = $cm;
$args->area = $area;
$args->itemid = $itemid;
$args->client_id = $client_id;
$args->component = $component;
$manager = new comment($args);
echo $OUTPUT->header();
// send headers
// process ajax request
switch ($action) {
case 'add':
if ($manager->can_post()) {
$result = $manager->add($content);
if (!empty($result) && is_object($result)) {
$result->count = $manager->count();
$result->client_id = $client_id;
echo json_encode($result);
die;
}
}
break;
case 'delete':
$comment_record = $DB->get_record('comments', array('id' => $commentid));
if ($manager->can_delete($commentid) || $comment_record->userid == $USER->id) {
if ($manager->delete($commentid)) {
$result = array('client_id' => $client_id, 'commentid' => $commentid);
echo json_encode($result);
die;
示例4: upgrade
/**
* Upgrade the submission from the old assignment to the new one
*
* @param context $oldcontext The context for the old assignment
* @param stdClass $oldassignment The data record for the old assignment
* @param stdClass $oldsubmission The data record for the old submission
* @param stdClass $submission The new submission record
* @param string $log Record upgrade messages in the log
* @return bool true or false - false will trigger a rollback
*/
public function upgrade(context $oldcontext, stdClass $oldassignment, stdClass $oldsubmission, stdClass $submission, &$log)
{
if ($oldsubmission->data1 != '') {
// need to used this innit() otherwise it shows up undefined !
// require js for commenting
comment::init();
$options = new stdClass();
$options->area = 'submission_comments_upgrade';
$options->course = $this->assignment->get_course();
$options->context = $this->assignment->get_context();
$options->itemid = $submission->id;
$options->component = 'assignsubmission_comments';
$options->showcount = true;
$options->displaycancel = true;
$comment = new comment($options);
$comment->add($oldsubmission->data1);
$comment->set_view_permission(true);
return $comment->output(true);
}
return true;
}
示例5: test_data_comment_deleted_event
/**
* Test comment_deleted event.
*/
public function test_data_comment_deleted_event()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/comment/lib.php';
$this->resetAfterTest();
// Create a record for deleting.
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$record = new stdClass();
$record->course = $course->id;
$record->name = "Mod data delete test";
$record->intro = "Some intro of some sort";
$record->comments = 1;
$module = $this->getDataGenerator()->create_module('data', $record);
$field = data_get_field_new('text', $module);
$fielddetail = new stdClass();
$fielddetail->name = 'Name';
$fielddetail->description = 'Some name';
$field->define_field($fielddetail);
$field->insert_field();
$recordid = data_add_record($module);
$datacontent = array();
$datacontent['fieldid'] = $field->field->id;
$datacontent['recordid'] = $recordid;
$datacontent['content'] = 'Asterix';
$contentid = $DB->insert_record('data_content', $datacontent);
$cm = get_coursemodule_from_instance('data', $module->id, $course->id);
$context = context_module::instance($module->cmid);
$cmt = new stdClass();
$cmt->context = $context;
$cmt->course = $course;
$cmt->cm = $cm;
$cmt->area = 'database_entry';
$cmt->itemid = $recordid;
$cmt->showcount = true;
$cmt->component = 'mod_data';
$comment = new comment($cmt);
$newcomment = $comment->add('New comment 1');
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$comment->delete($newcomment->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\\mod_data\\event\\comment_deleted', $event);
$this->assertEquals($context, $event->get_context());
$url = new moodle_url('/mod/data/view.php', array('id' => $module->cmid));
$this->assertEquals($url, $event->get_url());
$this->assertEventContextNotUsed($event);
}
示例6: test_comment_deleted
/**
* Test comment_deleted event.
*/
public function test_comment_deleted()
{
global $CFG;
require_once $CFG->dirroot . '/comment/lib.php';
// Create a record for deleting comment.
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course));
$glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
$entry = $glossarygenerator->create_content($glossary);
$context = context_module::instance($glossary->cmid);
$cm = get_coursemodule_from_instance('glossary', $glossary->id, $course->id);
$cmt = new stdClass();
$cmt->component = 'mod_glossary';
$cmt->context = $context;
$cmt->course = $course;
$cmt->cm = $cm;
$cmt->area = 'glossary_entry';
$cmt->itemid = $entry->id;
$cmt->showcount = true;
$comment = new comment($cmt);
$newcomment = $comment->add('New comment 1');
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$comment->delete($newcomment->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\\mod_glossary\\event\\comment_deleted', $event);
$this->assertEquals($context, $event->get_context());
$url = new moodle_url('/mod/glossary/view.php', array('id' => $glossary->cmid));
$this->assertEquals($url, $event->get_url());
$this->assertEventContextNotUsed($event);
}
示例7: upgrade
/**
* Upgrade the submission from the old setaskment to the new one
*
* @param context $oldcontext The context for the old setaskment
* @param stdClass $oldsetaskment The data record for the old setaskment
* @param stdClass $oldsubmission The data record for the old submission
* @param stdClass $submission The new submission record
* @param string $log Record upgrade messages in the log
* @return bool true or false - false will trigger a rollback
*/
public function upgrade(context $oldcontext, stdClass $oldsetaskment, stdClass $oldsubmission, stdClass $submission, &$log)
{
if ($oldsubmission->data1 != '') {
// Need to used this init() otherwise it does not have the javascript includes.
comment::init();
$options = new stdClass();
$options->area = 'submission_comments_upgrade';
$options->course = $this->setaskment->get_course();
$options->context = $this->setaskment->get_context();
$options->itemid = $submission->id;
$options->component = 'setasksubmission_comments';
$options->showcount = true;
$options->displaycancel = true;
$comment = new comment($options);
$comment->add($oldsubmission->data1);
$comment->set_view_permission(true);
return $comment->output(true);
}
return true;
}
示例8: test_comment_deleted
/**
* Test comment_deleted event.
*/
public function test_comment_deleted() {
global $CFG;
require_once($CFG->dirroot . '/comment/lib.php');
// Comment on course page.
$context = context_course::instance($this->course->id);
$args = new stdClass;
$args->context = $context;
$args->course = $this->course;
$args->area = 'page_comments';
$args->itemid = 0;
$args->component = 'block_comments';
$args->linktext = get_string('showcomments');
$args->notoggle = true;
$args->autostart = true;
$args->displaycancel = false;
$comment = new comment($args);
$newcomment = $comment->add('New comment');
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$comment->delete($newcomment->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\block_comments\event\comment_deleted', $event);
$this->assertEquals($context, $event->get_context());
$url = new moodle_url('/course/view.php', array('id' => $this->course->id));
$this->assertEquals($url, $event->get_url());
// Comments when block is on module (wiki) page.
$context = context_module::instance($this->wiki->id);
$args = new stdClass;
$args->context = $context;
$args->course = $this->course;
$args->area = 'page_comments';
$args->itemid = 0;
$args->component = 'block_comments';
$args->linktext = get_string('showcomments');
$args->notoggle = true;
$args->autostart = true;
$args->displaycancel = false;
$comment = new comment($args);
$newcomment = $comment->add('New comment 1');
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$comment->delete($newcomment->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\block_comments\event\comment_deleted', $event);
$this->assertEquals($context, $event->get_context());
$url = new moodle_url('/mod/wiki/view.php', array('id' => $this->wiki->id));
$this->assertEquals($url, $event->get_url());
$this->assertEventContextNotUsed($event);
}
示例9: test_comment_deleted
/**
* Test comment_deleted event.
*/
public function test_comment_deleted()
{
global $CFG;
require_once $CFG->dirroot . '/comment/lib.php';
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$submission = $assign->get_user_submission($this->students[0]->id, true);
$context = $assign->get_context();
$options = new stdClass();
$options->area = 'submission_comments';
$options->course = $assign->get_course();
$options->context = $context;
$options->itemid = $submission->id;
$options->component = 'assignsubmission_comments';
$options->showcount = true;
$options->displaycancel = true;
$comment = new comment($options);
$newcomment = $comment->add('New comment 1');
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$comment->delete($newcomment->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\\assignsubmission_comments\\event\\comment_deleted', $event);
$this->assertEquals($context, $event->get_context());
$url = new moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id));
$this->assertEquals($url, $event->get_url());
$this->assertEventContextNotUsed($event);
}
示例10: redirect
if (empty($CFG->usecomments)) {
throw new comment_exception('commentsnotenabled', 'moodle');
}
$contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
list($context, $course, $cm) = get_context_info_array($contextid);
require_login($course, true, $cm);
require_sesskey();
$action = optional_param('action', '', PARAM_ALPHA);
$area = optional_param('area', '', PARAM_AREA);
$content = optional_param('content', '', PARAM_RAW);
$itemid = optional_param('itemid', '', PARAM_INT);
$returnurl = optional_param('returnurl', '/', PARAM_LOCALURL);
$component = optional_param('component', '', PARAM_COMPONENT);
// Currently this script can only add comments
if ($action !== 'add') {
redirect($returnurl);
}
$cmt = new stdClass();
$cmt->contextid = $contextid;
$cmt->courseid = $course->id;
$cmt->cm = $cm;
$cmt->area = $area;
$cmt->itemid = $itemid;
$cmt->component = $component;
$comment = new comment($cmt);
if ($comment->can_post()) {
$cmt = $comment->add($content);
if (!empty($cmt) && is_object($cmt)) {
redirect($returnurl);
}
}
示例11: test_course_check_module_updates_since
public function test_course_check_module_updates_since()
{
global $CFG, $DB, $USER;
require_once $CFG->dirroot . '/mod/glossary/lib.php';
require_once $CFG->dirroot . '/rating/lib.php';
require_once $CFG->dirroot . '/comment/lib.php';
$this->resetAfterTest(true);
$CFG->enablecompletion = true;
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course->id, 'completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1, 'allowcomments' => 1, 'assessed' => RATING_AGGREGATE_AVERAGE, 'scale' => 100));
$glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
$context = context_module::instance($glossary->cmid);
$modinfo = get_fast_modinfo($course);
$cm = $modinfo->get_cm($glossary->cmid);
$user = $this->getDataGenerator()->create_user();
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
$from = time();
$teacher = $this->getDataGenerator()->create_user();
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
$this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id);
assign_capability('mod/glossary:viewanyrating', CAP_ALLOW, $studentrole->id, $context->id, true);
// Check nothing changed right now.
$updates = course_check_module_updates_since($cm, $from);
$this->assertFalse($updates->configuration->updated);
$this->assertFalse($updates->completion->updated);
$this->assertFalse($updates->gradeitems->updated);
$this->assertFalse($updates->comments->updated);
$this->assertFalse($updates->ratings->updated);
$this->assertFalse($updates->introfiles->updated);
$this->assertFalse($updates->outcomes->updated);
$this->waitForSecond();
// Do some changes.
$this->setUser($user);
$entry = $glossarygenerator->create_content($glossary);
$this->setUser($teacher);
// Name.
set_coursemodule_name($glossary->cmid, 'New name');
// Add some ratings.
$rm = new rating_manager();
$result = $rm->add_rating($cm, $context, 'mod_glossary', 'entry', $entry->id, 100, 50, $user->id, RATING_AGGREGATE_AVERAGE);
// Change grades.
$glossary->cmidnumber = $glossary->cmid;
glossary_update_grades($glossary, $user->id);
$this->setUser($user);
// Completion status.
glossary_view($glossary, $course, $cm, $context, 'letter');
// Add one comment.
$args = new stdClass();
$args->context = $context;
$args->course = $course;
$args->cm = $cm;
$args->area = 'glossary_entry';
$args->itemid = $entry->id;
$args->client_id = 1;
$args->component = 'mod_glossary';
$manager = new comment($args);
$manager->add('blah blah blah');
// Check upgrade status.
$updates = course_check_module_updates_since($cm, $from);
$this->assertTrue($updates->configuration->updated);
$this->assertTrue($updates->completion->updated);
$this->assertTrue($updates->gradeitems->updated);
$this->assertTrue($updates->comments->updated);
$this->assertTrue($updates->ratings->updated);
$this->assertFalse($updates->introfiles->updated);
$this->assertFalse($updates->outcomes->updated);
}
示例12: test_blog_comment_deleted_event
/**
* Test comment_deleted event.
*/
public function test_blog_comment_deleted_event()
{
global $USER, $CFG;
$this->setAdminUser();
require_once $CFG->dirroot . '/comment/lib.php';
$context = context_user::instance($USER->id);
$cmt = new stdClass();
$cmt->context = $context;
$cmt->courseid = $this->courseid;
$cmt->area = 'format_blog';
$cmt->itemid = $this->postid;
$cmt->showcount = 1;
$cmt->component = 'blog';
$manager = new comment($cmt);
$newcomment = $manager->add("New comment");
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$manager->delete($newcomment->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\\core\\event\\blog_comment_deleted', $event);
$this->assertEquals($context, $event->get_context());
$this->assertEquals($this->postid, $event->other['itemid']);
$url = new moodle_url('/blog/index.php', array('entryid' => $this->postid));
$this->assertEquals($url, $event->get_url());
$this->assertEventContextNotUsed($event);
}
示例13: comment
require 'components/query_string_standard.php';
require 'subclasses/comment.php';
$dbh_comment = new comment();
$object_name = 'dbh_comment';
require 'components/create_form_data.php';
extract($arr_form_data);
if ($_POST['btn_cancel']) {
log_action('Pressed cancel button');
redirect("listview_comment.php?{$query_string}");
}
if ($_POST['btn_submit']) {
log_action('Pressed submit button');
$message .= $dbh_comment->sanitize($arr_form_data)->lst_error;
extract($arr_form_data);
if ($dbh_comment->check_uniqueness($arr_form_data)->is_unique) {
//Good, no duplicate in database
} else {
$message = "Record already exists with the same primary identifiers!";
}
if ($message == "") {
$dbh_comment->add($arr_form_data);
redirect("listview_comment.php?{$query_string}");
}
}
}
require 'subclasses/comment_html.php';
$html = new comment_html();
$html->draw_header('Add Comment', $message, $message_type);
$html->draw_listview_referrer_info($filter_field_used, $filter_used, $page_from, $filter_sort_asc, $filter_sort_desc);
$html->draw_controls('add');
$html->draw_footer();
示例14: test_user_competency_comment_deleted
/**
* Test plan comment deleted event.
*/
public function test_user_competency_comment_deleted()
{
$this->resetAfterTest(true);
$this->setAdminUser();
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$user = $dg->create_user();
$fr = $lpg->create_framework();
$c = $lpg->create_competency(array('competencyframeworkid' => $fr->get_id()));
$uc = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c->get_id()));
$context = context_user::instance($user->id);
$cmt = new stdClass();
$cmt->context = $context;
$cmt->area = 'user_competency';
$cmt->itemid = $uc->get_id();
$cmt->component = 'competency';
$manager = new comment($cmt);
$newcomment = $manager->add("Comment to be deleted");
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$manager->delete($newcomment->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\\core\\event\\competency_comment_deleted', $event);
$this->assertEquals($context, $event->get_context());
$this->assertEquals($uc->get_id(), $event->other['itemid']);
$this->assertEventContextNotUsed($event);
$this->assertDebuggingNotCalled();
}
示例15: header
header("Location:index.php?page=post&s=view&id={$id}");
exit;
}
if (!$anon_comment && $user_nolog == "Anonymous") {
header('Location: index.php?page=account&s=home');
exit;
}
if (isset($_POST['post_anonymous']) || $_POST['post_anonymous'] == true) {
$user = "Anonymous";
$query = "SELECT id FROM {$user_table} WHERE user='{$user}' LIMIT 1";
$result = $db->query($query);
$row = $result->fetch_assoc();
$user_id = $row['id'];
$anon_id = $row['id'];
}
$comment->add($_POST['comment'], $user, $id, $ip, $user_id);
$cache = new cache();
$cache->destroy_page_cache("cache/" . $id);
$cache->create_page_cache("cache/" . $id);
header("Location:index.php?page=post&s=view&id={$id}");
} else {
if (isset($_GET['s']) && isset($_GET['cid']) && is_numeric($_GET['cid']) && isset($_GET['vote'])) {
$vote = $_GET['vote'];
$id = $_GET['post_id'];
$cid = $_GET['cid'];
if ($user == "Anonymous" && !$anon_vote) {
header('Location: index.php?page=account&s=home');
exit;
}
$cache = new cache();
@$cache->destroy_page_cache("cache/" . $id);