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


PHP external_api::validate_context方法代码示例

本文整理汇总了PHP中external_api::validate_context方法的典型用法代码示例。如果您正苦于以下问题:PHP external_api::validate_context方法的具体用法?PHP external_api::validate_context怎么用?PHP external_api::validate_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在external_api的用法示例。


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

示例1: tool_usertours_inplace_editable

/**
 * Manage inplace editable saves.
 *
 * @param   string      $itemtype       The type of item.
 * @param   int         $itemid         The ID of the item.
 * @param   mixed       $newvalue       The new value
 * @return  string
 */
function tool_usertours_inplace_editable($itemtype, $itemid, $newvalue)
{
    $context = \context_system::instance();
    external_api::validate_context($context);
    require_capability('tool/usertours:managetours', $context);
    if ($itemtype === 'tourname') {
        $tour = helper::get_tour($itemid);
        $tour->set_name($newvalue)->persist();
        return helper::render_tourname_inplace_editable($tour);
    } else {
        if ($itemtype === 'tourdescription') {
            $tour = helper::get_tour($itemid);
            $tour->set_description($newvalue)->persist();
            return helper::render_tourdescription_inplace_editable($tour);
        } else {
            if ($itemtype === 'tourenabled') {
                $tour = helper::get_tour($itemid);
                $tour->set_enabled(!!$newvalue)->persist();
                return helper::render_tourenabled_inplace_editable($tour);
            } else {
                if ($itemtype === 'stepname') {
                    $step = helper::get_step($itemid);
                    $step->set_title($newvalue)->persist();
                    return helper::render_stepname_inplace_editable($step);
                }
            }
        }
    }
}
开发者ID:dg711,项目名称:moodle,代码行数:37,代码来源:lib.php

示例2: core_tag_inplace_editable

/**
 * Implements callback inplace_editable() allowing to edit values in-place
 *
 * @param string $itemtype
 * @param int $itemid
 * @param mixed $newvalue
 * @return \core\output\inplace_editable
 */
function core_tag_inplace_editable($itemtype, $itemid, $newvalue)
{
    \external_api::validate_context(context_system::instance());
    if ($itemtype === 'tagname') {
        return \core_tag\output\tagname::update($itemid, $newvalue);
    } else {
        if ($itemtype === 'tagareaenable') {
            return \core_tag\output\tagareaenabled::update($itemid, $newvalue);
        } else {
            if ($itemtype === 'tagareacollection') {
                return \core_tag\output\tagareacollection::update($itemid, $newvalue);
            } else {
                if ($itemtype === 'tagareashowstandard') {
                    return \core_tag\output\tagareashowstandard::update($itemid, $newvalue);
                } else {
                    if ($itemtype === 'tagcollname') {
                        return \core_tag\output\tagcollname::update($itemid, $newvalue);
                    } else {
                        if ($itemtype === 'tagcollsearchable') {
                            return \core_tag\output\tagcollsearchable::update($itemid, $newvalue);
                        } else {
                            if ($itemtype === 'tagflag') {
                                return \core_tag\output\tagflag::update($itemid, $newvalue);
                            } else {
                                if ($itemtype === 'tagisstandard') {
                                    return \core_tag\output\tagisstandard::update($itemid, $newvalue);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
开发者ID:evltuma,项目名称:moodle,代码行数:43,代码来源:lib.php

示例3: update

 /**
  * Updates cohort name and returns instance of this object
  *
  * @param int $cohortid
  * @param string $newvalue
  * @return static
  */
 public static function update($cohortid, $newvalue)
 {
     global $DB;
     $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
     $cohortcontext = \context::instance_by_id($cohort->contextid);
     \external_api::validate_context($cohortcontext);
     require_capability('moodle/cohort:manage', $cohortcontext);
     $record = (object) array('id' => $cohort->id, 'idnumber' => $newvalue, 'contextid' => $cohort->contextid);
     cohort_update_cohort($record);
     $cohort->idnumber = $newvalue;
     return new static($cohort);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:19,代码来源:cohortidnumber.php

示例4: update

 /**
  * Updates course module name
  *
  * @param int $itemid course module id
  * @param string $newvalue new name
  * @return static
  */
 public static function update($itemid, $newvalue)
 {
     $context = context_module::instance($itemid);
     // Check access.
     \external_api::validate_context($context);
     require_capability('moodle/course:manageactivities', $context);
     // Update value.
     set_coursemodule_name($itemid, $newvalue);
     $coursemodulerecord = get_coursemodule_from_id('', $itemid, 0, false, MUST_EXIST);
     // Return instance.
     $cm = get_fast_modinfo($coursemodulerecord->course)->get_cm($itemid);
     return new static($cm, true);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:20,代码来源:course_module_name.php

示例5: update

 /**
  * Updates cohort name and returns instance of this object
  *
  * @param int $cohortid
  * @param string $newvalue
  * @return static
  */
 public static function update($cohortid, $newvalue)
 {
     global $DB;
     $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
     $cohortcontext = \context::instance_by_id($cohort->contextid);
     \external_api::validate_context($cohortcontext);
     require_capability('moodle/cohort:manage', $cohortcontext);
     $newvalue = clean_param($newvalue, PARAM_TEXT);
     if (strval($newvalue) !== '') {
         $record = (object) array('id' => $cohort->id, 'name' => $newvalue, 'contextid' => $cohort->contextid);
         cohort_update_cohort($record);
         $cohort->name = $newvalue;
     }
     return new static($cohort);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:22,代码来源:cohortname.php

示例6: inplace_editable_update_section_name

 /**
  * Updates the value in the database and modifies this object respectively.
  *
  * ALWAYS check user permissions before performing an update! Throw exceptions if permissions are not sufficient
  * or value is not legit.
  *
  * @param stdClass $section
  * @param string $itemtype
  * @param mixed $newvalue
  * @return \core\output\inplace_editable
  */
 public function inplace_editable_update_section_name($section, $itemtype, $newvalue)
 {
     if ($itemtype === 'sectionname' || $itemtype === 'sectionnamenl') {
         $context = context_course::instance($section->course);
         external_api::validate_context($context);
         require_capability('moodle/course:update', $context);
         $newtitle = clean_param($newvalue, PARAM_TEXT);
         if (strval($section->name) !== strval($newtitle)) {
             course_update_section($section->course, $section, array('name' => $newtitle));
         }
         return $this->inplace_editable_render_section_name($section, $itemtype === 'sectionname', true);
     }
 }
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:24,代码来源:lib.php

示例7: validate_courses

 /**
  * Validate a list of courses, returning the complete course objects for valid courses.
  *
  * @param  array $courseids A list of course ids
  * @param  array $courses   An array of courses already pre-fetched, indexed by course id.
  * @return array            An array of courses and the validation warnings
  */
 public static function validate_courses($courseids, $courses = array())
 {
     // Delete duplicates.
     $courseids = array_unique($courseids);
     $warnings = array();
     // Remove courses which are not even requested.
     $courses = array_intersect_key($courses, array_flip($courseids));
     foreach ($courseids as $cid) {
         // Check the user can function in this context.
         try {
             $context = context_course::instance($cid);
             external_api::validate_context($context);
             if (!isset($courses[$cid])) {
                 $courses[$cid] = get_course($cid);
             }
         } catch (Exception $e) {
             unset($courses[$cid]);
             $warnings[] = array('item' => 'course', 'itemid' => $cid, 'warningcode' => '1', 'message' => 'No access rights in course context');
         }
     }
     return array($courses, $warnings);
 }
开发者ID:jackdaniels79,项目名称:moodle,代码行数:29,代码来源:externallib.php

示例8: validate_courses

 /**
  * Validate a list of courses, returning the complete course objects for valid courses.
  *
  * @param  array $courseids A list of course ids
  * @return array            An array of courses and the validation warnings
  */
 public static function validate_courses($courseids)
 {
     // Delete duplicates.
     $courseids = array_unique($courseids);
     $courses = array();
     $warnings = array();
     foreach ($courseids as $cid) {
         // Check the user can function in this context.
         try {
             $context = context_course::instance($cid);
             external_api::validate_context($context);
             $courses[$cid] = get_course($cid);
         } catch (Exception $e) {
             $warnings[] = array('item' => 'course', 'itemid' => $cid, 'warningcode' => '1', 'message' => 'No access rights in course context');
         }
     }
     return array($courses, $warnings);
 }
开发者ID:papillon326,项目名称:moodle-51419,代码行数:24,代码来源:externallib.php


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