• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP context_block类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __construct

 /**
  * Constructor - instantiates one object of this class
  */
 public function __construct($name, $blockid, $moduleid = null, $plan = null)
 {
     global $DB;
     // Check blockid exists
     if (!($block = $DB->get_record('block_instances', array('id' => $blockid)))) {
         throw new backup_task_exception('block_task_block_instance_not_found', $blockid);
     }
     $this->blockid = $blockid;
     $this->blockname = $block->blockname;
     $this->contextid = context_block::instance($this->blockid)->id;
     $this->moduleid = $moduleid;
     $this->modulename = null;
     $this->parentcontextid = null;
     // If moduleid passed, check exists, supports moodle2 format and save info
     // Check moduleid exists
     if (!empty($moduleid)) {
         if (!($coursemodule = get_coursemodule_from_id(false, $moduleid))) {
             throw new backup_task_exception('block_task_coursemodule_not_found', $moduleid);
         }
         // Check activity supports this moodle2 backup format
         if (!plugin_supports('mod', $coursemodule->modname, FEATURE_BACKUP_MOODLE2)) {
             throw new backup_task_exception('block_task_activity_lacks_moodle2_backup_support', $coursemodule->modname);
         }
         $this->moduleid = $moduleid;
         $this->modulename = $coursemodule->modname;
         $this->parentcontextid = context_module::instance($this->moduleid)->id;
     }
     parent::__construct($name, $plan);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:32,代码来源:backup_block_task.class.php


示例2: get_content

 /**
  * Used to generate the content for the block.
  * @return string
  */
 public function get_content()
 {
     global $DB, $OUTPUT;
     if ($this->content !== null) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $rs = $DB->get_records('block_links', array('defaultshow' => BLOCK_LINKS_SHOWLINK), 'linktext');
     if (!is_array($rs)) {
         $rs = array();
     }
     $link = new stdClass();
     foreach ($rs as $link) {
         if (block_links_check_permissions($link)) {
             // Does the user have permission, or is it viewable to all?
             $this->add_link($link);
         }
     }
     if (empty($this->instance->pinned)) {
         $context = context_block::instance($this->instance->id);
     } else {
         $context = context_system::instance();
         // Pinned blocks do not have own context.
     }
     if (has_capability('moodle/site:manageblocks', $context) && has_capability('block/links:managelinks', $context)) {
         $link->url = new moodle_url('/blocks/links/config_global_action.php');
         $link->linktext = html_writer::tag('span', get_string('managelinks', 'block_links'), array('class' => 'links-bold'));
         $this->content->items[] = html_writer::tag('a', $link->linktext, array('href' => $link->url));
         $this->content->icons[] = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('web', 'block_links'), 'class' => 'icon'));
     }
     return $this->content;
 }
开发者ID:sbourget,项目名称:moodle-block_links,代码行数:39,代码来源:block_links.php


示例3: xmldb_block_nurs_navigation_upgrade

/**
 * This is the upgrade script for the project.
 *
 * @package    block_nurs_navigation
 * @category   block
 * @copyright  2012 Craig Jamieson
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function xmldb_block_nurs_navigation_upgrade($oldversion = 0)
{
    global $DB;
    $dbman = $DB->get_manager();
    $result = true;
    // June 17, 2013 version changed the way that contexts are stored in the files table.
    if ($oldversion < 2013061706) {
        $query = "SELECT * FROM {nurs_navigation} WHERE courseid <> 1";
        $records = $DB->get_records_sql($query);
        $fs = get_file_storage();
        foreach ($records as $record) {
            $coursecontext = context_course::instance($record->courseid);
            // Explicit check here since sometimes there are old nurs_navigation records that point to deleted courses.
            if (isset($coursecontext->id)) {
                $params = array($coursecontext->id, 'nurs_navigation');
                $query = "SELECT * FROM {block_instances} WHERE parentcontextid = ? AND blockname = ?";
                $block = $DB->get_record_sql($query, $params, IGNORE_MULTIPLE);
                $blockcontext = context_block::instance($block->id);
                // This can return multiple records because of how the multiple file terminator works.
                $filerecords = $DB->get_records('files', array('contextid' => $coursecontext->id, 'itemid' => $record->fileid));
                foreach ($filerecords as $filerecord) {
                    $filerecord->contextid = $blockcontext->id;
                    // Path hash must be updated as well with a context change.
                    $filerecord->pathnamehash = $fs->get_pathname_hash($filerecord->contextid, BNN_BLOCK_SAVE_COMPONENT, BNN_BLOCK_SAVE_AREA, $filerecord->itemid, $filerecord->filepath, $filerecord->filename);
                    $DB->update_record('files', $filerecord);
                }
            }
        }
    }
    // Create the second table.
    if ($oldversion < 2012110200) {
        // Define table nurs_navigation_settings to be created.
        $table = new xmldb_table('nurs_navigation_settings');
        // Adding fields to table nurs_navigation_settings.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
        $table->add_field('sectionname', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null);
        $table->add_field('disableicon', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
        $table->add_field('customlabel', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
        // Adding keys to table nurs_navigation_settings.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for nurs_navigation_settings.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define field disableicon to be dropped from nurs_navigation.
        $table = new xmldb_table('nurs_navigation');
        $field = new xmldb_field('disableicon');
        // Conditionally launch drop field courseid.
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }
        // Update savepoint.
        upgrade_block_savepoint(true, 2012110200, 'nurs_navigation');
    }
    return $result;
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:65,代码来源:upgrade.php


示例4: create_instance

 /**
  * Create new block instance
  * @param array|stdClass $record
  * @param array $options
  * @return stdClass activity record with extra cmid field
  */
 public function create_instance($record = null, $options = null)
 {
     global $DB;
     $this->instancecount++;
     $record = (object) (array) $record;
     $options = (array) $options;
     $record = $this->prepare_record($record);
     $id = $DB->insert_record('block_instances', $record);
     context_block::instance($id);
     $instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
     return $instance;
 }
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:18,代码来源:lib.php


示例5: create_instance

 /**
  * Create new block instance
  * @param array|stdClass $record
  * @param array $options
  * @return stdClass activity record with extra cmid field
  */
 public function create_instance($record = null, array $options = null)
 {
     global $DB, $CFG;
     require_once "{$CFG->dirroot}/mod/page/locallib.php";
     $this->instancecount++;
     $record = (object) (array) $record;
     $options = (array) $options;
     $record = $this->prepare_record($record);
     $id = $DB->insert_record('block_instances', $record);
     context_block::instance($id);
     $instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
     return $instance;
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:19,代码来源:lib.php


示例6: create_instance

 /**
  * Create new block instance
  * @param array|stdClass $record
  * @param array $config Instance configurations
  * @return stdClass instance record
  */
 public function create_instance($record = null, array $config = null)
 {
     global $DB, $CFG;
     require_once "{$CFG->dirroot}/mod/page/locallib.php";
     $this->instancecount++;
     $record = (object) (array) $record;
     $config = (object) (array) $config;
     $record = $this->prepare_record($record);
     if (!isset($config->sped_version)) {
         $config->sped_version = 0;
     }
     $record->configdata = base64_encode(serialize($config));
     $id = $DB->insert_record('block_instances', $record);
     $context = context_block::instance($id);
     $instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
     return $instance;
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:23,代码来源:lib.php


示例7: get_content

 /**
  * @see block_base::get_content()
  */
 public function get_content()
 {
     global $CFG, $PAGE, $USER, $COURSE, $OUTPUT;
     if ($this->content !== null) {
         return $this->content;
     }
     // Display admin or user page depending capability.
     $context = context_block::instance($this->instance->id);
     $this->content = new stdClass();
     if (has_capability('moodle/course:managegroups', $context)) {
         $this->content->text = '<a href="' . $CFG->wwwroot . '/blocks/upload_group/index.php?id=' . $COURSE->id . '">Upload groups</a>';
     } else {
         $this->content->text = '';
     }
     $this->content->footer = '';
     return $this->content;
 }
开发者ID:at-tools,项目名称:moodle-block_uploadgroups,代码行数:20,代码来源:block_upload_group.php


示例8: __construct

 /**
  * @throws coding_exception
  */
 public function __construct()
 {
     global $PAGE, $COURSE;
     // Page path blacklist for admin menu.
     $adminblockblacklist = ['/user/profile.php'];
     if (in_array(local::current_url_path(), $adminblockblacklist)) {
         return;
     }
     // Admin users always see the admin menu with the exception of blacklisted pages.
     // The admin menu shows up for other users if they are a teacher in the current course.
     if (!is_siteadmin()) {
         // We don't want students to see the admin menu ever.
         // Editing teachers are identified as people who can manage activities and non editing teachers as those who
         // can view the gradebook. As editing teachers are almost certain to also be able to view the gradebook, the
         // grader:view capability is checked first.
         $caps = ['gradereport/grader:view', 'moodle/course:manageactivities'];
         $canmanageacts = has_any_capability($caps, $PAGE->context);
         $isstudent = !$canmanageacts && !is_role_switched($COURSE->id);
         if ($isstudent) {
             return;
         }
     }
     if (!$PAGE->blocks->is_block_present('settings')) {
         // Throw error if on front page or course page.
         // (There are pages that don't have a settings block so we shouldn't throw an error on those pages).
         if (strpos($PAGE->pagetype, 'course-view') === 0 || $PAGE->pagetype === 'site-index') {
             debugging('Settings block was not found on this page', DEBUG_DEVELOPER);
         }
         return;
     }
     // Core Moodle API appears to be missing a 'get block by name' function.
     // Cycle through all regions and block instances until we find settings.
     foreach ($PAGE->blocks->get_regions() as $region) {
         foreach ($PAGE->blocks->get_blocks_for_region($region) as $block) {
             if (isset($block->instance) && $block->instance->blockname == 'settings') {
                 $this->instanceid = $block->instance->id;
                 break 2;
             }
         }
     }
     if (!has_capability('moodle/block:view', \context_block::instance($this->instanceid))) {
         return;
     }
     $this->output = true;
 }
开发者ID:pramithkm,项目名称:moodle-theme_snap,代码行数:48,代码来源:settings_link.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: my_copy_page

function my_copy_page($userid, $private = MY_PAGE_PRIVATE, $pagetype = 'my-index')
{
    global $DB;
    if ($customised = $DB->get_record('my_pages', array('userid' => $userid, 'private' => $private))) {
        return $customised;
        // We're done!
    }
    // Get the system default page
    if (!($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => $private)))) {
        return false;
        // error
    }
    // Clone the basic system page record
    $page = clone $systempage;
    unset($page->id);
    $page->userid = $userid;
    $page->id = $DB->insert_record('my_pages', $page);
    // Clone ALL the associated blocks as well
    $systemcontext = context_system::instance();
    $usercontext = context_user::instance($userid);
    $blockinstances = $DB->get_records('block_instances', array('parentcontextid' => $systemcontext->id, 'pagetypepattern' => $pagetype, 'subpagepattern' => $systempage->id));
    foreach ($blockinstances as $instance) {
        $originalid = $instance->id;
        unset($instance->id);
        $instance->parentcontextid = $usercontext->id;
        $instance->subpagepattern = $page->id;
        $instance->id = $DB->insert_record('block_instances', $instance);
        $blockcontext = context_block::instance($instance->id);
        // Just creates the context record
        $block = block_instance($instance->blockname, $instance);
        if (!$block->instance_copy($originalid)) {
            debugging("Unable to copy block-specific data for original block instance: {$originalid}\n                to new block instance: {$instance->id}", DEBUG_DEVELOPER);
        }
    }
    // FIXME: block position overrides should be merged in with block instance
    //$blockpositions = $DB->get_records('block_positions', array('subpage' => $page->name));
    //foreach($blockpositions as $positions) {
    //    $positions->subpage = $page->name;
    //    $DB->insert_record('block_positions', $tc);
    //}
    return $page;
}
开发者ID:dg711,项目名称:moodle,代码行数:42,代码来源:lib.php


示例11: get_content

 /**
  * Return the block content.
  * @uses $CFG
  * @return string The block content.
  */
 public function get_content()
 {
     global $CFG;
     // Checking content cached
     if ($this->content !== NULL) {
         return $this->content;
     }
     // Creating new content
     $this->content = new stdClass();
     $this->content->footer = '';
     // Getting context
     $context = context_block::instance($this->instance->id);
     // Setting content depending on capabilities
     if (isloggedin()) {
         if (has_capability('local/vmoodle:managevmoodles', $context)) {
             $this->content->footer = '<a href="' . $CFG->wwwroot . '/local/vmoodle/view.php">' . get_string('administrate', 'block_vmoodle') . '</a><br/>';
             $this->content->text = $this->_print_status();
         } else {
             $this->content->text = get_string('notallowed', 'block_vmoodle');
         }
     }
     // Returning content
     return $this->content;
 }
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:29,代码来源:block_vmoodle.php


示例12: block_progress_get_block_context

/**
 * Gets the block context, allowing for old and new Moodle instances.
 *
 * @param int $block The block ID
 * @return stdClass The context object
 */
function block_progress_get_block_context($blockid)
{
    if (class_exists('context_block')) {
        return context_block::instance($blockid);
    } else {
        return get_context_instance(CONTEXT_BLOCK, $blockid);
    }
}
开发者ID:HarcourtsAcademy,项目名称:Moodle-block_progress,代码行数:14,代码来源:lib.php


示例13: required_param

require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtMoodleUserDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsSentMessageDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtUserStatsDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/renderers/QuickFormRendererWithSlides.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/MoodletxtSendMessageForm.php';
require_once $CFG->dirroot . '/blocks/moodletxt/connect/MoodletxtOutboundControllerFactory.php';
$courseId = required_param('course', PARAM_INT);
$instanceId = required_param('instance', PARAM_INT);
$replyType = optional_param('replyType', '', PARAM_ALPHA);
$replyValue = optional_param('replyValue', '', PARAM_RAW_TRIMMED);
if ($replyType == 'additional' && !MoodletxtPhoneNumber::validatePhoneNumber($replyValue)) {
    $replyType = '';
    $replyValue = '';
}
require_login($courseId, false);
$blockcontext = context_block::instance($instanceId);
require_capability('block/moodletxt:sendmessages', $blockcontext, $USER->id);
// OK, so you're legit. Let's load DAOs and required DB data
$templateDAO = new MoodletxtTemplatesDAO();
$accountDAO = new TxttoolsAccountDAO();
$addressbookDAO = new MoodletxtAddressbookDAO();
$userDAO = new MoodletxtMoodleUserDAO();
$messageDAO = new TxttoolsSentMessageDAO();
$statsDAO = new MoodletxtUserStatsDAO();
$course = $DB->get_record('course', array('id' => $courseId));
$notifications = '';
// Set up the page for rendering
$PAGE->set_url('/blocks/moodletxt/send.php');
$PAGE->set_title(get_string('titlesend', 'block_moodletxt') . ' ' . $course->fullname);
$PAGE->set_heading(get_string('headersend', 'block_moodletxt'));
$PAGE->set_pagelayout('incourse');
开发者ID:educacionbe,项目名称:campus,代码行数:31,代码来源:send.php


示例14: dirname

 * File         generate_coupon_step_four.php
 * Encoding     UTF-8
 *
 * @package     block_coupon
 *
 * @copyright   Sebsoft.nl
 * @author      Menno de Ridder <[email protected]>
 * @author      R.J. van Dongen <[email protected]>
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(__FILE__) . '/../../../config.php';
require_once $CFG->dirroot . '/blocks/coupon/classes/settings.php';
use block_coupon\helper;
$id = required_param('id', PARAM_INT);
$instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
$context = \context_block::instance($instance->id);
$coursecontext = $context->get_course_context(false);
$course = false;
if ($coursecontext !== false) {
    $course = $DB->get_record("course", array("id" => $coursecontext->instanceid));
}
if ($course === false) {
    $course = get_site();
}
require_login($course, true);
$PAGE->navbar->add(get_string('page:generate_coupon_step_four.php:title', 'block_coupon'));
$url = new moodle_url('/blocks/coupon/view/generate_coupon_step_four.php', array('id' => $id));
$PAGE->set_url($url);
$PAGE->set_title(get_string('view:generate_coupon:title', 'block_coupon'));
$PAGE->set_heading(get_string('view:generate_coupon:heading', 'block_coupon'));
$PAGE->set_context($context);
开发者ID:sebastianberm,项目名称:moodle-block_coupon,代码行数:31,代码来源:generate_coupon_step_four.php


示例15: required_param

$courseid = required_param('courseid', PARAM_INT);
$blockid = required_param('blockid', PARAM_INT);
// Next look for optional variables.
$occurrenceid = optional_param('occurrenceid', 0, PARAM_INT);
$mode = optional_param('mode', 'list', PARAM_ALPHANUMEXT);
// Force the browse mode  ('list')
$edit = optional_param('edit', -1, PARAM_INT);
$approve = optional_param('approve', 0, PARAM_INT);
//approval recordid
$delete = optional_param('delete', 0, PARAM_INT);
//delete recordid
if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
    print_error('invalidcourse', 'block_referentiel', $courseid);
}
$contextcourse = context_course::instance($course->id);
$context = context_block::instance($blockid);
require_login($course);
$params = array("blockid" => $blockid, "courseid" => $courseid, "occurrenceid" => $occurrenceid);
$occurrence_object = new occurrence($params);
$currenttab = 'list';
if ($mode == 'edit') {
    $currenttab = 'edit';
}
$pagetitle = get_string('occurrence', 'block_referentiel', $occurrence_object->referentiel->code_referentiel);
$PAGE->set_url('/blocks/referentiel/view.php', array('blockid' => $blockid, 'courseid' => $courseid, 'occurrenceid' => $occurrenceid, 'mode' => $mode));
$PAGE->requires->css('/mod/referentiel/referentiel.css');
$PAGE->requires->js('/mod/referentiel/functions.js');
$PAGE->set_pagelayout('standard');
$PAGE->set_heading($course->fullname);
$PAGE->set_title($pagetitle);
$PAGE->navbar->add($occurrence_object->referentiel->code_referentiel);
开发者ID:jfruitet,项目名称:moodle_referentiel,代码行数:31,代码来源:view.php


示例16: test_create_instance

 /**
  * Covers basic testing of instance creation.
  *
  * @return void
  */
 public function test_create_instance()
 {
     global $DB;
     $this->resetAfterTest(true);
     $course = $this->getDataGenerator()->create_course();
     $user = $this->getDataGenerator()->create_user();
     $block = $this->getDataGenerator()->create_block('online_users');
     $type = $this->getDataGenerator()->create_repository_type('webdav');
     $record = new stdClass();
     $record->name = 'A WebDAV instance';
     $record->webdav_type = '1';
     $record->webdav_server = 'localhost';
     $record->webdav_port = '12345';
     $record->webdav_path = '/nothing';
     $record->webdav_user = 'me';
     $record->webdav_password = '\\o/';
     $record->webdav_auth = 'basic';
     $instance = $this->getDataGenerator()->create_repository('webdav', $record);
     $this->assertEquals(1, $DB->count_records('repository_instances', array('typeid' => $type->id)));
     $this->assertEquals($record->name, $DB->get_field('repository_instances', 'name', array('id' => $instance->id)));
     $entries = $DB->get_records('repository_instance_config', array('instanceid' => $instance->id));
     $config = new stdClass();
     foreach ($entries as $entry) {
         $config->{$entry->name} = $entry->value;
     }
     unset($record->name);
     $this->assertEquals($config, $record);
     // Course context.
     $record = new stdClass();
     $record->contextid = context_course::instance($course->id)->id;
     $instance = $this->getDataGenerator()->create_repository('webdav', $record);
     $this->assertEquals(2, $DB->count_records('repository_instances', array('typeid' => $type->id)));
     $this->assertEquals($record->contextid, $instance->contextid);
     // User context.
     $record->contextid = context_user::instance($user->id)->id;
     $instance = $this->getDataGenerator()->create_repository('webdav', $record);
     $this->assertEquals(3, $DB->count_records('repository_instances', array('typeid' => $type->id)));
     $this->assertEquals($record->contextid, $instance->contextid);
     // Invalid context.
     $this->expectException('coding_exception');
     $record->contextid = context_block::instance($block->id)->id;
     $instance = $this->getDataGenerator()->create_repository('webdav', $record);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:48,代码来源:generator_test.php


示例17: test_check_capability

 public function test_check_capability()
 {
     $this->resetAfterTest(true);
     $syscontext = context_system::instance();
     $course1 = $this->getDataGenerator()->create_course();
     $course1context = context_course::instance($course1->id);
     $course2 = $this->getDataGenerator()->create_course();
     $course2context = context_course::instance($course2->id);
     $forumdata = new stdClass();
     $forumdata->course = $course1->id;
     $forumc1 = $this->getDataGenerator()->create_module('forum', $forumdata);
     $forumc1context = context_module::instance($forumc1->cmid);
     $forumdata->course = $course2->id;
     $forumc2 = $this->getDataGenerator()->create_module('forum', $forumdata);
     $forumc2context = context_module::instance($forumc2->cmid);
     $blockdata = new stdClass();
     $blockdata->parentcontextid = $course1context->id;
     $blockc1 = $this->getDataGenerator()->create_block('online_users', $blockdata);
     $blockc1context = context_block::instance($blockc1->id);
     $blockdata->parentcontextid = $course2context->id;
     $blockc2 = $this->getDataGenerator()->create_block('online_users', $blockdata);
     $blockc2context = context_block::instance($blockc2->id);
     $user1 = $this->getDataGenerator()->create_user();
     $user1context = context_user::instance($user1->id);
     $user2 = $this->getDataGenerator()->create_user();
     $user2context = context_user::instance($user2->id);
     // New role prohibiting Flickr Public access.
     $roleid = create_role('No Flickr Public', 'noflickrpublic', 'No Flickr Public', '');
     assign_capability('repository/flickr_public:view', CAP_PROHIBIT, $roleid, $syscontext, true);
     // Disallow system access to Flickr Public to user 2.
     role_assign($roleid, $user2->id, $syscontext->id);
     accesslib_clear_all_caches_for_unit_testing();
     // Enable repositories.
     $this->getDataGenerator()->create_repository_type('flickr_public');
     $this->getDataGenerator()->create_repository_type('dropbox');
     // Instance on a site level.
     $repoid = $this->getDataGenerator()->create_repository('flickr_public')->id;
     $systemrepo = repository::get_repository_by_id($repoid, $syscontext);
     // Check that everyone with right capability can view a site-wide repository.
     $this->setUser($user1);
     $this->assertTrue($systemrepo->check_capability());
     // Without the capability, we cannot view a site-wide repository.
     $this->setUser($user2);
     $caughtexception = false;
     try {
         $systemrepo->check_capability();
     } catch (repository_exception $e) {
         $caughtexception = true;
     }
     $this->assertTrue($caughtexception);
     // Instance on a course level.
     $record = new stdClass();
     $record->contextid = $course1context->id;
     $courserepoid = $this->getDataGenerator()->create_repository('flickr_public', $record)->id;
     // Within the course, I can view the repository.
     $courserepo = repository::get_repository_by_id($courserepoid, $course1context);
     $this->setUser($user1);
     $this->assertTrue($courserepo->check_capability());
     // But not without the capability.
     $this->setUser($user2);
     $caughtexception = false;
     try {
         $courserepo->check_capability();
     } catch (repository_exception $e) {
         $caughtexception = true;
     }
     $this->assertTrue($caughtexception);
     // From another course I cannot, with or without the capability.
     $courserepo = repository::get_repository_by_id($courserepoid, $course2context);
     $this->setUser($user1);
     $caughtexception = false;
     try {
         $courserepo->check_capability();
     } catch (repository_exception $e) {
         $caughtexception = true;
     }
     $this->assertTrue($caughtexception);
     $this->setUser($user2);
     $caughtexception = false;
     try {
         $courserepo->check_capability();
     } catch (repository_exception $e) {
         $caughtexception = true;
     }
     $this->assertTrue($caughtexception);
     // From a module within the course, I can view the repository.
     $courserepo = repository::get_repository_by_id($courserepoid, $forumc1context);
     $this->setUser($user1);
     $this->assertTrue($courserepo->check_capability());
     // But not without the capability.
     $this->setUser($user2);
     $caughtexception = false;
     try {
         $courserepo->check_capability();
     } catch (repository_exception $e) {
         $caughtexception = true;
     }
     $this->assertTrue($caughtexception);
     // From a module in the wrong course, I cannot view the repository.
     $courserepo = repository::get_repository_by_id($courserepoid, $forumc2context);
//.........这里部分代码省略.........
开发者ID:alanaipe2015,项目名称:moodle,代码行数:101,代码来源:repositorylib_test.php


示例18: process_block

 public function process_block($data)
 {
     global $DB, $CFG;
     $data = (object) $data;
     // Handy
     $oldcontextid = $data->contextid;
     $oldid = $data->id;
     $positions = isset($data->block_positions['block_position']) ? $data->block_positions['block_position'] : array();
     // Look for the parent contextid
     if (!($data->parentcontextid = $this->get_mappingid('context', $data->parentcontextid))) {
         throw new restore_step_exception('restore_block_missing_parent_ctx', $data->parentcontextid);
     }
     // TODO: it would be nice to use standard plugin supports instead of this instance_allow_multiple()
     // If there is already one block of that type in the parent context
     // and the block is not multiple, stop processing
     // Use blockslib loader / method executor
     if (!($bi = block_instance($data->blockname))) {
         return false;
     }
     if (!$bi->instance_allow_multiple()) {
         if ($DB->record_exists_sql("SELECT bi.id\n                                          FROM {block_instances} bi\n                                          JOIN {block} b ON b.name = bi.blockname\n                                         WHERE bi.parentcontextid = ?\n                                           AND bi.blockname = ?", array($data->parentcontextid, $data->blockname))) {
             return false;
         }
     }
     // If there is already one block of that type in the parent context
     // with the same showincontexts, pagetypepattern, subpagepattern, defaultregion and configdata
     // stop processing
     $params = array('blockname' => $data->blockname, 'parentcontextid' => $data->parentcontextid, 'showinsubcontexts' => $data->showinsubcontexts, 'pagetypepattern' => $data->pagetypepattern, 'subpagepattern' => $data->subpagepattern, 'defaultregion' => $data->defaultregion);
     if ($birecs = $DB->get_records('block_instances', $params)) {
         foreach ($birecs as $birec) {
             if ($birec->configdata == $data->configdata) {
                 return false;
             }
         }
     }
     // Set task old contextid, blockid and blockname once we know them
     $this->task->set_old_contextid($oldcontextid);
     $this->task->set_old_blockid($oldid);
     $this->task->set_blockname($data->blockname);
     // Let's look for anything within configdata neededing processing
     // (nulls and uses of legacy file.php)
     if ($attrstotransform = $this->task->get_configdata_encoded_attributes()) {
         $configdata = (array) unserialize(base64_decode($data->configdata));
         foreach ($configdata as $attribute => $value) {
             if (in_array($attribute, $attrstotransform)) {
                 $configdata[$attribute] = $this->contentprocessor->process_cdata($value);
             }
         }
         $data->configdata = base64_encode(serialize((object) $configdata));
     }
     // Create the block instance
     $newitemid = $DB->insert_record('block_instances', $data);
     // Save the mapping (with restorefiles support)
     $this->set_mapping('block_instance', $oldid, $newitemid, true);
     // Create the block context
     $newcontextid = context_block::instance($newitemid)->id;
     // Save the block contexts mapping and sent it to task
     $this->set_mapping('context', $oldcontextid, $newcontextid);
     $this->task->set_contextid($newcontextid);
     $this->task->set_blockid($newitemid);
     // Restore block fileareas if declared
     $component = 'block_' . $this->task->get_blockname();
     foreach ($this->task->get_fileareas() as $filearea) {
         // Simple match by contextid. No itemname needed
         $this->add_related_files($component, $filearea, null);
     }
     // Process block positions, creating them or accumulating for final step
     foreach ($positions as $position) {
         $position = (object) $position;
         $position->blockinstanceid = $newitemid;
         // The instance is always the restored one
         // If position is for one already mapped (known) contextid
         // process it now, creating the position
         if ($newpositionctxid = $this->get_mappingid('context', $position->contextid)) {
             $position->contextid = $newpositionctxid;
             // Create the block position
             $DB->insert_record('block_positions', $position);
             // The position belongs to an unknown context, send it to backup_ids
             // to process them as part of the final steps of restore. We send the
             // whole $position object there, hence use the low level method.
         } else {
             restore_dbops::set_backup_ids_record($this->get_restoreid(), 'block_position', $position->id, 0, null, $position);
         }
     }
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:85,代码来源:restore_stepslib.php


示例19: process_block

 public function process_block($data)
 {
     global $DB, $CFG;
     $data = (object) $data;
     // Handy
     $oldcontextid = $data->contextid;
     $oldid = $data->id;
     $positions = isset($data->block_positions['block_position']) ? $data->block_positions['block_position'] : array();
     // Look for the parent contextid
     if (!($data->parentcontextid = $this->get_mappingid('context', $data->parentcontextid))) {
         throw new restore_step_exception('restore_block_missing_parent_ctx', $data->parentcontextid);
     }
     // TODO: it would be nice to use standard plugin supports instead of this instance_allow_multiple()
     // If there is already one block of that type in the parent context
     // and the block is not multiple, stop processing
     // Use blockslib loader / method executor
     if (!($bi = block_instance($data->blockname))) {
         return false;
     }
     if (!$bi->instance_allow_multiple()) {
         // The block cannot be added twice, so we will check if the same block is already being
         // displayed on the same page. For this, rather than mocking a page and using the block_manager
         // we use a similar query to the one in block_manager::load_blocks(), this will give us
         // a very good idea of the blocks already displayed in the context.
         $params = array('blockname' => $data->blockname);
         // Context matching test.
         $context = context::instance_by_id($data->parentcontextid);
         $contextsql = 'bi.parentcontextid = :contextid';
         $params['contextid'] = $context->id;
         $parentcontextids = $context->get_parent_context_ids();
         if ($parentcontextids) {
             list($parentcontextsql, $parentcontextparams) = $DB->get_in_or_equal($parentcontextids, SQL_PARAMS_NAMED);
             $contextsql = "({$contextsql} OR (bi.showinsubcontexts = 1 AND bi.parentcontextid {$parentcontextsql}))";
             $params = array_merge($params, $parentcontextparams);
         }
         // Page type pattern test.
         $pagetypepatterns = matching_page_type_patterns_from_pattern($data->pagetypepattern);
         list($pagetypepatternsql, $pagetypepatternparams) = $DB->get_in_or_equal($pagetypepatterns, SQL_PARAMS_NAMED);
         $params = array_merge($params, $pagetypepatternparams);
         // Sub page pattern test.
         $subpagepatternsql = 'bi.subpagepattern IS NULL';
         if ($data->subpagepattern !== null) {
             $subpagepatternsql = "({$subpagepatternsql} OR bi.subpagepattern = :subpagepattern)";
             $params['subpagepattern'] = $data->subpagepattern;
         }
         $exists = $DB->record_exists_sql("SELECT bi.id\n                                                FROM {block_instances} bi\n                                                JOIN {block} b ON b.name = bi.blockname\n                                               WHERE bi.blockname = :blockname\n                                                 AND {$contextsql}\n                                                 AND bi.pagetypepattern {$pagetypepatternsql}\n                                                 AND {$subpagepatternsql}", $params);
         if ($exists) {
             // There is at least one very similar block visible on the page where we
             // are trying to restore the block. In these c 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP context_course类代码示例发布时间:2022-05-23
下一篇:
PHP context类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap