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


PHP context_user::instance方法代码示例

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


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

示例1: test_event

 /**
  * Test the event.
  */
 public function test_event()
 {
     $this->resetAfterTest();
     $user1 = $this->getDataGenerator()->create_user();
     $context1 = context_user::instance($user1->id);
     $user2 = $this->getDataGenerator()->create_user();
     $context2 = context_user::instance($user2->id);
     $this->setUser($user1);
     // Changing own password.
     $event = \core\event\user_password_updated::create_from_user($user1);
     $this->assertEventContextNotUsed($event);
     $this->assertEquals($user1->id, $event->relateduserid);
     $this->assertSame($context1, $event->get_context());
     $this->assertEventLegacyLogData(null, $event);
     $this->assertFalse($event->other['forgottenreset']);
     $event->trigger();
     // Changing password of other user.
     $event = \core\event\user_password_updated::create_from_user($user2);
     $this->assertEventContextNotUsed($event);
     $this->assertEquals($user2->id, $event->relateduserid);
     $this->assertSame($context2, $event->get_context());
     $this->assertEventLegacyLogData(null, $event);
     $this->assertFalse($event->other['forgottenreset']);
     $event->trigger();
     // Password reset.
     $event = \core\event\user_password_updated::create_from_user($user1, true);
     $this->assertEventContextNotUsed($event);
     $this->assertEquals($user1->id, $event->relateduserid);
     $this->assertSame($context1, $event->get_context());
     $this->assertEventLegacyLogData(array(SITEID, 'user', 'set password', 'profile.php?id=' . $user1->id, $user1->id), $event);
     $this->assertTrue($event->other['forgottenreset']);
     $event->trigger();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:36,代码来源:event_user_password_updated_test.php

示例2: validation

    function validation($data, $files) {
        global $USER;

        if ($errors = parent::validation($data, $files)) {
            return $errors;
        }

        $usercontext = context_user::instance($USER->id);
        $fs = get_file_storage();

        if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['package'], 'id', false)) {
            if (!$this->current->instance) {
                $errors['package'] = get_string('required');
                return $errors;
            }
        } else {
            $file = reset($files);
            if ($file->get_mimetype() != 'application/zip') {
                $errors['package'] = get_string('invalidfiletype', 'error', '', $file);
                // better delete current file, it is not usable anyway
                $fs->delete_area_files($usercontext->id, 'user', 'draft', $data['package']);
            }
        }

        return $errors;
    }
开发者ID:JP-Git,项目名称:moodle,代码行数:26,代码来源:mod_form.php

示例3: get_content

    public function get_content() {
    global $CFG,$USER;    
    
    if ($this->content !== null) {
      return $this->content;
    }   
    if(!isloggedin()){
        return $this->content;
    }
    
    $this->content =  new stdClass;
    $systemcontext = context_system::instance();

    $usercontext = context_user::instance($USER->id);
      

    if(has_capability('local/gradeletter:manage', $usercontext) || is_siteadmin() ){		 
    $this->content->text=array();
    $icon = html_writer::empty_tag('img',array('src'=>$CFG->wwwroot.'/pix/i/navigationitem.png'));
    $this->content->text[]=html_writer::tag('a',$icon.get_string('addbatch','block_managebatches'),array('href' =>$CFG->wwwroot.'/local/batches/index.php'));
    //$this->content->text[]=html_writer::empty_tag('br');
    $this->content->text[]=html_writer::tag('a',$icon.get_string('assignbatch','block_managebatches'), array('href' =>$CFG->wwwroot.'/local/batches/bulk_enroll.php?mode=new'));
    //$this->content->text[]=html_writer::empty_tag('br');
    $this->content->text[]=html_writer::tag('a',$icon.get_string('enrolbatch','block_managebatches'), array('href' => $CFG->wwwroot.'/local/batches/bulk_enroll.php?mode=exists')); 
    //$this->content->text[]=html_writer::empty_tag('br');
 //   $this->content->text[]=html_writer::tag('a',$icon.get_string('reports','block_managebatches') , array('href' => $CFG->wwwroot.'/admin/index.php?cache=1')); 
    
    $this->content->text=implode('',$this->content->text);
     return $this->content;
    }    
    
    else
     return $this->content;    
   
  }
开发者ID:anilch,项目名称:Personel,代码行数:35,代码来源:block_managebatches.php

示例4: atto_managefiles_params_for_js

/**
 * Sends the parameters to JS module.
 *
 * @return array
 */
function atto_managefiles_params_for_js($elementid, $options, $fpoptions)
{
    global $CFG, $USER;
    require_once $CFG->dirroot . '/repository/lib.php';
    // Load constants.
    // Disabled if:
    // - Not logged in or guest.
    // - Files are not allowed.
    // - Only URL are supported.
    $disabled = !isloggedin() || isguestuser() || (!isset($options['maxfiles']) || $options['maxfiles'] == 0) || isset($options['return_types']) && !($options['return_types'] & ~FILE_EXTERNAL);
    $params = array('disabled' => $disabled, 'area' => array(), 'usercontext' => null);
    if (!$disabled) {
        $params['usercontext'] = context_user::instance($USER->id)->id;
        foreach (array('itemid', 'context', 'areamaxbytes', 'maxbytes', 'subdirs', 'return_types') as $key) {
            if (isset($options[$key])) {
                if ($key === 'context' && is_object($options[$key])) {
                    // Just context id is enough.
                    $params['area'][$key] = $options[$key]->id;
                } else {
                    $params['area'][$key] = $options[$key];
                }
            }
        }
    }
    return $params;
}
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:lib.php

示例5: atto_panoptobutton_params_for_js

/**
 * Return the js params required for this module.
 * @return array of additional params to pass to javascript init function for this module.
 */
function atto_panoptobutton_params_for_js($elementid, $options, $fpoptions)
{
    global $USER, $COURSE, $DB;
    //coursecontext
    $coursecontext = context_course::instance($COURSE->id);
    //Gets Panopto folder ID and for course from database on the server to which the course was provisioned.
    //If the course has not been provisioned, this will not return a value and the user will be able to select
    //folders and videos from the server specified as default during the plugin setup.
    $panoptoid = $DB->get_field('block_panopto_foldermap', 'panopto_id', array('moodleid' => $coursecontext->instanceid));
    $servername = $DB->get_field('block_panopto_foldermap', 'panopto_server', array('moodleid' => $coursecontext->instanceid));
    //usercontextid
    $usercontextid = context_user::instance($USER->id)->id;
    $disabled = false;
    //config array
    $params = array();
    $params['usercontextid'] = $usercontextid;
    $params['coursecontext'] = $panoptoid;
    $params['servename'] = $servername;
    //If they don't have permission don't show it
    if (!has_capability('atto/panoptobutton:visible', $coursecontext)) {
        $disabled = true;
    }
    //add disabled param
    $params['disabled'] = $disabled;
    //add our default server
    $params['defaultserver'] = get_config('atto_panoptobutton', 'defaultserver');
    return $params;
}
开发者ID:s-fanou,项目名称:Panopto-Button-for-Atto,代码行数:32,代码来源:lib.php

示例6: get_document

 /**
  * Returns the document associated with this message record.
  *
  * @param stdClass $record
  * @param array    $options
  * @return \core_search\document
  */
 public function get_document($record, $options = array())
 {
     try {
         $usercontext = \context_user::instance($options['user1id']);
     } catch (\moodle_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     }
     // Prepare associative array with data from DB.
     $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
     $doc->set('title', content_to_text($record->subject, false));
     $doc->set('itemid', $record->id);
     $doc->set('content', content_to_text($record->smallmessage, false));
     $doc->set('contextid', $usercontext->id);
     $doc->set('courseid', SITEID);
     $doc->set('owneruserid', $options['user1id']);
     $doc->set('userid', $options['user2id']);
     $doc->set('modified', $record->timecreated);
     // Check if this document should be considered new.
     if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $record->timecreated) {
         // If the document was created after the last index time, it must be new.
         $doc->set_is_new(true);
     }
     return $doc;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:33,代码来源:base_message.php

示例7: atto_streamings_params_for_js

/**
 * Return the js params required for this module.
 * @return array of additional params to pass to javascript init function for this module.
 */
function atto_streamings_params_for_js($elementid, $options, $fpoptions)
{
    global $USER, $COURSE;
    //coursecontext
    $coursecontext = context_course::instance($COURSE->id);
    //usercontextid
    $usercontextid = context_user::instance($USER->id)->id;
    $disabled = false;
    //config our array of data
    $params = array();
    $params['usercontextid'] = $usercontextid;
    //If they don't have permission don't show it
    if (!has_capability('atto/streamings:visible', $coursecontext)) {
        $disabled = true;
    }
    //add our disabled param
    $params['disabled'] = $disabled;
    //add our default video
    $params['defaultvideo'] = get_config('atto_streamings', 'defaultvideo');
    //add our default rtmp
    $params['defaultrtmp'] = get_config('atto_streamings', 'defaultrtmp');
    //add our default playlist
    $params['defaultplaylist'] = get_config('atto_streamings', 'defaultplaylist');
    //add our default web
    $params['defaultweb'] = get_config('atto_streamings', 'defaultweb');
    //add our default image
    $params['defaultimage'] = get_config('atto_streamings', 'defaultimage');
    return $params;
}
开发者ID:altrome,项目名称:moodle-atto_streamings,代码行数:33,代码来源:lib.php

示例8: get_content

 function get_content()
 {
     global $CFG, $USER;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (!isloggedin()) {
         return $this->content;
     }
     if (is_siteadmin()) {
         return $this->content;
     }
     //this block is for students
     $usercontext = context_user::instance($USER->id);
     if (!has_capability('local/clclasses:enrollclass', $usercontext)) {
         return $this->content;
     }
     // Prep the content
     $this->content = new stdClass();
     require_once 'academic_status.php';
     //$id=optional_param('id',5,PARAM_INT);
     $events = get_semslist();
     $this->content->text = $events;
     return $this->content;
     // Prepare the footer for this block
     // No footer to display
     $this->content->footer = '';
     // Return the content object
     return $this->content;
 }
开发者ID:anilch,项目名称:Personel,代码行数:30,代码来源:block_academic_status.php

示例9: test_create_instance

 public function test_create_instance()
 {
     global $DB, $CFG, $USER;
     $this->resetAfterTest();
     $this->setAdminUser();
     $course = $this->getDataGenerator()->create_course();
     $this->assertFalse($DB->record_exists('imscp', array('course' => $course->id)));
     $imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course));
     $records = $DB->get_records('imscp', array('course' => $course->id), 'id');
     $this->assertEquals(1, count($records));
     $this->assertTrue(array_key_exists($imscp->id, $records));
     $params = array('course' => $course->id, 'name' => 'Another imscp');
     $imscp = $this->getDataGenerator()->create_module('imscp', $params);
     $records = $DB->get_records('imscp', array('course' => $course->id), 'id');
     $this->assertEquals(2, count($records));
     $this->assertEquals('Another imscp', $records[$imscp->id]->name);
     // Examples of specifying the package file (do not validate anything, just check for exceptions).
     // 1. As path to the file in filesystem:
     $params = array('course' => $course->id, 'packagepath' => $CFG->dirroot . '/mod/imscp/tests/packages/singlescobasic.zip');
     $imscp = $this->getDataGenerator()->create_module('imscp', $params);
     // 2. As file draft area id:
     $fs = get_file_storage();
     $params = array('course' => $course->id, 'package' => file_get_unused_draft_itemid());
     $usercontext = context_user::instance($USER->id);
     $filerecord = array('component' => 'user', 'filearea' => 'draft', 'contextid' => $usercontext->id, 'itemid' => $params['package'], 'filename' => 'singlescobasic.zip', 'filepath' => '/');
     $fs->create_file_from_pathname($filerecord, $CFG->dirroot . '/mod/imscp/tests/packages/singlescobasic.zip');
     $imscp = $this->getDataGenerator()->create_module('imscp', $params);
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:28,代码来源:generator_test.php

示例10: core_badges_myprofile_navigation

/**
 * Add nodes to myprofile page.
 *
 * @param \core_user\output\myprofile\tree $tree Tree object
 * @param stdClass $user user object
 * @param bool $iscurrentuser
 * @param stdClass $course Course object
 *
 * @return bool
 */
function core_badges_myprofile_navigation(\core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course)
{
    global $CFG, $PAGE, $USER, $SITE;
    require_once $CFG->dirroot . '/badges/renderer.php';
    if (empty($CFG->enablebadges) || !empty($course) && empty($CFG->badges_allowcoursebadges)) {
        // Y U NO LIKE BADGES ?
        return true;
    }
    // Add category. This node should appear after 'contact' so that administration block appears towards the end. Refer MDL-49928.
    $category = new core_user\output\myprofile\category('badges', get_string('badges', 'badges'), 'contact');
    $tree->add_category($category);
    $context = context_user::instance($user->id);
    $courseid = empty($course) ? 0 : $course->id;
    if ($USER->id == $user->id || has_capability('moodle/badges:viewotherbadges', $context)) {
        $records = badges_get_user_badges($user->id, $courseid, null, null, null, true);
        $renderer = new core_badges_renderer($PAGE, '');
        // Local badges.
        if ($records) {
            $title = get_string('localbadgesp', 'badges', format_string($SITE->fullname));
            $content = $renderer->print_badges_list($records, $user->id, true);
            $localnode = $mybadges = new core_user\output\myprofile\node('badges', 'localbadges', $title, null, null, $content);
            $tree->add_node($localnode);
        }
        // External badges.
        if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) {
            $backpack = get_backpack_settings($user->id);
            if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) {
                $title = get_string('externalbadgesp', 'badges');
                $content = $renderer->print_badges_list($backpack->badges, $user->id, true, true);
                $externalnode = $mybadges = new core_user\output\myprofile\node('badges', 'externalbadges', $title, null, null, $content);
                $tree->add_node($externalnode);
            }
        }
    }
}
开发者ID:evltuma,项目名称:moodle,代码行数:45,代码来源:lib.php

示例11: xmldb_local_lae_upgrade

function xmldb_local_lae_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2013061200) {
        // Update course table to support display defaults
        $table = new xmldb_table('course');
        $field = new xmldb_field('filedisplaydefault', XMLDB_TYPE_INTEGER, '2', null, null, null, null, null);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_plugin_savepoint(true, 2013061200, 'local', 'lae');
    }
    if ($oldversion < 2014010900) {
        // Add mnethostid and email address to Anonymous User.
        $user = $DB->get_record('user', array('id' => $CFG->anonymous_userid));
        if (empty($user->email)) {
            $user->email = get_string('auser_email', 'local_lae');
        }
        $user->mnethostid = $CFG->mnet_localhost_id;
        $DB->update_record('user', $user);
        upgrade_plugin_savepoint(true, 2014010900, 'local', 'lae');
    }
    if ($oldversion < 2014041600) {
        // Set context for Anonymous User.
        $user = $DB->get_record('user', array('id' => $CFG->anonymous_userid));
        context_user::instance($user->id);
        upgrade_plugin_savepoint(true, 2014041600, 'local', 'lae');
    }
}
开发者ID:mackensen,项目名称:moodle-local_lae,代码行数:30,代码来源:upgrade.php

示例12: __construct

 public function __construct()
 {
     global $USER;
     $this->context = context_user::instance($USER->id);
     $fs = get_file_storage();
     $this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0);
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:7,代码来源:renderer.php

示例13: class_delete

 /**
  * Performs class deletion
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error deleting the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function class_delete(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::class_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Get the class.
     $clsid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $data['idnumber']));
     if (empty($clsid)) {
         throw new data_object_exception('ws_class_delete_fail_invalid_idnumber', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:class_delete', \local_elisprogram\context\pmclass::instance($clsid));
     // Delete the class.
     $pmclass = new pmclass($clsid);
     $pmclass->delete();
     // Verify class deleted & respond.
     if (!$DB->record_exists(pmclass::TABLE, array('id' => $clsid))) {
         return array('messagecode' => get_string('ws_class_delete_success_code', 'local_datahub'), 'message' => get_string('ws_class_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_class_delete_fail', 'local_datahub');
     }
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:37,代码来源:class_delete.class.php

示例14: test_upgrade_fix_missing_root_folders_draft

 public function test_upgrade_fix_missing_root_folders_draft()
 {
     global $DB, $SITE;
     $this->resetAfterTest(true);
     $user = $this->getDataGenerator()->create_user();
     $usercontext = context_user::instance($user->id);
     $this->setUser($user);
     $resource1 = $this->getDataGenerator()->get_plugin_generator('mod_resource')->create_instance(array('course' => $SITE->id));
     $context = context_module::instance($resource1->cmid);
     $draftitemid = 0;
     file_prepare_draft_area($draftitemid, $context->id, 'mod_resource', 'content', 0);
     $queryparams = array('component' => 'user', 'contextid' => $usercontext->id, 'filearea' => 'draft', 'itemid' => $draftitemid);
     // Make sure there are two records in files for the draft file area and one of them has filename '.'.
     $records = $DB->get_records_menu('files', $queryparams, '', 'id, filename');
     $this->assertEquals(2, count($records));
     $this->assertTrue(in_array('.', $records));
     $originalhash = $DB->get_field('files', 'pathnamehash', $queryparams + array('filename' => '.'));
     // Delete record with filename '.' and make sure it does not exist any more.
     $DB->delete_records('files', $queryparams + array('filename' => '.'));
     $records = $DB->get_records_menu('files', $queryparams, '', 'id, filename');
     $this->assertEquals(1, count($records));
     $this->assertFalse(in_array('.', $records));
     // Run upgrade script and make sure the record is restored.
     upgrade_fix_missing_root_folders_draft();
     $records = $DB->get_records_menu('files', $queryparams, '', 'id, filename');
     $this->assertEquals(2, count($records));
     $this->assertTrue(in_array('.', $records));
     $newhash = $DB->get_field('files', 'pathnamehash', $queryparams + array('filename' => '.'));
     $this->assertEquals($originalhash, $newhash);
 }
开发者ID:rushi963,项目名称:moodle,代码行数:30,代码来源:upgradelib_test.php

示例15: report_comments_can_access_user_report

/**
 * Is current user allowed to access this report
 *
 * @private defined in lib.php for performance reasons
 *
 * @param stdClass $user
 * @param stdClass $course
 * @return bool
 */
function report_comments_can_access_user_report($user, $course)
{
    global $USER, $CFG;
    if (empty($CFG->enablecomments)) {
        return false;
    }
    if ($course->id != SITEID and !$course->enablecomments) {
        return false;
    }
    $coursecontext = context_course::instance($course->id);
    if (has_capability('report/comments:view', $coursecontext)) {
        return true;
    }
    $personalcontext = context_user::instance($user->id);
    if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
        if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
            return true;
        }
    } else {
        if ($user->id == $USER->id) {
            if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
                return true;
            }
        }
    }
    return false;
}
开发者ID:ewallah,项目名称:moodle-report_comments,代码行数:36,代码来源:lib.php


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