當前位置: 首頁>>代碼示例>>PHP>>正文


PHP external_api::contextrestriction方法代碼示例

本文整理匯總了PHP中external_api::contextrestriction方法的典型用法代碼示例。如果您正苦於以下問題:PHP external_api::contextrestriction方法的具體用法?PHP external_api::contextrestriction怎麽用?PHP external_api::contextrestriction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在external_api的用法示例。


在下文中一共展示了external_api::contextrestriction方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validate_context

 /**
  * Makes sure user may execute functions in this context.
  * @param object $context
  * @return void
  */
 protected static function validate_context($context)
 {
     global $CFG;
     if (empty($context)) {
         throw new invalid_parameter_exception('Context does not exist');
     }
     if (empty(self::$contextrestriction)) {
         self::$contextrestriction = get_context_instance(CONTEXT_SYSTEM);
     }
     $rcontext = self::$contextrestriction;
     if ($rcontext->contextlevel == $context->contextlevel) {
         if ($rcontext->id != $context->id) {
             throw new restricted_context_exception();
         }
     } else {
         if ($rcontext->contextlevel > $context->contextlevel) {
             throw new restricted_context_exception();
         } else {
             $parents = get_parent_contexts($context);
             if (!in_array($rcontext->id, $parents)) {
                 throw new restricted_context_exception();
             }
         }
     }
     if ($context->contextlevel >= CONTEXT_COURSE) {
         list($context, $course, $cm) = get_context_info_array($context->id);
         require_login($course, false, $cm, false, true);
     }
 }
開發者ID:vuchannguyen,項目名稱:web,代碼行數:34,代碼來源:externallib.php

示例2: validate_context

 /**
  * Makes sure user may execute functions in this context.
  *
  * @param stdClass $context
  * @since Moodle 2.0
  */
 public static function validate_context($context)
 {
     global $CFG, $PAGE;
     if (empty($context)) {
         throw new invalid_parameter_exception('Context does not exist');
     }
     if (empty(self::$contextrestriction)) {
         self::$contextrestriction = context_system::instance();
     }
     $rcontext = self::$contextrestriction;
     if ($rcontext->contextlevel == $context->contextlevel) {
         if ($rcontext->id != $context->id) {
             throw new restricted_context_exception();
         }
     } else {
         if ($rcontext->contextlevel > $context->contextlevel) {
             throw new restricted_context_exception();
         } else {
             $parents = $context->get_parent_context_ids();
             if (!in_array($rcontext->id, $parents)) {
                 throw new restricted_context_exception();
             }
         }
     }
     $PAGE->reset_theme_and_output();
     list($unused, $course, $cm) = get_context_info_array($context->id);
     require_login($course, false, $cm, false, true);
     $PAGE->set_context($context);
 }
開發者ID:jackdaniels79,項目名稱:moodle,代碼行數:35,代碼來源:externallib.php

示例3: set_context_restriction

 /**
  * Set context restriction for all following subsequent function calls.
  * @param stdClass $contex
  * @return void
  */
 public static function set_context_restriction($context)
 {
     self::$contextrestriction = $context;
 }
開發者ID:rboyatt,項目名稱:mahara,代碼行數:9,代碼來源:lib.php


注:本文中的external_api::contextrestriction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。