/** * 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; }
/** * 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; }
/** * 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')); }
/** * Print a forum post * * @global object * @global object * @uses FORUM_MODE_THREADED * @uses PORTFOLIO_FORMAT_PLAINHTML * @uses PORTFOLIO_FORMAT_FILE * @uses PORTFOLIO_FORMAT_RICHHTML * @uses PORTFOLIO_ADD_TEXT_LINK * @uses CONTEXT_MODULE * @param object $post The post to print. * @param object $discussion * @param object $forum * @param object $cm * @param object $course * @param boolean $ownpost Whether this post belongs to the current user. * @param boolean $reply Whether to print a 'reply' link at the bottom of the message. * @param boolean $link Just print a shortened version of the post as a link to the full post. * @param string $footer Extra stuff to print after the message. * @param string $highlight Space-separated list of terms to highlight. * @param int $post_read true, false or -99. If we already know whether this user * has read this post, pass that in, otherwise, pass in -99, and this * function will work it out. * @param boolean $dummyifcantsee When forum_user_can_see_post says that * the current user can't see this post, if this argument is true * (the default) then print a dummy 'you can't see this post' post. * If false, don't output anything at all. * @param bool|null $istracked * @return void */ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=false, $reply=false, $link=false, $footer="", $highlight="", $postisread=null, $dummyifcantsee=true, $istracked=null, $return=false) { global $USER, $CFG, $OUTPUT; require_once($CFG->libdir . '/filelib.php'); // String cache static $str; $modcontext = context_module::instance($cm->id); $post->course = $course->id; $post->forum = $forum->id; $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_forum', 'post', $post->id); if (!empty($CFG->enableplagiarism)) { require_once($CFG->libdir.'/plagiarismlib.php'); $post->message .= plagiarism_get_links(array('userid' => $post->userid, 'content' => $post->message, 'cmid' => $cm->id, 'course' => $post->course, 'forum' => $post->forum)); } // caching if (!isset($cm->cache)) { $cm->cache = new stdClass; } if (!isset($cm->cache->caps)) { $cm->cache->caps = array(); $cm->cache->caps['mod/forum:viewdiscussion'] = has_capability('mod/forum:viewdiscussion', $modcontext); $cm->cache->caps['moodle/site:viewfullnames'] = has_capability('moodle/site:viewfullnames', $modcontext); $cm->cache->caps['mod/forum:editanypost'] = has_capability('mod/forum:editanypost', $modcontext); $cm->cache->caps['mod/forum:splitdiscussions'] = has_capability('mod/forum:splitdiscussions', $modcontext); $cm->cache->caps['mod/forum:deleteownpost'] = has_capability('mod/forum:deleteownpost', $modcontext); $cm->cache->caps['mod/forum:deleteanypost'] = has_capability('mod/forum:deleteanypost', $modcontext); $cm->cache->caps['mod/forum:viewanyrating'] = has_capability('mod/forum:viewanyrating', $modcontext); $cm->cache->caps['mod/forum:exportpost'] = has_capability('mod/forum:exportpost', $modcontext); $cm->cache->caps['mod/forum:exportownpost'] = has_capability('mod/forum:exportownpost', $modcontext); } if (!isset($cm->uservisible)) { $cm->uservisible = coursemodule_visible_for_user($cm); } if ($istracked && is_null($postisread)) { $postisread = forum_tp_is_post_read($USER->id, $post); } if (!forum_user_can_see_post($forum, $discussion, $post, NULL, $cm)) { $output = ''; if (!$dummyifcantsee) { if ($return) { return $output; } echo $output; return; } $output .= html_writer::tag('a', '', array('id'=>'p'.$post->id)); $output .= html_writer::start_tag('div', array('class'=>'forumpost clearfix')); $output .= html_writer::start_tag('div', array('class'=>'row header')); $output .= html_writer::tag('div', '', array('class'=>'left picture')); // Picture if ($post->parent) { $output .= html_writer::start_tag('div', array('class'=>'topic')); } else { $output .= html_writer::start_tag('div', array('class'=>'topic starter')); } $output .= html_writer::tag('div', get_string('forumsubjecthidden','forum'), array('class'=>'subject')); // Subject $output .= html_writer::tag('div', get_string('forumauthorhidden','forum'), array('class'=>'author')); // author $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); // row $output .= html_writer::start_tag('div', array('class'=>'row')); $output .= html_writer::tag('div', ' ', array('class'=>'left side')); // Groups $output .= html_writer::tag('div', get_string('forumbodyhidden','forum'), array('class'=>'content')); // Content $output .= html_writer::end_tag('div'); // row $output .= html_writer::end_tag('div'); // forumpost if ($return) { return $output; } echo $output; return; } if (empty($str)) { $str = new stdClass; $str->edit = get_string('edit', 'forum'); $str->delete = get_string('delete', 'forum'); $str->reply = get_string('reply', 'forum'); $str->parent = get_string('parent', 'forum'); $str->pruneheading = get_string('pruneheading', 'forum'); $str->prune = get_string('prune', 'forum'); $str->displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode); $str->markread = get_string('markread', 'forum'); $str->markunread = get_string('markunread', 'forum'); } $discussionlink = new moodle_url('/mod/forum/discuss.php', array('d'=>$post->discussion)); // Build an object that represents the posting user $postuser = new stdClass; $postuser->id = $post->userid; $postuser->firstname = $post->firstname; $postuser->lastname = $post->lastname; $postuser->imagealt = $post->imagealt; $postuser->picture = $post->picture; $postuser->email = $post->email; // Some handy things for later on $postuser->fullname = fullname($postuser, $cm->cache->caps['moodle/site:viewfullnames']); $postuser->profilelink = new moodle_url('/user/view.php', array('id'=>$post->userid, 'course'=>$course->id)); // Prepare the groups the posting user belongs to 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); } if ($forum->type == 'single' and $discussion->firstpost == $post->id) { // Do not allow deleting of first post in single simple type. } else if (($ownpost && $age < $CFG->maxeditingtime && $cm->cache->caps['mod/forum:deleteownpost']) || $cm->cache->caps['mod/forum:deleteanypost']) { $commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('delete'=>$post->id)), 'text'=>$str->delete); } if ($reply) { $commands[] = array('url'=>new moodle_url('/mod/forum/post.php#mformforum', array('reply'=>$post->id)), 'text'=>$str->reply); } if ($CFG->enableportfolios && ($cm->cache->caps['mod/forum:exportpost'] || ($ownpost && $cm->cache->caps['mod/forum:exportownpost']))) { $p = array('postid' => $post->id); require_once($CFG->libdir.'/portfoliolib.php'); $button = new portfolio_add_button(); $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id), 'mod_forum'); if (empty($attachments)) { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } $porfoliohtml = $button->to_html(PORTFOLIO_ADD_TEXT_LINK); if (!empty($porfoliohtml)) { $commands[] = $porfoliohtml; } } // Finished building commands // Begin output $output = ''; if ($istracked) { if ($postisread) { $forumpostclass = ' read'; } else { $forumpostclass = ' unread'; $output .= html_writer::tag('a', '', array('name'=>'unread')); } } else { // ignore trackign status if not tracked or tracked param missing $forumpostclass = ''; } $topicclass = ''; if (empty($post->parent)) { $topicclass = ' firstpost starter'; } $output .= html_writer::tag('a', '', array('id'=>'p'.$post->id)); $output .= html_writer::start_tag('div', array('class'=>'forumpost clearfix'.$forumpostclass.$topicclass)); $output .= html_writer::start_tag('div', array('class'=>'row header clearfix')); $output .= html_writer::start_tag('div', array('class'=>'left picture')); $output .= $OUTPUT->user_picture($postuser, array('courseid'=>$course->id)); $output .= html_writer::end_tag('div'); $output .= html_writer::start_tag('div', array('class'=>'topic'.$topicclass)); $postsubject = $post->subject; if (empty($post->subjectnoformat)) { $postsubject = format_string($postsubject); } $output .= html_writer::tag('div', $postsubject, array('class'=>'subject')); $by = new stdClass(); $by->name = html_writer::link($postuser->profilelink, $postuser->fullname); $by->date = userdate($post->modified); $output .= html_writer::tag('div', get_string('bynameondate', 'forum', $by), array('class'=>'author')); $output .= html_writer::end_tag('div'); //topic $output .= html_writer::end_tag('div'); //row $output .= html_writer::start_tag('div', array('class'=>'row maincontent clearfix')); $output .= html_writer::start_tag('div', array('class'=>'left')); $groupoutput = ''; if ($groups) { $groupoutput = print_group_picture($groups, $course->id, false, true, true); } if (empty($groupoutput)) { $groupoutput = ' '; } $output .= html_writer::tag('div', $groupoutput, array('class'=>'grouppictures')); $output .= html_writer::end_tag('div'); //left side $output .= html_writer::start_tag('div', array('class'=>'no-overflow')); $output .= html_writer::start_tag('div', array('class'=>'content')); if (!empty($attachments)) { $output .= html_writer::tag('div', $attachments, array('class'=>'attachments')); } $options = new stdClass; $options->para = false; $options->trusted = $post->messagetrust; $options->context = $modcontext; if ($shortenpost) { // Prepare shortened version $postclass = 'shortenedpost'; $postcontent = format_text(forum_shorten_post($post->message), $post->messageformat, $options, $course->id); $postcontent .= html_writer::link($discussionlink, get_string('readtherest', 'forum')); $postcontent .= html_writer::tag('div', '('.get_string('numwords', 'moodle', count_words($post->message)).')', array('class'=>'post-word-count')); } else { // Prepare whole post $postclass = 'fullpost'; $postcontent = format_text($post->message, $post->messageformat, $options, $course->id); if (!empty($highlight)) { $postcontent = highlight($highlight, $postcontent); } if (!empty($forum->displaywordcount)) { $postcontent .= html_writer::tag('div', get_string('numwords', 'moodle', count_words($post->message)), array('class'=>'post-word-count')); } $postcontent .= html_writer::tag('div', $attachedimages, array('class'=>'attachedimages')); } // Output the post content $output .= html_writer::tag('div', $postcontent, array('class'=>'posting '.$postclass)); $output .= html_writer::end_tag('div'); // Content $output .= html_writer::end_tag('div'); // Content mask $output .= html_writer::end_tag('div'); // Row $output .= html_writer::start_tag('div', array('class'=>'row side')); $output .= html_writer::tag('div',' ', array('class'=>'left')); $output .= html_writer::start_tag('div', array('class'=>'options clearfix')); // Output ratings if (!empty($post->rating)) { $output .= html_writer::tag('div', $OUTPUT->render($post->rating), array('class'=>'forum-post-rating')); } // Output the commands $commandhtml = array(); foreach ($commands as $command) { if (is_array($command)) { $commandhtml[] = html_writer::link($command['url'], $command['text']); } else { $commandhtml[] = $command; } } $output .= html_writer::tag('div', implode(' | ', $commandhtml), array('class'=>'commands')); // Output link to post if required if ($link) { if ($post->replies == 1) { $replystring = get_string('repliesone', 'forum', $post->replies); } else { $replystring = get_string('repliesmany', 'forum', $post->replies); } $output .= html_writer::start_tag('div', array('class'=>'link')); $output .= html_writer::link($discussionlink, get_string('discussthistopic', 'forum')); $output .= ' ('.$replystring.')'; $output .= html_writer::end_tag('div'); // link } // Output footer if required if ($footer) { $output .= html_writer::tag('div', $footer, array('class'=>'footer')); } // Close remaining open divs $output .= html_writer::end_tag('div'); // content $output .= html_writer::end_tag('div'); // row $output .= html_writer::end_tag('div'); // forumpost // Mark the forum post as read if required if ($istracked && !$CFG->forum_usermarksread && !$postisread) { forum_tp_mark_post_read($USER->id, $post, $forum->id); } if ($return) { return $output; } echo $output; return; }
/** * 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; }
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)); }
/** * 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); }
* @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;
/** * 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; }
/** * 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; }
} 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
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;
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; }
/** * 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; }
/** * 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()); }
/** * 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 ($sr !== null) { if ($sr) { $displaymode = COURSE_DISPLAY_MULTIPAGE; $sectionno = $sr; } else { $displaymode = COURSE_DISPLAY_SINGLEPAGE; } } else { $displaymode = $this->get_section_display_mode($section); } if ($sectionno != 0 && $displaymode == COURSE_DISPLAY_MULTIPAGE) { $url->param('section', $sectionno); } else { if (!empty($options['navigation'])) { return null; } $url->set_anchor('section-' . $sectionno); } } return $url; }
/** * Get URL related to the action * * @return \moodle_url */ public function get_url() { $url = new \moodle_url('/mod/dialogue/conversation.php', array('conversationid' => $this->other['conversationid'], 'id' => $this->contextinstanceid)); $url->set_anchor('m-' . $this->objectid); return $url; }
/** * Outputs the forum post indicated by $activity. * * @param object $activity the activity object the forum resides in * @param int $courseid the id of the course the forum resides in * @param bool $detail not used, but required for compatibilty with other modules * @param int $modnames not used, but required for compatibilty with other modules * @param bool $viewfullnames not used, but required for compatibilty with other modules */ function forum_print_recent_mod_activity($activity, $courseid, $detail, $modnames, $viewfullnames) { global $OUTPUT; $content = $activity->content; if ($content->parent) { $class = 'reply'; } else { $class = 'discussion'; } $tableoptions = ['border' => '0', 'cellpadding' => '3', 'cellspacing' => '0', 'class' => 'forum-recent']; $output = html_writer::start_tag('table', $tableoptions); $output .= html_writer::start_tag('tr'); $post = (object) ['parent' => $content->parent]; $forum = (object) ['type' => $content->forumtype]; $authorhidden = forum_is_author_hidden($post, $forum); // Show user picture if author should not be hidden. if (!$authorhidden) { $pictureoptions = ['courseid' => $courseid, 'link' => $authorhidden, 'alttext' => $authorhidden]; $picture = $OUTPUT->user_picture($activity->user, $pictureoptions); $output .= html_writer::tag('td', $picture, ['class' => 'userpicture', 'valign' => 'top']); } // Discussion title and author. $output .= html_writer::start_tag('td', ['class' => $class]); if ($content->parent) { $class = 'title'; } else { // Bold the title of new discussions so they stand out. $class = 'title bold'; } $output .= html_writer::start_div($class); if ($detail) { $aname = s($activity->name); $output .= html_writer::img($OUTPUT->pix_url('icon', $activity->type), $aname, ['class' => 'icon']); } $discussionurl = new moodle_url('/mod/forum/discuss.php', ['d' => $content->discussion]); $discussionurl->set_anchor('p' . $activity->content->id); $output .= html_writer::link($discussionurl, $content->subject); $output .= html_writer::end_div(); $timestamp = userdate($activity->timestamp); if ($authorhidden) { $authornamedate = $timestamp; } else { $fullname = fullname($activity->user, $viewfullnames); $userurl = new moodle_url('/user/view.php'); $userurl->params(['id' => $activity->user->id, 'course' => $courseid]); $by = new stdClass(); $by->name = html_writer::link($userurl, $fullname); $by->date = $timestamp; $authornamedate = get_string('bynameondate', 'forum', $by); } $output .= html_writer::div($authornamedate, 'user'); $output .= html_writer::end_tag('td'); $output .= html_writer::end_tag('tr'); $output .= html_writer::end_tag('table'); echo $output; }
} } } if (!$current and $bookingopen and has_capability('mod/booking:choose', $context)) { echo $OUTPUT->box(booking_show_maxperuser($booking, $USER, $bookinglist), 'box mdl-align'); unset($urlParams['sort']); $tmpUrlParams = $urlParams; $tmpUrlParams['whichview'] = 'showactive'; $urlActive = new moodle_url('/mod/booking/view.php', $tmpUrlParams); $urlActive->set_anchor('goenrol'); $tmpUrlParams['whichview'] = 'showall'; $urlAll = new moodle_url('/mod/booking/view.php', $tmpUrlParams); $urlAll->set_anchor('goenrol'); $tmpUrlParams['whichview'] = 'mybooking'; $urlMy = new moodle_url('/mod/booking/view.php', $tmpUrlParams); $urlMy->set_anchor('goenrol'); $showAll = "<a href=\"{$urlAll}\">" . get_string('showallbookings', 'booking') . "</a>"; $mybooking = "<a href=\"{$urlMy}\">" . get_string('showmybookings', 'booking') . "</a>"; $showactive = "<a href=\"{$urlActive}\">" . get_string('showactive', 'booking') . "</a>"; $search = '<a href="#" id="showHideSearch">' . get_string('search') . "</a>"; switch ($whichview) { case 'mybooking': $mybooking = "<a href=\"{$urlMy}\"><b>" . get_string('showmybookings', 'booking') . "</b></a>"; break; case 'showall': $showAll = "<a href=\"{$urlAll}\"><b>" . get_string('showallbookings', 'booking') . "</b></a>"; break; case 'showactive': $showactive = "<a href=\"{$urlActive}\"><b>" . get_string('showactive', 'booking') . "</b></a>"; break; default:
/** * 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()) { global $CFG; $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 ($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 { $url->set_anchor('section-' . $sectionno); } } return $url; }
} else { if ($data->duration == 2) { $data->timeduration = $data->timedurationminutes * MINSECS; } else { $data->timeduration = 0; } } $event->update($data); $eventurl = new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'day')); if (!empty($event->courseid)) { $eventurl->param('course', $event->courseid); } $eventurl->param('cal_d', date('j', $event->timestart)); $eventurl->param('cal_m', date('n', $event->timestart)); $eventurl->param('cal_y', date('Y', $event->timestart)); $eventurl->set_anchor('event_' . $event->id); redirect($eventurl); } $PAGE->navbar->add($strcalendar, $link); $PAGE->navbar->add($title); $PAGE->set_title($site->shortname . ': ' . $strcalendar . ': ' . $title); $PAGE->set_heading($COURSE->fullname); calendar_set_filters($calendar->courses, $calendar->groups, $calendar->users); $renderer = $PAGE->get_renderer('core_calendar'); $calendar->add_sidecalendar_blocks($renderer); echo $OUTPUT->header(); echo $renderer->start_layout(); echo $OUTPUT->heading($title); $mform->display(); echo $renderer->complete_layout(); echo $OUTPUT->footer();
/** * Replace add_to_log() statement. * * @return array of parameters to be passed to legacy add_to_log() function. */ protected function get_legacy_logdata() { $logurl = new \moodle_url('index.php', array('course' => $this->courseid, 'user' => $this->relateduserid)); $logurl->set_anchor('note-' . $this->objectid); return array($this->courseid, 'notes', 'update', $logurl, 'update note'); }
/** * Creates access hidden skip to links for the displayed sections. * * @param bool $displaycategorylisting * @param bool $displaycourselisting * @param bool $displaycoursedetail * @return string */ public function accessible_skipto_links($displaycategorylisting, $displaycourselisting, $displaycoursedetail) { $html = html_writer::start_div('skiplinks accesshide'); $url = new moodle_url($this->page->url); if ($displaycategorylisting) { $url->set_anchor('category-listing'); $html .= html_writer::link($url, get_string('skiptocategorylisting'), array('class' => 'skip')); } if ($displaycourselisting) { $url->set_anchor('course-listing'); $html .= html_writer::link($url, get_string('skiptocourselisting'), array('class' => 'skip')); } if ($displaycoursedetail) { $url->set_anchor('course-detail'); $html .= html_writer::link($url, get_string('skiptocoursedetails'), array('class' => 'skip')); } $html .= html_writer::end_div(); return $html; }
/** * Get URL related to the action * * @return \moodle_url */ public function get_url() { if ($this->other['forumtype'] == 'single') { // Single discussion forums are an exception. We show // the forum itself since it only has one discussion // thread. $url = new \moodle_url('/mod/forum/view.php', array('f' => $this->other['forumid'])); } else { $url = new \moodle_url('/mod/forum/discuss.php', array('d' => $this->other['discussionid'])); } $url->set_anchor('p' . $this->objectid); return $url; }
/** * The URL to use for the specified course (with section) * * This function calls function callback_FORMATNAME_get_section_url() if it exists * * @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()) { // Use course formatter callback if it exists $featurefunction = 'callback_' . $this->format . '_get_section_url'; if (function_exists($featurefunction) && ($course = $this->get_course())) { if (is_object($section)) { $sectionnum = $section->section; } else { $sectionnum = $section; } if ($sectionnum) { $url = $featurefunction($course, $sectionnum); if ($url || !empty($options['navigation'])) { return $url; } } } // if function is not defined if (!$this->uses_sections() || !array_key_exists('coursedisplay', $this->course_format_options())) { // default behaviour return parent::get_view_url($section, $options); } $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 ($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; }
/** * The URL to use for the specified course (with section) * * Please note that course view page /course/view.php?id=COURSEID is hardcoded in many * places in core and contributed modules. If course format wants to change the location * of the view script, it is not enough to change just this function. Do not forget * to add proper redirection. * * @param int|stdClass $section Section object from database or just field course_sections.section * if null 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()) { global $CFG; $course = $this->get_course(); $url = new moodle_url('/course/view.php', array('id' => $course->id)); if (array_key_exists('sr', $options)) { $sectionno = $options['sr']; } else { if (is_object($section)) { $sectionno = $section->section; } else { $sectionno = $section; } } if (empty($CFG->linkcoursesections) && !empty($options['navigation']) && $sectionno !== null) { // by default assume that sections are never displayed on separate pages return null; } if ($this->uses_sections() && $sectionno !== null) { $url->set_anchor('section-' . $sectionno); } return $url; }
/** * Return the content of any success notification to be sent. * Both an HTML and Plain Text variant must be provided. * * @param \stdClass $messagedata The message data. * @param \stdClass $handlerresult The record for the newly created post. * @return \stdClass with keys `html` and `plain`. */ public function get_success_message(\stdClass $messagedata, $handlerresult) { $a = new \stdClass(); $a->subject = $handlerresult->subject; $discussionurl = new \moodle_url('/mod/forum/discuss.php', array('d' => $handlerresult->discussion)); $discussionurl->set_anchor('p' . $handlerresult->id); $a->discussionurl = $discussionurl->out(); $message = new \stdClass(); $message->plain = get_string('postbymailsuccess', 'mod_forum', $a); $message->html = get_string('postbymailsuccess_html', 'mod_forum', $a); return $message; }