本文整理匯總了PHP中moodle_page::has_set_url方法的典型用法代碼示例。如果您正苦於以下問題:PHP moodle_page::has_set_url方法的具體用法?PHP moodle_page::has_set_url怎麽用?PHP moodle_page::has_set_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類moodle_page
的用法示例。
在下文中一共展示了moodle_page::has_set_url方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: page_set_course
/**
* Allows course format to execute code on moodle_page::set_course()
*
* If user is on course view page and there is no scorm module added to the course
* and the user has 'moodle/course:update' capability, redirect to create module
* form. This function is executed before the output starts
*
* @param moodle_page $page instance of page calling set_course
*/
public function page_set_course(moodle_page $page)
{
global $PAGE;
if ($PAGE == $page && $page->has_set_url() && $page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
$modinfo = get_fast_modinfo($this->courseid);
if (empty($modinfo->instances['scorm']) && has_capability('moodle/course:update', context_course::instance($this->courseid))) {
// Redirect to create a new activity
$url = new moodle_url('/course/modedit.php', array('course' => $this->courseid, 'section' => 0, 'add' => 'scorm'));
redirect($url);
}
}
}
示例2: page_set_course
/**
* Allows course format to execute code on moodle_page::set_course()
*
* This function is executed before the output starts.
*
* If everything is configured correctly, user is redirected from the
* default course view page to the activity view page.
*
* "Section 1" is the administrative page to manage orphaned activities
*
* If user is on course view page and there is no module added to the course
* and the user has 'moodle/course:manageactivities' capability, redirect to create module
* form.
*
* @param moodle_page $page instance of page calling set_course
*/
public function page_set_course(moodle_page $page)
{
global $PAGE;
$page->add_body_class('format-' . $this->get_format());
if ($PAGE == $page && $page->has_set_url() && $page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
$edit = optional_param('edit', -1, PARAM_BOOL);
if (($edit == 0 || $edit == 1) && confirm_sesskey()) {
// This is a request to turn editing mode on or off, do not redirect here, /course/view.php will do redirection.
return;
}
$cm = $this->get_activity();
$cursection = optional_param('section', null, PARAM_INT);
if (!empty($cursection) && has_capability('moodle/course:viewhiddensections', context_course::instance($this->courseid))) {
// Display orphaned activities (course view page, section 1).
return;
}
if (!$this->get_activitytype()) {
if (has_capability('moodle/course:update', context_course::instance($this->courseid))) {
// Teacher is redirected to edit course page.
$url = new moodle_url('/course/edit.php', array('id' => $this->courseid));
redirect($url, get_string('erroractivitytype', 'format_singleactivity'));
} else {
// Student sees an empty course page.
return;
}
}
if ($cm === null) {
if ($this->can_add_activity()) {
// This is a user who has capability to create an activity.
if ($this->activity_has_subtypes()) {
// Activity that requires subtype can not be added automatically.
if (optional_param('addactivity', 0, PARAM_INT)) {
return;
} else {
$url = new moodle_url('/course/view.php', array('id' => $this->courseid, 'addactivity' => 1));
redirect($url);
}
}
// Redirect to the add activity form.
$url = new moodle_url('/course/mod.php', array('id' => $this->courseid, 'section' => 0, 'sesskey' => sesskey(), 'add' => $this->get_activitytype()));
redirect($url);
} else {
// Student views an empty course page.
return;
}
} else {
if (!$cm->uservisible || !$cm->get_url()) {
// Activity is set but not visible to current user or does not have url.
// Display course page (either empty or with availability restriction info).
return;
} else {
// Everything is set up and accessible, redirect to the activity page!
redirect($cm->get_url());
}
}
}
}