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


PHP moodle_url::compare方法代码示例

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


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

示例1: array

 function test_compare_url()
 {
     $url1 = new moodle_url('index.php', array('var1' => 1, 'var2' => 2));
     $url2 = new moodle_url('index2.php', array('var1' => 1, 'var2' => 2, 'var3' => 3));
     $this->assertFalse($url1->compare($url2, URL_MATCH_BASE));
     $this->assertFalse($url1->compare($url2, URL_MATCH_PARAMS));
     $this->assertFalse($url1->compare($url2, URL_MATCH_EXACT));
     $url2 = new moodle_url('index.php', array('var1' => 1, 'var3' => 3));
     $this->assertTrue($url1->compare($url2, URL_MATCH_BASE));
     $this->assertFalse($url1->compare($url2, URL_MATCH_PARAMS));
     $this->assertFalse($url1->compare($url2, URL_MATCH_EXACT));
     $url2 = new moodle_url('index.php', array('var1' => 1, 'var2' => 2, 'var3' => 3));
     $this->assertTrue($url1->compare($url2, URL_MATCH_BASE));
     $this->assertTrue($url1->compare($url2, URL_MATCH_PARAMS));
     $this->assertFalse($url1->compare($url2, URL_MATCH_EXACT));
     $url2 = new moodle_url('index.php', array('var2' => 2, 'var1' => 1));
     $this->assertTrue($url1->compare($url2, URL_MATCH_BASE));
     $this->assertTrue($url1->compare($url2, URL_MATCH_PARAMS));
     $this->assertTrue($url1->compare($url2, URL_MATCH_EXACT));
 }
开发者ID:rolandovanegas,项目名称:moodle,代码行数:20,代码来源:testweblib.php

示例2: get_matching_tourdata

 /**
  * Fetch all enabled tours matching the specified target.
  *
  * @param   moodle_url  $targetmatch    The URL to match.
  */
 public static function get_matching_tourdata(\moodle_url $targetmatch)
 {
     $tours = self::get_enabled_tourdata();
     // Attempt to determine whether this is the front page.
     // This is a special case because the frontpage uses a shortened page path making it difficult to detect exactly.
     $isfrontpage = $targetmatch->compare(new \moodle_url('/'), URL_MATCH_BASE);
     $target = $targetmatch->out_as_local_url();
     return array_filter($tours, function ($tour) use($isfrontpage, $target) {
         if ($isfrontpage && $tour->pathmatch === 'FRONTPAGE') {
             return true;
         }
         $pattern = preg_quote($tour->pathmatch, '@');
         $pattern = str_replace('%', '.*', $pattern);
         return !!preg_match("@{$pattern}@", $target);
     });
 }
开发者ID:Chocolate-lightning,项目名称:moodle,代码行数:21,代码来源:cache.php

示例3: blog_get_headers

/**
 * This function encapsulates all the logic behind the complex
 * navigation, titles and headings of the blog listing page, depending
 * on URL params. It looks at URL params and at the current context level.
 * It builds and returns an array containing:
 *
 * 1. heading: The heading displayed above the blog entries
 * 2. stradd:  The text to be used as the "Add entry" link
 * 3. strview: The text to be used as the "View entries" link
 * 4. url:     The moodle_url object used as the base for add and view links
 * 5. filters: An array of parameters used to filter blog listings. Used by index.php and the Recent blogs block
 *
 * All other variables are set directly in $PAGE
 *
 * It uses the current URL to build these variables.
 * A number of mutually exclusive use cases are used to structure this function.
 *
 * @return array
 */
function blog_get_headers($courseid = null, $groupid = null, $userid = null, $tagid = null)
{
    global $CFG, $PAGE, $DB, $USER;
    $id = optional_param('id', null, PARAM_INT);
    $tag = optional_param('tag', null, PARAM_NOTAGS);
    $tagid = optional_param('tagid', $tagid, PARAM_INT);
    $userid = optional_param('userid', $userid, PARAM_INT);
    $modid = optional_param('modid', null, PARAM_INT);
    $entryid = optional_param('entryid', null, PARAM_INT);
    $groupid = optional_param('groupid', $groupid, PARAM_INT);
    $courseid = optional_param('courseid', $courseid, PARAM_INT);
    $search = optional_param('search', null, PARAM_RAW);
    $action = optional_param('action', null, PARAM_ALPHA);
    $confirm = optional_param('confirm', false, PARAM_BOOL);
    // Ignore userid when action == add
    if ($action == 'add' && $userid) {
        unset($userid);
        $PAGE->url->remove_params(array('userid'));
    } else {
        if ($action == 'add' && $entryid) {
            unset($entryid);
            $PAGE->url->remove_params(array('entryid'));
        }
    }
    $headers = array('title' => '', 'heading' => '', 'cm' => null, 'filters' => array());
    $blogurl = new moodle_url('/blog/index.php');
    // If the title is not yet set, it's likely that the context isn't set either, so skip this part
    $pagetitle = $PAGE->title;
    if (!empty($pagetitle)) {
        $contexturl = blog_get_context_url();
        // Look at the context URL, it may have additional params that are not in the current URL
        if (!$blogurl->compare($contexturl)) {
            $blogurl = $contexturl;
            if (empty($courseid)) {
                $courseid = $blogurl->param('courseid');
            }
            if (empty($modid)) {
                $modid = $blogurl->param('modid');
            }
        }
    }
    $headers['stradd'] = get_string('addnewentry', 'blog');
    $headers['strview'] = null;
    $site = $DB->get_record('course', array('id' => SITEID));
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    // Common Lang strings
    $strparticipants = get_string("participants");
    $strblogentries = get_string("blogentries", 'blog');
    // Prepare record objects as needed
    if (!empty($courseid)) {
        $headers['filters']['course'] = $courseid;
        $course = $DB->get_record('course', array('id' => $courseid));
    }
    if (!empty($userid)) {
        $headers['filters']['user'] = $userid;
        $user = $DB->get_record('user', array('id' => $userid));
    }
    if (!empty($groupid)) {
        // groupid always overrides courseid
        $headers['filters']['group'] = $groupid;
        $group = $DB->get_record('groups', array('id' => $groupid));
        $course = $DB->get_record('course', array('id' => $group->courseid));
    }
    $PAGE->set_pagelayout('standard');
    // modid always overrides courseid, so the $course object may be reset here
    if (!empty($modid) && $CFG->useblogassociations) {
        $headers['filters']['module'] = $modid;
        // A groupid param may conflict with this coursemod's courseid. Ignore groupid in that case
        $courseid = $DB->get_field('course_modules', 'course', array('id' => $modid));
        $course = $DB->get_record('course', array('id' => $courseid));
        $cm = $DB->get_record('course_modules', array('id' => $modid));
        $cm->modname = $DB->get_field('modules', 'name', array('id' => $cm->module));
        $cm->name = $DB->get_field($cm->modname, 'name', array('id' => $cm->instance));
        $a = new stdClass();
        $a->type = get_string('modulename', $cm->modname);
        $PAGE->set_cm($cm, $course);
        $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
        $headers['strview'] = get_string('viewallmodentries', 'blog', $a);
    }
    // Case 1: No entry, mod, course or user params: all site entries to be shown (filtered by search and tag/tagid)
    // Note: if action is set to 'add' or 'edit', we do this at the end
//.........这里部分代码省略.........
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:101,代码来源:lib.php

示例4: upgrade_install_plugins

/**
 * Helper procedure/macro for installing remote plugins at admin/index.php
 *
 * Does not return, always redirects or exits.
 *
 * @param array $installable list of \core\update\remote_info
 * @param bool $confirmed false: display the validation screen, true: proceed installation
 * @param string $heading validation screen heading
 * @param moodle_url|string|null $continue URL to proceed with installation at the validation screen
 * @param moodle_url|string|null $return URL to go back on cancelling at the validation screen
 */
function upgrade_install_plugins(array $installable, $confirmed, $heading = '', $continue = null, $return = null)
{
    global $CFG, $PAGE;
    if (empty($return)) {
        $return = $PAGE->url;
    }
    if (!empty($CFG->disableupdateautodeploy)) {
        redirect($return);
    }
    if (empty($installable)) {
        redirect($return);
    }
    $pluginman = core_plugin_manager::instance();
    if ($confirmed) {
        // Installation confirmed at the validation results page.
        if (!$pluginman->install_plugins($installable, true, true)) {
            throw new moodle_exception('install_plugins_failed', 'core_plugin', $return);
        }
        // Always redirect to admin/index.php to perform the database upgrade.
        // Do not throw away the existing $PAGE->url parameters such as
        // confirmupgrade or confirmrelease if $PAGE->url is a superset of the
        // URL we must go to.
        $mustgoto = new moodle_url('/admin/index.php', array('cache' => 0, 'confirmplugincheck' => 0));
        if ($mustgoto->compare($PAGE->url, URL_MATCH_PARAMS)) {
            redirect($PAGE->url);
        } else {
            redirect($mustgoto);
        }
    } else {
        $output = $PAGE->get_renderer('core', 'admin');
        echo $output->header();
        if ($heading) {
            echo $output->heading($heading, 3);
        }
        echo html_writer::start_tag('pre', array('class' => 'plugin-install-console'));
        $validated = $pluginman->install_plugins($installable, false, false);
        echo html_writer::end_tag('pre');
        if ($validated) {
            echo $output->plugins_management_confirm_buttons($continue, $return);
        } else {
            echo $output->plugins_management_confirm_buttons(null, $return);
        }
        echo $output->footer();
        die;
    }
}
开发者ID:dg711,项目名称:moodle,代码行数:57,代码来源:upgradelib.php

示例5: test_get_return_url

 /**
  * Test the method mod_workshop_portfolio_caller::get_return_url()
  */
 public function test_get_return_url()
 {
     $this->resetAfterTest(true);
     $student1 = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($student1->id, $this->workshop->course->id);
     $workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop');
     $subid1 = $workshopgenerator->create_submission($this->workshop->id, $student1->id);
     $portfoliocaller = new mod_workshop_portfolio_caller(['id' => $this->workshop->cm->id, 'submissionid' => $subid1]);
     $portfoliocaller->set_formats_from_button([]);
     $portfoliocaller->load_data();
     $expected = new moodle_url('/mod/workshop/submission.php', ['cmid' => $this->workshop->cm->id, 'id' => $subid1]);
     $actual = new moodle_url($portfoliocaller->get_return_url());
     $this->assertTrue($expected->compare($actual));
 }
开发者ID:dg711,项目名称:moodle,代码行数:17,代码来源:portfolio_caller_test.php

示例6: override_option_values

 /**
  * Override the URLs of the default popup_form, which only supports one base URL
  * @param array $options value=>label pairs representing select options
  * @return void
  */
 public function override_option_values($options)
 {
     global $PAGE;
     $originalcount = count($options);
     $this->initialise_options();
     $newcount = count($this->options);
     $first = true;
     reset($options);
     foreach ($this->options as $optkey => $optgroup) {
         if ($optgroup instanceof html_select_optgroup) {
             foreach ($optgroup->options as $key => $option) {
                 next($options);
                 $this->options[$optkey]->options[$key]->value = key($options);
                 $optionurl = new moodle_url(key($options));
                 if ($optionurl->compare($PAGE->url, URL_MATCH_PARAMS)) {
                     $this->options[$optkey]->options[$key]->selected = 'selected';
                 }
             }
             next($options);
         } else {
             if ($optgroup instanceof html_select_option && !($first && $originalcount < $newcount)) {
                 $this->options[$optkey]->value = key($options);
                 $optionurl = new moodle_url(key($options));
                 if ($optionurl->compare($PAGE->url, URL_MATCH_PARAMS)) {
                     $this->options[$optkey]->selected = 'selected';
                 }
                 next($options);
             }
         }
         $first = false;
     }
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:37,代码来源:outputcomponents.php


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