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


PHP context_helper::get_class_for_level方法代码示例

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


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

示例1: get_export_xml

 /**
  * Generate role export xml file.
  *
  * @param $roleid
  * @return string
  */
 public static function get_export_xml($roleid)
 {
     global $DB;
     $role = $DB->get_record('role', array('id' => $roleid), '*', MUST_EXIST);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $top = $dom->createElement('role');
     $dom->appendChild($top);
     $top->appendChild($dom->createElement('shortname', $role->shortname));
     $top->appendChild($dom->createElement('name', htmlspecialchars($role->name, ENT_COMPAT | ENT_HTML401, 'UTF-8')));
     $top->appendChild($dom->createElement('description', htmlspecialchars($role->description, ENT_COMPAT | ENT_HTML401, 'UTF-8')));
     $top->appendChild($dom->createElement('archetype', $role->archetype));
     $contextlevels = $dom->createElement('contextlevels');
     $top->appendChild($contextlevels);
     foreach (get_role_contextlevels($roleid) as $level) {
         $name = context_helper::get_class_for_level($level);
         $name = preg_replace('/^context_/', '', $name);
         $contextlevels->appendChild($dom->createElement('level', $name));
     }
     foreach (array('assign', 'override', 'switch') as $type) {
         $allows = $dom->createElement('allow' . $type);
         $top->appendChild($allows);
         $records = $DB->get_records('role_allow_' . $type, array('roleid' => $roleid), "allow{$type} ASC");
         foreach ($records as $record) {
             if (!($ar = $DB->get_record('role', array('id' => $record->{'allow' . $type})))) {
                 continue;
             }
             $allows->appendChild($dom->createElement('shortname', $ar->shortname));
         }
     }
     $permissions = $dom->createElement('permissions');
     $top->appendChild($permissions);
     $capabilities = $DB->get_records_sql_menu("SELECT capability, permission\n               FROM {role_capabilities}\n              WHERE contextid = :syscontext AND roleid = :roleid\n           ORDER BY capability ASC", array('syscontext' => context_system::instance()->id, 'roleid' => $roleid));
     $allcapabilities = $DB->get_records('capabilities', array(), 'name ASC');
     foreach ($allcapabilities as $cap) {
         if (!isset($capabilities[$cap->name])) {
             $permissions->appendChild($dom->createElement('inherit', $cap->name));
         }
     }
     foreach ($capabilities as $capability => $permission) {
         if ($permission == CAP_ALLOW) {
             $permissions->appendChild($dom->createElement('allow', $capability));
         }
     }
     foreach ($capabilities as $capability => $permission) {
         if ($permission == CAP_PREVENT) {
             $permissions->appendChild($dom->createElement('prevent', $capability));
         }
     }
     foreach ($capabilities as $capability => $permission) {
         if ($permission == CAP_PROHIBIT) {
             $permissions->appendChild($dom->createElement('prohibit', $capability));
         }
     }
     return $dom->saveXML();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:61,代码来源:preset.php

示例2: get_level_name

 /**
  * Returns the name of specified context level
  *
  * @static
  * @param int $contextlevel
  * @return string name of the context level
  */
 public static function get_level_name($contextlevel)
 {
     $classname = context_helper::get_class_for_level($contextlevel);
     return $classname::get_level_name();
 }
开发者ID:rolandovanegas,项目名称:moodle,代码行数:12,代码来源:accesslib.php

示例3: process_course_group_node


//.........这里部分代码省略.........
             if ($end) {
                 $coursemanagement->enddate = $end->nodeValue;
             }
             if (isset($coursemanagement->startdate) && $coursemanagement->startdate > 0 && isset($coursemanagement->enddate) && $coursemanagement->enddate > 0) {
                 // The course validly has both start and end dates.
                 $coursemanagement->courseid = $course->id;
                 $coursemanagement->timemodified = time();
                 $DB->insert_record("eclass_course_management", $coursemanagement);
             } else {
                 if (isset($coursemanagement->startdate) || isset($coursemanagement->enddate)) {
                     // Something isn't right with the start or end date.
                     throw new Exception('UAIMS: Course Creation without valid start or end date');
                 }
             }
             // No else needed. No actions required if the course is validly lacking both start and end dates.
         } else {
             // Update existing Course, if corresponding eclass_course_management exist. Otherwise, create a
             // corresponding eclass_course_management entry.
             $ecourse = $DB->get_record('course', array('idnumber' => $course->idnumber), '*', MUST_EXIST);
             $enableqrtoggle = $this->get_config('enableqrvisibilitytoggle');
             // Disable or enable QR toggling.
             if (!isset($enableqrtoggle) || !$enableqrtoggle) {
                 unset($course->visible);
             } else {
                 // Otherwise update the startend dates in the eclass_course_management table from uaims documents.
                 $coursemanagement = $DB->get_record('eclass_course_management', array('courseid' => $ecourse->id), $fields = 'id', $strictness = IGNORE_MISSING);
                 // Get the start and end date for the course.
                 $begin = $xpath->evaluate("timeframe/begin", $groupnode)->item(0);
                 $end = $xpath->evaluate("timeframe/end", $groupnode)->item(0);
                 // To avoid errors when course is created outside of uaims (doesn't have eclass_course_management entry),
                 // create and set appropriate attributes of $coursemanagement that matches eclass_course_management
                 // database schema (or atleast NOT NULL fields).
                 $coursemanagementexist = $coursemanagement != false;
                 if (!$coursemanagementexist) {
                     $enrol = enrol_get_plugin('manual');
                     if ($audroleid = $DB->get_field('role', 'id', array('shortname' => 'auditor'))) {
                         $enrol->add_instance($ecourse, array('roleid' => $audroleid));
                     } else {
                         $enrol->add_instance($ecourse);
                     }
                     $coursemanagement = new stdClass();
                     // The test process_imsdoc_test::test_process_imsdoc_should_update_course_with_minimal_imsdoc
                     // implies that one of the requirement of this module is to ignore updates/insert in the case where
                     // course exist, yet no start/end date. (Note this differ from the case where the course don't exist
                     // in which case the requirements of this module requires it to throw an exception.
                     if ($begin and $end) {
                         // Set appropriate eclass_course_management row attributes and finally insert it to db.
                         $coursemanagement->courseid = $ecourse->id;
                         $coursemanagement->startdate = $begin->nodeValue;
                         $coursemanagement->enddate = $end->nodeValue;
                         $coursemanagement->timemodified = time();
                         $DB->insert_record("eclass_course_management", $coursemanagement);
                     }
                 } else {
                     // Since corresponding eclass_course_management entry exist, only we don't need all parameters
                     // to be present. Either/both $begin/$end dates is/are sufficient.
                     if ($begin) {
                         $coursemanagement->startdate = $begin->nodeValue;
                     }
                     if ($end) {
                         $coursemanagement->enddate = $end->nodeValue;
                     }
                     if (isset($coursemanagement->startdate) || isset($coursemanagement->enddate)) {
                         // If one of them is there then do the update.
                         if ($coursemanagement->startdate || $coursemanagement->enddate) {
                             $coursemanagement->timemodified = time();
                             $DB->update_record("eclass_course_management", $coursemanagement);
                         }
                     }
                 }
             }
             // The $course var should never have an 'id' attribute, but lets make sure.
             if (isset($course->id)) {
                 unset($course->id);
             }
             $ecourse = $this->extend($ecourse, $course);
             $DB->update_record('course', $ecourse);
             $classname = context_helper::get_class_for_level(CONTEXT_COURSE);
             $context = $classname::instance($ecourse->id, IGNORE_MISSING);
             $classname = context_helper::get_class_for_level(CONTEXT_COURSECAT);
             $newparent = $classname::instance($ecourse->category, IGNORE_MISSING);
             $context->update_moved($newparent);
             if (!($instanceid = $DB->get_field('enrol', 'id', array('enrol' => 'manual', 'courseid' => $ecourse->id)))) {
                 $enrol = enrol_get_plugin('manual');
                 if ($audroleid = $DB->get_field('role', 'id', array('shortname' => 'auditor'))) {
                     $enrol->add_instance($ecourse, array('roleid' => $audroleid));
                 } else {
                     $enrol->add_instance(${$ecourse});
                 }
             }
         }
     } else {
         $idnumber = $xpath->evaluate("sourcedid/id", $groupnode)->item(0);
         if ($idnumber) {
             $idnumber = htmlspecialchars_decode($idnumber->nodeValue);
             $course = $DB->get_record('course', array('idnumber' => $idnumber));
             delete_course($course, false);
         }
     }
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:101,代码来源:lib.php

示例4: delete_context

/**
 * Remove a context record and any dependent entries,
 * removes context from static context cache too
 *
 * @deprecated since Moodle 2.2
 * @see context_helper::delete_instance() or context::delete_content()
 * @param int $contextlevel
 * @param int $instanceid
 * @param bool $deleterecord false means keep record for now
 * @return bool returns true or throws an exception
 */
function delete_context($contextlevel, $instanceid, $deleterecord = true)
{
    if ($deleterecord) {
        debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER);
        context_helper::delete_instance($contextlevel, $instanceid);
    } else {
        debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER);
        $classname = context_helper::get_class_for_level($contextlevel);
        if ($context = $classname::instance($instanceid, IGNORE_MISSING)) {
            $context->delete_content();
        }
    }
    return true;
}
开发者ID:Hirenvaghasiya,项目名称:moodle,代码行数:25,代码来源:deprecatedlib.php

示例5: get_context_instance

/**
 * Get the context instance as an object. This function will create the
 * context instance if it does not exist yet.
 *
 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
 *      for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
 *      MUST_EXIST means throw exception if no record or multiple records found
 * @return context The context object.
 */
function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING)
{
    debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
    $instances = (array) $instance;
    $contexts = array();
    $classname = context_helper::get_class_for_level($contextlevel);
    // we do not load multiple contexts any more, PAGE should be responsible for any preloading
    foreach ($instances as $inst) {
        $contexts[$inst] = $classname::instance($inst, $strictness);
    }
    if (is_array($instance)) {
        return $contexts;
    } else {
        return $contexts[$instance];
    }
}
开发者ID:evltuma,项目名称:moodle,代码行数:29,代码来源:deprecatedlib.php

示例6: test_process_cohort_group_node

    /**
     * Tests for the enrol_uaims process_cohort_group_node function.
     *
     * Test to make sure that the cohort is created in the correct
     * category context.
     *
     * @package    enrol_uaims
     * @copyright  2014 Anthony Radziszewski radzisze@ualberta.ca
     * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
     */
    public function test_process_cohort_group_node()
    {
        global $DB, $CFG;
        $this->resetAfterTest(true);
        $xmldoc = <<<DOC
<?xml version="1.0" encoding="utf-8"?>
<enterprise xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<group recstatus="1">    <sourcedid>      <id>test_cohort_id</id>    </sourcedid>    <grouptype>
<typevalue>Cohort</typevalue>    </grouptype>       <description>      <short>Test Cohort</short>
<long>Test Cohort</long>    </description>    <org />    <timeframe>      <begin />      <end />
</timeframe>    <enrollcontrol />    <relationship>      <sourcedid>        <id>UOFAB-AU</id>
</sourcedid>    </relationship>  </group></enterprise>
DOC;
        $enrol = new enrol_uaims_plugin();
        $category = new stdClass();
        $category->name = "test";
        $category->description = "UOFAB-AU";
        $category->idnumber = "UOFAB-AU";
        $category->timemodified = time();
        $category->id = $DB->insert_record('course_categories', $category);
        $classname = context_helper::get_class_for_level(CONTEXT_COURSECAT);
        $category->context = $classname::instance($category->id, IGNORE_MISSING);
        $category->context->mark_dirty();
        $DB->update_record('course_categories', $category);
        fix_course_sortorder();
        $enrol->process_imsdoc($xmldoc);
        // Make sure the cohort exists.
        $getcohort = $DB->get_record('cohort', array('idnumber' => "test_cohort_id"), $fields = '*');
        $this->assertEquals($getcohort->idnumber, "test_cohort_id");
        $this->assertEquals($getcohort->visible, 0);
        // Make sure the cohort contextid matches the id from the context table for the specified category.
        $getcategory = $DB->get_record('course_categories', array('idnumber' => "UOFAB-AU"), $fields = '*');
        $this->assertEquals($getcategory->description, "UOFAB-AU");
        $getcontext = $DB->get_record('context', array('contextlevel' => 40, 'instanceid' => $getcategory->id), $fields = '*');
        $this->assertEquals($getcontext->instanceid, $getcategory->id);
        $this->assertEquals($getcontext->id, $getcohort->contextid);
    }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:47,代码来源:process_imsdoc_test.php

示例7: search

 /**
  * Executes the search
  *
  * @global moodle_database $DB
  * @return int The number of results
  */
 public final function search()
 {
     global $DB;
     if (!is_null($this->results)) {
         return $this->results;
     }
     $this->results = array();
     $this->totalcount = 0;
     $contextlevel = $this->get_itemcontextlevel();
     list($sql, $params) = $this->get_searchsql();
     $blocksz = 5000;
     $offs = 0;
     // Get total number, to avoid some incorrect iterations
     $countsql = preg_replace('/ORDER BY.*/', '', $sql);
     $totalcourses = $DB->count_records_sql("SELECT COUNT(*) FROM ({$countsql}) sel", $params);
     // User to be checked is always the same (usually null, get it form first element)
     $firstcap = reset($this->requiredcapabilities);
     $userid = isset($firstcap['user']) ? $firstcap['user'] : null;
     // Extract caps to check, this saves us a bunch of iterations
     $requiredcaps = array();
     foreach ($this->requiredcapabilities as $cap) {
         $requiredcaps[] = $cap['capability'];
     }
     // Iterate while we have records and haven't reached MAXRESULTS
     while ($totalcourses > $offs and $this->totalcount < self::$MAXRESULTS) {
         $resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz);
         foreach ($resultset as $result) {
             context_instance_preload($result);
             $classname = context_helper::get_class_for_level($contextlevel);
             $context = $classname::instance($result->id);
             if (count($requiredcaps) > 0) {
                 if (!has_all_capabilities($requiredcaps, $context, $userid)) {
                     continue;
                 }
             }
             $this->results[$result->id] = $result;
             $this->totalcount++;
             if ($this->totalcount >= self::$MAXRESULTS) {
                 break;
             }
         }
         $offs += $blocksz;
     }
     return $this->totalcount;
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:51,代码来源:restore_ui_components.php

示例8: search

 /**
  * Executes the search
  *
  * @global moodle_database $DB
  * @return int The number of results
  */
 public final function search()
 {
     global $DB;
     if (!is_null($this->results)) {
         return $this->results;
     }
     $this->results = array();
     $this->totalcount = 0;
     $contextlevel = $this->get_itemcontextlevel();
     list($sql, $params) = $this->get_searchsql();
     // Get total number, to avoid some incorrect iterations.
     $countsql = preg_replace('/ORDER BY.*/', '', $sql);
     $totalcourses = $DB->count_records_sql("SELECT COUNT(*) FROM ({$countsql}) sel", $params);
     if ($totalcourses > 0) {
         // User to be checked is always the same (usually null, get it from first element).
         $firstcap = reset($this->requiredcapabilities);
         $userid = isset($firstcap['user']) ? $firstcap['user'] : null;
         // Extract caps to check, this saves us a bunch of iterations.
         $requiredcaps = array();
         foreach ($this->requiredcapabilities as $cap) {
             $requiredcaps[] = $cap['capability'];
         }
         // Iterate while we have records and haven't reached $this->maxresults.
         $resultset = $DB->get_recordset_sql($sql, $params);
         foreach ($resultset as $result) {
             context_helper::preload_from_record($result);
             $classname = context_helper::get_class_for_level($contextlevel);
             $context = $classname::instance($result->id);
             if (count($requiredcaps) > 0) {
                 if (!has_all_capabilities($requiredcaps, $context, $userid)) {
                     continue;
                 }
             }
             // Check if we are over the limit.
             if ($this->totalcount + 1 > $this->maxresults) {
                 $this->hasmoreresults = true;
                 break;
             }
             // If not, then continue.
             $this->totalcount++;
             $this->results[$result->id] = $result;
         }
         $resultset->close();
     }
     return $this->totalcount;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:52,代码来源:restore_ui_components.php

示例9: hotpot_get_context

/**
 * context
 *
 * a wrapper method to offer consistent API to get contexts
 * in Moodle 2.0 and 2.1, we use get_context_instance() function
 * in Moodle >= 2.2, we use static context_xxx::instance() method
 *
 * @param integer $contextlevel
 * @param integer $instanceid (optional, default=0)
 * @param int $strictness (optional, default=0 i.e. IGNORE_MISSING)
 * @return required context
 * @todo Finish documenting this function
 */
function hotpot_get_context($contextlevel, $instanceid = 0, $strictness = 0)
{
    if (class_exists('context_helper')) {
        // use call_user_func() to prevent syntax error in PHP 5.2.x
        // return $classname::instance($instanceid, $strictness);
        $class = context_helper::get_class_for_level($contextlevel);
        return call_user_func(array($class, 'instance'), $instanceid, $strictness);
    } else {
        return get_context_instance($contextlevel, $instanceid);
    }
}
开发者ID:hapaxapah,项目名称:moodle-mod_hotpot,代码行数:24,代码来源:lib.php

示例10: defined

// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * IMS Enterprise enrolments plugin settings and presets.
 *
 * @package    enrol
 * @subpackage imsenterprise
 * @copyright  2010 Eugene Venter
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die;
global $CFG;
if ($ADMIN->fulltree) {
    require_once $CFG->dirroot . '/enrol/uaims/locallib.php';
    $settings->add(new admin_setting_configcheckbox('enrol_uaims/enableautocourseopenclose', new lang_string('enableautocourseopenclose', 'enrol_uaims'), new lang_string('enableautocourseopenclosedesc', 'enrol_uaims'), 0));
    $settings->add(new admin_setting_configcheckbox('enrol_uaims/enableqrvisibilitytoggle', new lang_string('enableqrvisibilitytoggle', 'enrol_uaims'), new lang_string('enableqrvisibilitytoggledesc', 'enrol_uaims'), 1));
    if (!during_initial_install()) {
        $classname = context_helper::get_class_for_level(CONTEXT_COURSE);
        $coursecontext = $classname::instance(SITEID, IGNORE_MISSING);
        $assignableroles = get_assignable_roles($coursecontext);
        $assignableroles = array('0' => get_string('ignore', 'enrol_uaims')) + $assignableroles;
        $imsroles = new uaims_roles();
        foreach ($imsroles->get_imsroles() as $imsrolenum => $imsrolename) {
            $settings->add(new admin_setting_configselect('enrol_uaims/imsrolemap' . $imsrolenum, format_string('"' . $imsrolename . '" (' . $imsrolenum . ')'), '', (int) $imsroles->determine_default_rolemapping($imsrolenum), $assignableroles));
        }
    }
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:31,代码来源:settings.php


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