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


PHP block_base::user_can_edit方法代码示例

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


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

示例1: definition

 function definition()
 {
     $mform =& $this->_form;
     // First show fields specific to this type of block.
     $this->specific_definition($mform);
     // Then show the fields about where this block appears.
     $mform->addElement('header', 'whereheader', get_string('wherethisblockappears', 'block'));
     // If the current weight of the block is out-of-range, add that option in.
     $blockweight = $this->block->instance->weight;
     $weightoptions = array();
     if ($blockweight < -block_manager::MAX_WEIGHT) {
         $weightoptions[$blockweight] = $blockweight;
     }
     for ($i = -block_manager::MAX_WEIGHT; $i <= block_manager::MAX_WEIGHT; $i++) {
         $weightoptions[$i] = $i;
     }
     if ($blockweight > block_manager::MAX_WEIGHT) {
         $weightoptions[$blockweight] = $blockweight;
     }
     $first = reset($weightoptions);
     $weightoptions[$first] = get_string('bracketfirst', 'block', $first);
     $last = end($weightoptions);
     $weightoptions[$last] = get_string('bracketlast', 'block', $last);
     $regionoptions = $this->page->theme->get_all_block_regions();
     $parentcontext = get_context_instance_by_id($this->block->instance->parentcontextid);
     $mform->addElement('static', 'contextname', get_string('thisblockbelongsto', 'block'), print_context_name($parentcontext));
     $mform->addElement('selectyesno', 'bui_showinsubcontexts', get_string('appearsinsubcontexts', 'block'));
     $pagetypeoptions = matching_page_type_patterns($this->page->pagetype);
     $pagetypeoptions = array_combine($pagetypeoptions, $pagetypeoptions);
     $mform->addElement('select', 'bui_pagetypepattern', get_string('pagetypes', 'block'), $pagetypeoptions);
     if ($this->page->subpage) {
         $subpageoptions = array('%@NULL@%' => get_string('anypagematchingtheabove', 'block'), $this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage));
         $mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions);
     }
     $defaultregionoptions = $regionoptions;
     $defaultregion = $this->block->instance->defaultregion;
     if (!array_key_exists($defaultregion, $defaultregionoptions)) {
         $defaultregionoptions[$defaultregion] = $defaultregion;
     }
     $mform->addElement('select', 'bui_defaultregion', get_string('defaultregion', 'block'), $defaultregionoptions);
     $mform->addElement('select', 'bui_defaultweight', get_string('defaultweight', 'block'), $weightoptions);
     // Where this block is positioned on this page.
     $mform->addElement('header', 'whereheader', get_string('onthispage', 'block'));
     $mform->addElement('selectyesno', 'bui_visible', get_string('visible', 'block'));
     $blockregion = $this->block->instance->region;
     if (!array_key_exists($blockregion, $regionoptions)) {
         $regionoptions[$blockregion] = $blockregion;
     }
     $mform->addElement('select', 'bui_region', get_string('region', 'block'), $regionoptions);
     $mform->addElement('select', 'bui_weight', get_string('weight', 'block'), $weightoptions);
     $pagefields = array('bui_visible', 'bui_region', 'bui_weight');
     if (!$this->block->user_can_edit()) {
         $mform->hardFreezeAllVisibleExcept($pagefields);
     }
     if (!$this->page->user_can_edit_blocks()) {
         $mform->hardFreeze($pagefields);
     }
     $this->add_action_buttons();
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:59,代码来源:edit_form.php

示例2: user_can_delete_block

 /**
  * @param block_base $block a block that appears on this page.
  * @return boolean boolean whether the currently logged in user is allowed to delete this block.
  */
 protected function user_can_delete_block($block)
 {
     return $this->page->user_can_edit_blocks() && $block->user_can_edit() && $block->user_can_addto($this->page) && !in_array($block->instance->blockname, self::get_undeletable_block_types());
 }
开发者ID:Burick,项目名称:moodle,代码行数:8,代码来源:blocklib.php

示例3: definition


//.........这里部分代码省略.........
                 // but if course managers select mod-* as pagetype patterns, block system will overwrite this option
                 // to 1 (display on current context and child contexts)
                 $mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
             } else {
                 if ($parentcontext->contextlevel == CONTEXT_MODULE or $parentcontext->contextlevel == CONTEXT_USER) {
                     // module context doesn't have child contexts, so display in current context only
                     $mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
                 } else {
                     $parentcontextname = $parentcontext->get_context_name();
                     $contextoptions[BUI_CONTEXTS_CURRENT] = get_string('showoncontextonly', 'block', $parentcontextname);
                     $contextoptions[BUI_CONTEXTS_CURRENT_SUBS] = get_string('showoncontextandsubs', 'block', $parentcontextname);
                     $mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
                 }
             }
         }
     }
     $mform->setType('bui_contexts', PARAM_INT);
     // Generate pagetype patterns by callbacks if necessary (has not been set specifically)
     if (empty($pagetypelist)) {
         $pagetypelist = generate_page_type_patterns($this->page->pagetype, $parentcontext, $this->page->context);
         $displaypagetypewarning = false;
         if (!array_key_exists($this->block->instance->pagetypepattern, $pagetypelist)) {
             // Pushing block's existing page type pattern
             $pagetypestringname = 'page-' . str_replace('*', 'x', $this->block->instance->pagetypepattern);
             if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) {
                 $pagetypelist[$this->block->instance->pagetypepattern] = get_string($pagetypestringname, 'pagetype');
             } else {
                 //as a last resort we could put the page type pattern in the select box
                 //however this causes mod-data-view to be added if the only option available is mod-data-*
                 // so we are just showing a warning to users about their prev setting being reset
                 $displaypagetypewarning = true;
             }
         }
     }
     // hide page type pattern select box if there is only one choice
     if (count($pagetypelist) > 1) {
         if ($displaypagetypewarning) {
             $mform->addElement('static', 'pagetypewarning', '', get_string('pagetypewarning', 'block'));
         }
         $mform->addElement('select', 'bui_pagetypepattern', get_string('restrictpagetypes', 'block'), $pagetypelist);
     } else {
         $values = array_keys($pagetypelist);
         $value = array_pop($values);
         $mform->addElement('hidden', 'bui_pagetypepattern', $value);
         $mform->setType('bui_pagetypepattern', PARAM_RAW);
         // Now we are really hiding a lot (both page-contexts and page-type-patterns),
         // specially in some systemcontext pages having only one option (my/user...)
         // so, until it's decided if we are going to add the 'bring-back' pattern to
         // all those pages or no (see MDL-30574), we are going to show the unique
         // element statically
         // TODO: Revisit this once MDL-30574 has been decided and implemented, although
         // perhaps it's not bad to always show this statically when only one pattern is
         // available.
         if (!$editingatfrontpage) {
             // Try to beautify it
             $strvalue = $value;
             $strkey = 'page-' . str_replace('*', 'x', $strvalue);
             if (get_string_manager()->string_exists($strkey, 'pagetype')) {
                 $strvalue = get_string($strkey, 'pagetype');
             }
             // Show as static (hidden has been set already)
             $mform->addElement('static', 'bui_staticpagetypepattern', get_string('restrictpagetypes', 'block'), $strvalue);
         }
     }
     if ($this->page->subpage) {
         if ($parentcontext->contextlevel == CONTEXT_USER) {
             $mform->addElement('hidden', 'bui_subpagepattern', '%@NULL@%');
             $mform->setType('bui_subpagepattern', PARAM_RAW);
         } else {
             $subpageoptions = array('%@NULL@%' => get_string('anypagematchingtheabove', 'block'), $this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage));
             $mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions);
         }
     }
     $defaultregionoptions = $regionoptions;
     $defaultregion = $this->block->instance->defaultregion;
     if (!array_key_exists($defaultregion, $defaultregionoptions)) {
         $defaultregionoptions[$defaultregion] = $defaultregion;
     }
     $mform->addElement('select', 'bui_defaultregion', get_string('defaultregion', 'block'), $defaultregionoptions);
     $mform->addHelpButton('bui_defaultregion', 'defaultregion', 'block');
     $mform->addElement('select', 'bui_defaultweight', get_string('defaultweight', 'block'), $weightoptions);
     $mform->addHelpButton('bui_defaultweight', 'defaultweight', 'block');
     // Where this block is positioned on this page.
     $mform->addElement('header', 'onthispage', get_string('onthispage', 'block'));
     $mform->addElement('selectyesno', 'bui_visible', get_string('visible', 'block'));
     $blockregion = $this->block->instance->region;
     if (!array_key_exists($blockregion, $regionoptions)) {
         $regionoptions[$blockregion] = $blockregion;
     }
     $mform->addElement('select', 'bui_region', get_string('region', 'block'), $regionoptions);
     $mform->addElement('select', 'bui_weight', get_string('weight', 'block'), $weightoptions);
     $pagefields = array('bui_visible', 'bui_region', 'bui_weight');
     if (!$this->block->user_can_edit()) {
         $mform->hardFreezeAllVisibleExcept($pagefields);
     }
     if (!$this->page->user_can_edit_blocks()) {
         $mform->hardFreeze($pagefields);
     }
     $this->add_action_buttons();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:edit_form.php

示例4:

 function user_can_edit()
 {
     $test = has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM));
     return parent::user_can_edit() && $test;
 }
开发者ID:bjornbe,项目名称:wwassignment,代码行数:5,代码来源:block_wwlink.php

示例5:

 function user_can_edit()
 {
     require_capability('moode/site:doanything', get_context_instance(CONTEXT_SYSTEM));
     return parent::user_can_edit();
 }
开发者ID:bjornbe,项目名称:wwassignment,代码行数:5,代码来源:block_wwlink.php

示例6: definition

 function definition()
 {
     $mform =& $this->_form;
     // First show fields specific to this type of block.
     $this->specific_definition($mform);
     // Then show the fields about where this block appears.
     $mform->addElement('header', 'whereheader', get_string('wherethisblockappears', 'block'));
     // If the current weight of the block is out-of-range, add that option in.
     $blockweight = $this->block->instance->weight;
     $weightoptions = array();
     if ($blockweight < -block_manager::MAX_WEIGHT) {
         $weightoptions[$blockweight] = $blockweight;
     }
     for ($i = -block_manager::MAX_WEIGHT; $i <= block_manager::MAX_WEIGHT; $i++) {
         $weightoptions[$i] = $i;
     }
     if ($blockweight > block_manager::MAX_WEIGHT) {
         $weightoptions[$blockweight] = $blockweight;
     }
     $first = reset($weightoptions);
     $weightoptions[$first] = get_string('bracketfirst', 'block', $first);
     $last = end($weightoptions);
     $weightoptions[$last] = get_string('bracketlast', 'block', $last);
     $regionoptions = $this->page->theme->get_all_block_regions();
     $parentcontext = get_context_instance_by_id($this->block->instance->parentcontextid);
     $mform->addElement('hidden', 'bui_parentcontextid', $parentcontext->id);
     $contextoptions = array();
     if ($parentcontext->contextlevel == CONTEXT_COURSE && $parentcontext->instanceid == SITEID || $parentcontext->contextlevel == CONTEXT_SYSTEM) {
         // Home page
         $contextoptions[0] = get_string('showonfrontpageonly', 'block');
         $contextoptions[1] = get_string('showonfrontpageandsubs', 'block');
         $contextoptions[2] = get_string('showonentiresite', 'block');
     } else {
         $parentcontextname = print_context_name($parentcontext);
         $contextoptions[0] = get_string('showoncontextonly', 'block', $parentcontextname);
         $contextoptions[1] = get_string('showoncontextandsubs', 'block', $parentcontextname);
     }
     $mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
     if ($this->page->pagetype == 'site-index') {
         // No need for pagetype list on home page
         $pagetypelist = array('*');
     } else {
         $pagetypelist = matching_page_type_patterns($this->page->pagetype);
     }
     $pagetypeoptions = array();
     foreach ($pagetypelist as $pagetype) {
         // Find human-readable names for the pagetypes
         $pagetypeoptions[$pagetype] = $pagetype;
         $pagetypestringname = 'page-' . str_replace('*', 'x', $pagetype);
         // Better names MDL-21375
         if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) {
             $pagetypeoptions[$pagetype] .= ' (' . get_string($pagetypestringname, 'pagetype') . ')';
         }
     }
     $mform->addElement('select', 'bui_pagetypepattern', get_string('restrictpagetypes', 'block'), $pagetypeoptions);
     if ($this->page->subpage) {
         $subpageoptions = array('%@NULL@%' => get_string('anypagematchingtheabove', 'block'), $this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage));
         $mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions);
     }
     $defaultregionoptions = $regionoptions;
     $defaultregion = $this->block->instance->defaultregion;
     if (!array_key_exists($defaultregion, $defaultregionoptions)) {
         $defaultregionoptions[$defaultregion] = $defaultregion;
     }
     $mform->addElement('select', 'bui_defaultregion', get_string('defaultregion', 'block'), $defaultregionoptions);
     $mform->addElement('select', 'bui_defaultweight', get_string('defaultweight', 'block'), $weightoptions);
     // Where this block is positioned on this page.
     $mform->addElement('header', 'whereheader', get_string('onthispage', 'block'));
     $mform->addElement('selectyesno', 'bui_visible', get_string('visible', 'block'));
     $blockregion = $this->block->instance->region;
     if (!array_key_exists($blockregion, $regionoptions)) {
         $regionoptions[$blockregion] = $blockregion;
     }
     $mform->addElement('select', 'bui_region', get_string('region', 'block'), $regionoptions);
     $mform->addElement('select', 'bui_weight', get_string('weight', 'block'), $weightoptions);
     $pagefields = array('bui_visible', 'bui_region', 'bui_weight');
     if (!$this->block->user_can_edit()) {
         $mform->hardFreezeAllVisibleExcept($pagefields);
     }
     if (!$this->page->user_can_edit_blocks()) {
         $mform->hardFreeze($pagefields);
     }
     $this->add_action_buttons();
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:84,代码来源:edit_form.php

示例7: definition


//.........这里部分代码省略.........
     // parse pagetype patterns
     $bits = explode('-', $this->page->pagetype);
     $contextoptions = array();
     if ($parentcontext->contextlevel == CONTEXT_COURSE && $parentcontext->instanceid == SITEID || $parentcontext->contextlevel == CONTEXT_SYSTEM) {
         // Home page
         if ($bits[0] == 'tag' || $bits[0] == 'admin') {
             // tag and admin pages always use system context
             // the contexts options don't make differences, so we use
             // page type patterns only
             $mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_ENTIRE_SITE);
         } else {
             $contextoptions[BUI_CONTEXTS_FRONTPAGE_ONLY] = get_string('showonfrontpageonly', 'block');
             $contextoptions[BUI_CONTEXTS_FRONTPAGE_SUBS] = get_string('showonfrontpageandsubs', 'block');
             $contextoptions[BUI_CONTEXTS_ENTIRE_SITE] = get_string('showonentiresite', 'block');
             $mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
             $mform->addHelpButton('bui_contexts', 'contexts', 'block');
         }
     } else {
         if ($parentcontext->contextlevel == CONTEXT_COURSE) {
             // 0 means display on current context only, not child contexts
             // but if course managers select mod-* as pagetype patterns, block system will overwrite this option
             // to 1 (display on current context and child contexts)
             $mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
         } else {
             if ($parentcontext->contextlevel == CONTEXT_MODULE or $parentcontext->contextlevel == CONTEXT_USER) {
                 // module context doesn't have child contexts, so display in current context only
                 $mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
             } else {
                 $parentcontextname = print_context_name($parentcontext);
                 $contextoptions[BUI_CONTEXTS_CURRENT] = get_string('showoncontextonly', 'block', $parentcontextname);
                 $contextoptions[BUI_CONTEXTS_CURRENT_SUBS] = get_string('showoncontextandsubs', 'block', $parentcontextname);
                 $mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
             }
         }
     }
     $displaypagetypewarning = false;
     if ($this->page->pagetype == 'site-index') {
         // No need for pagetype list on home page
         $pagetypelist = array('*' => get_string('page-x', 'pagetype'));
     } else {
         // Generate pagetype patterns by callbacks
         $pagetypelist = generate_page_type_patterns($this->page->pagetype, $parentcontext, $this->page->context);
         if (!array_key_exists($this->block->instance->pagetypepattern, $pagetypelist)) {
             // Pushing block's existing page type pattern
             $pagetypestringname = 'page-' . str_replace('*', 'x', $this->block->instance->pagetypepattern);
             if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) {
                 $pagetypelist[$this->block->instance->pagetypepattern] = get_string($pagetypestringname, 'pagetype');
             } else {
                 //as a last resort we could put the page type pattern in the select box
                 //however this causes mod-data-view to be added if the only option available is mod-data-*
                 // so we are just showing a warning to users about their prev setting being reset
                 $displaypagetypewarning = true;
             }
         }
     }
     // hide page type pattern select box if there is only one choice
     if (count($pagetypelist) > 1) {
         if ($displaypagetypewarning) {
             $mform->addElement('static', 'pagetypewarning', '', get_string('pagetypewarning', 'block'));
         }
         $mform->addElement('select', 'bui_pagetypepattern', get_string('restrictpagetypes', 'block'), $pagetypelist);
     } else {
         $value = array_pop(array_keys($pagetypelist));
         $mform->addElement('hidden', 'bui_pagetypepattern', $value);
     }
     if ($this->page->subpage) {
         if ($parentcontext->contextlevel == CONTEXT_USER) {
             $mform->addElement('hidden', 'bui_subpagepattern', '%@NULL@%');
         } else {
             $subpageoptions = array('%@NULL@%' => get_string('anypagematchingtheabove', 'block'), $this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage));
             $mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions);
         }
     }
     $defaultregionoptions = $regionoptions;
     $defaultregion = $this->block->instance->defaultregion;
     if (!array_key_exists($defaultregion, $defaultregionoptions)) {
         $defaultregionoptions[$defaultregion] = $defaultregion;
     }
     $mform->addElement('select', 'bui_defaultregion', get_string('defaultregion', 'block'), $defaultregionoptions);
     $mform->addHelpButton('bui_defaultregion', 'defaultregion', 'block');
     $mform->addElement('select', 'bui_defaultweight', get_string('defaultweight', 'block'), $weightoptions);
     $mform->addHelpButton('bui_defaultweight', 'defaultweight', 'block');
     // Where this block is positioned on this page.
     $mform->addElement('header', 'whereheader', get_string('onthispage', 'block'));
     $mform->addElement('selectyesno', 'bui_visible', get_string('visible', 'block'));
     $blockregion = $this->block->instance->region;
     if (!array_key_exists($blockregion, $regionoptions)) {
         $regionoptions[$blockregion] = $blockregion;
     }
     $mform->addElement('select', 'bui_region', get_string('region', 'block'), $regionoptions);
     $mform->addElement('select', 'bui_weight', get_string('weight', 'block'), $weightoptions);
     $pagefields = array('bui_visible', 'bui_region', 'bui_weight');
     if (!$this->block->user_can_edit()) {
         $mform->hardFreezeAllVisibleExcept($pagefields);
     }
     if (!$this->page->user_can_edit_blocks()) {
         $mform->hardFreeze($pagefields);
     }
     $this->add_action_buttons();
 }
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:101,代码来源:edit_form.php


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