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

PHP get_course_context函数代码示例

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

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



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

示例1: get_file_info

 /**
  * Return information about this specific context level
  *
  * @param $component
  * @param $filearea
  * @param $itemid
  * @param $filepath
  * @param $filename
  */
 public function get_file_info($component, $filearea, $itemid, $filepath, $filename)
 {
     // try to emulate require_login() tests here
     if (!isloggedin()) {
         return null;
     }
     $coursecontext = get_course_context($this->context);
     if (!$this->course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
         return null;
     }
     if (!is_viewing($this->context) and !is_enrolled($this->context)) {
         // no peaking here if not enrolled or inspector
         return null;
     }
     $modinfo = get_fast_modinfo($this->course);
     $cminfo = $modinfo->get_cm($this->cm->id);
     if (!$cminfo->uservisible) {
         // activity hidden sorry
         return null;
     }
     if (empty($component)) {
         return $this;
     }
     if ($component == 'mod_' . $this->modname and $filearea === 'intro') {
         return $this->get_area_intro($itemid, $filepath, $filename);
     } else {
         if ($component == 'backup' and $filearea === 'activity') {
             return $this->get_area_backup($itemid, $filepath, $filename);
         }
     }
     $functionname = 'mod_' . $this->modname . '_get_file_info';
     $functionname_old = $this->modname . '_get_file_info';
     if (function_exists($functionname)) {
         return $functionname($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
     } else {
         if (function_exists($functionname_old)) {
             return $functionname_old($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
         }
     }
     return null;
 }
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:50,代码来源:file_info_context_module.php


示例2: get_name

 public function get_name() {
     list($context, $course, $cm) = get_context_info_array($this->context->id);
     if (!empty($course)) {
         return get_string('courselegacyfiles') . format_string($course->shortname, true, array('context' => get_course_context($context)));
     } else {
         return get_string('courselegacyfiles');
     }
 }
开发者ID:nigeldaley,项目名称:moodle,代码行数:8,代码来源:lib.php


示例3: test_everything_in_accesslib


//.........这里部分代码省略.........
            context_block::instance(-1);
            $this->fail('exception expected');
        } catch (Exception $e) {
            $this->assertTrue(true);
        }


        // ======= $context->get_url(), $context->get_context_name(), $context->get_capabilities() =========

        $testcontexts = array();
        $testcontexts[CONTEXT_SYSTEM]    = context_system::instance();
        $testcontexts[CONTEXT_COURSECAT] = context_coursecat::instance($testcategories[0]);
        $testcontexts[CONTEXT_COURSE]    = context_course::instance($testcourses[0]);
        $testcontexts[CONTEXT_MODULE]    = context_module::instance($testpages[0]);
        $testcontexts[CONTEXT_BLOCK]     = context_block::instance($testblocks[0]);

        foreach ($testcontexts as $context) {
            $name = $context->get_context_name(true, true);
            $this->assertFalse(empty($name));

            $this->assertTrue($context->get_url() instanceof moodle_url);

            $caps = $context->get_capabilities();
            $this->assertTrue(is_array($caps));
            foreach ($caps as $cap) {
                $cap = (array)$cap;
                $this->assertSame(array_keys($cap), array('id', 'name', 'captype', 'contextlevel', 'component', 'riskbitmask'));
            }
        }
        unset($testcontexts);

        // ===== $context->get_course_context() =========================================

        $this->assertFalse($systemcontext->get_course_context(false));
        try {
            $systemcontext->get_course_context();
            $this->fail('exception expected');
        } catch (Exception $e) {
            $this->assertTrue(true);
        }
        $context = context_coursecat::instance($testcategories[0]);
        $this->assertFalse($context->get_course_context(false));
        try {
            $context->get_course_context();
            $this->fail('exception expected');
        } catch (Exception $e) {
            $this->assertTrue(true);
        }
        $this->assertSame($frontpagecontext->get_course_context(true), $frontpagecontext);
        $this->assertSame($frontpagepagecontext->get_course_context(true), $frontpagecontext);
        $this->assertSame($frontpagepageblockcontext->get_course_context(true), $frontpagecontext);


        // ======= $context->get_parent_context(), $context->get_parent_contexts(), $context->get_parent_context_ids() =======

        $userid = reset($testusers);
        $usercontext = context_user::instance($userid);
        $this->assertSame($usercontext->get_parent_context(), $systemcontext);
        $this->assertSame($usercontext->get_parent_contexts(), array($systemcontext->id=>$systemcontext));
        $this->assertSame($usercontext->get_parent_contexts(true), array($usercontext->id=>$usercontext, $systemcontext->id=>$systemcontext));

        $this->assertSame($systemcontext->get_parent_contexts(), array());
        $this->assertSame($systemcontext->get_parent_contexts(true), array($systemcontext->id=>$systemcontext));
        $this->assertSame($systemcontext->get_parent_context_ids(), array());
        $this->assertSame($systemcontext->get_parent_context_ids(true), array($systemcontext->id));
开发者ID:numbas,项目名称:moodle,代码行数:66,代码来源:accesslib_test.php


示例4: get_enrolled_sql

/**
 * Returns array with sql code and parameters returning all ids
 * of users enrolled into course.
 *
 * This function is using 'eu[0-9]+_' prefix for table names and parameters.
 *
 * @param object $context
 * @param string $withcapability
 * @param int $groupid 0 means ignore groups, any other value limits the result by group id
 * @param bool $onlyactive consider only active enrolments in enabled plugins and time restrictions
 * @return array list($sql, $params)
 */
function get_enrolled_sql($context, $withcapability = '', $groupid = 0, $onlyactive = false)
{
    global $DB, $CFG;
    // use unique prefix just in case somebody makes some SQL magic with the result
    static $i = 0;
    $i++;
    $prefix = 'eu' . $i . '_';
    // first find the course context
    $coursecontext = get_course_context($context);
    $isfrontpage = $coursecontext->instanceid == SITEID;
    $joins = array();
    $wheres = array();
    $params = array();
    list($contextids, $contextpaths) = get_context_info_list($context);
    // get all relevant capability info for all roles
    if ($withcapability) {
        list($incontexts, $cparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED, 'ctx');
        $cparams['cap'] = $withcapability;
        $defs = array();
        $sql = "SELECT rc.id, rc.roleid, rc.permission, ctx.path\n                  FROM {role_capabilities} rc\n                  JOIN {context} ctx on rc.contextid = ctx.id\n                 WHERE rc.contextid {$incontexts} AND rc.capability = :cap";
        $rcs = $DB->get_records_sql($sql, $cparams);
        foreach ($rcs as $rc) {
            $defs[$rc->path][$rc->roleid] = $rc->permission;
        }
        $access = array();
        if (!empty($defs)) {
            foreach ($contextpaths as $path) {
                if (empty($defs[$path])) {
                    continue;
                }
                foreach ($defs[$path] as $roleid => $perm) {
                    if ($perm == CAP_PROHIBIT) {
                        $access[$roleid] = CAP_PROHIBIT;
                        continue;
                    }
                    if (!isset($access[$roleid])) {
                        $access[$roleid] = (int) $perm;
                    }
                }
            }
        }
        unset($defs);
        // make lists of roles that are needed and prohibited
        $needed = array();
        // one of these is enough
        $prohibited = array();
        // must not have any of these
        foreach ($access as $roleid => $perm) {
            if ($perm == CAP_PROHIBIT) {
                unset($needed[$roleid]);
                $prohibited[$roleid] = true;
            } else {
                if ($perm == CAP_ALLOW and empty($prohibited[$roleid])) {
                    $needed[$roleid] = true;
                }
            }
        }
        $defaultuserroleid = isset($CFG->defaultuserroleid) ? $CFG->defaultuserroleid : 0;
        $defaultfrontpageroleid = isset($CFG->defaultfrontpageroleid) ? $CFG->defaultfrontpageroleid : 0;
        $nobody = false;
        if ($isfrontpage) {
            if (!empty($prohibited[$defaultuserroleid]) or !empty($prohibited[$defaultfrontpageroleid])) {
                $nobody = true;
            } else {
                if (!empty($needed[$defaultuserroleid]) or !empty($needed[$defaultfrontpageroleid])) {
                    // everybody not having prohibit has the capability
                    $needed = array();
                } else {
                    if (empty($needed)) {
                        $nobody = true;
                    }
                }
            }
        } else {
            if (!empty($prohibited[$defaultuserroleid])) {
                $nobody = true;
            } else {
                if (!empty($needed[$defaultuserroleid])) {
                    // everybody not having prohibit has the capability
                    $needed = array();
                } else {
                    if (empty($needed)) {
                        $nobody = true;
                    }
                }
            }
        }
        if ($nobody) {
//.........这里部分代码省略.........
开发者ID:LMSeXT,项目名称:SAWEE-WS_server-lib,代码行数:101,代码来源:accesslib.php


示例5: load_users

 /**
  * pulls out the userids of the users to be display, and sorts them
  */
 public function load_users()
 {
     global $CFG, $DB;
     //limit to users with a gradeable role
     list($gradebookrolessql, $gradebookrolesparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0');
     //limit to users with an active enrollment
     list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context);
     //fields we need from the user table
     $userfields = user_picture::fields('u', array('idnumber'));
     $sortjoin = $sort = $params = null;
     //if the user has clicked one of the sort asc/desc arrows
     if (is_numeric($this->sortitemid)) {
         $params = array_merge(array('gitemid' => $this->sortitemid), $gradebookrolesparams, $this->groupwheresql_params, $enrolledparams);
         $sortjoin = "LEFT JOIN {grade_grades} g ON g.userid = u.id AND g.itemid = {$this->sortitemid}";
         $sort = "g.finalgrade {$this->sortorder}";
     } else {
         $sortjoin = '';
         switch ($this->sortitemid) {
             case 'lastname':
                 $sort = "u.lastname {$this->sortorder}, u.firstname {$this->sortorder}";
                 break;
             case 'firstname':
                 $sort = "u.firstname {$this->sortorder}, u.lastname {$this->sortorder}";
                 break;
             case 'idnumber':
             default:
                 $sort = "u.idnumber {$this->sortorder}";
                 break;
         }
         $params = array_merge($gradebookrolesparams, $this->groupwheresql_params, $enrolledparams);
     }
     $sql = "SELECT {$userfields}\n                  FROM {user} u\n                  JOIN ({$enrolledsql}) je ON je.id = u.id\n                       {$this->groupsql}\n                       {$sortjoin}\n                  JOIN (\n                           SELECT DISTINCT ra.userid\n                             FROM {role_assignments} ra\n                            WHERE ra.roleid IN ({$this->gradebookroles})\n                              AND ra.contextid " . get_related_contexts_string($this->context) . "\n                       ) rainner ON rainner.userid = u.id\n                   AND u.deleted = 0\n                   {$this->groupwheresql}\n              ORDER BY {$sort}";
     $this->users = $DB->get_records_sql($sql, $params, $this->get_pref('studentsperpage') * $this->page, $this->get_pref('studentsperpage'));
     if (empty($this->users)) {
         $this->userselect = '';
         $this->users = array();
         $this->userselect_params = array();
     } else {
         list($usql, $uparams) = $DB->get_in_or_equal(array_keys($this->users), SQL_PARAMS_NAMED, 'usid0');
         $this->userselect = "AND g.userid {$usql}";
         $this->userselect_params = $uparams;
         //add a flag to each user indicating whether their enrolment is active
         $sql = "SELECT ue.userid\n                      FROM {user_enrolments} ue\n                      JOIN {enrol} e ON e.id = ue.enrolid\n                     WHERE ue.userid {$usql}\n                           AND ue.status = :uestatus\n                           AND e.status = :estatus\n                           AND e.courseid = :courseid\n                  GROUP BY ue.userid";
         $coursecontext = get_course_context($this->context);
         $params = array_merge($uparams, array('estatus' => ENROL_INSTANCE_ENABLED, 'uestatus' => ENROL_USER_ACTIVE, 'courseid' => $coursecontext->instanceid));
         $useractiveenrolments = $DB->get_records_sql($sql, $params);
         foreach ($this->users as $user) {
             $this->users[$user->id]->suspendedenrolment = !array_key_exists($user->id, $useractiveenrolments);
         }
     }
     return $this->users;
 }
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:55,代码来源:lib.php


示例6: test_everything_in_accesslib


//.........这里部分代码省略.........
     }
     try {
         context_module::instance(-1);
         $this->fail('exception expected');
     } catch (Exception $e) {
         $this->assertTrue(true);
     }
     try {
         context_block::instance(-1);
         $this->fail('exception expected');
     } catch (Exception $e) {
         $this->assertTrue(true);
     }
     // ======= $context->get_url(), $context->get_context_name(), $context->get_capabilities() =========
     $testcontexts = array();
     $testcontexts[CONTEXT_SYSTEM] = context_system::instance();
     $testcontexts[CONTEXT_COURSECAT] = context_coursecat::instance($testcategories[0]);
     $testcontexts[CONTEXT_COURSE] = context_course::instance($testcourses[0]);
     $testcontexts[CONTEXT_MODULE] = context_module::instance($testpages[0]);
     $testcontexts[CONTEXT_BLOCK] = context_block::instance($testblocks[0]);
     foreach ($testcontexts as $context) {
         $name = $context->get_context_name(true, true);
         $this->assertFalse(empty($name));
         $this->assertTrue($context->get_url() instanceof moodle_url);
         $caps = $context->get_capabilities();
         $this->assertTrue(is_array($caps));
         foreach ($caps as $cap) {
             $cap = (array) $cap;
             $this->assertIdentical(array_keys($cap), array('id', 'name', 'captype', 'contextlevel', 'component', 'riskbitmask'));
         }
     }
     unset($testcontexts);
     // ===== $context->get_course_context() =========================================
     $this->assertFalse($systemcontext->get_course_context(false));
     try {
         $systemcontext->get_course_context();
         $this->fail('exception expected');
     } catch (Exception $e) {
         $this->assertTrue(true);
     }
     $context = context_coursecat::instance($testcategories[0]);
     $this->assertFalse($context->get_course_context(false));
     try {
         $context->get_course_context();
         $this->fail('exception expected');
     } catch (Exception $e) {
         $this->assertTrue(true);
     }
     $this->assertIdentical($frontpagecontext->get_course_context(true), $frontpagecontext);
     $this->assertIdentical($frontpagepagecontext->get_course_context(true), $frontpagecontext);
     $this->assertIdentical($frontpagepageblockcontext->get_course_context(true), $frontpagecontext);
     // ======= $context->get_parent_context(), $context->get_parent_contexts(), $context->get_parent_context_ids() =======
     $userid = reset($testusers);
     $usercontext = context_user::instance($userid);
     $this->assertIdentical($usercontext->get_parent_context(), $systemcontext);
     $this->assertIdentical($usercontext->get_parent_contexts(), array($systemcontext->id => $systemcontext));
     $this->assertIdentical($usercontext->get_parent_contexts(true), array($usercontext->id => $usercontext, $systemcontext->id => $systemcontext));
     $this->assertIdentical($systemcontext->get_parent_contexts(), array());
     $this->assertIdentical($systemcontext->get_parent_contexts(true), array($systemcontext->id => $systemcontext));
     $this->assertIdentical($systemcontext->get_parent_context_ids(), array());
     $this->assertIdentical($systemcontext->get_parent_context_ids(true), array($systemcontext->id));
     $this->assertIdentical($frontpagecontext->get_parent_context(), $systemcontext);
     $this->assertIdentical($frontpagecontext->get_parent_contexts(), array($systemcontext->id => $systemcontext));
     $this->assertIdentical($frontpagecontext->get_parent_contexts(true), array($frontpagecontext->id => $frontpagecontext, $systemcontext->id => $systemcontext));
     $this->assertIdentical($frontpagecontext->get_parent_context_ids(), array($systemcontext->id));
     $this->assertEqual($frontpagecontext->get_parent_context_ids(true), array($frontpagecontext->id, $systemcontext->id));
开发者ID:rolandovanegas,项目名称:moodle,代码行数:67,代码来源:fulltestaccesslib.php


示例7: get_reference_details

 /**
  * Return human readable reference information
  * {@link stored_file::get_reference()}
  *
  * @param string $reference
  * @return string|null
  */
 public function get_reference_details($reference)
 {
     $params = file_storage::unpack_reference($reference);
     list($context, $course, $cm) = get_context_info_array($params['contextid']);
     $coursename = '';
     if (!empty($course)) {
         $coursename = '"' . format_string($course->shortname, true, array('context' => get_course_context($context))) . '" ' . get_string('courselegacyfiles');
     } else {
         $coursename = get_string('courselegacyfiles');
     }
     // Indicate this is from user private area
     return $coursename . ': ' . $params['filepath'] . $params['filename'];
 }
开发者ID:nmicha,项目名称:moodle,代码行数:20,代码来源:lib.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP get_course_display_name_for_list函数代码示例发布时间:2022-05-15
下一篇:
PHP get_course_category_tree函数代码示例发布时间: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