• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP forum_user_can_see_discussion函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中forum_user_can_see_discussion函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_user_can_see_discussion函数的具体用法?PHP forum_user_can_see_discussion怎么用?PHP forum_user_can_see_discussion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了forum_user_can_see_discussion函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: forum_check_throttling

if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) && !empty($discussion->id) && !forum_user_has_posted($forum->id, $discussion->id, $USER->id)) {
    echo $OUTPUT->notification(get_string('qandanotify', 'forum'));
}
forum_check_throttling($forum, $cm);
if (!empty($parent)) {
    if (!($discussion = $DB->get_record('forum_discussions', array('id' => $parent->discussion)))) {
        print_error('notpartofdiscussion', 'forum');
    }
    // #marginalia begin
    $moodlemia = moodle_marginalia::get_instance();
    $miaprofile = $moodlemia->get_profile($PAGE->url->out(false));
    if ($miaprofile) {
        $miaprofile->emit_body();
        $miaprofile->emit_margin_controls();
    }
    // #marginalia end
    forum_print_post($parent, $discussion, $forum, $cm, $course, false, false, false);
    if (empty($post->edit)) {
        if ($forum->type != 'qanda' || forum_user_can_see_discussion($forum, $discussion, $modcontext)) {
            $forumtracked = forum_tp_is_tracked($forum);
            $posts = forum_get_all_discussion_posts($discussion->id, "created ASC", $forumtracked);
            forum_print_posts_threaded($course, $cm, $forum, $discussion, $parent, 0, false, $forumtracked, $posts);
        }
    }
} else {
    if (!empty($forum->intro)) {
        echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro');
    }
}
$mform_post->display();
echo $OUTPUT->footer();
开发者ID:njorth,项目名称:marginalia,代码行数:31,代码来源:post.php


示例2: forum_print_latest_discussions


//.........这里部分代码省略.........
            // If the forum can be tracked, display the unread column.
            if ($cantrack) {
                echo '<th class="header replies" scope="col">'.get_string('unread', 'forum');
                if ($forumtracked) {
                    echo '<a title="'.get_string('markallread', 'forum').
                         '" href="'.$CFG->wwwroot.'/mod/forum/markposts.php?f='.
                         $forum->id.'&amp;mark=read&amp;returnpage=view.php">'.
                         '<img src="'.$OUTPUT->pix_url('t/markasread') . '" class="iconsmall" alt="'.get_string('markallread', 'forum').'" /></a>';
                }
                echo '</th>';
            }
        }
        echo '<th class="header lastpost" scope="col">'.get_string('lastpost', 'forum').'</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
    }

    foreach ($discussions as $discussion) {
        if (!empty($replies[$discussion->discussion])) {
            $discussion->replies = $replies[$discussion->discussion]->replies;
            $discussion->lastpostid = $replies[$discussion->discussion]->lastpostid;
        } else {
            $discussion->replies = 0;
        }

        // SPECIAL CASE: The front page can display a news item post to non-logged in users.
        // All posts are read in this case.
        if (!$forumtracked) {
            $discussion->unread = '-';
        } else if (empty($USER)) {
            $discussion->unread = 0;
        } else {
            if (empty($unreads[$discussion->discussion])) {
                $discussion->unread = 0;
            } else {
                $discussion->unread = $unreads[$discussion->discussion];
            }
        }

        if (isloggedin()) {
            $ownpost = ($discussion->userid == $USER->id);
        } else {
            $ownpost=false;
        }
        // Use discussion name instead of subject of first post
        $discussion->subject = $discussion->name;

        switch ($displayformat) {
            case 'header':
                if ($groupmode > 0) {
                    if (isset($groups[$discussion->groupid])) {
                        $group = $groups[$discussion->groupid];
                    } else {
                        $group = $groups[$discussion->groupid] = groups_get_group($discussion->groupid);
                    }
                } else {
                    $group = -1;
                }
                forum_print_discussion_header($discussion, $forum, $group, $strdatestring, $cantrack, $forumtracked,
                    $canviewparticipants, $context);
            break;
            default:
                $link = false;

                if ($discussion->replies) {
                    $link = true;
                } else {
                    $modcontext = context_module::instance($cm->id);
                    $link = forum_user_can_see_discussion($forum, $discussion, $modcontext, $USER);
                }

                $discussion->forum = $forum->id;

                forum_print_post($discussion, $discussion, $forum, $cm, $course, $ownpost, 0, $link, false,
                        '', null, true, $forumtracked);
            break;
        }
    }

    if ($displayformat == "header") {
        echo '</tbody>';
        echo '</table>';
    }

    if ($olddiscussionlink) {
        if ($forum->type == 'news') {
            $strolder = get_string('oldertopics', 'forum');
        } else {
            $strolder = get_string('olderdiscussions', 'forum');
        }
        echo '<div class="forumolddiscuss">';
        echo '<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'&amp;showall=1">';
        echo $strolder.'</a> ...</div>';
    }

    if ($page != -1) { ///Show the paging bar
        echo $OUTPUT->paging_bar($numdiscussions, $page, $perpage, "view.php?f=$forum->id");
    }
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:lib.php


示例3: forum_rss_feed_contents

/**
 * This function return the XML rss contents about the forum
 * It returns false if something is wrong
 *
 * @param stdClass $forum the forum object
 * @param string $sql the SQL used to retrieve the contents from the database
 * @param array $params the SQL parameters used
 * @param object $context the context this forum relates to
 * @return bool|string false if the contents is empty, otherwise the contents of the feed is returned
 *
 * @Todo MDL-31129 implement post attachment handling
 */

function forum_rss_feed_contents($forum, $sql, $params, $context) {
    global $CFG, $DB, $USER;

    $status = true;

    $recs = $DB->get_recordset_sql($sql, $params, 0, $forum->rssarticles);

    //set a flag. Are we displaying discussions or posts?
    $isdiscussion = true;
    if (!empty($forum->rsstype) && $forum->rsstype!=1) {
        $isdiscussion = false;
    }

    if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
        print_error('invalidcoursemodule');
    }

    $formatoptions = new stdClass();
    $items = array();
    foreach ($recs as $rec) {
            $item = new stdClass();
            $user = new stdClass();

            $discussion = new stdClass();
            $discussion->id = $rec->discussionid;
            $discussion->groupid = $rec->groupid;
            $discussion->timestart = $rec->timestart;
            $discussion->timeend = $rec->timeend;

            $post = null;
            if (!$isdiscussion) {
                $post = new stdClass();
                $post->id = $rec->postid;
                $post->parent = $rec->postparent;
                $post->userid = $rec->userid;
            }

            if ($isdiscussion && !forum_user_can_see_discussion($forum, $discussion, $context)) {
                // This is a discussion which the user has no permission to view
                $item->title = get_string('forumsubjecthidden', 'forum');
                $message = get_string('forumbodyhidden', 'forum');
                $item->author = get_string('forumauthorhidden', 'forum');
            } else if (!$isdiscussion && !forum_user_can_see_post($forum, $discussion, $post, $USER, $cm)) {
                // This is a post which the user has no permission to view
                $item->title = get_string('forumsubjecthidden', 'forum');
                $message = get_string('forumbodyhidden', 'forum');
                $item->author = get_string('forumauthorhidden', 'forum');
            } else {
                // The user must have permission to view
                if ($isdiscussion && !empty($rec->discussionname)) {
                    $item->title = format_string($rec->discussionname);
                } else if (!empty($rec->postsubject)) {
                    $item->title = format_string($rec->postsubject);
                } else {
                    //we should have an item title by now but if we dont somehow then substitute something somewhat meaningful
                    $item->title = format_string($forum->name.' '.userdate($rec->postcreated,get_string('strftimedatetimeshort', 'langconfig')));
                }
                $user->firstname = $rec->userfirstname;
                $user->lastname = $rec->userlastname;
                $item->author = fullname($user);
                $message = file_rewrite_pluginfile_urls($rec->postmessage, 'pluginfile.php', $context->id,
                        'mod_forum', 'post', $rec->postid);
                $formatoptions->trusted = $rec->posttrust;
            }

            if ($isdiscussion) {
                $item->link = $CFG->wwwroot."/mod/forum/discuss.php?d=".$rec->discussionid;
            } else {
                $item->link = $CFG->wwwroot."/mod/forum/discuss.php?d=".$rec->discussionid."&parent=".$rec->postid;
            }

            $formatoptions->trusted = $rec->posttrust;
            $item->description = format_text($message, $rec->postformat, $formatoptions, $forum->course);

            //TODO: MDL-31129 implement post attachment handling
            /*if (!$isdiscussion) {
                $post_file_area_name = str_replace('//', '/', "$forum->course/$CFG->moddata/forum/$forum->id/$rec->postid");
                $post_files = get_directory_list("$CFG->dataroot/$post_file_area_name");

                if (!empty($post_files)) {
                    $item->attachments = array();
                }
            }*/
            $item->pubdate = $rec->postcreated;

            $items[] = $item;
        }
//.........这里部分代码省略.........
开发者ID:verbazend,项目名称:AWFA,代码行数:101,代码来源:rsslib.php


示例4: get_forum_discussions

 /**
  * Returns a list of forum discussions as well as a summary of the discussion
  * in a provided list of forums.
  *
  * @param array $forumids the forum ids
  * @param int $limitfrom limit from SQL data
  * @param int $limitnum limit number SQL data
  *
  * @return array the forum discussion details
  * @since Moodle 2.5
  */
 public static function get_forum_discussions($forumids, $limitfrom = 0, $limitnum = 0)
 {
     global $CFG, $DB, $USER;
     require_once $CFG->dirroot . "/mod/forum/lib.php";
     // Validate the parameter.
     $params = self::validate_parameters(self::get_forum_discussions_parameters(), array('forumids' => $forumids, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum));
     $forumids = $params['forumids'];
     $limitfrom = $params['limitfrom'];
     $limitnum = $params['limitnum'];
     // Array to store the forum discussions to return.
     $arrdiscussions = array();
     // Keep track of the users we have looked up in the DB.
     $arrusers = array();
     // Loop through them.
     foreach ($forumids as $id) {
         // Get the forum object.
         $forum = $DB->get_record('forum', array('id' => $id), '*', MUST_EXIST);
         $course = get_course($forum->course);
         $modinfo = get_fast_modinfo($course);
         $forums = $modinfo->get_instances_of('forum');
         $cm = $forums[$forum->id];
         // Get the module context.
         $modcontext = context_module::instance($cm->id);
         // Validate the context.
         self::validate_context($modcontext);
         require_capability('mod/forum:viewdiscussion', $modcontext);
         // Get the discussions for this forum.
         $params = array();
         $groupselect = "";
         $groupmode = groups_get_activity_groupmode($cm, $course);
         if ($groupmode and $groupmode != VISIBLEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext)) {
             // Get all the discussions from all the groups this user belongs to.
             $usergroups = groups_get_user_groups($course->id);
             if (!empty($usergroups['0'])) {
                 list($sql, $params) = $DB->get_in_or_equal($usergroups['0']);
                 $groupselect = "AND (groupid {$sql} OR groupid = -1)";
             }
         }
         array_unshift($params, $id);
         $select = "forum = ? {$groupselect}";
         if ($discussions = $DB->get_records_select('forum_discussions', $select, $params, 'timemodified DESC', '*', $limitfrom, $limitnum)) {
             // Check if they can view full names.
             $canviewfullname = has_capability('moodle/site:viewfullnames', $modcontext);
             // Get the unreads array, this takes a forum id and returns data for all discussions.
             $unreads = array();
             if ($cantrack = forum_tp_can_track_forums($forum)) {
                 if ($forumtracked = forum_tp_is_tracked($forum)) {
                     $unreads = forum_get_discussions_unread($cm);
                 }
             }
             // The forum function returns the replies for all the discussions in a given forum.
             $replies = forum_count_discussion_replies($id);
             foreach ($discussions as $discussion) {
                 // This function checks capabilities, timed discussions, groups and qanda forums posting.
                 if (!forum_user_can_see_discussion($forum, $discussion, $modcontext)) {
                     continue;
                 }
                 $usernamefields = user_picture::fields();
                 // If we don't have the users details then perform DB call.
                 if (empty($arrusers[$discussion->userid])) {
                     $arrusers[$discussion->userid] = $DB->get_record('user', array('id' => $discussion->userid), $usernamefields, MUST_EXIST);
                 }
                 // Get the subject.
                 $subject = $DB->get_field('forum_posts', 'subject', array('id' => $discussion->firstpost), MUST_EXIST);
                 // Create object to return.
                 $return = new stdClass();
                 $return->id = (int) $discussion->id;
                 $return->course = $discussion->course;
                 $return->forum = $discussion->forum;
                 $return->name = $discussion->name;
                 $return->userid = $discussion->userid;
                 $return->groupid = $discussion->groupid;
                 $return->assessed = $discussion->assessed;
                 $return->timemodified = (int) $discussion->timemodified;
                 $return->usermodified = $discussion->usermodified;
                 $return->timestart = $discussion->timestart;
                 $return->timeend = $discussion->timeend;
                 $return->firstpost = (int) $discussion->firstpost;
                 $return->firstuserfullname = fullname($arrusers[$discussion->userid], $canviewfullname);
                 $return->firstuserimagealt = $arrusers[$discussion->userid]->imagealt;
                 $return->firstuserpicture = $arrusers[$discussion->userid]->picture;
                 $return->firstuseremail = $arrusers[$discussion->userid]->email;
                 $return->subject = $subject;
                 $return->numunread = '';
                 if ($cantrack && $forumtracked) {
                     if (isset($unreads[$discussion->id])) {
                         $return->numunread = (int) $unreads[$discussion->id];
                     }
                 }
//.........这里部分代码省略.........
开发者ID:educacionbe,项目名称:cursos,代码行数:101,代码来源:externallib.php


示例5: get_forum_discussions_paginated

 /**
  * Returns a list of forum discussions optionally sorted and paginated.
  *
  * @param int $forumid the forum instance id
  * @param string $sortby sort by this element (id, timemodified, timestart or timeend)
  * @param string $sortdirection sort direction: ASC or DESC
  * @param int $page page number
  * @param int $perpage items per page
  *
  * @return array the forum discussion details including warnings
  * @since Moodle 2.8
  */
 public static function get_forum_discussions_paginated($forumid, $sortby = 'timemodified', $sortdirection = 'DESC', $page = -1, $perpage = 0)
 {
     global $CFG, $DB, $USER;
     require_once $CFG->dirroot . "/mod/forum/lib.php";
     $warnings = array();
     $discussions = array();
     $params = self::validate_parameters(self::get_forum_discussions_paginated_parameters(), array('forumid' => $forumid, 'sortby' => $sortby, 'sortdirection' => $sortdirection, 'page' => $page, 'perpage' => $perpage));
     // Compact/extract functions are not recommended.
     $forumid = $params['forumid'];
     $sortby = $params['sortby'];
     $sortdirection = $params['sortdirection'];
     $page = $params['page'];
     $perpage = $params['perpage'];
     $sortallowedvalues = array('id', 'timemodified', 'timestart', 'timeend');
     if (!in_array($sortby, $sortallowedvalues)) {
         throw new invalid_parameter_exception('Invalid value for sortby parameter (value: ' . $sortby . '),' . 'allowed values are: ' . implode(',', $sortallowedvalues));
     }
     $sortdirection = strtoupper($sortdirection);
     $directionallowedvalues = array('ASC', 'DESC');
     if (!in_array($sortdirection, $directionallowedvalues)) {
         throw new invalid_parameter_exception('Invalid value for sortdirection parameter (value: ' . $sortdirection . '),' . 'allowed values are: ' . implode(',', $directionallowedvalues));
     }
     $forum = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST);
     $course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST);
     $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
     // Validate the module context. It checks everything that affects the module visibility (including groupings, etc..).
     $modcontext = context_module::instance($cm->id);
     self::validate_context($modcontext);
     // Check they have the view forum capability.
     require_capability('mod/forum:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'forum');
     $sort = 'd.' . $sortby . ' ' . $sortdirection;
     $alldiscussions = forum_get_discussions($cm, $sort, true, -1, -1, true, $page, $perpage);
     if ($alldiscussions) {
         $canviewfullname = has_capability('moodle/site:viewfullnames', $modcontext);
         // Get the unreads array, this takes a forum id and returns data for all discussions.
         $unreads = array();
         if ($cantrack = forum_tp_can_track_forums($forum)) {
             if ($forumtracked = forum_tp_is_tracked($forum)) {
                 $unreads = forum_get_discussions_unread($cm);
             }
         }
         // The forum function returns the replies for all the discussions in a given forum.
         $replies = forum_count_discussion_replies($forumid, $sort, -1, $page, $perpage);
         foreach ($alldiscussions as $discussion) {
             // This function checks for qanda forums.
             // Note that the forum_get_discussions returns as id the post id, not the discussion id so we need to do this.
             $discussionrec = clone $discussion;
             $discussionrec->id = $discussion->discussion;
             if (!forum_user_can_see_discussion($forum, $discussionrec, $modcontext)) {
                 $warning = array();
                 // Function forum_get_discussions returns forum_posts ids not forum_discussions ones.
                 $warning['item'] = 'post';
                 $warning['itemid'] = $discussion->id;
                 $warning['warningcode'] = '1';
                 $warning['message'] = 'You can\'t see this discussion';
                 $warnings[] = $warning;
                 continue;
             }
             $discussion->numunread = 0;
             if ($cantrack && $forumtracked) {
                 if (isset($unreads[$discussion->discussion])) {
                     $discussion->numunread = (int) $unreads[$discussion->discussion];
                 }
             }
             $discussion->numreplies = 0;
             if (!empty($replies[$discussion->discussion])) {
                 $discussion->numreplies = (int) $replies[$discussion->discussion]->replies;
             }
             // Load user objects from the results of the query.
             $user = new stdclass();
             $user->id = $discussion->userid;
             $user = username_load_fields_from_object($user, $discussion);
             $discussion->userfullname = fullname($user, $canviewfullname);
             // We can have post written by users that are deleted. In this case, those users don't have a valid context.
             $usercontext = context_user::instance($user->id, IGNORE_MISSING);
             if ($usercontext) {
                 $discussion->userpictureurl = moodle_url::make_webservice_pluginfile_url($usercontext->id, 'user', 'icon', null, '/', 'f1')->out(false);
             } else {
                 $discussion->userpictureurl = '';
             }
             $usermodified = new stdclass();
             $usermodified->id = $discussion->usermodified;
             $usermodified = username_load_fields_from_object($usermodified, $discussion, 'um');
             $discussion->usermodifiedfullname = fullname($usermodified, $canviewfullname);
             // We can have post written by users that are deleted. In this case, those users don't have a valid context.
             $usercontext = context_user::instance($usermodified->id, IGNORE_MISSING);
             if ($usercontext) {
                 $discussion->usermodifiedpictureurl = moodle_url::make_webservice_pluginfile_url($usercontext->id, 'user', 'icon', null, '/', 'f1')->out(false);
//.........这里部分代码省略.........
开发者ID:educakanchay,项目名称:campus,代码行数:101,代码来源:externallib.php


示例6: site_frontpage_news

    /**
     * Alternative rendering of front page news, called from layout/faux_site_index.php which
     * replaces the standard news output with this.
     *
     * @return string
     */
    public function site_frontpage_news()
    {
        global $CFG, $SITE;
        require_once $CFG->dirroot . '/mod/forum/lib.php';
        if (!($forum = forum_get_course_forum($SITE->id, 'news'))) {
            print_error('cannotfindorcreateforum', 'forum');
        }
        $cm = get_coursemodule_from_instance('forum', $forum->id, $SITE->id, false, MUST_EXIST);
        $context = \context_module::instance($cm->id, MUST_EXIST);
        $output = html_writer::start_tag('div', array('id' => 'site-news-forum', 'class' => 'clearfix'));
        $output .= $this->heading(format_string($forum->name, true, array('context' => $context)));
        $groupmode = groups_get_activity_groupmode($cm, $SITE);
        $currentgroup = groups_get_activity_group($cm);
        if (!($discussions = forum_get_discussions($cm, 'p.modified DESC', true, null, $SITE->newsitems, false, -1, $SITE->newsitems))) {
            $output .= html_writer::tag('div', '(' . get_string('nonews', 'forum') . ')', array('class' => 'forumnodiscuss'));
            if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
                $output .= html_writer::link(new moodle_url('/mod/forum/post.php', array('forum' => $forum->id)), get_string('addanewtopic', 'forum'), array('class' => 'btn btn-primary'));
            } else {
                // No news and user cannot edit, so return nothing.
                return '';
            }
            return $output . '</div>';
        }
        $output .= html_writer::start_div('', array('id' => 'news-articles'));
        foreach ($discussions as $discussion) {
            if (!forum_user_can_see_discussion($forum, $discussion, $context)) {
                continue;
            }
            $message = file_rewrite_pluginfile_urls($discussion->message, 'pluginfile.php', $context->id, 'mod_forum', 'post', $discussion->id);
            $imagestyle = '';
            $imgarr = \theme_snap\local::extract_first_image($message);
            if ($imgarr) {
                $imageurl = s($imgarr['src']);
                $imagestyle = " style=\"background-image:url('{$imageurl}')\"";
            }
            $name = format_string($discussion->name, true, array('context' => $context));
            $date = userdate($discussion->timemodified, get_string('strftimedatetime', 'langconfig'));
            $readmorebtn = "<a class='btn btn-default toggle' href='" . $CFG->wwwroot . "/mod/forum/discuss.php?d=" . $discussion->discussion . "'>" . get_string('readmore', 'theme_snap') . "</a>";
            $preview = '';
            $newsimage = '';
            if (!$imagestyle) {
                $preview = html_to_text($message, 0, false);
                $preview = "<div class='news-article-preview'><p>" . shorten_text($preview, 200) . "</p>\n                <p class='text-right'>" . $readmorebtn . "</p></div>";
            } else {
                $newsimage = '<div class="news-article-image toggle"' . $imagestyle . ' title="' . get_string('readmore', 'theme_snap') . '"></div>';
            }
            $close = get_string('close', 'theme_snap');
            $output .= <<<HTML
<div class="news-article clearfix">
    {$newsimage}
    <div class="news-article-inner">
        <div class="news-article-content">
            <h3 class='toggle'><a href="{$CFG->wwwroot}/mod/forum/discuss.php?d={$discussion->discussion}">{$name}</a></h3>
            <em class="news-article-date">{$date}</em>
        </div>
    </div>
    {$preview}
    <div class="news-article-message" tabindex="-1">
        {$message}
        <div><hr><a class="snap-action-icon toggle" href="#">
        <i class="icon icon-close"></i><small>{$close}</small></a></div>
    </div>
</div>
HTML;
        }
        $actionlinks = html_writer::link(new moodle_url('/mod/forum/view.php', array('id' => $cm->id)), get_string('morenews', 'theme_snap'), array('class' => 'btn btn-default'));
        if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
            $actionlinks .= html_writer::link(new moodle_url('/mod/forum/post.php', array('forum' => $forum->id)), get_string('addanewtopic', 'forum'), array('class' => 'btn btn-primary'));
        }
        $output .= html_writer::end_div();
        $output .= "<br><div class='text-center'>{$actionlinks}</div>";
        $output .= html_writer::end_tag('div');
        return $output;
    }
开发者ID:pramithkm,项目名称:moodle-theme_snap,代码行数:80,代码来源:core_renderer.php


示例7: get_forum_discussions_paginated

 /**
  * Returns a list of forum discussions optionally sorted and paginated.
  *
  * @param int $forumid the forum instance id
  * @param string $sortby sort by this element (id, timemodified, timestart or timeend)
  * @param string $sortdirection sort direction: ASC or DESC
  * @param int $page page number
  * @param int $perpage items per page
  *
  * @return array the forum discussion details including warnings
  * @since Moodle 2.8
  */
 public static function get_forum_discussions_paginated($forumid, $sortby = 'timemodified', $sortdirection = 'DESC', $page = -1, $perpage = 0)
 {
     global $CFG, $DB, $USER, $PAGE;
     require_once $CFG->dirroot . "/mod/forum/lib.php";
     $warnings = array();
     $discussions = array();
     $params = self::validate_parameters(self::get_forum_discussions_paginated_parameters(), array('forumid' => $forumid, 'sortby' => $sortby, 'sortdirection' => $sortdirection, 'page' => $page, 'perpage' => $perpage));
     // Compact/extract functions are not recommended.
     $forumid = $params['forumid'];
     $sortby = $params['sortby'];
     $sortdirection = $params['sortdirection'];
     $page = $params['page'];
     $perpage = $params['perpage'];
     $sortallowedvalues = array('id', 'timemodified', 'timestart', 'timeend');
     if (!in_array($sortby, $sortallowedvalues)) {
         throw new invalid_parameter_exception('Invalid value for sortby parameter (value: ' . $sortby . '),' . 'allowed values are: ' . implode(',', $sortallowedvalues));
     }
     $sortdirection = strtoupper($sortdirection);
     $directionallowedvalues = array('ASC', 'DESC');
     if (!in_array($sortdirection, $directionallowedvalues)) {
         throw new invalid_parameter_exception('Invalid value for sortdirection parameter (value: ' . $sortdirection . '),' . 'allowed values are: ' . implode(',', $directionallowedvalues));
     }
     $forum = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST);
     $course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST);
     $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
     // Validate the module context. It checks everything that affects the module visibility (including groupings, etc..).
     $modcontext = context_module::instance($cm->id);
     self::validate_context($modcontext);
     // Check they have the view forum capability.
     require_capability('mod/forum:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'forum');
     $sort = 'd.pinned DESC, d.' . $sortby . ' ' . $sortdirection;
     $alldiscussions = forum_get_discussions($cm, $sort, true, -1, -1, true, $page, $perpage, FORUM_POSTS_ALL_USER_GROUPS);
     if ($alldiscussions) {
         $canviewfullname = has_capability('moodle/site:viewfullnames', $modcontext);
         // Get the unreads array, this takes a forum id and returns data for all discussions.
         $unreads = array();
         if ($cantrack = forum_tp_can_track_forums($forum)) {
             if ($forumtracked = forum_tp_is_tracked($forum)) {
                 $unreads = forum_get_discussions_unread($cm);
             }
         }
         // The forum function returns the replies for all the discussions in a given forum.
         $replies = forum_count_discussion_replies($forumid, $sort, -1, $page, $perpage);
         foreach ($alldiscussions as $discussion) {
             // This function checks for qanda forums.
             // Note that the forum_get_discussions returns as id the post id, not the discussion id so we need to do this.
             $discussionrec = clone $discussion;
             $discussionrec->id = $discussion->discussion;
             if (!forum_user_can_see_discussion($forum, $discussionrec, $modcontext)) {
                 $warning = array();
                 // Function forum_get_discussions returns forum_posts ids not forum_discussions ones.
                 $warning['item'] = 'post';
                 $warning['itemid'] = $discussion->id;
                 $warning['warningcode'] = '1';
                 $warning['message'] = 'You can\'t see this discussion';
                 $warnings[] = $warning;
                 continue;
             }
             $discussion->numunread = 0;
             if ($cantrack && $forumtracked) {
                 if (isset($unreads[$discussion->discussion])) {
                     $discussion->numunread = (int) $unreads[$discussion->discussion];
                 }
             }
             $discussion->numreplies = 0;
             if (!empty($replies[$discussion->discussion])) {
                 $discussion->numreplies = (int) $replies[$discussion->discussion]->replies;
             }
             $discussion->name = external_format_string($discussion->name, $modcontext->id);
             $discussion->subject = external_format_string($discussion->subject, $modcontext->id);
             // Rewrite embedded images URLs.
             list($discussion->message, $discussion->messageformat) = external_format_text($discussion->message, $discussion->messageformat, $modcontext->id, 'mod_forum', 'post', $discussion->id);
             // List attachments.
             if (!empty($discussion->attachment)) {
                 $discussion->attachments = external_util::get_area_files($modcontext->id, 'mod_forum', 'attachment', $discussion->id);
             }
             $messageinlinefiles = external_util::get_area_files($modcontext->id, 'mod_forum', 'post', $discussion->id);
             if (!empty($messageinlinefiles)) {
                 $discussion->messageinlinefiles = $messageinlinefiles;
             }
             $discussion->locked = forum_discussion_is_locked($forum, $discussion);
             $discussion->canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
             if (forum_is_author_hidden($discussion, $forum)) {
                 $discussion->userid = null;
                 $discussion->userfullname = null;
                 $discussion->userpictureurl = null;
                 $discussion->usermodified = null;
                 $discussion->usermodifiedfullname = null;
//.........这里部分代码省略.........
开发者ID:lucaboesch,项目名称:moodle,代码行数:101,代码来源:externallib.php



注:本文中的forum_user_can_see_discussion函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP forum_user_can_see_post函数代码示例发布时间:2022-05-15
下一篇:
PHP forum_user_can_post_discussion函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap