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


PHP blocks_delete_instance函数代码示例

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


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

示例1: xmldb_block_completionstatus_upgrade

/**
 * Handles upgrading instances of this block.
 *
 * @param int $oldversion
 * @param object $block
 */
function xmldb_block_completionstatus_upgrade($oldversion, $block)
{
    global $DB;
    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this.
    if ($oldversion < 2012112901) {
        // Get the instances of this block.
        if ($blocks = $DB->get_records('block_instances', array('blockname' => 'completionstatus', 'pagetypepattern' => 'my-index'))) {
            // Loop through and remove them from the My Moodle page.
            foreach ($blocks as $block) {
                blocks_delete_instance($block);
            }
        }
        // Savepoint reached.
        upgrade_block_savepoint(true, 2012112901, 'completionstatus');
    }
    // Moodle v2.5.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.6.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.0.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:36,代码来源:upgrade.php

示例2: purge_blocks

 protected function purge_blocks()
 {
     global $DB;
     $this->resetAfterTest();
     $bis = $DB->get_records('block_instances');
     foreach ($bis as $instance) {
         blocks_delete_instance($instance);
     }
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:9,代码来源:blocklib_test.php

示例3: delete

 /**
  * Delete method.
  *
  * @param array $courses All courses we should be effecting.
  */
 public function delete($courses)
 {
     global $CFG;
     require_once $CFG->libdir . "/blocklib.php";
     // We now want to delete all blocks with that name.
     $instances = $this->get_instances($courses);
     foreach ($instances as $instance) {
         blocks_delete_instance($instance);
     }
 }
开发者ID:unikent,项目名称:moodle-tool_cat,代码行数:15,代码来源:block.php

示例4: xmldb_local_iomad_dashboard_uninstall

function xmldb_local_iomad_dashboard_uninstall()
{
    global $DB;
    // Remove blocks to the dashboard
    // yes, I know this isn't really what this is for!!
    $systemcontext = context_system::instance();
    $contextid = $systemcontext->id;
    $instances = $DB->get_recordset('block_instances', array('parentcontextid' => $contextid, 'pagetypepattern' => 'local-iomad-dashboard-index'));
    foreach ($instances as $instance) {
        blocks_delete_instance($instance, true);
    }
    return true;
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:13,代码来源:uninstall.php

示例5: process_url_delete

 /**
  * Handle deleting a block.
  * @return boolean true if anything was done. False if not.
  */
 public function process_url_delete()
 {
     $blockid = optional_param('bui_deleteid', null, PARAM_INTEGER);
     if (!$blockid) {
         return false;
     }
     require_sesskey();
     $block = $this->page->blocks->find_instance($blockid);
     if (!$block->user_can_edit() || !$this->page->user_can_edit_blocks() || !$block->user_can_addto($this->page)) {
         throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('deleteablock'));
     }
     blocks_delete_instance($block->instance);
     // If the page URL was a guess, it will contain the bui_... param, so we must make sure it is not there.
     $this->page->ensure_param_not_in_url('bui_deleteid');
     return true;
 }
开发者ID:nmicha,项目名称:moodle,代码行数:20,代码来源:blocklib.php

示例6: my_reset_page

function my_reset_page($userid, $private = MY_PAGE_PRIVATE, $pagetype = 'my-index')
{
    global $DB, $CFG;
    $page = my_get_page($userid, $private);
    if ($page->userid == $userid) {
        $context = context_user::instance($userid);
        if ($blocks = $DB->get_records('block_instances', array('parentcontextid' => $context->id, 'pagetypepattern' => $pagetype))) {
            foreach ($blocks as $block) {
                if (is_null($block->subpagepattern) || $block->subpagepattern == $page->id) {
                    blocks_delete_instance($block);
                }
            }
        }
        $DB->delete_records('my_pages', array('id' => $page->id));
    }
    // Get the system default page
    if (!($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => $private)))) {
        return false;
        // error
    }
    // Trigger dashboard has been reset event.
    $eventparams = array('context' => context_user::instance($userid), 'other' => array('private' => $private, 'pagetype' => $pagetype));
    $event = \core\event\dashboard_reset::create($eventparams);
    $event->trigger();
    return $systempage;
}
开发者ID:dg711,项目名称:moodle,代码行数:26,代码来源:lib.php

示例7: my_reset_page

function my_reset_page($userid, $private = MY_PAGE_PRIVATE, $pagetype = 'my-index')
{
    global $DB, $CFG;
    $page = my_get_page($userid, $private);
    if ($page->userid == $userid) {
        $context = context_user::instance($userid);
        if ($blocks = $DB->get_records('block_instances', array('parentcontextid' => $context->id, 'pagetypepattern' => $pagetype))) {
            foreach ($blocks as $block) {
                if (is_null($block->subpagepattern) || $block->subpagepattern == $page->id) {
                    blocks_delete_instance($block);
                }
            }
        }
        $DB->delete_records('my_pages', array('id' => $page->id));
    }
    // Get the system default page
    if (!($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => $private)))) {
        return false;
        // error
    }
    return $systempage;
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:22,代码来源:lib.php

示例8: empty_content

 /**
  * Delete all blocks in this region.
  */
 public function empty_content($courses)
 {
     // Our target is the name of a block region.
     $region = $this->get_identifier();
     // For each course, delete all blocks.
     foreach ($courses as $course) {
         $blockmanager = $this->get_block_manager($course);
         $blockmanager->add_region($region);
         $blockmanager->load_blocks();
         $blocks = $blockmanager->get_blocks_for_region($region);
         foreach ($blocks as $block) {
             blocks_delete_instance($block->instance);
         }
     }
 }
开发者ID:unikent,项目名称:moodle-tool_cat,代码行数:18,代码来源:block_region.php

示例9: delete

 /**
  * Deletes the rule block.
  */
 public function delete()
 {
     blocks_delete_instance($this->_block->instance);
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:7,代码来源:dataformrule.php

示例10: block_elisadmin_create_instance

/**
 * Sets up a default instance of the curr admin blocks that
 * is viewable anywhere on the site, and cleans all other instances
 */
function block_elisadmin_create_instance()
{
    global $DB;
    // First delete instances
    $params = array('blockname' => 'elisadmin');
    $instances = $DB->get_recordset('block_instances', $params);
    foreach ($instances as $instance) {
        blocks_delete_instance($instance);
    }
    unset($instances);
    // Set up the new instance
    $block_instance_record = new stdclass();
    $block_instance_record->blockname = 'elisadmin';
    $block_instance_record->pagetypepattern = '*';
    $block_instance_record->parentcontextid = 1;
    $block_instance_record->showinsubcontexts = 1;
    // Force location
    $block_instance_record->defaultregion = 'side-pre';
    $block_instance_record->defaultweight = -999;
    $DB->insert_record('block_instances', $block_instance_record);
}
开发者ID:jamesmcq,项目名称:elis,代码行数:25,代码来源:lib.php

示例11: uninstall_cleanup

 /**
  * Pre-uninstall hook.
  *
  * This is intended for disabling of plugin, some DB table purging, etc.
  *
  * NOTE: to be called from uninstall_plugin() only.
  * @private
  */
 public function uninstall_cleanup()
 {
     global $DB, $CFG;
     if ($block = $DB->get_record('block', array('name' => $this->name))) {
         // Inform block it's about to be deleted.
         if (file_exists("{$CFG->dirroot}/blocks/{$block->name}/block_{$block->name}.php")) {
             $blockobject = block_instance($block->name);
             if ($blockobject) {
                 $blockobject->before_delete();
                 // Only if we can create instance, block might have been already removed.
             }
         }
         // First delete instances and related contexts.
         $instances = $DB->get_records('block_instances', array('blockname' => $block->name));
         foreach ($instances as $instance) {
             blocks_delete_instance($instance);
         }
         // Delete block.
         $DB->delete_records('block', array('id' => $block->id));
     }
     parent::uninstall_cleanup();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:30,代码来源:block.php

示例12: process_url_delete

 /**
  * Handle deleting a block.
  * @return boolean true if anything was done. False if not.
  */
 public function process_url_delete()
 {
     global $CFG, $PAGE, $OUTPUT;
     $blockid = optional_param('bui_deleteid', null, PARAM_INT);
     $confirmdelete = optional_param('bui_confirm', null, PARAM_INT);
     if (!$blockid) {
         return false;
     }
     require_sesskey();
     $block = $this->page->blocks->find_instance($blockid);
     if (!$this->user_can_delete_block($block)) {
         throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('deleteablock'));
     }
     if (!$confirmdelete) {
         $deletepage = new moodle_page();
         $deletepage->set_pagelayout('admin');
         $deletepage->blocks->show_only_fake_blocks(true);
         $deletepage->set_course($this->page->course);
         $deletepage->set_context($this->page->context);
         if ($this->page->cm) {
             $deletepage->set_cm($this->page->cm);
         }
         $deleteurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring());
         $deleteurlparams = $this->page->url->params();
         $deletepage->set_url($deleteurlbase, $deleteurlparams);
         $deletepage->set_block_actions_done();
         // At this point we are either going to redirect, or display the form, so
         // overwrite global $PAGE ready for this. (Formslib refers to it.)
         $PAGE = $deletepage;
         //some functions like MoodleQuickForm::addHelpButton use $OUTPUT so we need to replace that too
         $output = $deletepage->get_renderer('core');
         $OUTPUT = $output;
         $site = get_site();
         $blocktitle = $block->get_title();
         $strdeletecheck = get_string('deletecheck', 'block', $blocktitle);
         $message = get_string('deleteblockcheck', 'block', $blocktitle);
         // If the block is being shown in sub contexts display a warning.
         if ($block->instance->showinsubcontexts == 1) {
             $parentcontext = context::instance_by_id($block->instance->parentcontextid);
             $systemcontext = context_system::instance();
             $messagestring = new stdClass();
             $messagestring->location = $parentcontext->get_context_name();
             // Checking for blocks that may have visibility on the front page and pages added on that.
             if ($parentcontext->id != $systemcontext->id && is_inside_frontpage($parentcontext)) {
                 $messagestring->pagetype = get_string('showonfrontpageandsubs', 'block');
             } else {
                 $pagetypes = generate_page_type_patterns($this->page->pagetype, $parentcontext);
                 $messagestring->pagetype = $block->instance->pagetypepattern;
                 if (isset($pagetypes[$block->instance->pagetypepattern])) {
                     $messagestring->pagetype = $pagetypes[$block->instance->pagetypepattern];
                 }
             }
             $message = get_string('deleteblockwarning', 'block', $messagestring);
         }
         $PAGE->navbar->add($strdeletecheck);
         $PAGE->set_title($blocktitle . ': ' . $strdeletecheck);
         $PAGE->set_heading($site->fullname);
         echo $OUTPUT->header();
         $confirmurl = new moodle_url($deletepage->url, array('sesskey' => sesskey(), 'bui_deleteid' => $block->instance->id, 'bui_confirm' => 1));
         $cancelurl = new moodle_url($deletepage->url);
         $yesbutton = new single_button($confirmurl, get_string('yes'));
         $nobutton = new single_button($cancelurl, get_string('no'));
         echo $OUTPUT->confirm($message, $yesbutton, $nobutton);
         echo $OUTPUT->footer();
         // Make sure that nothing else happens after we have displayed this form.
         exit;
     } else {
         blocks_delete_instance($block->instance);
         // bui_deleteid and bui_confirm should not be in the PAGE url.
         $this->page->ensure_param_not_in_url('bui_deleteid');
         $this->page->ensure_param_not_in_url('bui_confirm');
         return true;
     }
 }
开发者ID:stronk7,项目名称:moodle,代码行数:78,代码来源:blocklib.php

示例13: notice_yesno

     notice_yesno(get_string('blockdeleteconfirm', '', $strblockname), 'blocks.php?delete=' . $block->id . '&amp;confirm=1&amp;sesskey=' . sesskey(), 'blocks.php');
     admin_externalpage_print_footer();
     exit;
 } else {
     // Inform block it's about to be deleted
     $blockobject = block_instance($block->name);
     if ($blockobject) {
         $blockobject->before_delete();
         //only if we can create instance, block might have been already removed
     }
     // First delete instances and then block
     $instances = $DB->get_records('block_instances', array('blockname' => $block->name));
     if (!empty($instances)) {
         foreach ($instances as $instance) {
             blocks_delete_instance($instance);
             blocks_delete_instance($instance, true);
         }
     }
     // Delete block
     if (!$DB->delete_records('block', array('id' => $block->id))) {
         notify("Error occurred while deleting the {$strblockname} record from blocks table");
     }
     drop_plugin_tables($block->name, "{$CFG->dirroot}/blocks/{$block->name}/db/install.xml", false);
     // old obsoleted table names
     drop_plugin_tables('block_' . $block->name, "{$CFG->dirroot}/blocks/{$block->name}/db/install.xml", false);
     // Delete the capabilities that were defined by this block
     capabilities_cleanup('block/' . $block->name);
     // remove entent handlers and dequeue pending events
     events_uninstall('block/' . $block->name);
     $a->block = $strblockname;
     $a->directory = $CFG->dirroot . '/blocks/' . $block->name;
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:blocks.php

示例14: blocks_execute_action

function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceorid, $pinned = false, $redirect = true)
{
    global $CFG, $USER, $DB;
    if (!in_array($blockaction, array('config', 'add', 'delete'))) {
        throw new moodle_exception('Sorry, blocks editing is currently broken. Will be fixed. See MDL-19010.');
    }
    if (is_int($instanceorid)) {
        $blockid = $instanceorid;
    } else {
        if (is_object($instanceorid)) {
            $instance = $instanceorid;
        }
    }
    switch ($blockaction) {
        case 'config':
            // First of all check to see if the block wants to be edited
            if (!$instance->user_can_edit()) {
                break;
            }
            // Now get the title and AFTER that load up the instance
            $blocktitle = $instance->get_title();
            // Define the data we're going to silently include in the instance config form here,
            // so we can strip them from the submitted data BEFORE serializing it.
            $hiddendata = array('sesskey' => sesskey(), 'instanceid' => $instance->instance->id, 'blockaction' => 'config');
            // To this data, add anything the page itself needs to display
            $hiddendata = $page->url->params($hiddendata);
            if ($data = data_submitted()) {
                $remove = array_keys($hiddendata);
                foreach ($remove as $item) {
                    unset($data->{$item});
                }
                $instance->instance_config_save($data);
                redirect($page->url->out());
            } else {
                // We need to show the config screen, so we highjack the display logic and then die
                $strheading = get_string('blockconfiga', 'moodle', $blocktitle);
                $nav = build_navigation($strheading, $page->cm);
                print_header($strheading, $strheading, $nav);
                echo '<div class="block-config" id="' . $instance->name() . '">';
                /// Make CSS easier
                print_heading($strheading);
                echo '<form method="post" name="block-config" action="' . $page->url->out(false) . '">';
                echo '<p>';
                echo $page->url->hidden_params_out(array(), 0, $hiddendata);
                echo '</p>';
                $instance->instance_config_print();
                echo '</form>';
                echo '</div>';
                global $PAGE;
                $PAGE->set_docs_path('blocks/' . $instance->name());
                print_footer();
                die;
                // Do not go on with the other page-related stuff
            }
            break;
        case 'toggle':
            if (empty($instance)) {
                print_error('invalidblockinstance', '', '', $blockaction);
            }
            $instance->visible = $instance->visible ? 0 : 1;
            if (!empty($pinned)) {
                $DB->update_record('block_pinned_old', $instance);
            } else {
                $DB->update_record('block_instance_old', $instance);
            }
            break;
        case 'delete':
            if (empty($instance)) {
                print_error('invalidblockinstance', '', '', $blockaction);
            }
            blocks_delete_instance($instance->instance, $pinned);
            break;
        case 'moveup':
            if (empty($instance)) {
                print_error('invalidblockinstance', '', '', $blockaction);
            }
            if ($instance->weight == 0) {
                // The block is the first one, so a move "up" probably means it changes position
                // Where is the instance going to be moved?
                $newpos = $page->blocks_move_position($instance, BLOCK_MOVE_UP);
                $newweight = empty($blockmanager[$newpos]) ? 0 : max(array_keys($blockmanager[$newpos])) + 1;
                blocks_execute_repositioning($instance, $newpos, $newweight, $pinned);
            } else {
                // The block is just moving upwards in the same position.
                // This configuration will make sure that even if somehow the weights
                // become not continuous, block move operations will eventually bring
                // the situation back to normal without printing any warnings.
                if (!empty($blockmanager[$instance->position][$instance->weight - 1])) {
                    $other = $blockmanager[$instance->position][$instance->weight - 1];
                }
                if (!empty($other)) {
                    ++$other->weight;
                    if (!empty($pinned)) {
                        $DB->update_record('block_pinned_old', $other);
                    } else {
                        $DB->update_record('block_instance_old', $other);
                    }
                }
                --$instance->weight;
                if (!empty($pinned)) {
//.........这里部分代码省略.........
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:101,代码来源:blocklib.php

示例15: blocks_execute_action

function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, $pinned = false, $redirect = true)
{
    global $CFG;
    if (is_int($instanceorid)) {
        $blockid = $instanceorid;
    } else {
        if (is_object($instanceorid)) {
            $instance = $instanceorid;
        }
    }
    switch ($blockaction) {
        case 'config':
            global $USER;
            $block = blocks_get_record($instance->blockid);
            // Hacky hacky tricky stuff to get the original human readable block title,
            // even if the block has configured its title to be something else.
            // Create the object WITHOUT instance data.
            $blockobject = block_instance($block->name);
            if ($blockobject === false) {
                break;
            }
            // First of all check to see if the block wants to be edited
            if (!$blockobject->user_can_edit()) {
                break;
            }
            // Now get the title and AFTER that load up the instance
            $blocktitle = $blockobject->get_title();
            $blockobject->_load_instance($instance);
            optional_param('submitted', 0, PARAM_INT);
            // Define the data we're going to silently include in the instance config form here,
            // so we can strip them from the submitted data BEFORE serializing it.
            $hiddendata = array('sesskey' => $USER->sesskey, 'instanceid' => $instance->id, 'blockaction' => 'config');
            // To this data, add anything the page itself needs to display
            $hiddendata = array_merge($hiddendata, $page->url_get_parameters());
            if ($data = data_submitted()) {
                $remove = array_keys($hiddendata);
                foreach ($remove as $item) {
                    unset($data->{$item});
                }
                if (!$blockobject->instance_config_save($data, $pinned)) {
                    error('Error saving block configuration');
                }
                // And nothing more, continue with displaying the page
            } else {
                // We need to show the config screen, so we highjack the display logic and then die
                $strheading = get_string('blockconfiga', 'moodle', $blocktitle);
                $page->print_header(get_string('pageheaderconfigablock', 'moodle'), array($strheading => ''));
                echo '<div class="block-config" id="' . $block->name . '">';
                /// Make CSS easier
                print_heading($strheading);
                echo '<form method="post" name="block-config" action="' . $page->url_get_path() . '">';
                echo '<p>';
                foreach ($hiddendata as $name => $val) {
                    echo '<input type="hidden" name="' . $name . '" value="' . $val . '" />';
                }
                echo '</p>';
                $blockobject->instance_config_print();
                echo '</form>';
                echo '</div>';
                $CFG->pagepath = 'blocks/' . $block->name;
                print_footer();
                die;
                // Do not go on with the other page-related stuff
            }
            break;
        case 'toggle':
            if (empty($instance)) {
                error('Invalid block instance for ' . $blockaction);
            }
            $instance->visible = $instance->visible ? 0 : 1;
            if (!empty($pinned)) {
                update_record('block_pinned', $instance);
            } else {
                update_record('block_instance', $instance);
            }
            break;
        case 'delete':
            if (empty($instance)) {
                error('Invalid block instance for ' . $blockaction);
            }
            blocks_delete_instance($instance, $pinned);
            break;
        case 'moveup':
            if (empty($instance)) {
                error('Invalid block instance for ' . $blockaction);
            }
            if ($instance->weight == 0) {
                // The block is the first one, so a move "up" probably means it changes position
                // Where is the instance going to be moved?
                $newpos = $page->blocks_move_position($instance, BLOCK_MOVE_UP);
                $newweight = empty($pageblocks[$newpos]) ? 0 : max(array_keys($pageblocks[$newpos])) + 1;
                blocks_execute_repositioning($instance, $newpos, $newweight, $pinned);
            } else {
                // The block is just moving upwards in the same position.
                // This configuration will make sure that even if somehow the weights
                // become not continuous, block move operations will eventually bring
                // the situation back to normal without printing any warnings.
                if (!empty($pageblocks[$instance->position][$instance->weight - 1])) {
                    //define instance's position in the array
                    foreach ($pageblocks[$instance->position] as $instancekeysindex => $index) {
//.........这里部分代码省略.........
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:101,代码来源:blocklib.php


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