Example #1
0
$courseid = $_REQUEST['courseid'];
$activityid = $_REQUEST['activityid'];
$itemid = $_REQUEST['itemid'];
$commentarea = $_REQUEST['commentarea'];
$comment = $_REQUEST['comment'];
if (!$course = $DB->get_record("course", array("id" => $courseid))) {
    print_error("Course ID not found");
}
if ($courseid == SITEID)
    $context = context_system::instance();
else
    $context = context_course::instance($course->id);

$PAGE->set_context($context);
$comm = new stdClass;
$comm->courseid = $courseid;
$comm->activityid = $activityid;
$comm->itemid = $itemid;
$comm->commentarea = $commentarea;
$comm->userid = $USER->id;
$comm->comment = $comment;
$comm->time = time();
$string = str_replace(' ', '', $comment);
if ($string != '') {
    $comm->id = $DB->insert_record('local_comment', $comm);
    echo get_existing_comments($courseid, $itemid, $comm) . '!@' . $DB->count_records('local_comment', array('courseid' => $courseid, 'activityid' => $activityid, 'itemid' => $itemid, 'commentarea' => $commentarea));
}
?>


Example #2
0
<?php

require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot . '/local/ratings/lib.php');
global $USER, $DB, $CFG;

$courseid = $_REQUEST['courseid'];
$activityid = $_REQUEST['activityid'];
$itemid = $_REQUEST['itemid'];
$commentarea = $_REQUEST['commentarea'];
if (!$course = $DB->get_record("course", array("id" => $courseid))) {
    print_error("Course ID not found");
}
if ($courseid == SITEID)
    $context = context_system::instance();
else
    $context = context_course::instance($course->id);
$PAGE->set_context($context);
$records = $DB->get_records('local_comment', array('courseid' => $courseid, 'activityid' => $activityid, 'itemid' => $itemid, 'commentarea' => $commentarea));
$return = array();
foreach ($records as $record) {
    $return[] = get_existing_comments($courseid, $itemid, $record);
}
echo implode($return);
?>
Example #3
0
/**
 * @method  display_comment_area
 * @todo provides the option to give the comment
 * @param int $courseid course id 
 * @param string $activity activity id
 * @param int $itemid activity node
 * @param string $commentarea activity name,
 * @return provide the inteface to do comment
 */
function display_comment_area($courseid, $activityid, $itemid, $commentarea) {
    global $CFG, $USER, $DB;
    $result = html_writer::start_tag('div', array('class' => 'mycomment'));
    $params = array('courseid' => $courseid, 'activityid' => $activityid, 'itemid' => $itemid, 'commentarea' => $commentarea);
    $existing_comments = $DB->get_records('local_comment', $params, 'time DESC');
    $count_comments = $DB->count_records('local_comment', $params);
    if ($commentarea == "storywall")
        $result .= html_writer::tag('a', 'Share your Comment', array('id' => 'anchorclass_' . $itemid, "href" => "javascript:void(0)"));
    else
        $result .= html_writer::tag('a', 'Share your Comment', array('id' => 'anchorclass_' . $itemid, "href" => "javascript:void(0)", "onClick" => "fnViewAllComments($itemid)"));
    if ($commentarea !== 'forum') {
        $result .= '&nbsp;(<font class="commentcount_' . $itemid . '">' . $count_comments . '</font>)';
    }
    // used to make comment area visible by default   
    if ($commentarea == "storywall")
        $result .= html_writer::start_tag('div', array('class' => 'coursecomment', 'id' => 'comment_list_' . $itemid, 'style' => 'width:95% !important; position:relative'));
    else
        $result .= html_writer::start_tag('div', array('class' => 'coursecomment', 'id' => 'comment_list_' . $itemid, 'style' => 'display: none;'));

    $closeIcon = html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/local/ratings/pix/icon_close_popup.gif', 'title' => 'Close'));
    $result .= html_writer::tag('div', $closeIcon, array('style' => 'float: right; cursor: pointer;', 'class' => 'closeicon' . $itemid));
    if (isloggedin() && !isguestuser()) {
        $enroll = true;
        if ($courseid !== SITEID) {
            $context = context_course::instance($courseid);
            if (!is_enrolled($context, $USER->id) && !is_siteadmin()) {
                //&& !has_capability('local/feedback:view', $context)
                $enroll = false;
            }
        }
        if (!$enroll) {
            $result .= '<div>You need to enroll to the ' . $commentarea . ' to comment.</div>';
        } else {
            $result .= html_writer::start_tag('textarea', array('name' => 'commentarea', 'id' => 'mycomment_' . $itemid, 'rows' => '2', 'cols' => '50'));
            $result .= html_writer::end_tag('textarea');
            $button = html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/local/ratings/pix/add-comment.gif'));
            //$button = html_writer::tag('button', 'Comment', array());
            $result .= html_writer::tag('a', $button, array('class' => 'commentclick_' . $itemid, "href" => "javascript:void(0)", "onClick" => "fnComment($courseid, $activityid, $itemid, \"$commentarea\", \"$CFG->wwwroot\")", 'style' => 'font-size: 12px;'));
        }
    }
    $result .= html_writer::start_tag('div', array('class' => 'comment_' . $itemid));
    $result .= html_writer::end_tag('div'); // End of .comment_$itemid
    $i = 1;
    foreach ($existing_comments as $existing_comment) {
        if ($i > 3) {
            $result .= html_writer::start_tag('div', array('class' => 'viewallcomments' . $itemid, 'style' => 'display: none;'));
        }
        $result .= get_existing_comments($courseid, $itemid, $existing_comment);
        if ($i > 3) {
            $result .= html_writer::end_tag('div'); // End of .comment_$itemid
        }
        $i++;
    }
    if ($count_comments > 3) {
        //  only applied to storywall plugin
        if ($commentarea == "storywall")
            $result .= html_writer::tag('a', 'View All', array("href" => "javascript:void(0)", 'class' => 'viewall' . $itemid, 'style' => 'font-size: 12px;', "onClick" => "fnstorywallComments($itemid)"));
        else
            $result .= html_writer::tag('a', 'View All', array("href" => "javascript:void(0)", 'style' => 'font-size: 12px;', 'class' => 'viewall' . $itemid));
    }
    $result .= html_writer::end_tag('div'); // End of .comment_list
    $result .= html_writer::end_tag('div'); // End of .mycomment
    return $result;
}