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


PHP blocks_set_visibility函数代码示例

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


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

示例1: test_delete_instances

 public function test_delete_instances()
 {
     global $DB;
     $this->purge_blocks();
     $this->setAdminUser();
     $regionname = 'a-region';
     $blockname = $this->get_a_known_block_type();
     $context = context_system::instance();
     list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $context, 'page-type');
     $blockmanager->add_blocks(array($regionname => array($blockname, $blockname, $blockname)), null, null, false, 3);
     $blockmanager->load_blocks();
     $blocks = $blockmanager->get_blocks_for_region($regionname);
     $blockids = array();
     $preferences = array();
     // Create block related data.
     foreach ($blocks as $block) {
         $instance = $block->instance;
         $pref = 'block' . $instance->id . 'hidden';
         set_user_preference($pref, '123', 123);
         $preferences[] = $pref;
         $pref = 'docked_block_instance_' . $instance->id;
         set_user_preference($pref, '123', 123);
         $preferences[] = $pref;
         blocks_set_visibility($instance, $page, 1);
         $blockids[] = $instance->id;
     }
     // Confirm what has been set.
     $this->assertCount(3, $blockids);
     list($insql, $inparams) = $DB->get_in_or_equal($blockids);
     $this->assertEquals(3, $DB->count_records_select('block_positions', "blockinstanceid {$insql}", $inparams));
     list($insql, $inparams) = $DB->get_in_or_equal($preferences);
     $this->assertEquals(6, $DB->count_records_select('user_preferences', "name {$insql}", $inparams));
     // Keep a block on the side.
     $allblockids = $blockids;
     $tokeep = array_pop($blockids);
     // Delete and confirm what should have happened.
     blocks_delete_instances($blockids);
     // Reload the manager.
     list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $context, 'page-type');
     $blockmanager->load_blocks();
     $blocks = $blockmanager->get_blocks_for_region($regionname);
     $this->assertCount(1, $blocks);
     list($insql, $inparams) = $DB->get_in_or_equal($allblockids);
     $this->assertEquals(1, $DB->count_records_select('block_positions', "blockinstanceid {$insql}", $inparams));
     list($insql, $inparams) = $DB->get_in_or_equal($preferences);
     $this->assertEquals(2, $DB->count_records_select('user_preferences', "name {$insql}", $inparams));
     $this->assertFalse(context_block::instance($blockids[0], IGNORE_MISSING));
     $this->assertFalse(context_block::instance($blockids[1], IGNORE_MISSING));
     context_block::instance($tokeep);
     // Would throw an exception if it was deleted.
 }
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:51,代码来源:blocklib_test.php

示例2: process_url_show_hide

 /**
  * Handle showing or hiding a block.
  * @return boolean true if anything was done. False if not.
  */
 public function process_url_show_hide()
 {
     if ($blockid = optional_param('bui_hideid', null, PARAM_INT)) {
         $newvisibility = 0;
     } else {
         if ($blockid = optional_param('bui_showid', null, PARAM_INT)) {
             $newvisibility = 1;
         } else {
             return false;
         }
     }
     require_sesskey();
     $block = $this->page->blocks->find_instance($blockid);
     if (!$this->page->user_can_edit_blocks()) {
         throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('hideshowblocks'));
     } else {
         if (!$block->instance_can_be_hidden()) {
             return false;
         }
     }
     blocks_set_visibility($block->instance, $this->page, $newvisibility);
     // If the page URL was a guses, it will contain the bui_... param, so we must make sure it is not there.
     $this->page->ensure_param_not_in_url('bui_hideid');
     $this->page->ensure_param_not_in_url('bui_showid');
     return true;
 }
开发者ID:Burick,项目名称:moodle,代码行数:30,代码来源:blocklib.php

示例3: test_version1importdeletecoursedeletesassociations

 /**
  * Validate that the version 1 plugin deletes appropriate associations when
  * deleting a course
  */
 public function test_version1importdeletecoursedeletesassociations()
 {
     global $DB, $CFG, $USER;
     require_once $CFG->dirroot . '/user/lib.php';
     require_once $CFG->dirroot . '/lib/gradelib.php';
     require_once $CFG->dirroot . '/group/lib.php';
     require_once $CFG->dirroot . '/lib/conditionlib.php';
     require_once $CFG->dirroot . '/lib/enrollib.php';
     require_once $CFG->dirroot . '/tag/lib.php';
     require_once $CFG->dirroot . '/lib/questionlib.php';
     // Setup.
     $initialnumcontexts = $DB->count_records('context', array('contextlevel' => CONTEXT_COURSE));
     $DB->delete_records('block_instances');
     // Set up the course with one section, including default blocks.
     set_config('defaultblocks_topics', 'search_forums');
     set_config('maxsections', 10, 'moodlecourse');
     $this->run_core_course_import(array('shortname' => 'deleteassociationsshortname', 'numsections' => 1));
     // Create a user record.
     $record = new stdClass();
     $record->username = 'testuser';
     $record->password = 'Testpass!0';
     $userid = user_create_user($record);
     // Create a course-level role.
     $courseid = $DB->get_field('course', 'id', array('shortname' => 'deleteassociationsshortname'));
     $coursecontext = context_course::instance($courseid);
     $roleid = create_role('deleterole', 'deleterole', 'deleterole');
     set_role_contextlevels($roleid, array(CONTEXT_COURSE));
     $enrol = new stdClass();
     $enrol->enrol = 'manual';
     $enrol->courseid = $courseid;
     $enrol->status = ENROL_INSTANCE_ENABLED;
     if (!$DB->record_exists('enrol', (array) $enrol)) {
         $DB->insert_record('enrol', $enrol);
     }
     // Assign the user to the course-level role.
     enrol_try_internal_enrol($courseid, $userid, $roleid);
     // Create a grade item.
     $gradeitem = new grade_item(array('courseid' => $courseid, 'itemtype' => 'manual', 'itemname' => 'testitem'), false);
     $gradeitem->insert();
     $gradegrade = new grade_grade(array('itemid' => $gradeitem->id, 'userid' => $userid), false);
     // Assign the user a grade.
     $gradegrade->insert();
     // Create a grade outcome.
     $gradeoutcome = new grade_outcome(array('courseid' => $courseid, 'shortname' => 'bogusshortname', 'fullname' => 'bogusfullname'));
     $gradeoutcome->insert();
     // Create a grade scale.
     $gradescale = new grade_scale(array('courseid' => $courseid, 'name' => 'bogusname', 'userid' => $userid, 'scale' => 'bogusscale', 'description' => 'bogusdescription'));
     $gradescale->insert();
     // Set a grade setting value.
     grade_set_setting($courseid, 'bogus', 'bogus');
     // Set up a grade letter.
     $gradeletter = new stdClass();
     $gradeletter->contextid = $coursecontext->id;
     $gradeletter->lowerboundary = 80;
     $gradeletter->letter = 'A';
     $DB->insert_record('grade_letters', $gradeletter);
     // Set up a forum instance.
     $forum = new stdClass();
     $forum->course = $courseid;
     $forum->intro = 'intro';
     $forum->id = $DB->insert_record('forum', $forum);
     // Add it as a course module.
     $forum->module = $DB->get_field('modules', 'id', array('name' => 'forum'));
     $forum->instance = $forum->id;
     $cmid = add_course_module($forum);
     // Set up a completion record.
     $completion = new stdClass();
     $completion->coursemoduleid = $cmid;
     $completion->completionstate = 0;
     $completion->userid = 9999;
     $completion->timemodified = time();
     $DB->insert_record('course_modules_completion', $completion);
     // Set up a completion condition.
     $forum->id = $cmid;
     $ci = new condition_info($forum, CONDITION_MISSING_EVERYTHING, false);
     $ci->add_completion_condition($cmid, COMPLETION_ENABLED);
     // Set the blocks position.
     $instances = $DB->get_records('block_instances', array('parentcontextid' => $coursecontext->id));
     $page = new stdClass();
     $page->context = $coursecontext;
     $page->pagetype = 'course-view-*';
     $page->subpage = false;
     foreach ($instances as $instance) {
         blocks_set_visibility($instance, $page, 1);
     }
     // Create a group.
     $group = new stdClass();
     $group->name = 'testgroup';
     $group->courseid = $courseid;
     $groupid = groups_create_group($group);
     // Add the user to the group.
     groups_add_member($groupid, $userid);
     // Create a grouping containing our group.
     $grouping = new stdClass();
     $grouping->name = 'testgrouping';
     $grouping->courseid = $courseid;
//.........这里部分代码省略.........
开发者ID:jamesmcq,项目名称:elis,代码行数:101,代码来源:version1_course_import_test.php


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