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


PHP get_parent_contextid函数代码示例

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


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

示例1: qtype_ddmarker_course_context_id

function qtype_ddmarker_course_context_id($catcontextid)
{
    $context = get_context_instance_by_id($catcontextid);
    while ($context->contextlevel != CONTEXT_COURSE) {
        $context = get_context_instance_by_id(get_parent_contextid($context));
    }
    return $context->id;
}
开发者ID:ndunand,项目名称:moodle-qtype_ddmarker,代码行数:8,代码来源:lib.php

示例2: test_get_parent_contextid

 function test_get_parent_contextid()
 {
     $context = get_context_instance(CONTEXT_SYSTEM);
     $this->assertFalse(get_parent_contextid($context));
     $context = new stdClass();
     $context->path = '/1/25';
     $this->assertEqual(get_parent_contextid($context), 1);
     $context = new stdClass();
     $context->path = '/1/123/234/345/456';
     $this->assertEqual(get_parent_contextid($context), 345);
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:11,代码来源:testaccesslib.php

示例3: __construct

 /**
  * Constructor
  * @param context $context The context used for the capability check
  * @param string $capability The required capability
  * @param string $errormessage The error message to show the user
  * @param string $stringfile
  */
 function __construct($context, $capability, $errormessage, $stringfile)
 {
     $capabilityname = get_capability_string($capability);
     if ($context->contextlevel == CONTEXT_MODULE and preg_match('/:view$/', $capability)) {
         // we can not go to mod/xx/view.php because we most probably do not have cap to view it, let's go to course instead
         $paranetcontext = context::instance_by_id(get_parent_contextid($context));
         $link = get_context_url($paranetcontext);
     } else {
         $link = get_context_url($context);
     }
     parent::__construct($errormessage, $stringfile, $link, $capabilityname);
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:19,代码来源:setuplib.php

示例4: get_parent

 /**
  * Returns parent file_info instance
  *
  * @todo error checking if get_parent_contextid() returns false
  * @return file_info or null for root
  */
 public function get_parent()
 {
     //TODO: error checking if get_parent_contextid() returns false
     $pcid = get_parent_contextid($this->context);
     $parent = get_context_instance_by_id($pcid);
     return $this->browser->get_file_info($parent);
 }
开发者ID:nmicha,项目名称:moodle,代码行数:13,代码来源:file_info_context_course.php

示例5: set_context

    /**
     * Set the main context to which this page belongs.
     * @param object $context a context object, normally obtained with get_context_instance.
     */
    public function set_context($context) {
        if ($context === null) {
            // extremely ugly hack which sets context to some value in order to prevent warnings,
            // use only for core error handling!!!!
            if (!$this->_context) {
                $this->_context = get_context_instance(CONTEXT_SYSTEM);
            }
            return;
        }

        // ideally we should set context only once
        if (isset($this->_context)) {
            if ($context->id == $this->_context->id) {
                // fine - no change needed
            } else if ($this->_context->contextlevel == CONTEXT_SYSTEM or $this->_context->contextlevel == CONTEXT_COURSE) {
                // hmm - not ideal, but it might produce too many warnings due to the design of require_login
            } else if ($this->_context->contextlevel == CONTEXT_MODULE and $this->_context->id == get_parent_contextid($context)) {
                // hmm - most probably somebody did require_login() and after that set the block context
            } else {
                // we do not want devs to do weird switching of context levels on the fly,
                // because we might have used the context already such as in text filter in page title
                debugging('Coding problem: unsupported modification of PAGE->context from '.$this->_context->contextlevel.' to '.$context->contextlevel);
            }
        }

        $this->_context = $context;
    }
开发者ID:nottmoo,项目名称:moodle,代码行数:31,代码来源:pagelib.php

示例6: get_parent

 /**
  * TODO error checking if get_parent_contextid() returns false
  */
 public function get_parent()
 {
     $pcid = get_parent_contextid($this->context);
     $parent = get_context_instance_by_id($pcid);
     return $this->browser->get_file_info($parent);
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:9,代码来源:file_info_course.php

示例7: list

/// Now load those contexts.
if ($requiredcontexts) {
    list($sqlcontexttest, $contextparams) = $DB->get_in_or_equal($requiredcontexts);
    $contexts = get_sorted_contexts('ctx.id ' . $sqlcontexttest, $contextparams);
} else {
    $contexts = array();
}
/// Prepare some empty arrays to hold the data we are about to compute.
foreach ($contexts as $conid => $con) {
    $contexts[$conid]->children = array();
    $contexts[$conid]->roleassignments = array();
}
/// Put the contexts into a tree structure.
foreach ($contexts as $conid => $con) {
    $context = context::instance_by_id($conid);
    $parentcontextid = get_parent_contextid($context);
    if ($parentcontextid) {
        $contexts[$parentcontextid]->children[] = $conid;
    }
}
/// Put the role capabilities into the context tree.
foreach ($roleassignments as $ra) {
    $contexts[$ra->contextid]->roleassignments[$ra->roleid] = $ra;
}
$assignableroles = get_assignable_roles($usercontext, ROLENAME_BOTH);
$overridableroles = get_overridable_roles($usercontext, ROLENAME_BOTH);
/// Print the header
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext));
$straction = get_string('thisusersroles', 'role');
$title = get_string('xroleassignments', 'role', $fullname);
/// Course header
开发者ID:nmicha,项目名称:moodle,代码行数:31,代码来源:usersroles.php

示例8: question_delete_course_category

/**
 * Category is about to be deleted,
 * 1/ All question categories and their questions are deleted for this course category.
 * 2/ All questions are moved to new category
 *
 * @param object $category course category object
 * @param object $newcategory empty means everything deleted, otherwise id of category where content moved
 * @param boolean $feedback to specify if the process must output a summary of its work
 * @return boolean
 */
function question_delete_course_category($category, $newcategory, $feedback = true)
{
    $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
    if (empty($newcategory)) {
        $feedbackdata = array();
        // To store feedback to be showed at the end of the process
        $rescueqcategory = null;
        // See the code around the call to question_save_from_deletion.
        $strcatdeleted = get_string('unusedcategorydeleted', 'quiz');
        // Loop over question categories.
        if ($categories = get_records('question_categories', 'contextid', $context->id, 'parent', 'id, parent, name')) {
            foreach ($categories as $category) {
                // Deal with any questions in the category.
                if ($questions = get_records('question', 'category', $category->id)) {
                    // Try to delete each question.
                    foreach ($questions as $question) {
                        delete_question($question->id);
                    }
                    // Check to see if there were any questions that were kept because they are
                    // still in use somehow, even though quizzes in courses in this category will
                    // already have been deteted. This could happen, for example, if questions are
                    // added to a course, and then that course is moved to another category (MDL-14802).
                    $questionids = get_records_select_menu('question', 'category = ' . $category->id, '', 'id,1');
                    if (!empty($questionids)) {
                        if (!($rescueqcategory = question_save_from_deletion(implode(',', array_keys($questionids)), get_parent_contextid($context), print_context_name($context), $rescueqcategory))) {
                            return false;
                        }
                        $feedbackdata[] = array($category->name, get_string('questionsmovedto', 'question', $rescueqcategory->name));
                    }
                }
                // Now delete the category.
                if (!delete_records('question_categories', 'id', $category->id)) {
                    return false;
                }
                $feedbackdata[] = array($category->name, $strcatdeleted);
            }
            // End loop over categories.
        }
        // Output feedback if requested.
        if ($feedback and $feedbackdata) {
            $table = new stdClass();
            $table->head = array(get_string('questioncategory', 'question'), get_string('action'));
            $table->data = $feedbackdata;
            print_table($table);
        }
    } else {
        // Move question categories ot the new context.
        if (!($newcontext = get_context_instance(CONTEXT_COURSECAT, $newcategory->id))) {
            return false;
        }
        if (!set_field('question_categories', 'contextid', $newcontext->id, 'contextid', $context->id)) {
            return false;
        }
        if ($feedback) {
            $a = new stdClass();
            $a->oldplace = print_context_name($context);
            $a->newplace = print_context_name($newcontext);
            notify(get_string('movedquestionsandcategories', 'question', $a), 'notifysuccess');
        }
    }
    return true;
}
开发者ID:e-rasvet,项目名称:reader,代码行数:72,代码来源:questionlib.php

示例9: get_parent

 /**
  * Returns parent file_info instance
  *
  * @return file_info|null fileinfo instance or null for root directory
  */
 public function get_parent()
 {
     $cid = get_parent_contextid($this->context);
     $parent = context::instance_by_id($cid, IGNORE_MISSING);
     return $this->browser->get_file_info($parent);
 }
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:11,代码来源:file_info_context_coursecat.php

示例10: load_parent_permissions

 protected function load_parent_permissions()
 {
     global $DB;
     /// Get the capabilities from the parent context, so that can be shown in the interface.
     $parentcontext = context::instance_by_id(get_parent_contextid($this->context));
     $this->parentpermissions = role_context_capabilities($this->roleid, $parentcontext);
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:7,代码来源:lib.php

示例11: test_everything_in_accesslib


//.........这里部分代码省略.........
            context_user::instance($testusers[$i]);
            if ($i == CONTEXT_CACHE_MAX_SIZE - 1) {
                $this->assertEquals(context_inspection::test_context_cache_size(), CONTEXT_CACHE_MAX_SIZE);
            } else if ($i == CONTEXT_CACHE_MAX_SIZE) {
                // once the limit is reached roughly 1/3 of records should be removed from cache
                $this->assertEquals(context_inspection::test_context_cache_size(), (int)(CONTEXT_CACHE_MAX_SIZE * (2/3) +102));
            }
        }
        // We keep the first 100 cached
        $prevsize = context_inspection::test_context_cache_size();
        for ($i=0; $i<100; $i++) {
            context_user::instance($testusers[$i]);
            $this->assertEquals(context_inspection::test_context_cache_size(), $prevsize);
        }
        context_user::instance($testusers[102]);
        $this->assertEquals(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->assertSame(get_system_context(), context_system::instance());

        foreach ($DB->get_records('context') as $contextid=>$record) {
            $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');
开发者ID:numbas,项目名称:moodle,代码行数:67,代码来源:accesslib_test.php

示例12: get_course_context

/**
 * Find course context
 * @param object $context - course or lower context
 * @return object context of the enclosing course, throws exception when related course context can not be found
 */
function get_course_context($context)
{
    if (empty($context->contextlevel)) {
        throw new coding_exception('Invalid context parameter.');
    }
    if ($context->contextlevel == CONTEXT_COURSE) {
        return $context;
    } else {
        if ($context->contextlevel == CONTEXT_MODULE) {
            return get_context_instance_by_id(get_parent_contextid($context, MUST_EXIST));
        } else {
            if ($context->contextlevel == CONTEXT_BLOCK) {
                $parentcontext = get_context_instance_by_id(get_parent_contextid($context, MUST_EXIST));
                if ($parentcontext->contextlevel == CONTEXT_COURSE) {
                    return $parentcontext;
                } else {
                    if ($parentcontext->contextlevel == CONTEXT_MODULE) {
                        return get_context_instance_by_id(get_parent_contextid($parentcontext, MUST_EXIST));
                    } else {
                        throw new coding_exception('Invalid level of block context parameter.');
                    }
                }
            }
        }
    }
    throw new coding_exception('Invalid context level of parameter.');
}
开发者ID:LMSeXT,项目名称:SAWEE-WS_server-lib,代码行数:32,代码来源:accesslib.php

示例13: test_everything_in_accesslib


//.........这里部分代码省略.........
     context_helper::create_instances(null, true);
     context_helper::reset_caches();
     for ($i = 0; $i < CONTEXT_CACHE_MAX_SIZE + 100; $i++) {
         context_user::instance($testusers[$i]);
         if ($i == CONTEXT_CACHE_MAX_SIZE - 1) {
             $this->assertEqual(context_inspection::test_context_cache_size(), CONTEXT_CACHE_MAX_SIZE);
         } else {
             if ($i == CONTEXT_CACHE_MAX_SIZE) {
                 // once the limit is reached roughly 1/3 of records should be removed from cache
                 $this->assertEqual(context_inspection::test_context_cache_size(), (int) (CONTEXT_CACHE_MAX_SIZE * (2 / 3) + 102));
             }
         }
     }
     // We keep the first 100 cached
     $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);
开发者ID:rolandovanegas,项目名称:moodle,代码行数:67,代码来源:fulltestaccesslib.php

示例14: print_error

}
// This is a policy decision, rather than something that would be impossible to implement.
if (!in_array($context->contextlevel, array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE))) {
    print_error('cannotcustomisefiltersblockuser', 'error');
}
$isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID;
$contextname = print_context_name($context);
$baseurl = $CFG->wwwroot . '/filter/manage.php?contextid=' . $context->id;
if ($context->contextlevel == CONTEXT_COURSECAT) {
    $course = clone $SITE;
} else {
    if ($context->contextlevel == CONTEXT_COURSE) {
        $course = $DB->get_record('course', array('id' => $context->instanceid));
    } else {
        // Must be module context.
        $course = $DB->get_record_sql('SELECT c.* FROM {course} c JOIN {context} ctx ON c.id = ctx.instanceid WHERE ctx.id = ?', array(get_parent_contextid($context)));
    }
}
if (!$course) {
    print_error('invalidcourse', 'error');
}
/// Check login and permissions.
require_login($course);
require_capability('moodle/filter:manage', $context);
/// Get the list of available filters.
$availablefilters = filter_get_available_in_context($context);
if (!$isfrontpage && empty($availablefilters)) {
    print_error('nofiltersenabled', 'error');
}
// If we are handling local settings for a particular filter, start processing.
if ($forfilter) {
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:manage.php

示例15: send_file_not_found

                     if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
                         send_file_not_found();
                     }
                     session_get_instance()->write_close();
                     // unlock session during fileserving
                     send_stored_file($file, 0, 0, true);
                     // must force download - security!
                 } else {
                     send_file_not_found();
                 }
             }
         }
     }
 } else {
     if ($context->contextlevel == CONTEXT_MODULE) {
         if (!($coursecontext = get_context_instance_by_id(get_parent_contextid($context)))) {
             send_file_not_found();
         }
         if (!($course = $DB->get_record('course', array('id' => $coursecontext->instanceid)))) {
             send_file_not_found();
         }
         $modinfo = get_fast_modinfo($course);
         if (empty($modinfo->cms[$context->instanceid])) {
             send_file_not_found();
         }
         $cminfo = $modinfo->cms[$context->instanceid];
         $modname = $cminfo->modname;
         $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
         if (!file_exists($libfile)) {
             send_file_not_found();
         }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:pluginfile.php


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