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


PHP context_coursecat类代码示例

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


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

示例1: __construct

 public function __construct($actionurl, $companyid, $departmentid)
 {
     global $CFG, $USER;
     $this->selectedcompany = $companyid;
     $this->departmentid = $departmentid;
     $company = new company($this->selectedcompany);
     $parentlevel = company::get_company_parentnode($company->id);
     $this->companydepartment = $parentlevel->id;
     if (iomad::has_capability('block/iomad_company_admin:edit_all_departments', context_system::instance())) {
         $userhierarchylevel = $parentlevel->id;
     } else {
         $userlevel = company::get_userlevel($USER);
         $userhierarchylevel = $userlevel->id;
     }
     $this->subhierarchieslist = company::get_all_subdepartments($userhierarchylevel);
     if ($this->departmentid == 0) {
         $departmentid = $userhierarchylevel;
     } else {
         $departmentid = $this->departmentid;
     }
     $this->userdepartment = $userhierarchylevel;
     $options = array('context' => $this->context, 'multiselect' => true, 'companyid' => $this->selectedcompany, 'departmentid' => $departmentid, 'subdepartments' => $this->subhierarchieslist, 'parentdepartmentid' => $parentlevel, 'showopenshared' => true, 'license' => false);
     $this->currentcourses = new potential_subdepartment_course_selector('currentcourses', $options);
     $this->currentcourses->set_rows(20);
     $this->context = context_coursecat::instance($CFG->defaultrequestcategory);
     parent::moodleform($actionurl);
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:27,代码来源:company_user_create_form.php

示例2: __construct

 public function __construct($actionurl, $invoiceid)
 {
     global $CFG;
     $this->invoiceid = $invoiceid;
     $this->context = context_coursecat::instance($CFG->defaultrequestcategory);
     parent::__construct($actionurl);
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:7,代码来源:edit_order_form.php

示例3: __construct

 public function __construct($actionurl, $companyid, $editoroptions)
 {
     global $CFG;
     $this->selectedcompany = $companyid;
     $this->context = context_coursecat::instance($CFG->defaultrequestcategory);
     $this->editoroptions = $editoroptions;
     parent::__construct($actionurl);
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:8,代码来源:company_course_create_form.php

示例4: test_associate_moodle_course_during_class_create

 /**
  * Validate that class instance-moodle course associations
  * can be created during a class instance create action
  *
  * @param string $link The link attribute to use in the import, or 'auto' to auto-create
  *                     from template
  * @dataProvider link_course_provider
  */
 public function test_associate_moodle_course_during_class_create($link)
 {
     global $CFG, $DB, $USER;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/classmoodlecourse.class.php');
     require_once elispm::lib('data/coursetemplate.class.php');
     require_once elispm::lib('data/course.class.php');
     // Make sure $USER is set up for backup/restore.
     $USER = $DB->get_record_select('user', "username != 'guest' and DELETED = 0", array(), '*', IGNORE_MULTIPLE);
     $GLOBAL['USER'] = $USER;
     // Need the moodle/backup:backupcourse capability.
     $guestroleid = create_role('guestrole', 'guestrole', 'guestrole');
     set_config('guestroleid', $guestroleid);
     set_config('siteguest', '');
     $systemcontext = context_system::instance();
     $roleid = create_role('testrole', 'testrole', 'testrole');
     assign_capability('moodle/backup:backupcourse', CAP_ALLOW, $roleid, $systemcontext->id);
     role_assign($roleid, $USER->id, $systemcontext->id);
     set_config('siteadmins', $USER->id);
     $coursecategory = new stdClass();
     $coursecategory->name = 'testcoursecategoryname';
     $coursecategory->id = $DB->insert_record('course_categories', $coursecategory);
     context_coursecat::instance($coursecategory->id);
     $moodlecourse = new stdClass();
     $moodlecourse->category = $coursecategory->id;
     $moodlecourse->shortname = 'testcourseshortname';
     $moodlecourse->fullname = 'testcoursefullname';
     $moodlecourse = create_course($moodlecourse);
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     // Need this for the 'auto' case, at the very least.
     $coursetemplate = new coursetemplate(array('courseid' => $course->id, 'location' => $moodlecourse->id, 'templateclass' => 'moodlecourseurl'));
     $coursetemplate->save();
     // Run the class instance create action.
     $record = new stdClass();
     $record->idnumber = 'testclassidnumber';
     $record->assignment = 'testcourseidnumber';
     $record->link = $link;
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->class_create($record, 'bogus');
     $classid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => 'testclassidnumber'));
     // Validation.
     if ($record->link == 'auto') {
         $moodlecourseid = $moodlecourse->id + 1;
     } else {
         $moodlecourseid = $moodlecourse->id;
     }
     $dbautocreated = $record->link == 'auto' ? 1 : 0;
     $this->assertTrue($DB->record_exists(classmoodlecourse::TABLE, array('classid' => $classid, 'moodlecourseid' => $moodlecourseid, 'enroltype' => 0, 'enrolplugin' => 'crlm', 'autocreated' => $dbautocreated)));
     ini_set('max_execution_time', '0');
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:61,代码来源:class_associate_moodle_course_test.php

示例5: init_category_and_course

 /**
  * Initialize a test category and course, including their context records.
  *
  * @return object the course's context object
  * @uses $DB
  */
 private function init_category_and_course()
 {
     global $DB;
     // Category.
     $category = new stdClass();
     $category->name = 'category';
     $category->id = $DB->insert_record('course_categories', $category);
     context_coursecat::instance($category->id);
     // Course.
     $coursedata = new stdClass();
     $coursedata->category = $category->id;
     $coursedata->fullname = 'fullname';
     $course = create_course($coursedata);
     return context_course::instance($course->id);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:21,代码来源:custom_field_permissions_test.php

示例6: __construct

 public function __construct($actionurl, $isadding, $shopsettingsid, $course, $priceblocks, $editoroptions)
 {
     global $CFG;
     $this->isadding = $isadding;
     $this->shopsettingsid = $shopsettingsid;
     $this->course = $course;
     $this->priceblocks = $priceblocks;
     $this->context = context_coursecat::instance($CFG->defaultrequestcategory);
     $this->editoroptions = $editoroptions;
     if ($isadding) {
         $options = array('context' => $this->context, 'multiselect' => false, 'selectedid' => $shopsettingsid, 'searchanywhere' => true, 'file' => '/blocks/iomad_commerce/lib/course_selectors.php');
         $this->currentcourses = new nonshopcourse_selector('currentcourses', $options);
         $this->currentcourses->set_rows(1);
     }
     parent::__construct($actionurl);
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:16,代码来源:edit_course_shopsettings_form.php

示例7: test_user_sync_on_pm_user_create

 /**
  * Validate that appropriate fields are synched over to Moodle when PM user is enrolled in a class instance during an import.
  */
 public function test_user_sync_on_pm_user_create()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/classmoodlecourse.class.php');
     require_once elispm::lib('data/course.class.php');
     require_once elispm::lib('data/pmclass.class.php');
     require_once elispm::lib('data/user.class.php');
     // Configure the elis enrolment plugin.
     $roleid = $DB->get_field('role', 'id', array(), IGNORE_MULTIPLE);
     set_config('roleid', $roleid, 'enrol_elis');
     $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => 'test@useremail.com', 'country' => 'CA'));
     $user->save();
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     $class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
     $class->save();
     $category = new stdClass();
     $category->name = 'testcategoryname';
     $category->id = $DB->insert_record('course_categories', $category);
     // Create the associated context.
     context_coursecat::instance($category->id);
     $mdlcourse = new stdClass();
     $mdlcourse->category = $category->id;
     $mdlcourse->fullname = 'testcoursefullname';
     $mdlcourse = create_course($mdlcourse);
     // Associate class instance to Moodle course.
     $classmoodlecourse = new classmoodlecourse(array('classid' => $class->id, 'moodlecourseid' => $mdlcourse->id));
     $classmoodlecourse->save();
     // Run the enrolment create action.
     $record = new stdClass();
     $record->context = 'class_testclassidnumber';
     $record->user_username = 'testuserusername';
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->class_enrolment_create($record, 'bogus', 'testclassidnumber');
     // Validate the enrolment.
     $enrolid = $DB->get_field('enrol', 'id', array('enrol' => 'elis', 'courseid' => $mdlcourse->id));
     $this->assertNotEquals(false, $enrolid);
     $mdluserid = $DB->get_field('user', 'id', array('username' => 'testuserusername'));
     $this->assertNotEquals(false, $mdluserid);
     $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid' => $enrolid, 'userid' => $mdluserid)));
     // Validate the role assignment.
     $mdlcoursecontext = context_course::instance($mdlcourse->id);
     $this->assertTrue($DB->record_exists('role_assignments', array('roleid' => $roleid, 'contextid' => $mdlcoursecontext->id, 'userid' => $mdluserid)));
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:50,代码来源:elis_enrolment_sync_test.php

示例8: create_cohorts

 /**
  * Create one or more cohorts
  *
  * @param array $cohorts An array of cohorts to create.
  * @return array An array of arrays
  * @since Moodle 2.5
  */
 public static function create_cohorts($cohorts)
 {
     global $CFG, $DB;
     require_once "{$CFG->dirroot}/cohort/lib.php";
     $params = self::validate_parameters(self::create_cohorts_parameters(), array('cohorts' => $cohorts));
     $transaction = $DB->start_delegated_transaction();
     $syscontext = context_system::instance();
     $cohortids = array();
     foreach ($params['cohorts'] as $cohort) {
         $cohort = (object) $cohort;
         // Category type (context id).
         $categorytype = $cohort->categorytype;
         if (!in_array($categorytype['type'], array('idnumber', 'id', 'system'))) {
             throw new invalid_parameter_exception('category type must be id, idnumber or system:' . $categorytype['type']);
         }
         if ($categorytype['type'] === 'system') {
             $cohort->contextid = $syscontext->id;
         } else {
             if ($catid = $DB->get_field('course_categories', 'id', array($categorytype['type'] => $categorytype['value']))) {
                 $catcontext = context_coursecat::instance($catid);
                 $cohort->contextid = $catcontext->id;
             } else {
                 throw new invalid_parameter_exception('category not exists: category ' . $categorytype['type'] . ' = ' . $categorytype['value']);
             }
         }
         // Make sure that the idnumber doesn't already exist.
         if ($DB->record_exists('cohort', array('idnumber' => $cohort->idnumber))) {
             throw new invalid_parameter_exception('record already exists: idnumber=' . $cohort->idnumber);
         }
         $context = context::instance_by_id($cohort->contextid, MUST_EXIST);
         if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
             throw new invalid_parameter_exception('Invalid context');
         }
         self::validate_context($context);
         require_capability('moodle/cohort:manage', $context);
         // Validate format.
         $cohort->descriptionformat = external_validate_format($cohort->descriptionformat);
         $cohort->id = cohort_add_cohort($cohort);
         list($cohort->description, $cohort->descriptionformat) = external_format_text($cohort->description, $cohort->descriptionformat, $context->id, 'cohort', 'description', $cohort->id);
         $cohortids[] = (array) $cohort;
     }
     $transaction->allow_commit();
     return $cohortids;
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:51,代码来源:externallib.php

示例9: block_jmail_get_context

/**
 * Returns the jmail context
 *
 * @param  int $context The context
 * @param  int $id      The context id
 * @param  int $flags   The flags to be used
 * @return stdClass     An object instance
 */
function block_jmail_get_context($context, $id = null, $flags = null)
{
    if ($context == CONTEXT_SYSTEM) {
        if (class_exists('context_system')) {
            return context_system::instance();
        } else {
            return get_context_instance(CONTEXT_SYSTEM);
        }
    } else {
        if ($context == CONTEXT_COURSE) {
            if (class_exists('context_course')) {
                return context_course::instance($id, $flags);
            } else {
                return get_context_instance($context, $id, $flags);
            }
        } else {
            if ($context == CONTEXT_COURSECAT) {
                if (class_exists('context_coursecat')) {
                    return context_coursecat::instance($id, $flags);
                } else {
                    return get_context_instance($context, $id, $flags);
                }
            } else {
                if ($context == CONTEXT_BLOCK) {
                    if (class_exists('context_block')) {
                        return context_block::instance($id, $flags);
                    } else {
                        return get_context_instance($context, $id, $flags);
                    }
                } else {
                    if ($context == CONTEXT_USER) {
                        if (class_exists('context_user')) {
                            return context_user::instance($id, $flags);
                        } else {
                            return get_context_instance($context, $id, $flags);
                        }
                    }
                }
            }
        }
    }
}
开发者ID:borrown,项目名称:moodle-block_jmail,代码行数:50,代码来源:locallib.php

示例10: equella_getssotoken

/**
 * Create EQUELLA single sign on token for current user
 *
 * @return string
 */
function equella_getssotoken($course = null)
{
    global $USER, $CFG, $COURSE;
    if (empty($course)) {
        $course = $COURSE;
    }
    $context_sys = context_system::instance();
    $context_cc = null;
    if (!empty($course->category) && is_int($course->category)) {
        $context_cc = context_coursecat::instance($course->category);
    }
    $context_c = context_course::instance($course->id);
    // roles are ordered by shortname
    $editingroles = get_all_editing_roles();
    foreach ($editingroles as $role) {
        $hassystemrole = false;
        if (!empty($context_sys)) {
            $hassystemrole = user_has_role_assignment($USER->id, $role->id, $context_sys->id);
        }
        $hascategoryrole = false;
        if (!empty($context_cc)) {
            $hascategoryrole = user_has_role_assignment($USER->id, $role->id, $context_cc->id);
        }
        $hascourserole = false;
        if (!empty($context_c)) {
            $hascourserole = user_has_role_assignment($USER->id, $role->id, $context_c->id);
        }
        if ($hassystemrole || $hascategoryrole || $hascourserole) {
            // see if the user has a role that is linked to an equella role
            $shareid = $CFG->{"equella_{$role->shortname}_shareid"};
            if (!empty($shareid)) {
                return equella_getssotoken_raw($USER->username, $shareid, $CFG->{"equella_{$role->shortname}_sharedsecret"});
            }
        }
    }
    // no roles found, use the default shareid and secret
    $shareid = $CFG->equella_shareid;
    if (!empty($shareid)) {
        return equella_getssotoken_raw($USER->username, $shareid, $CFG->equella_sharedsecret);
    }
}
开发者ID:CTANZ,项目名称:moodle-mod_equella,代码行数:46,代码来源:lib.php

示例11: get_category_options

 protected function get_category_options($currentcontextid)
 {
     $displaylist = array();
     $parentlist = array();
     make_categories_list($displaylist, $parentlist, 'moodle/cohort:manage');
     $options = array();
     $syscontext = context_system::instance();
     if (has_capability('moodle/cohort:manage', $syscontext)) {
         $options[$syscontext->id] = $syscontext->get_context_name();
     }
     foreach ($displaylist as $cid => $name) {
         $context = context_coursecat::instance($cid);
         $options[$context->id] = $name;
     }
     // Always add current - this is not likely, but if the logic gets changed it might be a problem.
     if (!isset($options[$currentcontextid])) {
         $context = context::instance_by_id($currentcontextid, MUST_EXIST);
         $options[$context->id] = $syscontext->get_context_name();
     }
     return $options;
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:21,代码来源:edit_form.php

示例12: test_enrol_cohort_create_new_group

 /**
  * Test that a new group with the name of the cohort is created.
  */
 public function test_enrol_cohort_create_new_group()
 {
     global $DB;
     $this->resetAfterTest();
     // Create a category.
     $category = $this->getDataGenerator()->create_category();
     // Create two courses.
     $course = $this->getDataGenerator()->create_course(array('category' => $category->id));
     $course2 = $this->getDataGenerator()->create_course(array('category' => $category->id));
     // Create a cohort.
     $cohort = $this->getDataGenerator()->create_cohort(array('context' => context_coursecat::instance($category->id)->id));
     // Run the function.
     $groupid = enrol_cohort_create_new_group($course->id, $cohort->id);
     // Check the results.
     $group = $DB->get_record('groups', array('id' => $groupid));
     // The group name should match the cohort name.
     $this->assertEquals($cohort->name . ' cohort', $group->name);
     // Group course id should match the course id.
     $this->assertEquals($course->id, $group->courseid);
     // Create a group that will have the same name as the cohort.
     $groupdata = new stdClass();
     $groupdata->courseid = $course2->id;
     $groupdata->name = $cohort->name . ' cohort';
     groups_create_group($groupdata);
     // Create a group for the cohort in course 2.
     $groupid = enrol_cohort_create_new_group($course2->id, $cohort->id);
     $groupinfo = $DB->get_record('groups', array('id' => $groupid));
     // Check that the group name has been changed.
     $this->assertEquals($cohort->name . ' cohort (2)', $groupinfo->name);
     // Create another group that will have the same name as a generated cohort.
     $groupdata = new stdClass();
     $groupdata->courseid = $course2->id;
     $groupdata->name = $cohort->name . ' cohort (2)';
     groups_create_group($groupdata);
     // Create a group for the cohort in course 2.
     $groupid = enrol_cohort_create_new_group($course2->id, $cohort->id);
     $groupinfo = $DB->get_record('groups', array('id' => $groupid));
     // Check that the group name has been changed.
     $this->assertEquals($cohort->name . ' cohort (3)', $groupinfo->name);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:43,代码来源:cohortlib_test.php

示例13: xmldb_main_install

/**
 * Main post-install tasks to be executed after the BD schema is available
 *
 * This function is automatically executed after Moodle core DB has been
 * created at initial install. It's in charge of perform the initial tasks
 * not covered by the {@link install.xml} file, like create initial users,
 * roles, templates, moving stuff from other plugins...
 *
 * Note that the function is only invoked once, at install time, so if new tasks
 * are needed in the future, they will need to be added both here (for new sites)
 * and in the corresponding {@link upgrade.php} file (for existing sites).
 *
 * All plugins within Moodle (modules, blocks, reports...) support the existence of
 * their own install.php file, using the "Frankenstyle" component name as
 * defined at {@link http://docs.moodle.org/dev/Frankenstyle}, for example:
 *     - {@link xmldb_page_install()}. (modules don't require the plugintype ("mod_") to be used.
 *     - {@link xmldb_enrol_meta_install()}.
 *     - {@link xmldb_workshopform_accumulative_install()}.
 *     - ....
 *
 * Finally, note that it's also supported to have one uninstall.php file that is
 * executed also once, each time one plugin is uninstalled (before the DB schema is
 * deleted). Those uninstall files will contain one function, using the "Frankenstyle"
 * naming conventions, like {@link xmldb_enrol_meta_uninstall()} or {@link xmldb_workshop_uninstall()}.
 */
function xmldb_main_install()
{
    global $CFG, $DB, $SITE, $OUTPUT;
    // Make sure system context exists
    $syscontext = context_system::instance(0, MUST_EXIST, false);
    if ($syscontext->id != SYSCONTEXTID) {
        throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected new system context id!');
    }
    // Create site course
    if ($DB->record_exists('course', array())) {
        throw new moodle_exception('generalexceptionmessage', 'error', '', 'Can not create frontpage course, courses already exist.');
    }
    $newsite = new stdClass();
    $newsite->fullname = '';
    $newsite->shortname = '';
    $newsite->summary = NULL;
    $newsite->newsitems = 3;
    $newsite->numsections = 1;
    $newsite->category = 0;
    $newsite->format = 'site';
    // Only for this course
    $newsite->timecreated = time();
    $newsite->timemodified = $newsite->timecreated;
    if (defined('SITEID')) {
        $newsite->id = SITEID;
        $DB->import_record('course', $newsite);
        $DB->get_manager()->reset_sequence('course');
    } else {
        $newsite->id = $DB->insert_record('course', $newsite);
        define('SITEID', $newsite->id);
    }
    // set the field 'numsections'. We can not use format_site::update_format_options() because
    // the file is not loaded
    $DB->insert_record('course_format_options', array('courseid' => SITEID, 'format' => 'site', 'sectionid' => 0, 'name' => 'numsections', 'value' => $newsite->numsections));
    $SITE = get_site();
    if ($newsite->id != $SITE->id) {
        throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected new site course id!');
    }
    // Make sure site course context exists
    context_course::instance($SITE->id);
    // Update the global frontpage cache
    $SITE = $DB->get_record('course', array('id' => $newsite->id), '*', MUST_EXIST);
    // Create default course category
    if ($DB->record_exists('course_categories', array())) {
        throw new moodle_exception('generalexceptionmessage', 'error', '', 'Can not create default course category, categories already exist.');
    }
    $cat = new stdClass();
    $cat->name = get_string('miscellaneous');
    $cat->depth = 1;
    $cat->sortorder = MAX_COURSES_IN_CATEGORY;
    $cat->timemodified = time();
    $catid = $DB->insert_record('course_categories', $cat);
    $DB->set_field('course_categories', 'path', '/' . $catid, array('id' => $catid));
    // Make sure category context exists
    context_coursecat::instance($catid);
    $defaults = array('rolesactive' => '0', 'auth' => 'email', 'auth_pop3mailbox' => 'INBOX', 'enrol_plugins_enabled' => 'manual,guest,self,cohort', 'theme' => theme_config::DEFAULT_THEME, 'filter_multilang_converted' => 1, 'siteidentifier' => random_string(32) . get_host_from_url($CFG->wwwroot), 'backup_version' => 2008111700, 'backup_release' => '2.0 dev', 'mnet_dispatcher_mode' => 'off', 'sessiontimeout' => 7200, 'stringfilters' => '', 'filterall' => 0, 'texteditors' => 'atto,tinymce,textarea', 'upgrade_minmaxgradestepignored' => 1, 'upgrade_extracreditweightsstepignored' => 1, 'upgrade_calculatedgradeitemsignored' => 1);
    foreach ($defaults as $key => $value) {
        set_config($key, $value);
    }
    // Bootstrap mnet
    $mnethost = new stdClass();
    $mnethost->wwwroot = $CFG->wwwroot;
    $mnethost->name = '';
    $mnethost->name = '';
    $mnethost->public_key = '';
    if (empty($_SERVER['SERVER_ADDR'])) {
        // SERVER_ADDR is only returned by Apache-like webservers
        preg_match("@^(?:http[s]?://)?([A-Z0-9\\-\\.]+).*@i", $CFG->wwwroot, $matches);
        $my_hostname = $matches[1];
        $my_ip = gethostbyname($my_hostname);
        // Returns unmodified hostname on failure. DOH!
        if ($my_ip == $my_hostname) {
            $mnethost->ip_address = 'UNKNOWN';
        } else {
            $mnethost->ip_address = $my_ip;
//.........这里部分代码省略.........
开发者ID:alanaipe2015,项目名称:moodle,代码行数:101,代码来源:install.php

示例14: add_category

 /**
  * Adds a structured category to the navigation in the correct order/place
  *
  * @param stdClass $category
  * @param navigation_node $parent
  */
 protected function add_category(stdClass $category, navigation_node $parent)
 {
     if (array_key_exists($category->id, $this->addedcategories)) {
         return;
     }
     $url = new moodle_url('/course/category.php', array('id' => $category->id));
     $context = context_coursecat::instance($category->id);
     $categoryname = format_string($category->name, true, array('context' => $context));
     $categorynode = $parent->add($categoryname, $url, self::TYPE_CATEGORY, $categoryname, $category->id);
     if (empty($category->visible)) {
         if (has_capability('moodle/category:viewhiddencategories', get_system_context())) {
             $categorynode->hidden = true;
         } else {
             $categorynode->display = false;
         }
     }
     $this->addedcategories[$category->id] = $categorynode;
 }
开发者ID:nigeli,项目名称:moodle,代码行数:24,代码来源:navigationlib.php

示例15: delete_categories

    /**
     * Delete categories
     *
     * @param array $categories A list of category ids
     * @return array
     * @since Moodle 2.3
     */
    public static function delete_categories($categories) {
        global $CFG, $DB;
        require_once($CFG->dirroot . "/course/lib.php");
        require_once($CFG->libdir . "/coursecatlib.php");

        // Validate parameters.
        $params = self::validate_parameters(self::delete_categories_parameters(), array('categories' => $categories));

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['categories'] as $category) {
            $deletecat = coursecat::get($category['id'], MUST_EXIST);
            $context = context_coursecat::instance($deletecat->id);
            require_capability('moodle/category:manage', $context);
            self::validate_context($context);
            self::validate_context(get_category_or_system_context($deletecat->parent));

            if ($category['recursive']) {
                // If recursive was specified, then we recursively delete the category's contents.
                if ($deletecat->can_delete_full()) {
                    $deletecat->delete_full(false);
                } else {
                    throw new moodle_exception('youcannotdeletecategory', '', '', $deletecat->get_formatted_name());
                }
            } else {
                // In this situation, we don't delete the category's contents, we either move it to newparent or parent.
                // If the parent is the root, moving is not supported (because a course must always be inside a category).
                // We must move to an existing category.
                if (!empty($category['newparent'])) {
                    $newparentcat = coursecat::get($category['newparent']);
                } else {
                    $newparentcat = coursecat::get($deletecat->parent);
                }

                // This operation is not allowed. We must move contents to an existing category.
                if (!$newparentcat->id) {
                    throw new moodle_exception('movecatcontentstoroot');
                }

                self::validate_context(context_coursecat::instance($newparentcat->id));
                if ($deletecat->can_move_content_to($newparentcat->id)) {
                    $deletecat->delete_move($newparentcat->id, false);
                } else {
                    throw new moodle_exception('youcannotdeletecategory', '', '', $deletecat->get_formatted_name());
                }
            }
        }

        $transaction->allow_commit();
    }
开发者ID:rwijaya,项目名称:moodle,代码行数:57,代码来源:externallib.php


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