当前位置: 首页>>代码示例>>PHP>>正文


PHP forum_get_readable_forums函数代码示例

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


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

示例1: forum_search_posts

/**
 * Returns a list of posts found using an array of search terms.
 *
 * @global object
 * @global object
 * @global object
 * @param array $searchterms array of search terms, e.g. word +word -word
 * @param int $courseid if 0, we search through the whole site
 * @param int $limitfrom
 * @param int $limitnum
 * @param int &$totalcount
 * @param string $extrasql
 * @return array|bool Array of posts found or false
 */
function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=50,
                            &$totalcount, $extrasql='') {
    global $CFG, $DB, $USER;
    require_once($CFG->libdir.'/searchlib.php');

    $forums = forum_get_readable_forums($USER->id, $courseid);

    if (count($forums) == 0) {
        $totalcount = 0;
        return false;
    }

    $now = round(time(), -2); // db friendly

    $fullaccess = array();
    $where = array();
    $params = array();

    foreach ($forums as $forumid => $forum) {
        $select = array();

        if (!$forum->viewhiddentimedposts) {
            $select[] = "(d.userid = :userid{$forumid} OR (d.timestart < :timestart{$forumid} AND (d.timeend = 0 OR d.timeend > :timeend{$forumid})))";
            $params = array_merge($params, array('userid'.$forumid=>$USER->id, 'timestart'.$forumid=>$now, 'timeend'.$forumid=>$now));
        }

        $cm = $forum->cm;
        $context = $forum->context;

        if ($forum->type == 'qanda'
            && !has_capability('mod/forum:viewqandawithoutposting', $context)) {
            if (!empty($forum->onlydiscussions)) {
                list($discussionid_sql, $discussionid_params) = $DB->get_in_or_equal($forum->onlydiscussions, SQL_PARAMS_NAMED, 'qanda'.$forumid.'_');
                $params = array_merge($params, $discussionid_params);
                $select[] = "(d.id $discussionid_sql OR p.parent = 0)";
            } else {
                $select[] = "p.parent = 0";
            }
        }

        if (!empty($forum->onlygroups)) {
            list($groupid_sql, $groupid_params) = $DB->get_in_or_equal($forum->onlygroups, SQL_PARAMS_NAMED, 'grps'.$forumid.'_');
            $params = array_merge($params, $groupid_params);
            $select[] = "d.groupid $groupid_sql";
        }

        if ($select) {
            $selects = implode(" AND ", $select);
            $where[] = "(d.forum = :forum{$forumid} AND $selects)";
            $params['forum'.$forumid] = $forumid;
        } else {
            $fullaccess[] = $forumid;
        }
    }

    if ($fullaccess) {
        list($fullid_sql, $fullid_params) = $DB->get_in_or_equal($fullaccess, SQL_PARAMS_NAMED, 'fula');
        $params = array_merge($params, $fullid_params);
        $where[] = "(d.forum $fullid_sql)";
    }

    $selectdiscussion = "(".implode(" OR ", $where).")";

    $messagesearch = '';
    $searchstring = '';

    // Need to concat these back together for parser to work.
    foreach($searchterms as $searchterm){
        if ($searchstring != '') {
            $searchstring .= ' ';
        }
        $searchstring .= $searchterm;
    }

    // We need to allow quoted strings for the search. The quotes *should* be stripped
    // by the parser, but this should be examined carefully for security implications.
    $searchstring = str_replace("\\\"","\"",$searchstring);
    $parser = new search_parser();
    $lexer = new search_lexer($parser);

    if ($lexer->parse($searchstring)) {
        $parsearray = $parser->get_parsed_array();
    // Experimental feature under 1.8! MDL-8830
    // Use alternative text searches if defined
    // This feature only works under mysql until properly implemented for other DBs
    // Requires manual creation of text index for forum_posts before enabling it:
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:lib.php

示例2: forum_search_posts

/**
 * Returns a list of posts found using an array of search terms.
 *
 * @global object
 * @global object
 * @global object
 * @param array $searchterms array of search terms, e.g. word +word -word
 * @param int $courseid if 0, we search through the whole site
 * @param int $limitfrom
 * @param int $limitnum
 * @param int &$totalcount
 * @param string $extrasql
 * @return array|bool Array of posts found or false
 */
function forum_search_posts($searchterms, $courseid = 0, $limitfrom = 0, $limitnum = 50, &$totalcount, $extrasql = '')
{
    global $CFG, $DB, $USER;
    require_once $CFG->libdir . '/searchlib.php';
    $forums = forum_get_readable_forums($USER->id, $courseid);
    if (count($forums) == 0) {
        $totalcount = 0;
        return false;
    }
    $now = round(time(), -2);
    // db friendly
    $fullaccess = array();
    $where = array();
    $params = array();
    foreach ($forums as $forumid => $forum) {
        $select = array();
        if (!$forum->viewhiddentimedposts) {
            $select[] = "(d.userid = :userid{$forumid} OR (d.timestart < :timestart{$forumid} AND (d.timeend = 0 OR d.timeend > :timeend{$forumid})))";
            $params = array_merge($params, array('userid' . $forumid => $USER->id, 'timestart' . $forumid => $now, 'timeend' . $forumid => $now));
        }
        $cm = $forum->cm;
        $context = $forum->context;
        if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $context)) {
            if (!empty($forum->onlydiscussions)) {
                list($discussionid_sql, $discussionid_params) = $DB->get_in_or_equal($forum->onlydiscussions, SQL_PARAMS_NAMED, 'qanda' . $forumid . '_');
                $params = array_merge($params, $discussionid_params);
                $select[] = "(d.id {$discussionid_sql} OR p.parent = 0)";
            } else {
                $select[] = "p.parent = 0";
            }
        }
        if (!empty($forum->onlygroups)) {
            list($groupid_sql, $groupid_params) = $DB->get_in_or_equal($forum->onlygroups, SQL_PARAMS_NAMED, 'grps' . $forumid . '_');
            $params = array_merge($params, $groupid_params);
            $select[] = "d.groupid {$groupid_sql}";
        }
        if ($select) {
            $selects = implode(" AND ", $select);
            $where[] = "(d.forum = :forum{$forumid} AND {$selects})";
            $params['forum' . $forumid] = $forumid;
        } else {
            $fullaccess[] = $forumid;
        }
    }
    if ($fullaccess) {
        list($fullid_sql, $fullid_params) = $DB->get_in_or_equal($fullaccess, SQL_PARAMS_NAMED, 'fula');
        $params = array_merge($params, $fullid_params);
        $where[] = "(d.forum {$fullid_sql})";
    }
    $selectdiscussion = "(" . implode(" OR ", $where) . ")";
    $messagesearch = '';
    $searchstring = '';
    // Need to concat these back together for parser to work.
    foreach ($searchterms as $searchterm) {
        if ($searchstring != '') {
            $searchstring .= ' ';
        }
        $searchstring .= $searchterm;
    }
    // We need to allow quoted strings for the search. The quotes *should* be stripped
    // by the parser, but this should be examined carefully for security implications.
    $searchstring = str_replace("\\\"", "\"", $searchstring);
    $parser = new search_parser();
    $lexer = new search_lexer($parser);
    if ($lexer->parse($searchstring)) {
        $parsearray = $parser->get_parsed_array();
        list($messagesearch, $msparams) = search_generate_SQL($parsearray, 'p.message', 'p.subject', 'p.userid', 'u.id', 'u.firstname', 'u.lastname', 'p.modified', 'd.forum');
        $params = array_merge($params, $msparams);
    }
    $fromsql = "{forum_posts} p,\n                  {forum_discussions} d,\n                  {user} u";
    $selectsql = " {$messagesearch}\n               AND p.discussion = d.id\n               AND p.userid = u.id\n               AND {$selectdiscussion}\n                   {$extrasql}";
    $countsql = "SELECT COUNT(*)\n                   FROM {$fromsql}\n                  WHERE {$selectsql}";
    $allnames = get_all_user_name_fields(true, 'u');
    $searchsql = "SELECT p.*,\n                         d.forum,\n                         {$allnames},\n                         u.email,\n                         u.picture,\n                         u.imagealt\n                    FROM {$fromsql}\n                   WHERE {$selectsql}\n                ORDER BY p.modified DESC";
    $totalcount = $DB->count_records_sql($countsql, $params);
    return $DB->get_records_sql($searchsql, $params, $limitfrom, $limitnum);
}
开发者ID:rezaies,项目名称:moodle,代码行数:91,代码来源:lib.php

示例3: forum_search_posts

/**
 * Returns a list of posts found using an array of search terms.
 * @param $searchterms - array of search terms, e.g. word +word -word
 * @param $courseid - if 0, we search through the whole site
 * @param $page
 * @param $recordsperpage=50
 * @param &$totalcount
 * @param $extrasql
 * @return array of posts found
 */
function forum_search_posts($searchterms, $courseid = 0, $limitfrom = 0, $limitnum = 50, &$totalcount, $extrasql = '')
{
    global $CFG, $USER;
    require_once $CFG->libdir . '/searchlib.php';
    $forums = forum_get_readable_forums($USER->id, $courseid);
    if (count($forums) == 0) {
        $totalcount = 0;
        return false;
    }
    $now = round(time(), -2);
    // db friendly
    $fullaccess = array();
    $where = array();
    foreach ($forums as $forumid => $forum) {
        $select = array();
        if (!$forum->viewhiddentimedposts) {
            $select[] = "(d.userid = {$USER->id} OR (d.timestart < {$now} AND (d.timeend = 0 OR d.timeend > {$now})))";
        }
        if ($forum->type == 'qanda') {
            if (!empty($forum->onlydiscussions)) {
                $discussionsids = implode(',', $forum->onlydiscussions);
                $select[] = "(d.id IN ({$discussionsids}) OR p.parent = 0)";
            } else {
                $select[] = "p.parent = 0";
            }
        }
        if (!empty($forum->onlygroups)) {
            $groupids = implode(',', $forum->onlygroups);
            $select[] = "d.groupid IN ({$groupids})";
        }
        if ($select) {
            $selects = implode(" AND ", $select);
            $where[] = "(d.forum = {$forumid} AND {$selects})";
        } else {
            $fullaccess[] = $forumid;
        }
    }
    if ($fullaccess) {
        $fullids = implode(',', $fullaccess);
        $where[] = "(d.forum IN ({$fullids}))";
    }
    $selectdiscussion = "(" . implode(" OR ", $where) . ")";
    // Some differences SQL
    $LIKE = sql_ilike();
    $NOTLIKE = 'NOT ' . $LIKE;
    if ($CFG->dbfamily == 'postgres') {
        $REGEXP = '~*';
        $NOTREGEXP = '!~*';
    } else {
        $REGEXP = 'REGEXP';
        $NOTREGEXP = 'NOT REGEXP';
    }
    $messagesearch = '';
    $searchstring = '';
    // Need to concat these back together for parser to work.
    foreach ($searchterms as $searchterm) {
        if ($searchstring != '') {
            $searchstring .= ' ';
        }
        $searchstring .= $searchterm;
    }
    // We need to allow quoted strings for the search. The quotes *should* be stripped
    // by the parser, but this should be examined carefully for security implications.
    $searchstring = str_replace("\\\"", "\"", $searchstring);
    $parser = new search_parser();
    $lexer = new search_lexer($parser);
    if ($lexer->parse($searchstring)) {
        $parsearray = $parser->get_parsed_array();
        // Experimental feature under 1.8! MDL-8830
        // Use alternative text searches if defined
        // This feature only works under mysql until properly implemented for other DBs
        // Requires manual creation of text index for forum_posts before enabling it:
        // CREATE FULLTEXT INDEX foru_post_tix ON [prefix]forum_posts (subject, message)
        // Experimental feature under 1.8! MDL-8830
        if (!empty($CFG->forum_usetextsearches)) {
            $messagesearch = search_generate_text_SQL($parsearray, 'p.message', 'p.subject', 'p.userid', 'u.id', 'u.firstname', 'u.lastname', 'p.modified', 'd.forum');
        } else {
            $messagesearch = search_generate_SQL($parsearray, 'p.message', 'p.subject', 'p.userid', 'u.id', 'u.firstname', 'u.lastname', 'p.modified', 'd.forum');
        }
    }
    $fromsql = "{$CFG->prefix}forum_posts p,\n                  {$CFG->prefix}forum_discussions d,\n                  {$CFG->prefix}user u";
    $selectsql = " {$messagesearch}\n               AND p.discussion = d.id\n               AND p.userid = u.id\n               AND {$selectdiscussion}\n                   {$extrasql}";
    $countsql = "SELECT COUNT(*)\n                   FROM {$fromsql}\n                  WHERE {$selectsql}";
    $searchsql = "SELECT p.*,\n                         d.forum,\n                         u.firstname,\n                         u.lastname,\n                         u.email,\n                         u.picture,\n                         u.imagealt\n                    FROM {$fromsql}\n                   WHERE {$selectsql}\n                ORDER BY p.modified DESC";
    $totalcount = count_records_sql($countsql);
    return get_records_sql($searchsql, $limitfrom, $limitnum);
}
开发者ID:r007,项目名称:PMoodle,代码行数:97,代码来源:lib.php

示例4: populate_forums

 /**
  * Populate forum id arrays.
  * @throws \coding_exception
  */
 protected function populate_forums()
 {
     local::swap_global_user($this->user->id);
     // Note - we don't include the site in the list of courses. This is intentional - we want student engagement to
     // be increased in courses where learning takes place and the front page is unlikely to fit that model.
     // Currently we are using local::swap_global_user as a hack for the following function (MDL-51353).
     $this->courses = enrol_get_my_courses();
     $forums = [];
     $hsuforums = [];
     foreach ($this->courses as $course) {
         $forums = $forums + forum_get_readable_forums($this->user->id, $course->id);
         if (function_exists('hsuforum_get_readable_forums')) {
             $hsuforums = $hsuforums + hsuforum_get_readable_forums($this->user->id, $course->id, true);
         }
     }
     // Remove Q&A forums from array.
     $forums = $this->purge_qa_forums($forums);
     $hsuforums = $this->purge_qa_forums($hsuforums);
     // Rmove forums in courses not accessed for a long time.
     $forums = $this->process_stale_forums($forums);
     $hsuforums = $this->process_stale_forums($hsuforums, true);
     $this->forums = $forums;
     $this->hsuforums = $hsuforums;
     $this->forumids = array_keys($forums);
     $this->forumidsallgroups = $this->forumids_accessallgroups($forums);
     $this->hsuforumids = array_keys($hsuforums);
     $this->hsuforumidsallgroups = $this->forumids_accessallgroups($hsuforums, 'hsuforum');
     local::swap_global_user(false);
 }
开发者ID:pramithkm,项目名称:moodle-theme_snap,代码行数:33,代码来源:user_forums.php

示例5: offline_get_dynamic_files

/**
 * Retrieve all dynamic files
 *
 * @return string[] The array of dynamic files
 */
function offline_get_dynamic_files()
{
    global $CFG, $COURSE, $USER, $DB;
    require_once $CFG->dirroot . '/course/lib.php';
    // Include homepage and accessible course pages
    $files = array('.', $CFG->wwwroot . '/', $CFG->wwwroot . '/index.php', $CFG->wwwroot . '/lib/offline/go_offline.js', $CFG->wwwroot . '/user/editadvanced.php?id=' . $USER->id);
    // get all accessible courses
    if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
        $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', array('summary'));
    } else {
        if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() or $DB->count_records('course') <= FRONTPAGECOURSELIMIT) {
            $categories = get_child_categories(0);
            if (is_array($categories) && count($categories) == 1) {
                $category = array_shift($categories);
                $courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency'));
            } else {
                $courses = get_courses_wmanagers('all', 'c.sortorder ASC', array('password', 'summary', 'currency'));
            }
            unset($categories);
        }
    }
    // make sure the course is visible and retrieve other modules and main course pages
    foreach ($courses as $course) {
        if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', $course->context)) {
            $files[] = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
            //Get all the module main pages
            foreach (get_list_of_plugins() as $module) {
                if ($module != 'label') {
                    $files[] = $CFG->wwwroot . '/mod/' . $module . '/index.php?id=' . $course->id;
                }
            }
            //Get all the relevant forums
            require_once $CFG->dirroot . '/mod/forum/lib.php';
            $forums = forum_get_readable_forums($USER->id, $course->id);
            foreach ($forums as $forum) {
                $files[] = $CFG->wwwroot . '/mod/forum/view.php?f=' . $forum->id;
            }
            $modinfo =& get_fast_modinfo($course);
            get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
            foreach ($mods as $mod) {
                if ($mod->modname == 'forum') {
                    $files[] = $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id;
                    $cm = get_coursemodule_from_id('forum', $mod->id);
                    $discussions = forum_get_discussions($cm);
                    foreach ($discussions as $d) {
                        $files[] = $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $d->discussion;
                    }
                }
            }
            //Get all the relevant assignments
            foreach ($modinfo->instances['assignment'] as $cm) {
                if (!$cm->uservisible) {
                    continue;
                }
                $files[] = $CFG->wwwroot . '/mod/assignment/view.php?id=' . $cm->id;
            }
        }
    }
    $files = str_replace('&amp;', '&', $files);
    return $files;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:66,代码来源:lib.php


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