print_error('invalidpost', 'oublog');
}
if (!($oubloginstance = $DB->get_record('oublog_instances', array('id' => $post->oubloginstancesid)))) {
    print_error('invalidblog', 'oublog');
}
$url = new moodle_url('/mod/oublog/editcomment.php', array('blog' => $blog, 'post' => $postid, 'comment' => $commentid));
$PAGE->set_url($url);
// Check security.
$context = context_module::instance($cm->id);
oublog_check_view_permissions($oublog, $context, $cm);
$post->userid = $oubloginstance->userid;
// oublog_can_view_post needs this
if (!oublog_can_view_post($post, $USER, $context, $oublog->global)) {
    print_error('accessdenied', 'oublog');
}
oublog_get_activity_groupmode($cm, $course);
if (!oublog_can_comment($cm, $oublog, $post)) {
    print_error('accessdenied', 'oublog');
}
if ($oublog->allowcomments == OUBLOG_COMMENTS_PREVENT || $post->allowcomments == OUBLOG_COMMENTS_PREVENT) {
    print_error('commentsnotallowed', 'oublog');
}
$viewurl = 'viewpost.php?post=' . $post->id;
if ($oublog->global) {
    $blogtype = 'personal';
    if (!($oubloguser = $DB->get_record('user', array('id' => $oubloginstance->userid)))) {
        print_error('invaliduserid');
    }
} else {
    $blogtype = 'course';
}
 /**
  * @global object
  */
 public function load_data()
 {
     global $DB, $COURSE;
     if (!($this->oublog = $DB->get_record('oublog', array('id' => $this->oublogid)))) {
         throw new portfolio_caller_exception('invalidpostid', 'oublog');
     }
     if (!($this->cm = get_coursemodule_from_instance('oublog', $this->oublogid))) {
         throw new portfolio_caller_exception('invalidcoursemodule');
     }
     // Convert tag from id to name.
     if (!empty($this->tag)) {
         if ($tagrec = $DB->get_record('oublog_tags', array('id' => $this->tag), 'tag')) {
             $this->tag = $tagrec->tag;
         }
     }
     // Call early to cache group mode - stops debugging warning from oublog_get_posts later.
     $this->cm->activitygroupmode = oublog_get_activity_groupmode($this->cm, $COURSE);
     $context = context_module::instance($this->cm->id);
     $this->modcontext = $context;
     if ($this->canaudit == 1) {
         $this->canaudit = true;
     } else {
         $this->canaudit = false;
     }
     if (empty($this->oubloguserid)) {
         $this->oubloguserid = null;
     }
     if (empty($this->currentindividual) || $this->currentindividual == 0) {
         $this->currentindividual = -1;
     }
     list($this->posts, $recordcount) = oublog_get_posts($this->oublog, $context, $this->offset, $this->cm, $this->currentgroup, $this->currentindividual, $this->oubloguserid, $this->tag, $this->canaudit);
     $fs = get_file_storage();
     $this->multifiles = array();
     foreach ($this->posts as $post) {
         $files = array();
         $attach = $fs->get_area_files($this->modcontext->id, 'mod_oublog', 'attachment', $post->id);
         $embed = $fs->get_area_files($this->modcontext->id, 'mod_oublog', 'message', $post->id);
         if (!empty($post->comments)) {
             foreach ($post->comments as $commentpost) {
                 $embedcomments = $fs->get_area_files($this->modcontext->id, 'mod_oublog', 'messagecomment', $commentpost->id);
                 $files = array_merge($files, $embedcomments);
             }
         }
         $files = array_merge($files, $attach, $embed);
         if ($files) {
             $this->keyedfiles[$post->id] = $files;
         } else {
             continue;
         }
         $this->multifiles = array_merge($this->multifiles, $files);
     }
     $this->set_file_and_format_data($this->multifiles);
     if (empty($this->multifiles) && !empty($this->singlefile)) {
         $this->multifiles = array($this->singlefile);
         // Copy_files workaround.
     }
     // Depending on whether there are files or not, we might have to change richhtml/plainhtml.
     if (!empty($this->multifiles)) {
         $this->add_format(PORTFOLIO_FORMAT_RICHHTML);
     } else {
         $this->add_format(PORTFOLIO_FORMAT_PLAINHTML);
     }
 }
示例#3
0
/**
 * Get recent activity for a course
 *
 * @param array $activities
 * @param int $index
 * @param int $timestart
 * @param int $courseid
 * @param int $cmid
 * @param int $userid
 * @param int $groupid
 * @return bool
 */
function oublog_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid = 0, $groupid = 0)
{
    global $CFG, $COURSE, $DB;
    $sql = "SELECT i.oublogid, p.id AS postid, p.*, u.firstname, u.lastname, u.email, u.idnumber, u.picture, u.imagealt, i.userid\n            FROM {oublog_posts} p\n                INNER JOIN {oublog_instances} i ON p.oubloginstancesid = i.id\n                INNER JOIN {oublog} b ON i.oublogid = b.id\n                INNER JOIN {user} u ON i.userid = u.id\n            WHERE b.course = ? AND p.deletedby IS NULL AND p.timeposted >= ? ";
    if (!($rs = $DB->get_recordset_sql($sql, array($courseid, $timestart)))) {
        return true;
    }
    $modinfo = get_fast_modinfo($COURSE);
    foreach ($rs as $blog) {
        if (!isset($modinfo->instances['oublog'][$blog->oublogid])) {
            // not visible
            continue;
        }
        $cm = $modinfo->instances['oublog'][$blog->oublogid];
        if (!$cm->uservisible) {
            continue;
        }
        if (!has_capability('mod/oublog:view', context_module::instance($cm->id))) {
            continue;
        }
        if (!has_capability('mod/oublog:view', context_user::instance($blog->userid))) {
            continue;
        }
        $groupmode = oublog_get_activity_groupmode($cm, $COURSE);
        if ($groupmode) {
            if ($blog->groupid && $groupmode != VISIBLEGROUPS) {
                // separate mode
                if (isguestuser()) {
                    // shortcut
                    continue;
                }
                if (is_null($modinfo->groups)) {
                    $modinfo->groups = groups_get_user_groups($courseid);
                    // load all my groups and cache it in modinfo
                }
                if (!array_key_exists($blog->groupid, $modinfo->groups[0])) {
                    continue;
                }
            }
        }
        $tmpactivity = new object();
        $tmpactivity->type = 'oublog';
        $tmpactivity->cmid = $cm->id;
        $tmpactivity->name = $blog->title;
        $tmpactivity->sectionnum = $cm->sectionnum;
        $tmpactivity->timeposted = $blog->timeposted;
        $tmpactivity->content = new object();
        $tmpactivity->content->postid = $blog->postid;
        $tmpactivity->content->title = format_string($blog->title);
        $tmpactivity->user = new object();
        $tmpactivity->user->id = $blog->userid;
        $tmpactivity->user->firstname = $blog->firstname;
        $tmpactivity->user->lastname = $blog->lastname;
        $tmpactivity->user->picture = $blog->picture;
        $tmpactivity->user->imagealt = $blog->imagealt;
        $tmpactivity->user->email = $blog->email;
        $activities[$index++] = $tmpactivity;
    }
    $rs->close();
}
/**
 * Get last-modified time for blog, as it appears to this user. This takes into
 * account the user's groups/individual settings if required. Only works on
 * course blogs. (Does not check that user can view the blog.)
 * @param object $cm Course-modules entry for wiki
 * @param object $Course Course object
 * @param int $userid User ID or 0 = current
 * @return int Last-modified time for this user as seconds since epoch
 */
function oublog_get_last_modified($cm, $course, $userid = 0)
{
    global $CFG, $USER;
    if (!$userid) {
        $userid = $USER->id;
    }
    // Get blog record and groupmode
    if (!($oublog = get_record('oublog', 'id', $cm->instance))) {
        return false;
    }
    $groupmode = oublog_get_activity_groupmode($cm, $course);
    // Default applies no restriction
    $restrictjoin = '';
    $restrictwhere = '';
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    // Restrict to separate groups
    if ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context, $userid)) {
        if ($oublog->individual) {
            // In individual mode, group restriction works by shared grouping
            $restrictjoin .= "\nINNER JOIN {$CFG->prefix}groups_members gm2 ON gm.userid = bi.userid\nINNER JOIN {$CFG->prefix}groups g ON g.id = gm.groupid";
            $groupfield = "g.id";
            $restrictwhere .= "\nAND g.course = {$course->id}";
        } else {
            // Outside individual mode, group restriction works based on groupid
            // in post.
            $groupfield = "p.groupid";
        }
        $restrictjoin .= "\nINNER JOIN {$CFG->prefix}groups_members gm ON gm.groupid = {$groupfield}";
        $restrictwhere .= "\nAND gm.userid = {$userid}";
        if ($cm->groupingid) {
            $restrictjoin .= "\nINNER JOIN {$CFG->prefix}groupings_groups gg ON gg.groupid = {$groupfield}";
            $restrictwhere .= "\nAND gg.groupingid = {$cm->groupingid}";
        }
    }
    // Restrict to separate individuals
    if ($oublog->individual == OUBLOG_SEPARATE_INDIVIDUAL_BLOGS && !has_capability('mod/oublog:viewindividual', $context, $userid)) {
        // Um, only your own blog
        $restrictwhere .= "\nAND bi.userid = {$userid}";
    }
    // Query for newest version that follows these restrictions
    $result = get_field_sql($sql = "\nSELECT\n    MAX(p.timeposted)\nFROM\n    {$CFG->prefix}oublog_posts p\n    INNER JOIN {$CFG->prefix}oublog_instances bi ON p.oubloginstancesid = bi.id\n    {$restrictjoin}\nWHERE\n    bi.oublogid = {$oublog->id}\n    AND p.timedeleted IS NULL\n    {$restrictwhere}");
    return $result;
}
 /**
  * Print all user participation records for display
  *
  * @param object $cm current course module object
  * @param object $course current course object
  * @param object $oublog current oublog object
  * @param int $page html_table pagination page
  * @param array $participation mixed array of user participation values
  */
 public function render_all_users_participation_table($cm, $course, $oublog, $page, $limitnum, $participation, $getposts, $getcomments, $start, $end, $pagingurl)
 {
     global $DB, $CFG, $OUTPUT, $USER;
     require_once $CFG->dirroot . '/mod/oublog/participation_table.php';
     $groupmode = oublog_get_activity_groupmode($cm, $course);
     $thepagingbar = "";
     if (!empty($participation->posts) && $participation->postscount > $limitnum) {
         $thepagingbar = $OUTPUT->paging_bar($participation->postscount, $page, $limitnum, $pagingurl);
     } else {
         if (!empty($participation->comments) && $participation->commentscount > $limitnum) {
             $thepagingbar = $OUTPUT->paging_bar($participation->commentscount, $page, $limitnum, $pagingurl);
         }
     }
     if ($getposts) {
         $output = '';
         $output .= html_writer::tag('h2', $participation->postscount . ' ' . get_string('posts', 'oublog'));
         // Provide paging if postscount exceeds posts perpage.
         $output .= $thepagingbar;
         $poststable = new html_table();
         $poststable->head = array(get_string('user'), get_string('title', 'oublog'), get_string('date'), oublog_get_displayname($oublog, true));
         $poststable->size = array('25%', '25%', '25%', '25%');
         $poststable->colclasses = array('oublog_usersinfo_col', '', '', '');
         $poststable->attributes['class'] = 'oublog generaltable ';
         $poststable->data = array();
         foreach ($participation->posts as $post) {
             // Post user object required for user_picture.
             $postuser = new object();
             $postuser->id = $post->userid;
             $fields = explode(',', user_picture::fields('', null, '', 'poster'));
             foreach ($fields as $field) {
                 if ($field != 'id') {
                     $postuser->{$field} = $post->{$field};
                 }
             }
             $fullname = fullname($postuser);
             $row = array();
             $row[] = $OUTPUT->user_picture($postuser, array('class' => 'userpicture')) . $fullname;
             $url = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id));
             $postname = !empty($post->title) ? $post->title : get_string('untitledpost', 'oublog');
             $row[] = html_writer::div(html_writer::link($url, $postname), '');
             $row[] = html_writer::div(oublog_date($post->timeposted));
             $bparams = array('id' => $cm->id);
             $linktext = $name = $grpname = $dispname = '';
             if (oublog_get_displayname($oublog)) {
                 $dispname = oublog_get_displayname($oublog);
             }
             if ($post->blogname != "") {
                 $linktext = $post->blogname;
             } else {
                 if ($oublog->name != "") {
                     if ($groupmode > NOGROUPS && isset($post->groupid) && $post->groupid > 0) {
                         $bparams['group'] = $post->groupid;
                         $grpname = groups_get_group_name($post->groupid);
                     } else {
                         if ($oublog->individual != OUBLOG_NO_INDIVIDUAL_BLOGS) {
                             $bparams['individual'] = $post->userid;
                             $name = fullname($postuser);
                         }
                     }
                     if ($post->groupid == 0 && $oublog->individual > OUBLOG_NO_INDIVIDUAL_BLOGS) {
                         $name = fullname($postuser);
                     } else {
                         if (!$groupmode) {
                             $name = $oublog->name;
                         }
                     }
                     $a = (object) array('name' => $grpname . " " . $name, 'displayname' => $dispname);
                     $linktext = get_string('defaultpersonalblogname', 'oublog', $a);
                 }
             }
             if (!$groupmode && !$oublog->global && $oublog->individual == 0) {
                 $a = (object) array('name' => $grpname . " " . $name, 'displayname' => $dispname);
                 $linktext = get_string('defaultpersonalblogname', 'oublog', $a);
             }
             if (!$groupmode) {
                 $linktext = $name;
             }
             $burl = new moodle_url('/mod/oublog/view.php', $bparams);
             $row[] = html_writer::link($burl, $linktext);
             $poststable->data[] = $row;
         }
         $output .= html_writer::table($poststable);
         $output .= $thepagingbar;
         return $output;
     }
     if ($getcomments) {
         $output = '';
         // Do the comments stuff here.
         if (!$participation->comments) {
             $output .= html_writer::tag('h2', get_string('nousercomments', 'oublog'));
         } else {
             $output .= html_writer::tag('h2', $participation->commentscount . ' ' . get_string('comments', 'oublog'));
             // Provide paging if commentscount exceeds posts perpage.
             $output .= $thepagingbar;
             $commenttable = new html_table();
             $commenttable->head = array(get_string('user'), get_string('title', 'oublog'), get_string('date'), get_string('post'));
             $commenttable->size = array('25%', '25%', '25%', '25%');
             $commenttable->colclasses = array('oublog_usersinfo_col ', '', '', 'oublog_postsinfo_col');
             $commenttable->attributes['class'] = 'oublog generaltable ';
             $commenttable->data = array();
             unset($bparams);
             foreach ($participation->comments as $comment) {
                 $row = array();
                 // Comment author object required for user_picture.
                 $commentauthor = new stdClass();
                 $commentauthor->id = $comment->commenterid;
                 $fields = explode(',', user_picture::fields('', null, '', 'commenter'));
                 foreach ($fields as $field) {
                     if ($field != 'id') {
                         $cfield = "commenter" . $field;
                         $commentauthor->{$field} = $comment->{$cfield};
                     }
                 }
                 $viewposturl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $comment->postid));
                 $viewpostcommenturl = $viewposturl->out() . '#cid' . $comment->id;
                 $commenttitle = !empty($comment->title) ? $comment->title : get_string('untitledcomment', 'oublog');
                 $posttitle = !empty($comment->posttitle) ? $comment->posttitle : get_string('untitledpost', 'oublog');
                 $viewcommentlink = html_writer::link($viewpostcommenturl, s($commenttitle));
                 // User cell.
                 $usercell = $OUTPUT->user_picture($commentauthor, array('class' => 'userpicture'));
                 $usercell .= html_writer::start_tag('div', array('class' => ''));
                 $usercell .= fullname($commentauthor);
                 $usercell .= html_writer::end_tag('div');
                 $row[] = $usercell;
                 // Comments cell.
                 $row[] = $viewcommentlink;
                 // Comment date cell.
                 $row[] = userdate($comment->timeposted);
                 // Start of cell 4 code should resemble view page block code.
                 $postauthor = new stdClass();
                 $postauthor->id = $comment->posterid;
                 $postauthor->groupid = $comment->groupid;
                 $fields = explode(',', user_picture::fields('', null, '', 'poster'));
                 foreach ($fields as $field) {
                     if ($field != 'id') {
                         $pfield = "poster" . $field;
                         $postauthor->{$field} = $comment->{$pfield};
                     }
                 }
                 $bparams = array('id' => $cm->id);
                 $linktext = $name = $grpname = $dispname = '';
                 if (oublog_get_displayname($oublog)) {
                     $dispname = oublog_get_displayname($oublog);
                 }
                 if ($comment->bloginstancename != '') {
                     $bparams['individual'] = $comment->posterid;
                     $bparams['group'] = $comment->groupid;
                     $name = fullname($postauthor);
                 } else {
                     if ($oublog->name != "") {
                         if ($groupmode > NOGROUPS && isset($comment->groupid) && $comment->groupid > 0) {
                             $bparams['group'] = $comment->groupid;
                             $grpname = groups_get_group_name($comment->groupid);
                         } else {
                             if ($oublog->individual != OUBLOG_NO_INDIVIDUAL_BLOGS) {
                                 $bparams['individual'] = $comment->posterid;
                                 $name = fullname($postauthor);
                             }
                         }
                         if ($comment->groupid == 0 && $oublog->individual > OUBLOG_NO_INDIVIDUAL_BLOGS) {
                             $name = fullname($postauthor);
                         } else {
                             if (!$groupmode) {
                                 $name = $oublog->name;
                             }
                         }
                         $a = (object) array('name' => $grpname . $name, 'displayname' => $dispname);
                         $linktext = get_string('defaultpersonalblogname', 'oublog', $a);
                     }
                 }
                 if (!$groupmode && !$oublog->global && $oublog->individual == 0) {
                     // Personal or course wide.
                     $a = (object) array('name' => $grpname . $name, 'displayname' => $dispname);
                     $linktext = get_string('defaultpersonalblogname', 'oublog', $a);
                 }
                 if (!$groupmode) {
                     $linktext = $name;
                 }
                 $postauthorurl = new moodle_url('/mod/oublog/view.php', $bparams);
                 $postauthorlink = html_writer::link($postauthorurl, $linktext);
                 $viewpostlink = html_writer::link($viewposturl, s($posttitle));
                 // Posts cell.
                 $postscell = html_writer::start_tag('div', array('class' => 'oublog_postsinfo'));
                 $postscell .= $OUTPUT->user_picture($postauthor, array('courseid' => $oublog->course, 'class' => 'userpicture'));
                 $postscell .= html_writer::start_tag('div', array('class' => 'oublog_postscell'));
                 $postscell .= html_writer::start_tag('div', array('class' => 'oublog_postsinfo_label'));
                 $postscell .= html_writer::start_tag('div', array('class' => 'oublog_postscell_posttitle'));
                 $postscell .= html_writer::link($postauthorlink, $viewpostlink);
                 $postscell .= html_writer::end_tag('div');
                 $postscell .= html_writer::start_tag('div', array('class' => 'oublogstats_commentposts_blogname'));
                 $postscell .= html_writer::empty_tag('br', array());
                 $postscell .= oublog_date($comment->postdate);
                 $postscell .= html_writer::empty_tag('br', array());
                 $postscell .= $postauthorlink;
                 $postscell .= html_writer::end_tag('div');
                 $postscell .= html_writer::end_tag('div');
                 $postscell .= html_writer::end_tag('div');
                 $postscell .= html_writer::end_tag('div');
                 $postscell .= html_writer::end_tag('div');
                 $row[] = $postscell;
                 $commenttable->data[] = $row;
             }
             $output .= html_writer::table($commenttable);
             $output .= $thepagingbar;
             return $output;
         }
     }
 }