/** * Routes to a valid action. * * @param string $action * @access public * @return string Rendered output for display. */ public function display_action($action) { $this->renderer->setup_page($this); $method = "action_{$action}"; if (!method_exists(__CLASS__, $method)) { throw new \invalid_parameter_exception("Unknown action: {$action}"); } $output = $this->{$method}(); $completion = new \completion_info($this->course); $completion->set_module_viewed($this->cm); $header = $this->header(); $footer = $this->renderer->footer(); return $header . $output . $footer; }
/** * Read page * * @throws \coding_exception * @return stdClass */ private function read_page() { global $PAGE, $COURSE; $cm = $PAGE->cm; $page = \theme_snap\local::get_page_mod($cm); $context = $PAGE->context; // Trigger module instance viewed event. $event = \mod_page\event\course_module_viewed::create(array('objectid' => $page->id, 'context' => $context)); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course', $COURSE); $event->add_record_snapshot('page', $page); $event->trigger(); // Update 'viewed' state if required by completion system. $completion = new \completion_info($COURSE); $completion->set_module_viewed($cm); $renderer = $PAGE->get_renderer('core', 'course'); $page->completionhtml = $renderer->course_section_cm_completion($COURSE, $completion, $cm); return $page; }
/** * Mark the activity completed (if required) and trigger the course_module_viewed event. * * @param stdClass $survey survey object * @param stdClass $course course object * @param stdClass $cm course module object * @param stdClass $context context object * @param string $viewed which page viewed * @since Moodle 3.0 */ function survey_view($survey, $course, $cm, $context, $viewed) { // Trigger course_module_viewed event. $params = array( 'context' => $context, 'objectid' => $survey->id, 'courseid' => $course->id, 'other' => array('viewed' => $viewed) ); $event = \mod_survey\event\course_module_viewed::create($params); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('survey', $survey); $event->trigger(); // Completion. $completion = new completion_info($course); $completion->set_module_viewed($cm); }
redirect($CFG->wwwroot . '/'); } // AJAX-capable? $useajax = false; // This will add a new class to the header so we can style differently. $CFG->blocksdrag = $useajax; $completion = new completion_info($course); if ($completion->is_enabled()) { $PAGE->requires->string_for_js('completion-title-manual-y', 'completion'); $PAGE->requires->string_for_js('completion-title-manual-n', 'completion'); $PAGE->requires->string_for_js('completion-alt-manual-y', 'completion'); $PAGE->requires->string_for_js('completion-alt-manual-n', 'completion'); $PAGE->requires->js_init_call('M.core_completion.init'); } $completion = new completion_info($course); $completion->set_module_viewed($subpage->get_course_module()); $PAGE->set_title(strip_tags($subpage->get_course()->shortname . ': ' . format_string($subpage->get_name()))); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($subpage->get_name())); if ($completion->is_enabled()) { // This value tracks whether there has been a dynamic change to the page. // It is used so that if a user does this - (a) set some tickmarks, (b) // go to another page, (c) clicks Back button - the page will // automatically reload. Otherwise it would start with the wrong tick // values. echo html_writer::start_tag('form', array('action' => '.', 'method' => 'get')); echo html_writer::start_tag('div'); echo html_writer::empty_tag('input', array('type' => 'hidden', 'id' => 'completion_dynamic_change', 'name' => 'completion_dynamic_change', 'value' => '0')); echo html_writer::end_tag('div'); echo html_writer::end_tag('form');
/** * Mark the activity completed (if required) and trigger the course_module_viewed event. * * @param stdClass $forum forum object * @param stdClass $course course object * @param stdClass $cm course module object * @param stdClass $context context object * @since Moodle 2.9 */ function forum_view($forum, $course, $cm, $context) { // Completion. $completion = new completion_info($course); $completion->set_module_viewed($cm); // Trigger course_module_viewed event. $params = array('context' => $context, 'objectid' => $forum->id); $event = \mod_forum\event\course_module_viewed::create($params); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('forum', $forum); $event->trigger(); }
/** * Mark the activity completed (if required) and trigger the course_module_viewed event. * * @param stdClass $book book object * @param stdClass $chapter chapter object * @param bool $islaschapter is the las chapter of the book? * @param stdClass $course course object * @param stdClass $cm course module object * @param stdClass $context context object * @since Moodle 3.0 */ function book_view($book, $chapter, $islastchapter, $course, $cm, $context) { // First case, we are just opening the book. if (empty($chapter)) { \mod_book\event\course_module_viewed::create_from_book($book, $context)->trigger(); } else { \mod_book\event\chapter_viewed::create_from_chapter($book, $context, $chapter)->trigger(); if ($islastchapter) { // We cheat a bit here in assuming that viewing the last page means the user viewed the whole book. $completion = new completion_info($course); $completion->set_module_viewed($cm); } } }
/** * Update the module completion status (set it viewed). * * @since Moodle 3.2 */ public function set_module_viewed() { $completion = new completion_info($this->get_course()); $completion->set_module_viewed($this->get_course_module()); }
/** * Notify that the glossary was viewed. * * This will trigger relevant events and activity completion. * * @param stdClass $glossary The glossary object. * @param stdClass $course The course object. * @param stdClass $cm The course module object. * @param stdClass $context The context object. * @param string $mode The mode in which the glossary was viewed. * @since Moodle 3.1 */ function glossary_view($glossary, $course, $cm, $context, $mode) { // Completion trigger. $completion = new completion_info($course); $completion->set_module_viewed($cm); // Trigger the course module viewed event. $event = \mod_glossary\event\course_module_viewed::create(array('objectid' => $glossary->id, 'context' => $context, 'other' => array('mode' => $mode))); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('glossary', $glossary); $event->trigger(); }
/** * Save all the users rating to db * @param int $userid * @param array $data */ public function save_ratings_to_db($userid, array $data) { /* @var $DB moodle_database */ global $DB; $transaction = $DB->start_delegated_transaction(); $loggingdata = array(); try { foreach ($data as $id => $rdata) { $rating = new stdClass(); $rating->rating = $rdata['rating']; $ratingexists = array('choiceid' => $rdata['choiceid'], 'userid' => $userid); if ($DB->record_exists('ratingallocate_ratings', $ratingexists)) { // The rating exists, we need to update its value // We get the id from the database $oldrating = $DB->get_record('ratingallocate_ratings', $ratingexists); if ($oldrating->{this_db\ratingallocate_ratings::RATING} != $rating->rating) { $rating->id = $oldrating->id; $DB->update_record('ratingallocate_ratings', $rating); //Logging array_push($loggingdata, array('choiceid' => $oldrating->choiceid, 'rating' => $rating->rating)); } } else { // Create a new rating in the table $rating->userid = $userid; $rating->choiceid = $rdata['choiceid']; $rating->ratingallocateid = $this->ratingallocateid; $DB->insert_record('ratingallocate_ratings', $rating); //Logging array_push($loggingdata, array('choiceid' => $rating->choiceid, 'rating' => $rating->rating)); } $completion = new completion_info($this->course); $completion->set_module_viewed($this->coursemodule); } $transaction->allow_commit(); //Logging $event = \mod_ratingallocate\event\rating_saved::create_simple(context_course::instance($this->course->id), $this->ratingallocateid, $loggingdata); $event->trigger(); } catch (Exception $e) { $transaction->rollback($e); } }
/** * Mark the activity completed (if required) and trigger the course_module_viewed event. * * @param stdClass $quiz quiz object * @param stdClass $course course object * @param stdClass $cm course module object * @param stdClass $context context object * @since Moodle 3.1 */ function quiz_view($quiz, $course, $cm, $context) { $params = array('objectid' => $quiz->id, 'context' => $context); $event = \mod_quiz\event\course_module_viewed::create($params); $event->add_record_snapshot('quiz', $quiz); $event->trigger(); // Completion. $completion = new completion_info($course); $completion->set_module_viewed($cm); }
$PAGE->set_pagelayout('print'); } // Add User's Register Navigation node if ($userToProcess) { $registerNavNode = $PAGE->navigation->find($cm->id, navigation_node::TYPE_ACTIVITY); $userNavNode = $registerNavNode->add($userToProcessFullname, $url); $userNavNode->make_active(); } // ================================================== // Logs User's action and update completion-by-view // ================================================== attendanceregister_add_to_log($register, $cm->id, $inputAction, $userId, $groupId); /// On View Completion [fixed with isse #52] // If current user is the selected user (and completion is enabled) mark module as viewed if ($userId == $USER->id && $completion->is_enabled($cm)) { $completion->set_module_viewed($cm, $userId); } // ============================================== // Start Page Rendering // ============================================== echo $OUTPUT->header(); $headingStr = $register->name . ($userId ? ': ' . $userToProcessFullname : ''); echo $OUTPUT->heading(format_string($headingStr)); // ============================================== // Pepare Offline Session insert form, if needed // ============================================== // If a userID is defined, offline sessions are enabled and the user may insert Self.certificatins... // ...prepare the Form for Self.Cert. // Process the form (if submitted) // Note that the User is always the CURRENT User (no UserId param is passed by the form) $doShowContents = true;
/** * Handle view action. * * @return string * @throws \coding_exception */ public function handle_view() { $event = course_module_viewed::create(array('objectid' => $this->cm->instance, 'context' => $this->context)); $event->add_record_snapshot('course', $this->course); $event->add_record_snapshot($this->cm->modname, $this->collaborate); $event->trigger(); if ($this->collaborate->sessionid === null && has_capability('mod/collaborate:addinstance', $this->context)) { collaborate_update_instance($this->collaborate); } // Completion tracking on view. $completion = new \completion_info($this->course); $completion->set_module_viewed($this->cm); return $this->renderer->view_action($this->collaborate, $this->cm); }
/** * Mark the activity completed (if required) and trigger the all_files_downloaded event. * * @param stdClass $folder folder object * @param stdClass $course course object * @param stdClass $cm course module object * @param stdClass $context context object * @since Moodle 3.1 */ function folder_downloaded($folder, $course, $cm, $context) { $params = array('context' => $context, 'objectid' => $folder->id); $event = \mod_folder\event\all_files_downloaded::create($params); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('folder', $folder); $event->trigger(); // Completion. $completion = new completion_info($course); $completion->set_module_viewed($cm); }
/** * Sets the dataform page. * * @param string $pagefile current page file * @param array $params */ public function set_page($pagefile = 'view', $params = null) { global $CFG, $PAGE, $USER, $OUTPUT; $htmloutput = ''; $this->_pagefile = $pagefile == 'external' ? 'view' : $pagefile; $params = (object) $params; $urlparams = array(); if (!empty($params->urlparams)) { foreach ($params->urlparams as $param => $value) { if ($value != 0 and $value != '') { $urlparams[$param] = $value; } } } // Make sure there is at least dataform id param. $urlparams['d'] = $this->id; // Get the edit mode. $urlparams['edit'] = optional_param('edit', -1, PARAM_BOOL); // MANAGER. $manager = has_capability('mod/dataform:managetemplates', $this->context); // LOGIN REQUIREMENT. if (empty($params->nologin)) { // Guest auto login. $autologinguest = false; if ($pagefile == 'view' or $pagefile == 'embed' or $pagefile == 'external') { $autologinguest = true; } // Require login. require_login($this->course->id, $autologinguest, $this->cm); } // RENEW if requested. if ($manager and !empty($urlparams['renew']) and confirm_sesskey()) { $returnurl = new \moodle_url('/mod/dataform/view.php', array('id' => $this->cm->id)); if (empty($urlparams['confirmed'])) { $PAGE->set_url('/mod/dataform/view.php', $urlparams); $message = get_string('renewconfirm', 'dataform'); $yesparams = array('id' => $this->cm->id, 'renew' => 1, 'sesskey' => sesskey(), 'confirmed' => 1); $confirmedurl = new moodle_url('/mod/dataform/view.php', $yesparams); $output = $this->renderer; $headerparams = array('heading' => get_string('renewactivity', 'dataform') . ': ' . $this->name, 'urlparams' => $urlparams); echo $output->header($headerparams); // Print a confirmation page. echo $output->confirm($message, $confirmedurl, $returnurl); echo $output->footer(); exit; } else { $this->reset(); rebuild_course_cache($this->course->id); redirect($returnurl); } } // RSS. if (!empty($params->rss)) { $this->set_page_rss(); } // COMMENTS. if (!empty($params->comments)) { require_once "{$CFG->dirroot}/comment/lib.php"; comment::init(); } $externalpage = $pagefile == 'external'; // EDITING (not on external pages). $this->set_page_editing_mode($pagefile, $urlparams); // AUTO REFRESH. if (!empty($urlparams['refresh']) and !$externalpage) { $PAGE->set_periodic_refresh_delay($urlparams['refresh']); } // PAGE LAYOUT. if (!empty($params->pagelayout) and !$externalpage) { $PAGE->set_pagelayout($params->pagelayout); } // COMPLETION Mark as viewed. if (!empty($params->completion) and !$externalpage) { require_once $CFG->libdir . '/completionlib.php'; $completion = new completion_info($this->course); $completion->set_module_viewed($this->cm); } // CSS. $htmloutput .= !empty($params->css) ? $this->set_page_css() : ''; // JS. if (!empty($params->js)) { $this->set_page_js(); } $PAGE->set_title($this->name); $PAGE->set_heading($this->course->fullname); // Set current view and view's page requirements only if activity ready (with default view) // And access allowed. if ($this->defaultview) { $currentviewid = !empty($urlparams['view']) ? $urlparams['view'] : $this->defaultview; // Ensure access allowed. $params = array('dataformid' => $this->id, 'viewid' => $currentviewid); if (mod_dataform\access\view_access::validate($params)) { if ($this->_currentview = $this->view_manager->get_view_by_id($currentviewid)) { $this->_currentview->set_page($pagefile, $urlparams); } } } // Notifications for not ready, early and past due. $this->set_notification_activity_not_ready($pagefile); return $htmloutput; }
/** * Render all discussions view, including add discussion button, etc... * * @param stdClass $forum - forum row * @return string */ public function render_discussionsview($forum) { global $CFG, $DB, $PAGE, $SESSION; ob_start(); // YAK! todo, fix this rubbish. require_once $CFG->dirroot . '/mod/hsuforum/lib.php'; require_once $CFG->libdir . '/completionlib.php'; require_once $CFG->libdir . '/accesslib.php'; $output = ''; $modinfo = get_fast_modinfo($forum->course); $forums = $modinfo->get_instances_of('hsuforum'); if (!isset($forums[$forum->id])) { print_error('invalidcoursemodule'); } $cm = $forums[$forum->id]; $id = $cm->id; // Forum instance id (id in course modules table) $f = $forum->id; // Forum ID $config = get_config('hsuforum'); if ($id) { if (!($course = $DB->get_record("course", array("id" => $cm->course)))) { print_error('coursemisconf'); } } else { if ($f) { if (!($course = $DB->get_record("course", array("id" => $forum->course)))) { print_error('coursemisconf'); } // move require_course_login here to use forced language for course // fix for MDL-6926 require_course_login($course, true, $cm); } else { print_error('missingparameter'); } } $context = \context_module::instance($cm->id); if (!empty($CFG->enablerssfeeds) && !empty($config->enablerssfeeds) && $forum->rsstype && $forum->rssarticles) { require_once "{$CFG->libdir}/rsslib.php"; $rsstitle = format_string($course->shortname, true, array('context' => \context_course::instance($course->id))) . ': ' . format_string($forum->name); rss_add_http_header($context, 'mod_hsuforum', $forum, $rsstitle); } // Mark viewed if required $completion = new \completion_info($course); $completion->set_module_viewed($cm); /// Some capability checks. if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) { notice(get_string("activityiscurrentlyhidden")); } if (!has_capability('mod/hsuforum:viewdiscussion', $context)) { notice(get_string('noviewdiscussionspermission', 'hsuforum')); } $params = array('context' => $context, 'objectid' => $forum->id); $event = \mod_hsuforum\event\course_module_viewed::create($params); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('hsuforum', $forum); $event->trigger(); if (!defined(AJAX_SCRIPT) || !AJAX_SCRIPT) { // Return here if we post or set subscription etc (but not if we are calling this via ajax). $SESSION->fromdiscussion = qualified_me(); } $PAGE->requires->js_init_call('M.mod_hsuforum.init', null, false, $this->get_js_module()); $output .= $this->svg_sprite(); $this->view($course, $cm, $forum, $context); // Don't allow non logged in users, or guest to try to manage subscriptions. if (isloggedin() && !isguestuser()) { $url = new \moodle_url('/mod/hsuforum/index.php', ['id' => $course->id]); $manageforumsubscriptions = get_string('manageforumsubscriptions', 'mod_hsuforum'); $output .= \html_writer::link($url, $manageforumsubscriptions); } $output = ob_get_contents() . $output; ob_end_clean(); return $output; }
/** * Mark the activity completed (if required) and trigger the page_viewed event. * * @param stdClass $wiki Wiki object. * @param stdClass $page Page object. * @param stdClass $course Course object. * @param stdClass $cm Course module object. * @param stdClass $context Context object. * @param int $uid Optional User ID. * @param array $other Optional Other params: title, wiki ID, group ID, groupanduser, prettyview. * @param stdClass $subwiki Optional Subwiki. * @since Moodle 3.1 */ function wiki_page_view($wiki, $page, $course, $cm, $context, $uid = null, $other = null, $subwiki = null) { // Trigger course_module_viewed event. $params = array('context' => $context, 'objectid' => $page->id); if ($uid != null) { $params['relateduserid'] = $uid; } if ($other != null) { $params['other'] = $other; } $event = \mod_wiki\event\page_viewed::create($params); $event->add_record_snapshot('wiki_pages', $page); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('wiki', $wiki); if ($subwiki != null) { $event->add_record_snapshot('wiki_subwikis', $subwiki); } $event->trigger(); // Completion. $completion = new completion_info($course); $completion->set_module_viewed($cm); }
} // Send a copy of message to the instructor if appropriate. if (!empty($sendtoself)) { $nonsubmitters->send_message($USER->id, $subject, $message); } $do = "emailsent"; } $params = array('id' => $id, 'do' => $do, 'view_context' => 'box_solid'); redirect(new moodle_url('/mod/turnitintooltwo/view.php', $params)); exit; break; } } // Enable activity completion on page view. $completion = new completion_info($course); $completion->set_module_viewed($cm); // Show header and navigation if ($viewcontext == "box" || $viewcontext == "box_solid") { $PAGE->set_pagelayout('embedded'); $turnitintooltwoview->output_header($cm, $course, $url, '', '', array(), "", "", true, '', ''); } else { $turnitintooltwoview->output_header($cm, $course, $url, $turnitintooltwoassignment->turnitintooltwo->name, $SITE->fullname, array(), "", "", true, $OUTPUT->update_module_button($cm->id, "turnitintooltwo"), ''); // Dropdown to filter by groups. $groupmode = groups_get_activity_groupmode($cm); if ($groupmode) { groups_get_activity_group($cm, true); groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $id . '&do=' . $do); } $turnitintooltwoview->draw_tool_tab_menu($cm, $do); } echo html_writer::start_tag('div', array('class' => 'mod_turnitintooltwo'));
/** * Read media resource * * @throws \coding_exception * @return stdClass */ private function read_media() { global $PAGE, $COURSE, $DB; $cm = $PAGE->cm; $context = \context_module::instance($cm->id); // Trigger module instance viewed event. $event = \mod_resource\event\course_module_viewed::create(array('objectid' => $cm->instance, 'context' => $context)); $resource = $DB->get_record('resource', array('id' => $cm->instance)); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course', $COURSE); $event->add_record_snapshot('resource', $resource); $event->trigger(); $resource->content = $this->get_media_html($resource, $context, $cm); // Update 'viewed' state if required by completion system. $completion = new \completion_info($COURSE); $completion->set_module_viewed($cm); $renderer = $PAGE->get_renderer('core', 'course'); $resource->completionhtml = $renderer->course_section_cm_completion($COURSE, $completion, $cm); return $resource; }