本文整理汇总了PHP中moodle_url::set_anchor方法的典型用法代码示例。如果您正苦于以下问题:PHP moodle_url::set_anchor方法的具体用法?PHP moodle_url::set_anchor怎么用?PHP moodle_url::set_anchor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moodle_url
的用法示例。
在下文中一共展示了moodle_url::set_anchor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: embed
/**
* Generates code required to embed the player.
*
* The url contained in $urls must be a local file.
*
* Unlike other core_media_players, the $urls array should only contain
* a single url and the $options array is ignored.
*
* On failure, the function returns an empty string
*
* @see core_media_player::embed
* @param array $urls URL of media file
* @param string $name Display name; '' to use default
* @param int $width Optional width; 0 to use default
* @param int $height Optional height; 0 to use default
* @param array $options Options array
* @return string HTML code for embed
*/
public function embed($urls, $name, $width, $height, $options)
{
global $CFG;
// don't expect alternative urls
if (count($urls) !== 1) {
return '';
}
$file_url = new moodle_url($urls[0]);
$viewerjs_player_url = new moodle_url('/filter/viewerjs/lib/viewerjs');
// we assume the filter/viewerjs/lib/viewerjs directory will be four directories away from the initial public directory
$viewerjs_player_url->set_anchor('../../../..' . $file_url->out_as_local_url());
if (!$width) {
$width = '100%';
}
if (!$height) {
$height = 500;
}
$output = html_writer::tag('iframe', '', array('src' => $viewerjs_player_url->out(), 'width' => $width, 'height' => $height, 'webkitallowfullscreen' => 'webkitallowfullscreen', 'mozallowfullscreen' => 'mozallowfullscreen', 'allowfullscreen' => 'allowfullscreen'));
return $output;
}
示例2: course_get_url
/**
* The URL to use for the specified course (with section)
*
* @param stdClass $course The course to get the section name for
* @param int $sectionno The section number to return a link to
* @return moodle_url The url of course
*/
function course_get_url($course, $sectionno = null)
{
$url = new moodle_url('/course/view.php', array('id' => $course->id));
if (!is_null($sectionno)) {
if ($course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$url->param('section', $sectionno);
} else {
$url->set_anchor('section-' . $sectionno);
}
}
return $url;
}
示例3: note_delete
/**
* Deletes a note object based on its id.
*
* @param int|object $note id of the note to delete, or a note object which is to be deleted.
* @return boolean true if the object was deleted; false otherwise
*/
function note_delete($note) {
global $DB;
if (is_int($note)) {
$note = note_load($note);
debugging('Warning: providing note_delete with a note object would improve performance.',DEBUG_DEVELOPER);
}
$logurl = new moodle_url('index.php', array('course'=> $note->courseid, 'user'=>$note->userid));
$logurl->set_anchor('note-' . $note->id);
add_to_log($note->courseid, 'notes', 'delete', $logurl, 'delete note');
return $DB->delete_records('post', array('id'=>$note->id, 'module'=>'notes'));
}
示例4: forum_print_post
//.........这里部分代码省略.........
if (isset($cm->cache->usersgroups)) {
$groups = array();
if (isset($cm->cache->usersgroups[$post->userid])) {
foreach ($cm->cache->usersgroups[$post->userid] as $gid) {
$groups[$gid] = $cm->cache->groups[$gid];
}
}
} else {
$groups = groups_get_all_groups($course->id, $post->userid, $cm->groupingid);
}
// Prepare the attachements for the post, files then images
list($attachments, $attachedimages) = forum_print_attachments($post, $cm, 'separateimages');
// Determine if we need to shorten this post
$shortenpost = ($link && (strlen(strip_tags($post->message)) > $CFG->forum_longpost));
// Prepare an array of commands
$commands = array();
// SPECIAL CASE: The front page can display a news item post to non-logged in users.
// Don't display the mark read / unread controls in this case.
if ($istracked && $CFG->forum_usermarksread && isloggedin()) {
$url = new moodle_url($discussionlink, array('postid'=>$post->id, 'mark'=>'unread'));
$text = $str->markunread;
if (!$postisread) {
$url->param('mark', 'read');
$text = $str->markread;
}
if ($str->displaymode == FORUM_MODE_THREADED) {
$url->param('parent', $post->parent);
} else {
$url->set_anchor('p'.$post->id);
}
$commands[] = array('url'=>$url, 'text'=>$text);
}
// Zoom in to the parent specifically
if ($post->parent) {
$url = new moodle_url($discussionlink);
if ($str->displaymode == FORUM_MODE_THREADED) {
$url->param('parent', $post->parent);
} else {
$url->set_anchor('p'.$post->parent);
}
$commands[] = array('url'=>$url, 'text'=>$str->parent);
}
// Hack for allow to edit news posts those are not displayed yet until they are displayed
$age = time() - $post->created;
if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) {
$age = 0;
}
if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
if (has_capability('moodle/course:manageactivities', $modcontext)) {
// The first post in single simple is the forum description.
$commands[] = array('url'=>new moodle_url('/course/modedit.php', array('update'=>$cm->id, 'sesskey'=>sesskey(), 'return'=>1)), 'text'=>$str->edit);
}
} else if (($ownpost && $age < $CFG->maxeditingtime) || $cm->cache->caps['mod/forum:editanypost']) {
$commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('edit'=>$post->id)), 'text'=>$str->edit);
}
if ($cm->cache->caps['mod/forum:splitdiscussions'] && $post->parent && $forum->type != 'single') {
$commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('prune'=>$post->id)), 'text'=>$str->prune, 'title'=>$str->pruneheading);
示例5: get_view_url
/**
* The URL to use for the specified course (with section)
*
* @param int|stdClass $section Section object from database or just field course_sections.section
* if omitted the course view page is returned
* @param array $options options for view URL. At the moment core uses:
* 'navigation' (bool) if true and section has no separate page, the function returns null
* 'sr' (int) used by multipage formats to specify to which section to return
* @return null|moodle_url
*/
public function get_view_url($section, $options = array())
{
$url = new moodle_url('/course/view.php', array('id' => $this->courseid));
$sectionno = $this->get_section_number($section);
$section = $this->get_section($sectionno);
if ($sectionno && (!$section->uservisible || !$this->is_section_real_available($section))) {
return empty($options['navigation']) ? $url : null;
}
if (array_key_exists('sr', $options)) {
// return to the page for section with number $sr
$url->param('section', $options['sr']);
if ($sectionno) {
$url->set_anchor('section-' . $sectionno);
}
} else {
if (!empty($options['navigation'])) {
// this is called from navigation, create link only if this
// section has separate page
if ($section->collapsed == FORMAT_FLEXSECTIONS_COLLAPSED) {
$url->param('sectionid', $section->id);
} else {
return null;
}
} else {
if ($sectionno) {
// check if this section has separate page
if ($section->collapsed == FORMAT_FLEXSECTIONS_COLLAPSED) {
$url->param('sectionid', $section->id);
return $url;
}
// find the parent (or grandparent) page that is displayed on separate page
$url->param('sectionid', $this->find_collapsed_parent($section->parent, true));
$url->set_anchor('section-' . $sectionno);
return $url;
}
}
}
return $url;
}
示例6: test_compare_url
public 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));
$url1->set_anchor('test');
$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->set_anchor('test');
$this->assertTrue($url1->compare($url2, URL_MATCH_BASE));
$this->assertTrue($url1->compare($url2, URL_MATCH_PARAMS));
$this->assertTrue($url1->compare($url2, URL_MATCH_EXACT));
}
示例7: test_note_updated_event
/**
* Tests for event note_updated.
*/
public function test_note_updated_event()
{
// Delete a note.
$sink = $this->redirectEvents();
$note = clone $this->eventnote;
$note->publishstate = NOTES_STATE_DRAFT;
note_save($note);
$events = $sink->get_events();
$event = array_pop($events);
// Delete note event.
$sink->close();
// Validate event data.
$this->assertInstanceOf('\\core\\event\\note_updated', $event);
$this->assertEquals($note->id, $event->objectid);
$this->assertEquals($note->usermodified, $event->userid);
$this->assertEquals($note->userid, $event->relateduserid);
$this->assertEquals('post', $event->objecttable);
$this->assertEquals(NOTES_STATE_DRAFT, $event->other['publishstate']);
// Test legacy data.
$logurl = new \moodle_url('index.php', array('course' => $note->courseid, 'user' => $note->userid));
$logurl->set_anchor('note-' . $note->id);
$arr = array($note->courseid, 'notes', 'update', $logurl, 'update note');
$this->assertEventLegacyLogData($arr, $event);
$this->assertEventContextNotUsed($event);
}
示例8: array
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
require_once "../../config.php";
require_once $CFG->dirroot . '/mod/lesson/locallib.php';
require_once 'editpage_form.php';
// first get the preceeding page
$pageid = required_param('pageid', PARAM_INT);
$id = required_param('id', PARAM_INT);
// Course Module ID
$qtype = optional_param('qtype', 0, PARAM_INT);
$edit = optional_param('edit', false, PARAM_BOOL);
$returnto = optional_param('returnto', null, PARAM_URL);
if (empty($returnto)) {
$returnto = new moodle_url('/mod/lesson/edit.php', array('id' => $id));
$returnto->set_anchor('lesson-' . $pageid);
}
$cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST));
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/lesson:edit', $context);
$PAGE->set_url('/mod/lesson/editpage.php', array('pageid' => $pageid, 'id' => $id, 'qtype' => $qtype));
$PAGE->set_pagelayout('admin');
if ($edit) {
$editpage = lesson_page::load($pageid, $lesson);
$qtype = $editpage->qtype;
$edit = true;
} else {
$edit = false;
示例9: course_get_url
/**
* The URL to use for the specified course (with section)
*
* @param stdClass $course The course to get the section name for
* @param int $sectionno The section number to return a link to
* if omitted the course view page is returned
* @param array $options options for view URL. At the moment core uses:
* 'navigation' (bool) if true and section has no separate page, the function returns null
* 'sr' (int) used by multipage formats to specify to which section to return
* @return moodle_url The url of course
*/
function course_get_url($course, $sectionno = null, $options = array()) {
if ($course->id == SITEID) {
return new moodle_url('/');
}
$url = new moodle_url('/course/view.php', array('id' => $course->id));
$sr = null;
if (array_key_exists('sr', $options)) {
$sr = $options['sr'];
}
if ($sectionno !== null) {
if ($sr !== null) {
if ($sr) {
$usercoursedisplay = COURSE_DISPLAY_MULTIPAGE;
$sectionno = $sr;
} else {
$usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
}
} else {
$usercoursedisplay = $course->coursedisplay;
}
if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$url->param('section', $sectionno);
} else {
if (!empty($options['navigation'])) {
return null;
}
$url->set_anchor('section-'.$sectionno);
}
}
return $url;
}
示例10: get_view_url
/**
* The URL to use for the specified course (with section)
*
* @param int|stdClass $section Section object from database or just field course_sections.section
* if omitted the course view page is returned
* @param array $options options for view URL. At the moment core uses:
* 'navigation' (bool) if true and section has no separate page, the function returns null
* 'sr' (int) used by multipage formats to specify to which section to return
* @return null|moodle_url
*/
public function get_view_url($section, $options = array())
{
$course = $this->get_course();
$url = new moodle_url('/course/view.php', array('id' => $course->id));
$sr = null;
if (array_key_exists('sr', $options)) {
$sr = $options['sr'];
}
if (is_object($section)) {
$sectionno = $section->section;
} else {
$sectionno = $section;
}
if ($sectionno !== null) {
if (!empty($options['navigation'])) {
return null;
}
$url->set_anchor('section-' . $sectionno);
}
return $url;
}
示例11: trim
}
if ($user) {
$frm->username = $user->username;
} else {
$frm = data_submitted();
}
} else {
$frm = data_submitted();
}
}
// Restore the #anchor to the original wantsurl. Note that this
// will only work for internal auth plugins, SSO plugins such as
// SAML / CAS / OIDC will have to handle this correctly directly.
if ($anchor && isset($SESSION->wantsurl) && strpos($SESSION->wantsurl, '#') === false) {
$wantsurl = new moodle_url($SESSION->wantsurl);
$wantsurl->set_anchor(substr($anchor, 1));
$SESSION->wantsurl = $wantsurl->out();
}
/// Check if the user has actually submitted login data to us
if ($frm and isset($frm->username)) {
// Login WITH cookies
$frm->username = trim(core_text::strtolower($frm->username));
if (is_enabled_auth('none')) {
if ($frm->username !== core_user::clean_field($frm->username, 'username')) {
$errormsg = get_string('username') . ': ' . get_string("invalidusername");
$errorcode = 2;
$user = null;
}
}
if ($user) {
//user already supplied by aut plugin prelogin hook
示例12: array
if (has_capability('mod/booking:updatebooking', context_module::instance($cm->id))) {
$links[] = html_writer::link(new moodle_url('/mod/booking/teachers.php', array('id' => $id, 'optionid' => $optionid)), get_string('teachers', 'booking'), array());
}
if (has_capability('mod/booking:subscribeusers', $context)) {
$links[] = html_writer::link(new moodle_url('/mod/booking/subscribeusers.php', array('id' => $cm->id, 'optionid' => $optionid)), get_string('bookotherusers', 'booking'), array());
}
$links[] = '<a href="#" id="showHideSearch">' . get_string('search') . '</a>';
if (has_capability('mod/booking:communicate', context_module::instance($cm->id))) {
$links[] = html_writer::link(new moodle_url('/mod/booking/report.php', array('id' => $cm->id, 'optionid' => $optionid, 'action' => 'sendpollurlteachers')), get_string('booking:sendpollurltoteachers', 'booking'), array());
}
echo implode(" | ", $links);
if ($bookingData->option->courseid != 0) {
echo '<br>' . html_writer::start_span('') . get_string('associatedcourse', 'booking') . ': ' . html_writer::link(new moodle_url($bookingData->option->courseurl, array()), $bookingData->option->urltitle, array()) . html_writer::end_span() . '<br>';
}
$onlyOneURL = new moodle_url('/mod/booking/view.php', array('id' => $id, 'optionid' => $optionid, 'action' => 'showonlyone', 'whichview' => 'showonlyone'));
$onlyOneURL->set_anchor('goenrol');
echo '<br>' . html_writer::start_span('') . get_string('onlythisbookingurl', 'booking') . ': ' . html_writer::link($onlyOneURL, $onlyOneURL, array()) . html_writer::end_span() . '<br><br>';
$hidden = "";
foreach ($urlParams as $key => $value) {
if (!in_array($key, array('searchName', 'searchSurname', 'searchDate', 'searchFinished'))) {
$hidden .= '<input value="' . $value . '" type="hidden" name="' . $key . '">';
}
}
$row = new html_table_row(array(get_string('searchName', "booking"), '<form>' . $hidden . '<input value="' . $urlParams['searchName'] . '" id="searchName" type="text" name="searchName">', "", ""));
$tabledata[] = $row;
$rowclasses[] = "";
$row = new html_table_row(array(get_string('searchSurname', "booking"), '<input value="' . $urlParams['searchSurname'] . '" id="searchSurname" type="text" name="searchSurname">', "", ""));
$tabledata[] = $row;
$rowclasses[] = "";
$row = new html_table_row(array(get_string('searchDate', "booking"), html_writer::checkbox('searchDate', '1', $checked, '', array('id' => 'searchDate')) . html_writer::select_time('days', 'searchDateDay', $timestamp, 5) . ' ' . html_writer::select_time('months', 'searchDateMonth', $timestamp, 5) . ' ' . html_writer::select_time('years', 'searchDateYear', $timestamp, 5), "", ""));
$tabledata[] = $row;
示例13: send
public function send()
{
global $DB;
// add author to participants and save
$this->conversation->add_participant($this->_authorid);
$this->conversation->save_participants();
// update state to open
$this->_state = dialogue::STATE_OPEN;
$DB->set_field('dialogue_messages', 'state', $this->_state, array('id' => $this->_messageid));
// setup information for messageapi object
$cm = $this->dialogue->cm;
$conversationid = $this->conversation->conversationid;
$course = $this->dialogue->course;
$context = $this->dialogue->context;
$userfrom = $DB->get_record('user', array('id' => $this->_authorid), '*', MUST_EXIST);
$subject = format_string($this->conversation->subject, true, array('context' => $context));
$a = new \stdClass();
$a->userfrom = fullname($userfrom);
$a->subject = $subject;
$url = new \moodle_url('/mod/dialogue/view.php', array('id' => $cm->id));
$a->url = $url->out(false);
$posthtml = get_string('messageapibasicmessage', 'dialogue', $a);
$posttext = html_to_text($posthtml);
$smallmessage = get_string('messageapismallmessage', 'dialogue', fullname($userfrom));
$contexturlparams = array('id' => $cm->id, 'conversationid' => $conversationid);
$contexturl = new \moodle_url('/mod/dialogue/conversation.php', $contexturlparams);
$contexturl->set_anchor('m' . $this->_messageid);
// flags and messaging
$participants = $this->conversation->participants;
foreach ($participants as $participant) {
if ($participant->id == $this->_authorid) {
// so unread flag count displays properly for author, they wrote it, they should of read it.
$this->set_flag(dialogue::FLAG_READ, $this->author);
continue;
}
// give participant a sent flag
$this->set_flag(dialogue::FLAG_SENT, $participant);
$userto = $DB->get_record('user', array('id' => $participant->id), '*', MUST_EXIST);
$eventdata = new \stdClass();
$eventdata->component = 'mod_dialogue';
$eventdata->name = 'post';
$eventdata->userfrom = $userfrom;
$eventdata->userto = $userto;
$eventdata->subject = $subject;
$eventdata->fullmessage = $posttext;
$eventdata->fullmessageformat = FORMAT_HTML;
$eventdata->fullmessagehtml = $posthtml;
$eventdata->smallmessage = $smallmessage;
$eventdata->notification = 1;
$eventdata->contexturl = $contexturl->out(false);
$eventdata->contexturlname = $subject;
$result = message_send($eventdata);
if (!$result) {
//throw new moodle_exception('message not saved');
}
}
return true;
}
示例14: get_url
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url()
{
$url = new \moodle_url('/mod/oublog/viewpost.php', array('post' => $this->other['postid']));
$url->set_anchor('cid' . $this->objectid);
return $url;
}
示例15: test_post_updated_single
/**
* Test post_updated event.
*/
public function test_post_updated_single()
{
// Setup test data.
$course = $this->getDataGenerator()->create_course();
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id, 'type' => 'single'));
$user = $this->getDataGenerator()->create_user();
// Add a discussion.
$record = array();
$record['course'] = $course->id;
$record['forum'] = $forum->id;
$record['userid'] = $user->id;
$discussion = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
// Add a post.
$record = array();
$record['discussion'] = $discussion->id;
$record['userid'] = $user->id;
$post = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
$context = context_module::instance($forum->cmid);
$params = array('context' => $context, 'objectid' => $post->id, 'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id, 'forumtype' => $forum->type));
$event = \mod_forum\event\post_updated::create($params);
// Trigger and capturing the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\\mod_forum\\event\\post_updated', $event);
$this->assertEquals($context, $event->get_context());
$expected = array($course->id, 'forum', 'update post', "view.php?f={$forum->id}#p{$post->id}", $post->id, $forum->cmid);
$this->assertEventLegacyLogData($expected, $event);
$url = new \moodle_url('/mod/forum/view.php', array('f' => $forum->id));
$url->set_anchor('p' . $post->id);
$this->assertEquals($url, $event->get_url());
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());
}