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


PHP get_courseid_from_context函数代码示例

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


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

示例1: filter

 function filter($text, array $options = array())
 {
     if (!($courseid = get_courseid_from_context($this->context))) {
         return $text;
     }
     // Initialise/invalidate our trivial cache if dealing with a different course
     if (!isset(self::$cachedcourseid) || self::$cachedcourseid !== (int) $courseid) {
         self::$activitylist = null;
     }
     self::$cachedcourseid = (int) $courseid;
     /// It may be cached
     if (is_null(self::$activitylist)) {
         self::$activitylist = array();
         $modinfo = get_fast_modinfo($courseid);
         if (!empty($modinfo->cms)) {
             self::$activitylist = array();
             /// We will store all the activities here
             //Sort modinfo by name length
             $sortedactivities = fullclone($modinfo->cms);
             usort($sortedactivities, 'filter_activitynames_comparemodulenamesbylength');
             foreach ($sortedactivities as $cm) {
                 //Exclude labels, hidden activities and activities for group members only
                 if ($cm->visible and empty($cm->groupmembersonly) and $cm->has_view()) {
                     $title = s(trim(strip_tags($cm->name)));
                     $currentname = trim($cm->name);
                     $entitisedname = s($currentname);
                     /// Avoid empty or unlinkable activity names
                     if (!empty($title)) {
                         $href_tag_begin = html_writer::start_tag('a', array('class' => 'autolink', 'title' => $title, 'href' => $cm->get_url()));
                         self::$activitylist[$cm->id] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
                         if ($currentname != $entitisedname) {
                             /// If name has some entity (&amp; &quot; &lt; &gt;) add that filter too. MDL-17545
                             self::$activitylist[$cm->id . '-e'] = new filterobject($entitisedname, $href_tag_begin, '</a>', false, true);
                         }
                     }
                 }
             }
         }
     }
     $filterslist = array();
     if (self::$activitylist) {
         $cmid = $this->context->instanceid;
         if ($this->context->contextlevel == CONTEXT_MODULE && isset(self::$activitylist[$cmid])) {
             // remove filterobjects for the current module
             $filterslist = array_diff_key(self::$activitylist, array($cmid => 1, $cmid . '-e' => 1));
         } else {
             $filterslist = self::$activitylist;
         }
     }
     if ($filterslist) {
         return $text = filter_phrases($text, $filterslist);
     } else {
         return $text;
     }
 }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:55,代码来源:filter.php

示例2: filter

 function filter($text, array $options = array())
 {
     global $CFG, $COURSE, $DB;
     if (!($courseid = get_courseid_from_context($this->context))) {
         return $text;
     }
     // Initialise/invalidate our trivial cache if dealing with a different course
     if (!isset(self::$cachedcourseid) || self::$cachedcourseid !== (int) $courseid) {
         self::$activitylist = null;
     }
     self::$cachedcourseid = (int) $courseid;
     /// It may be cached
     if (is_null(self::$activitylist)) {
         self::$activitylist = array();
         if ($COURSE->id == $courseid) {
             $course = $COURSE;
         } else {
             $course = $DB->get_record("course", array("id" => $courseid));
         }
         if (!isset($course->modinfo)) {
             return $text;
         }
         /// Casting $course->modinfo to string prevents one notice when the field is null
         $modinfo = unserialize((string) $course->modinfo);
         if (!empty($modinfo)) {
             self::$activitylist = array();
             /// We will store all the activities here
             //Sort modinfo by name length
             usort($modinfo, 'filter_activitynames_comparemodulenamesbylength');
             foreach ($modinfo as $activity) {
                 //Exclude labels, hidden activities and activities for group members only
                 if ($activity->mod != "label" and $activity->visible and empty($activity->groupmembersonly)) {
                     $title = s(trim(strip_tags($activity->name)));
                     $currentname = trim($activity->name);
                     $entitisedname = s($currentname);
                     /// Avoid empty or unlinkable activity names
                     if (!empty($title)) {
                         $href_tag_begin = "<a class=\"autolink\" title=\"{$title}\" href=\"{$CFG->wwwroot}/mod/{$activity->mod}/view.php?id={$activity->cm}\">";
                         self::$activitylist[] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
                         if ($currentname != $entitisedname) {
                             /// If name has some entity (&amp; &quot; &lt; &gt;) add that filter too. MDL-17545
                             self::$activitylist[] = new filterobject($entitisedname, $href_tag_begin, '</a>', false, true);
                         }
                     }
                 }
             }
         }
     }
     if (self::$activitylist) {
         return $text = filter_phrases($text, self::$activitylist);
     } else {
         return $text;
     }
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:54,代码来源:filter.php

示例3: instance_delete

 function instance_delete()
 {
     global $DB, $CFG;
     if ($CFG->version < 2012120300) {
         $courseid = get_courseid_from_context($this->context);
     } else {
         $coursecontext = $this->context->get_course_context(true);
         $courseid = $coursecontext->instanceid;
     }
     // Disable the buttons when the block is removed from a course (but leave the record, in case it is enabled later)
     $settings = $DB->get_record('navbuttons', array('course' => $courseid));
     if ($settings) {
         if ($settings->enabled) {
             $updsettings = new stdClass();
             $updsettings->id = $settings->id;
             $updsettings->enabled = 0;
             $DB->update_record('navbuttons', $updsettings);
         }
     }
     return true;
 }
开发者ID:kbwebsolutions,项目名称:moodle-navbuttons,代码行数:21,代码来源:block_navbuttons.php

示例4: get_listing

 public function get_listing($encodedpath = '', $page = '')
 {
     $ret = array();
     $ret['dynload'] = true;
     $ret['nosearch'] = true;
     $ret['nologin'] = true;
     $ret['list'] = array();
     if (!($courseid = get_courseid_from_context($this->context))) {
         return $ret;
     }
     $modinfo = get_fast_modinfo($courseid);
     $list = array();
     foreach ($modinfo->get_cms() as $cm) {
         if (!$cm->uservisible) {
             continue;
         }
         $list[] = array('shorttitle' => $cm->name, 'title' => $cm->name, 'thumbnail' => $cm->get_icon_url()->out(false), 'thumbnail_height' => 50, 'thumbnail_width' => 50, 'size' => '', 'date' => '', 'source' => $cm->get_url()->out(false));
     }
     $ret['list'] = $list;
     return $ret;
 }
开发者ID:nadavkav,项目名称:moodle-repository_activitylinks,代码行数:21,代码来源:lib.php

示例5: __construct

 /**
  * Set any context-specific configuration for this filter.
  *
  * @param string $filterfunction
  * @param object $context The current context.
  * @param array $config Any context-specific configuration for this filter.
  */
 public function __construct($filterfunction, $context, array $localconfig)
 {
     parent::__construct($context, $localconfig);
     $this->filterfunction = $filterfunction;
     $this->courseid = get_courseid_from_context($this->context);
 }
开发者ID:raymondAntonio,项目名称:moodle,代码行数:13,代码来源:filterlib.php

示例6: filter

 public function filter($text, array $options = array())
 {
     global $CFG, $DB, $GLOSSARY_EXCLUDECONCEPTS, $PAGE;
     // Trivial-cache - keyed on $cachedcontextid
     static $cachedcontextid;
     static $conceptlist;
     static $jsinitialised;
     // To control unique js init
     static $nothingtodo;
     // To avoid processing if no glossaries / concepts are found
     // Try to get current course
     if (!($courseid = get_courseid_from_context($this->context))) {
         $courseid = 0;
     }
     // Initialise/invalidate our trivial cache if dealing with a different context
     if (!isset($cachedcontextid) || $cachedcontextid !== $this->context->id) {
         $cachedcontextid = $this->context->id;
         $conceptlist = array();
         $nothingtodo = false;
     }
     if ($nothingtodo === true || !has_capability('mod/glossary:view', $this->context)) {
         return $text;
     }
     // Create a list of all the concepts to search for.  It may be cached already.
     if (empty($conceptlist)) {
         // Find all the glossaries we need to examine
         if (!($glossaries = $DB->get_records_sql_menu('
                 SELECT g.id, g.name
                   FROM {glossary} g, {course_modules} cm, {modules} m
                  WHERE m.name = \'glossary\'
                    AND cm.module = m.id
                    AND cm.visible = 1
                    AND g.id = cm.instance
                    AND g.usedynalink != 0
                    AND (g.course = ? OR g.globalglossary = 1)
               ORDER BY g.globalglossary, g.id', array($courseid)))) {
             $nothingtodo = true;
             return $text;
         }
         // Make a list of glossary IDs for searching
         $glossarylist = implode(',', array_keys($glossaries));
         // Pull out all the raw data from the database for entries, categories and aliases
         $entries = $DB->get_records_select('glossary_entries', 'glossaryid IN (' . $glossarylist . ') AND usedynalink != 0 AND approved != 0 ', null, '', 'id,glossaryid, concept, casesensitive, 0 AS category, fullmatch');
         $categories = $DB->get_records_select('glossary_categories', 'glossaryid IN (' . $glossarylist . ') AND usedynalink != 0', null, '', 'id,glossaryid,name AS concept, 1 AS casesensitive, 1 AS category, 1 AS fullmatch');
         $aliases = $DB->get_records_sql('
                 SELECT ga.id, ge.id AS entryid, ge.glossaryid,
                        ga.alias AS concept, ge.concept AS originalconcept,
                        casesensitive, 0 AS category, fullmatch
                   FROM {glossary_alias} ga,
                        {glossary_entries} ge
                   WHERE ga.entryid = ge.id
                     AND ge.glossaryid IN (' . $glossarylist . ')
                     AND ge.usedynalink != 0
                     AND ge.approved != 0', null);
         // Combine them into one big list
         $concepts = array();
         if ($entries and $categories) {
             $concepts = array_merge($entries, $categories);
         } else {
             if ($categories) {
                 $concepts = $categories;
             } else {
                 if ($entries) {
                     $concepts = $entries;
                 }
             }
         }
         if ($aliases) {
             $concepts = array_merge($concepts, $aliases);
         }
         if (!empty($concepts)) {
             foreach ($concepts as $key => $concept) {
                 // Trim empty or unlinkable concepts
                 $currentconcept = trim(strip_tags($concept->concept));
                 if (empty($currentconcept)) {
                     unset($concepts[$key]);
                     continue;
                 } else {
                     $concepts[$key]->concept = $currentconcept;
                 }
                 // Rule out any small integers.  See bug 1446
                 $currentint = intval($currentconcept);
                 if ($currentint && strval($currentint) == $currentconcept && $currentint < 1000) {
                     unset($concepts[$key]);
                 }
             }
         }
         if (empty($concepts)) {
             $nothingtodo = true;
             return $text;
         }
         usort($concepts, 'filter_glossary::sort_entries_by_length');
         $strcategory = get_string('category', 'glossary');
         // Loop through all the concepts, setting up our data structure for the filter
         $conceptlist = array();
         // We will store all the concepts here
         foreach ($concepts as $concept) {
             $glossaryname = str_replace(':', '-', $glossaries[$concept->glossaryid]);
             if ($concept->category) {
                 // Link to a category
//.........这里部分代码省略.........
开发者ID:numbas,项目名称:moodle,代码行数:101,代码来源:filter.php

示例7: test_everything_in_accesslib


//.........这里部分代码省略.........
            $context = context::instance_by_id($contextid);
            $this->assertSame(get_context_instance_by_id($contextid), $context);
            $this->assertSame(get_context_instance($record->contextlevel, $record->instanceid), $context);
            $this->assertSame(get_parent_contexts($context), $context->get_parent_context_ids());
            if ($context->id == SYSCONTEXTID) {
                $this->assertSame(get_parent_contextid($context), false);
            } else {
                $this->assertSame(get_parent_contextid($context), $context->get_parent_context()->id);
            }
        }

        $CFG->debug = 0;
        $children = get_child_contexts($systemcontext);
        $CFG->debug = DEBUG_DEVELOPER;
        $this->assertEquals(count($children), $DB->count_records('context')-1);
        unset($children);

        $DB->delete_records('context', array('contextlevel'=>CONTEXT_BLOCK));
        create_contexts();
        $this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_BLOCK)));

        $DB->set_field('context', 'depth', 0, array('contextlevel'=>CONTEXT_BLOCK));
        build_context_path();
        $this->assertFalse($DB->record_exists('context', array('depth'=>0)));

        $lastcourse = $DB->get_field_sql("SELECT MAX(id) FROM {course}");
        $DB->delete_records('course', array('id'=>$lastcourse));
        $lastcategory = $DB->get_field_sql("SELECT MAX(id) FROM {course_categories}");
        $DB->delete_records('course_categories', array('id'=>$lastcategory));
        $lastuser = $DB->get_field_sql("SELECT MAX(id) FROM {user} WHERE deleted=0");
        $DB->delete_records('user', array('id'=>$lastuser));
        $DB->delete_records('block_instances', array('parentcontextid'=>$frontpagepagecontext->id));
        $DB->delete_records('course_modules', array('id'=>$frontpagepagecontext->instanceid));
        cleanup_contexts();
        $count = 1; //system
        $count += $DB->count_records('user', array('deleted'=>0));
        $count += $DB->count_records('course_categories');
        $count += $DB->count_records('course');
        $count += $DB->count_records('course_modules');
        $count += $DB->count_records('block_instances');
        $this->assertEquals($DB->count_records('context'), $count);

        context_helper::reset_caches();
        preload_course_contexts($SITE->id);
        $this->assertEquals(context_inspection::test_context_cache_size(), 1);

        context_helper::reset_caches();
        list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSECAT, 'ctx');
        $sql = "SELECT c.id $select FROM {course_categories} c $join";
        $records = $DB->get_records_sql($sql);
        foreach ($records as $record) {
            context_instance_preload($record);
            $record = (array)$record;
            $this->assertEquals(1, count($record)); // only id left
        }
        $this->assertEquals(count($records), context_inspection::test_context_cache_size());

        accesslib_clear_all_caches(true);
        $DB->delete_records('cache_flags', array());
        mark_context_dirty($systemcontext->path);
        $dirty = get_cache_flags('accesslib/dirtycontexts', time()-2);
        $this->assertTrue(isset($dirty[$systemcontext->path]));

        accesslib_clear_all_caches(false);
        $DB->delete_records('cache_flags', array());
        $course = $DB->get_record('course', array('id'=>$testcourses[2]));
        $context = get_context_instance(CONTEXT_COURSE, $course->id);
        $oldpath = $context->path;
        $miscid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}");
        $categorycontext = context_coursecat::instance($miscid);
        $course->category = $miscid;
        $DB->update_record('course', $course);
        context_moved($context, $categorycontext);
        $context = get_context_instance(CONTEXT_COURSE, $course->id);
        $this->assertEquals($context->get_parent_context(), $categorycontext);

        $this->assertTrue($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$testcourses[2])));
        delete_context(CONTEXT_COURSE, $testcourses[2]);
        $this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$testcourses[2])));

        $name = get_contextlevel_name(CONTEXT_COURSE);
        $this->assertFalse(empty($name));

        $context = get_context_instance(CONTEXT_COURSE, $testcourses[2]);
        $name = print_context_name($context);
        $this->assertFalse(empty($name));

        $url = get_context_url($coursecontext);
        $this->assertFalse($url instanceof modole_url);

        $page = $DB->get_record('page', array('id'=>$testpages[7]));
        $context = get_context_instance(CONTEXT_MODULE, $page->id);
        $coursecontext = get_course_context($context);
        $this->assertEquals($coursecontext->contextlevel, CONTEXT_COURSE);
        $this->assertEquals(get_courseid_from_context($context), $page->course);

        $caps = fetch_context_capabilities($systemcontext);
        $this->assertTrue(is_array($caps));
        unset($caps);
    }
开发者ID:numbas,项目名称:moodle,代码行数:101,代码来源:accesslib_test.php

示例8: filter

 public function filter($text, array $options = array())
 {
     global $CFG, $DB;
     // Trivial-cache - keyed on $cachedcontextid
     static $cachedcontextid;
     static $contentlist;
     static $nothingtodo;
     // Try to get current course
     if (!($courseid = get_courseid_from_context($this->context))) {
         $courseid = 0;
     }
     // Initialise/invalidate our trivial cache if dealing with a different context
     if (!isset($cachedcontextid) || $cachedcontextid !== $this->context->id) {
         $cachedcontextid = $this->context->id;
         $contentlist = array();
         $nothingtodo = false;
     }
     if ($nothingtodo === true) {
         return $text;
     }
     // Create a list of all the resources to search for. It may be cached already.
     if (empty($contentlist)) {
         $coursestosearch = $courseid ? array($courseid) : array();
         // Add courseid if found
         if (get_site()->id != $courseid) {
             // Add siteid if was not courseid
             $coursestosearch[] = get_site()->id;
         }
         // We look for text field contents only if have autolink enabled (param1)
         list($coursesql, $params) = $DB->get_in_or_equal($coursestosearch);
         $sql = 'SELECT dc.id AS contentid, dr.id AS recordid, dc.content AS content, d.id AS dataid
                   FROM {data} d
                   JOIN {data_fields} df ON df.dataid = d.id
                   JOIN {data_records} dr ON dr.dataid = d.id
                   JOIN {data_content} dc ON dc.fieldid = df.id AND dc.recordid = dr.id
                  WHERE d.course ' . $coursesql . '
                    AND df.type = \'text\'
                    AND ' . $DB->sql_compare_text('df.param1', 1) . " = '1'";
         if (!($contents = $DB->get_records_sql($sql, $params))) {
             $nothingtodo = true;
             return $text;
         }
         foreach ($contents as $key => $content) {
             // Trim empty or unlinkable concepts
             $currentcontent = trim(strip_tags($content->content));
             if (empty($currentcontent)) {
                 unset($contents[$key]);
                 continue;
             } else {
                 $contents[$key]->content = $currentcontent;
             }
             // Rule out any small integers.  See bug 1446
             $currentint = intval($currentcontent);
             if ($currentint && strval($currentint) == $currentcontent && $currentint < 1000) {
                 unset($contents[$key]);
             }
         }
         if (empty($contents)) {
             $nothingtodo = true;
             return $text;
         }
         usort($contents, 'filter_data::sort_entries_by_length');
         foreach ($contents as $content) {
             $href_tag_begin = '<a class="data autolink dataid' . $content->dataid . '" title="' . $content->content . '" ' . 'href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $content->dataid . '&amp;rid=' . $content->recordid . '">';
             $contentlist[] = new filterobject($content->content, $href_tag_begin, '</a>', false, true);
         }
         $contentlist = filter_remove_duplicates($contentlist);
         // Clean dupes
     }
     return filter_phrases($text, $contentlist);
     // Look for all these links in the text
 }
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:72,代码来源:filter.php

示例9: get_courseid_from_context

/**
 * Returns current course id or null if outside of course based on context parameter.
 * @param object $context
 * @return int|bool related course id or false
 */
function get_courseid_from_context($context)
{
    if (empty($context->contextlevel)) {
        debugging('Invalid context object specified in get_courseid_from_context() call');
        return false;
    }
    if ($context->contextlevel == CONTEXT_COURSE) {
        return $context->instanceid;
    }
    if ($context->contextlevel < CONTEXT_COURSE) {
        return false;
    }
    if ($context->contextlevel == CONTEXT_MODULE) {
        $parentcontexts = get_parent_contexts($context, false);
        $parent = reset($parentcontexts);
        $parent = get_context_instance_by_id($parent);
        return $parent->instanceid;
    }
    if ($context->contextlevel == CONTEXT_BLOCK) {
        $parentcontexts = get_parent_contexts($context, false);
        $parent = reset($parentcontexts);
        return get_courseid_from_context(get_context_instance_by_id($parent));
    }
    return false;
}
开发者ID:LMSeXT,项目名称:SAWEE-WS_server-lib,代码行数:30,代码来源:accesslib.php

示例10: test_everything_in_accesslib


//.........这里部分代码省略.........
     $prevsize = context_inspection::test_context_cache_size();
     for ($i = 0; $i < 100; $i++) {
         context_user::instance($testusers[$i]);
         $this->assertEqual(context_inspection::test_context_cache_size(), $prevsize);
     }
     context_user::instance($testusers[102]);
     $this->assertEqual(context_inspection::test_context_cache_size(), $prevsize + 1);
     unset($testusers);
     // =================================================================
     // ======= basic test of legacy functions ==========================
     // =================================================================
     // note: watch out, the fake site might be pretty borked already
     $this->assertIdentical(get_system_context(), context_system::instance());
     foreach ($DB->get_records('context') as $contextid => $record) {
         $context = context::instance_by_id($contextid);
         $this->assertIdentical(get_context_instance_by_id($contextid), $context);
         $this->assertIdentical(get_context_instance($record->contextlevel, $record->instanceid), $context);
         $this->assertIdentical(get_parent_contexts($context), $context->get_parent_context_ids());
         if ($context->id == SYSCONTEXTID) {
             $this->assertIdentical(get_parent_contextid($context), false);
         } else {
             $this->assertIdentical(get_parent_contextid($context), $context->get_parent_context()->id);
         }
     }
     $children = get_child_contexts($systemcontext);
     $this->assertEqual(count($children), $DB->count_records('context') - 1);
     unset($children);
     $DB->delete_records('context', array('contextlevel' => CONTEXT_BLOCK));
     create_contexts();
     $this->assertFalse($DB->record_exists('context', array('contextlevel' => CONTEXT_BLOCK)));
     $DB->set_field('context', 'depth', 0, array('contextlevel' => CONTEXT_BLOCK));
     build_context_path();
     $this->assertFalse($DB->record_exists('context', array('depth' => 0)));
     $lastcourse = $DB->get_field_sql("SELECT MAX(id) FROM {course}");
     $DB->delete_records('course', array('id' => $lastcourse));
     $lastcategory = $DB->get_field_sql("SELECT MAX(id) FROM {course_categories}");
     $DB->delete_records('course_categories', array('id' => $lastcategory));
     $lastuser = $DB->get_field_sql("SELECT MAX(id) FROM {user} WHERE deleted=0");
     $DB->delete_records('user', array('id' => $lastuser));
     $DB->delete_records('block_instances', array('parentcontextid' => $frontpagepagecontext->id));
     $DB->delete_records('course_modules', array('id' => $frontpagepagecontext->instanceid));
     cleanup_contexts();
     $count = 1;
     //system
     $count += $DB->count_records('user', array('deleted' => 0));
     $count += $DB->count_records('course_categories');
     $count += $DB->count_records('course');
     $count += $DB->count_records('course_modules');
     $count += $DB->count_records('block_instances');
     $this->assertEqual($DB->count_records('context'), $count);
     context_helper::reset_caches();
     preload_course_contexts($SITE->id);
     $this->assertEqual(context_inspection::test_context_cache_size(), 1);
     context_helper::reset_caches();
     list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSECAT, 'ctx');
     $sql = "SELECT c.id {$select} FROM {course_categories} c {$join}";
     $records = $DB->get_records_sql($sql);
     foreach ($records as $record) {
         context_instance_preload($record);
         $record = (array) $record;
         $this->assertEqual(1, count($record));
         // only id left
     }
     $this->assertEqual(count($records), context_inspection::test_context_cache_size());
     accesslib_clear_all_caches(true);
     $DB->delete_records('cache_flags', array());
     mark_context_dirty($systemcontext->path);
     $dirty = get_cache_flags('accesslib/dirtycontexts', time() - 2);
     $this->assertTrue(isset($dirty[$systemcontext->path]));
     accesslib_clear_all_caches(false);
     $DB->delete_records('cache_flags', array());
     $course = $DB->get_record('course', array('id' => $testcourses[2]));
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
     $oldpath = $context->path;
     $miscid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}");
     $categorycontext = context_coursecat::instance($miscid);
     $course->category = $miscid;
     $DB->update_record('course', $course);
     context_moved($context, $categorycontext);
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
     $this->assertIdentical($context->get_parent_context(), $categorycontext);
     $this->assertTrue($DB->record_exists('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $testcourses[2])));
     delete_context(CONTEXT_COURSE, $testcourses[2]);
     $this->assertFalse($DB->record_exists('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $testcourses[2])));
     $name = get_contextlevel_name(CONTEXT_COURSE);
     $this->assertFalse(empty($name));
     $context = get_context_instance(CONTEXT_COURSE, $testcourses[2]);
     $name = print_context_name($context);
     $this->assertFalse(empty($name));
     $url = get_context_url($coursecontext);
     $this->assertFalse($url instanceof modole_url);
     $page = $DB->get_record('page', array('id' => $testpages[7]));
     $context = get_context_instance(CONTEXT_MODULE, $page->id);
     $coursecontext = get_course_context($context);
     $this->assertEqual($coursecontext->contextlevel, CONTEXT_COURSE);
     $this->assertEqual(get_courseid_from_context($context), $page->course);
     $caps = fetch_context_capabilities($systemcontext);
     $this->assertTrue(is_array($caps));
     unset($caps);
 }
开发者ID:rolandovanegas,项目名称:moodle,代码行数:101,代码来源:fulltestaccesslib.php

示例11: get_courseid_from_context

/**
 * Returns current course id or null if outside of course based on context parameter.
 * @param object $context
 * @return int|bool related course id or false
 */
function get_courseid_from_context($context)
{
    if ($context->contextlevel == CONTEXT_COURSE) {
        return $context->instanceid;
    }
    if ($context->contextlevel < CONTEXT_COURSE) {
        return false;
    }
    if ($context->contextlevel == CONTEXT_MODULE) {
        $parentcontexts = get_parent_contexts($context, false);
        $parent = reset($parentcontexts);
        $parent = get_context_instance_by_id($parent);
        return $parent->instanceid;
    }
    if ($context->contextlevel == CONTEXT_BLOCK) {
        $parentcontexts = get_parent_contexts($context, false);
        $parent = reset($parentcontexts);
        return get_courseid_from_context($parent);
    }
    return false;
}
开发者ID:vuchannguyen,项目名称:web,代码行数:26,代码来源:accesslib.php


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