/** * Returns a list of items in the recycle bin for this course. * * @return array the list of items. */ public function get_items() { global $DB; $items = $DB->get_records('tool_recyclebin_category', array('categoryid' => $this->_categoryid)); foreach ($items as $item) { $item->name = get_course_display_name_for_list($item); } return $items; }
public function test_get_course_display_name_for_list() { global $CFG; $this->resetAfterTest(true); $course = $this->getDataGenerator()->create_course(array('shortname' => 'FROG101', 'fullname' => 'Introduction to pond life')); $CFG->courselistshortnames = 0; $this->assertEquals('Introduction to pond life', get_course_display_name_for_list($course)); $CFG->courselistshortnames = 1; $this->assertEquals('FROG101 Introduction to pond life', get_course_display_name_for_list($course)); }
/** * Returns localised name of enrol instance * * @param stdClass $instance (null is accepted too) * @return string */ public function get_instance_name($instance) { global $DB; if (empty($instance)) { $enrol = $this->get_name(); return get_string('pluginname', 'enrol_' . $enrol); } else { if (empty($instance->name)) { $enrol = $this->get_name(); $course = $DB->get_record('course', array('id' => $instance->customint1)); if ($course) { $coursename = format_string(get_course_display_name_for_list($course)); } else { // Use course id, if course is deleted. $coursename = $instance->customint1; } return get_string('pluginname', 'enrol_' . $enrol) . ' (' . $coursename . ')'; } else { return format_string($instance->name); } } }
/** * Construct contents of course_overview block * * @param array $courses list of courses in sorted order * @param array $overviews list of course overviews * @return string html to be displayed in course_overview block */ public function course_overview($courses, $overviews) { $html = ''; $config = get_config('block_course_overview'); $ismovingcourse = false; $courseordernumber = 0; $maxcourses = count($courses); $userediting = false; // Intialise string/icon etc if user is editing and courses > 1 if ($this->page->user_is_editing() && count($courses) > 1) { $userediting = true; // If ajaxenabled then include DND JS and replace link with move image. if (ajaxenabled()) { $this->page->requires->js_init_call('M.block_course_overview.add_handles'); } // Check if course is moving $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL); $movingcourseid = optional_param('courseid', 0, PARAM_INT); } // Render first movehere icon. if ($ismovingcourse) { // Remove movecourse param from url. $this->page->ensure_param_not_in_url('movecourse'); // Show moving course notice, so user knows what is being moved. $html .= $this->output->box_start('notice'); $a = new stdClass(); $a->fullname = $courses[$movingcourseid]->fullname; $a->cancellink = html_writer::link($this->page->url, get_string('cancel')); $html .= get_string('movingcourse', 'block_course_overview', $a); $html .= $this->output->box_end(); $moveurl = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid)); // Create move icon, so it can be used. $movetofirsticon = html_writer::empty_tag('img', array('src' => $this->output->pix_url('movehere'), 'alt' => get_string('movetofirst', 'block_course_overview', $courses[$movingcourseid]->fullname), 'title' => get_string('movehere'))); $moveurl = html_writer::link($moveurl, $movetofirsticon); $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } foreach ($courses as $key => $course) { // If moving course, then don't show course which needs to be moved. if ($ismovingcourse && $course->id == $movingcourseid) { continue; } $html .= $this->output->box_start('coursebox', "course-{$course->id}"); $html .= html_writer::start_tag('div', array('class' => 'course_title')); // If user is editing, then add move icons. if ($userediting && !$ismovingcourse) { $moveicon = html_writer::empty_tag('img', array('src' => $this->pix_url('t/move')->out(false), 'alt' => get_string('movecourse', 'block_course_overview', $course->fullname), 'title' => get_string('move'))); $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id)); $moveurl = html_writer::link($moveurl, $moveicon); $html .= html_writer::tag('div', $moveurl, array('class' => 'move')); } // No need to pass title through s() here as it will be done automatically by html_writer. $attributes = array('title' => $course->fullname); if ($course->id > 0) { if (empty($course->visible)) { $attributes['class'] = 'dimmed'; } $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id); $link = html_writer::link($courseurl, $coursefullname, $attributes); $html .= $this->output->heading($link, 2, 'title'); } else { $html .= $this->output->heading(html_writer::link(new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id=' . $course->remoteid)), format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); } $html .= $this->output->box('', 'flush'); $html .= html_writer::end_tag('div'); if (!empty($config->showchildren) && $course->id > 0) { // List children here. if ($children = block_course_overview_get_child_shortnames($course->id)) { $html .= html_writer::tag('span', $children, array('class' => 'coursechildren')); } } // If user is moving courses, then down't show overview. if (isset($overviews[$course->id]) && !$ismovingcourse) { $html .= $this->activity_display($course->id, $overviews[$course->id]); } $html .= $this->output->box('', 'flush'); $html .= $this->output->box_end(); $courseordernumber++; if ($ismovingcourse) { $moveurl = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid)); $a = new stdClass(); $a->movingcoursename = $courses[$movingcourseid]->fullname; $a->currentcoursename = $course->fullname; $movehereicon = html_writer::empty_tag('img', array('src' => $this->output->pix_url('movehere'), 'alt' => get_string('moveafterhere', 'block_course_overview', $a), 'title' => get_string('movehere'))); $moveurl = html_writer::link($moveurl, $movehereicon); $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } } // Wrap course list in a div and return. return html_writer::tag('div', $html, array('class' => 'course_list')); }
/** * Set the value of this element. If values can be added or are unknown, we will * make sure they exist in the options array. * @param string|array $value The value to set. * @return boolean */ public function setValue($value) { global $DB; $values = (array) $value; $coursestofetch = array(); foreach ($values as $onevalue) { if (!$this->optionExists($onevalue) && $onevalue !== '_qf__force_multiselect_submission') { array_push($coursestofetch, $onevalue); } } if (empty($coursestofetch)) { return $this->setSelected(array()); } // There is no API function to load a list of course from a list of ids. $ctxselect = context_helper::get_preload_record_columns_sql('ctx'); $fields = array('c.id', 'c.category', 'c.sortorder', 'c.shortname', 'c.fullname', 'c.idnumber', 'c.startdate', 'c.visible', 'c.cacherev'); list($whereclause, $params) = $DB->get_in_or_equal($coursestofetch, SQL_PARAMS_NAMED, 'id'); $sql = "SELECT " . join(',', $fields) . ", {$ctxselect}\n FROM {course} c\n JOIN {context} ctx ON c.id = ctx.instanceid AND ctx.contextlevel = :contextcourse\n WHERE c.id " . $whereclause . " ORDER BY c.sortorder"; $list = $DB->get_records_sql($sql, array('contextcourse' => CONTEXT_COURSE) + $params); $coursestoselect = array(); foreach ($list as $course) { context_helper::preload_from_record($course); // Make sure we can see the course. if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { continue; } $label = get_course_display_name_for_list($course); $this->addOption($label, $course->id); array_push($coursestoselect, $course->id); } return $this->setSelected($coursestoselect); }
function get_remote_courses() { global $CFG, $USER, $OUTPUT; if (!is_enabled_auth('mnet')) { // no need to query anything remote related return; } $icon = '<img src="' . $OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="" />'; // shortcut - the rest is only for logged in users! if (!isloggedin() || isguestuser()) { return false; } if ($courses = get_my_remotecourses()) { $this->content->items[] = get_string('remotecourses', 'mnet'); $this->content->icons[] = ''; foreach ($courses as $course) { $coursecontext = context_course::instance($course->id); $this->content->items[] = "<a title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" " . "href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}\">" . $icon . format_string(get_course_display_name_for_list($course)) . "</a>"; } // if we listed courses, we are done return true; } if ($hosts = get_my_remotehosts()) { $this->content->items[] = get_string('remotehosts', 'mnet'); $this->content->icons[] = ''; foreach ($USER->mnet_foreign_host_array as $somehost) { $this->content->items[] = $somehost['count'] . get_string('courseson', 'mnet') . '<a title="' . $somehost['name'] . '" href="' . $somehost['url'] . '">' . $icon . $somehost['name'] . '</a>'; } // if we listed hosts, done return true; } return false; }
<td><p><em>Day, time</em></p><p><em>Day, time</em></p></td> </tr> <tr> <td><strong>Lecturer</strong></td> <td>************</td> <td><a href="mailto:***@kent.ac.uk">***@kent.ac.uk</a></td> <td>01227 82****</td> <td><p><em>Day, time</em></p><p><em>Day, time</em></p></td></tr></tbody></table><em> </em> HTML5; $rule = \tool_cat\rule::from_record(array('id' => \tool_cat\rule::FAKE_RULE_ID, 'order' => 1, 'rule' => 'prepend_to', 'target' => 'section', 'targetid' => 0, 'datatype' => 'text', 'data' => serialize(array('text' => $summary)))); $rule->apply($courses); // Apply first section. foreach ($courses as $course) { // We can't use a rule for this. $DB->set_field('course_sections', 'name', get_course_display_name_for_list($course), array('course' => $course->id, 'section' => 0)); // Prepend an announcements forum. $rule = \tool_cat\rule::from_record(array('id' => \tool_cat\rule::FAKE_RULE_ID, 'order' => 1, 'rule' => 'append_to', 'target' => 'course', 'targetid' => null, 'datatype' => 'news', 'data' => serialize(array('intro' => 'Announcements relating to ' . $course->shortname . ' will be posted here.', 'showdescription' => 1)))); $rule->apply(array($course)); // Append a discussion forum. $rule = \tool_cat\rule::from_record(array('id' => \tool_cat\rule::FAKE_RULE_ID, 'order' => 1, 'rule' => 'append_to', 'target' => 'section', 'targetid' => '0', 'datatype' => 'activity', 'data' => serialize(array('activity' => 'forum', 'name' => 'Discussion Forum ', 'intro' => '<p>(optional) Use this Discussion Forum to discuss the material of ' . $course->shortname . ' with other students and/or staff.</p><p>Please note that posts seeking (or providing) direct solutions to coursework, either assessed or unassessed, are not permitted.</p>', 'showdescription' => 1)))); $rule->apply(array($course)); } // Apply a rule to prepend to the section. $rule = \tool_cat\rule::from_record(array('id' => \tool_cat\rule::FAKE_RULE_ID, 'order' => 1, 'rule' => 'prepend_to', 'target' => 'section', 'targetid' => '0', 'datatype' => 'activity', 'data' => serialize(array('activity' => 'aspirelists', 'name' => 'Reading list')))); $rule->apply($courses); // Append a URL mod to the 7th section. $rule = \tool_cat\rule::from_record(array('id' => \tool_cat\rule::FAKE_RULE_ID, 'order' => 1, 'rule' => 'append_to', 'target' => 'section', 'targetid' => '6', 'datatype' => 'activity', 'data' => serialize(array('activity' => 'url', 'name' => 'Past exam papers Link', 'url' => '')))); $rule->apply($courses); // So we can work something out. print_r(array_keys($courses));
/** * This function is used to generate and display selector form * * @param report_courselog_renderable $reportlog log report. */ public function report_selector_form(report_courselog_renderable $reportlog) { echo html_writer::start_tag('form', array('class' => 'logselecform', 'action' => $reportlog->url, 'method' => 'get')); echo html_writer::start_div(); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'chooselog', 'value' => '1')); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'showusers', 'value' => $reportlog->showusers)); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'showcourses', 'value' => $reportlog->showcourses)); $selectedcourseid = empty($reportlog->course) ? 0 : $reportlog->course->id; // Add course selector. $sitecontext = context_system::instance(); $courses = $reportlog->get_course_list(); if (!empty($courses) && $reportlog->showcourses) { echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide')); echo html_writer::select($courses, "id", $selectedcourseid, null); } else { $courses = array(); $courses[$selectedcourseid] = get_course_display_name_for_list($reportlog->course) . ($selectedcourseid == SITEID ? ' (' . get_string('site') . ') ' : ''); echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide')); echo html_writer::select($courses, "id", $selectedcourseid, false); // Check if user is admin and this came because of limitation on number of courses to show in dropdown. if (has_capability('report/log:view', $sitecontext)) { $a = new stdClass(); $a->url = new moodle_url('/report/courselog/index.php', array('chooselog' => 0, 'group' => $reportlog->get_selected_group(), 'user' => $reportlog->userid, 'id' => $selectedcourseid, 'date' => $reportlog->date, 'modid' => $reportlog->modid, 'showcourses' => 1, 'showusers' => $reportlog->showusers)); $a->url = $a->url->out(false); print_string('logtoomanycourses', 'moodle', $a); } } // Add group selector. $groups = $reportlog->get_group_list(); if (!empty($groups)) { echo html_writer::label(get_string('selectagroup'), 'menugroup', false, array('class' => 'accesshide')); echo html_writer::select($groups, "group", $reportlog->groupid, get_string("allgroups")); } // Add user selector. $users = $reportlog->get_user_list(); if ($reportlog->showusers) { echo html_writer::label(get_string('selctauser'), 'menuuser', false, array('class' => 'accesshide')); echo html_writer::select($users, "user", $reportlog->userid, get_string("allparticipants")); } else { $users = array(); if (!empty($reportlog->userid)) { $users[$reportlog->userid] = $reportlog->get_selected_user_fullname(); } else { $users[0] = get_string('allparticipants'); } echo html_writer::label(get_string('selctauser'), 'menuuser', false, array('class' => 'accesshide')); echo html_writer::select($users, "user", $reportlog->userid, false); $a = new stdClass(); $a->url = new moodle_url('/report/courselog/index.php', array('chooselog' => 0, 'group' => $reportlog->get_selected_group(), 'user' => $reportlog->userid, 'id' => $selectedcourseid, 'date' => $reportlog->date, 'modid' => $reportlog->modid, 'showusers' => 1, 'showcourses' => $reportlog->showcourses)); $a->url = $a->url->out(false); print_string('logtoomanyusers', 'moodle', $a); } // Add date selector. $dates = $reportlog->get_date_options(); echo html_writer::label(get_string('date'), 'menudate', false, array('class' => 'accesshide')); echo html_writer::select($dates, "date", $reportlog->date, get_string("alldays")); // Add activity selector. $activities = $reportlog->get_activities_list(); echo html_writer::label(get_string('activities'), 'menumodid', false, array('class' => 'accesshide')); echo html_writer::select($activities, "modid", $reportlog->modid, get_string("allactivities")); // Add actions selector. echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide')); echo html_writer::select($reportlog->get_actions(), 'modaction', $reportlog->action, get_string("allactions")); // Add edulevel. $edulevel = $reportlog->get_edulevel_options(); echo html_writer::label(get_string('edulevel'), 'menuedulevel', false, array('class' => 'accesshide')); echo html_writer::select($edulevel, 'edulevel', $reportlog->edulevel, false); // Add reader option. // If there is some reader available then only show submit button. $readers = $reportlog->get_readers(true); if (!empty($readers)) { if (count($readers) == 1) { $attributes = array('type' => 'hidden', 'name' => 'logreader', 'value' => key($readers)); echo html_writer::empty_tag('input', $attributes); } else { echo html_writer::label(get_string('selectlogreader', 'report_courselog'), 'menureader', false, array('class' => 'accesshide')); echo html_writer::select($readers, 'logreader', $reportlog->selectedlogreader, false); } echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('gettheselogs'))); } echo html_writer::end_div(); echo html_writer::end_tag('form'); }
/** * Print a description of a course, suitable for browsing in a list. * * @param object $course the course object. * @param string $highlightterms (optional) some search terms that should be highlighted in the display. */ function print_course($course, $highlightterms = '') { global $CFG, $USER, $DB, $OUTPUT; $context = get_context_instance(CONTEXT_COURSE, $course->id); // Rewrite file URLs so that they are correct $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL); echo html_writer::start_tag('div', array('class' => 'coursebox clearfix')); echo html_writer::start_tag('div', array('class' => 'info')); echo html_writer::start_tag('h3', array('class' => 'name')); $linkhref = new moodle_url('/course/view.php', array('id' => $course->id)); $coursename = get_course_display_name_for_list($course); $linktext = highlight($highlightterms, format_string($coursename)); $linkparams = array('title' => get_string('entercourse')); if (empty($course->visible)) { $linkparams['class'] = 'dimmed'; } echo html_writer::link($linkhref, $linktext, $linkparams); echo html_writer::end_tag('h3'); /// first find all roles that are supposed to be displayed if (!empty($CFG->coursecontact)) { $managerroles = explode(',', $CFG->coursecontact); $namesarray = array(); $rusers = array(); if (!isset($course->managers)) { $rusers = get_role_users($managerroles, $context, true, 'ra.id AS raid, u.id, u.username, u.firstname, u.lastname, r.name AS rolename, r.sortorder, r.id AS roleid', 'r.sortorder ASC, u.lastname ASC'); } else { // use the managers array if we have it for perf reasosn // populate the datastructure like output of get_role_users(); foreach ($course->managers as $manager) { $u = new stdClass(); $u = $manager->user; $u->roleid = $manager->roleid; $u->rolename = $manager->rolename; $rusers[] = $u; } } /// Rename some of the role names if needed if (isset($context)) { $aliasnames = $DB->get_records('role_names', array('contextid' => $context->id), '', 'roleid,contextid,name'); } $namesarray = array(); $canviewfullnames = has_capability('moodle/site:viewfullnames', $context); foreach ($rusers as $ra) { if (isset($namesarray[$ra->id])) { // only display a user once with the higest sortorder role continue; } if (isset($aliasnames[$ra->roleid])) { $ra->rolename = $aliasnames[$ra->roleid]->name; } $fullname = fullname($ra, $canviewfullnames); $namesarray[$ra->id] = format_string($ra->rolename) . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $ra->id, 'course' => SITEID)), $fullname); } if (!empty($namesarray)) { echo html_writer::start_tag('ul', array('class' => 'teachers')); foreach ($namesarray as $name) { echo html_writer::tag('li', $name); } echo html_writer::end_tag('ul'); } } echo html_writer::end_tag('div'); // End of info div echo html_writer::start_tag('div', array('class' => 'summary')); $options = new stdClass(); $options->noclean = true; $options->para = false; $options->overflowdiv = true; if (!isset($course->summaryformat)) { $course->summaryformat = FORMAT_MOODLE; } echo highlight($highlightterms, format_text($course->summary, $course->summaryformat, $options, $course->id)); if ($icons = enrol_get_course_info_icons($course)) { echo html_writer::start_tag('div', array('class' => 'enrolmenticons')); foreach ($icons as $icon) { echo $OUTPUT->render($icon); } echo html_writer::end_tag('div'); // End of enrolmenticons div } echo html_writer::end_tag('div'); // End of summary div echo html_writer::end_tag('div'); // End of coursebox div }
/** * This function is used to generate and display Mnet selector form * * @global stdClass $USER * @global stdClass $CFG * @global stdClass $SITE * @global moodle_database $DB * @global core_renderer $OUTPUT * @global stdClass $SESSION * @uses CONTEXT_SYSTEM * @uses COURSE_MAX_COURSES_PER_DROPDOWN * @uses CONTEXT_COURSE * @uses SEPARATEGROUPS * @param int $hostid host id * @param stdClass $course course instance * @param int $selecteduser id of the selected user * @param string $selecteddate Date selected * @param string $modname course_module->id * @param string $modid number or 'site_errors' * @param string $modaction an action as recorded in the logs * @param int $selectedgroup Group to display * @param int $showcourses whether to show courses if we're over our limit. * @param int $showusers whether to show users if we're over our limit. * @param string $logformat Format of the logs (downloadascsv, showashtml, downloadasods, downloadasexcel) * @return void */ function report_log_print_mnet_selector_form($hostid, $course, $selecteduser = 0, $selecteddate = 'today', $modname = "", $modid = 0, $modaction = '', $selectedgroup = -1, $showcourses = 0, $showusers = 0, $logformat = 'showashtml') { global $USER, $CFG, $SITE, $DB, $OUTPUT, $SESSION; require_once $CFG->dirroot . '/mnet/peer.php'; $mnet_peer = new mnet_peer(); $mnet_peer->set_id($hostid); $sql = "SELECT DISTINCT course, hostid, coursename FROM {mnet_log}"; $courses = $DB->get_records_sql($sql); $remotecoursecount = count($courses); // first check to see if we can override showcourses and showusers $numcourses = $remotecoursecount + $DB->count_records('course'); if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { $showcourses = 1; } $sitecontext = context_system::instance(); // Context for remote data is always SITE // Groups for remote data are always OFF if ($hostid == $CFG->mnet_localhost_id) { $context = context_course::instance($course->id); /// Setup for group handling. if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { $selectedgroup = -1; $showgroups = false; } else { if ($course->groupmode) { $showgroups = true; } else { $selectedgroup = 0; $showgroups = false; } } if ($selectedgroup === -1) { if (isset($SESSION->currentgroup[$course->id])) { $selectedgroup = $SESSION->currentgroup[$course->id]; } else { $selectedgroup = groups_get_all_groups($course->id, $USER->id); if (is_array($selectedgroup)) { $selectedgroup = array_shift(array_keys($selectedgroup)); $SESSION->currentgroup[$course->id] = $selectedgroup; } else { $selectedgroup = 0; } } } } else { $context = $sitecontext; } // Get all the possible users $users = array(); // Define limitfrom and limitnum for queries below // If $showusers is enabled... don't apply limitfrom and limitnum $limitfrom = empty($showusers) ? 0 : ''; $limitnum = empty($showusers) ? COURSE_MAX_USERS_PER_DROPDOWN + 1 : ''; // If looking at a different host, we're interested in all our site users if ($hostid == $CFG->mnet_localhost_id && $course->id != SITEID) { $courseusers = get_enrolled_users($context, '', $selectedgroup, 'u.id, ' . get_all_user_name_fields(true, 'u'), null, $limitfrom, $limitnum); } else { // this may be a lot of users :-( $courseusers = $DB->get_records('user', array('deleted' => 0), 'lastaccess DESC', 'id, ' . get_all_user_name_fields(true), $limitfrom, $limitnum); } if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) { $showusers = 1; } if ($showusers) { if ($courseusers) { foreach ($courseusers as $courseuser) { $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); } } $users[$CFG->siteguest] = get_string('guestuser'); } // Get all the hosts that have log records $sql = "select distinct\n h.id,\n h.name\n from\n {mnet_host} h,\n {mnet_log} l\n where\n h.id = l.hostid\n order by\n h.name"; if ($hosts = $DB->get_records_sql($sql)) { foreach ($hosts as $host) { $hostarray[$host->id] = $host->name; } } $hostarray[$CFG->mnet_localhost_id] = $SITE->fullname; asort($hostarray); $dropdown = array(); foreach ($hostarray as $hostid => $name) { $courses = array(); $sites = array(); if ($CFG->mnet_localhost_id == $hostid) { if (has_capability('report/log:view', $sitecontext) && $showcourses) { if ($ccc = $DB->get_records("course", null, "fullname", "id,shortname,fullname,category")) { foreach ($ccc as $cc) { if ($cc->id == SITEID) { $sites["{$hostid}/{$cc->id}"] = format_string($cc->fullname) . ' (' . get_string('site') . ')'; } else { $courses["{$hostid}/{$cc->id}"] = format_string(get_course_display_name_for_list($cc)); } } } } } else { if (has_capability('report/log:view', $sitecontext) && $showcourses) { $sql = "SELECT DISTINCT course, coursename FROM {mnet_log} where hostid = ?"; if ($ccc = $DB->get_records_sql($sql, array($hostid))) { foreach ($ccc as $cc) { if (1 == $cc->course) { // TODO: this might be wrong - site course may have another id $sites["{$hostid}/{$cc->course}"] = $cc->coursename . ' (' . get_string('site') . ')'; } else { $courses["{$hostid}/{$cc->course}"] = $cc->coursename; } } } } } asort($courses); $dropdown[] = array($name => $sites + $courses); } $activities = array(); $selectedactivity = ""; $modinfo = get_fast_modinfo($course); if (!empty($modinfo->cms)) { $section = 0; $thissection = array(); foreach ($modinfo->cms as $cm) { if (!$cm->uservisible || !$cm->has_view()) { continue; } if ($cm->sectionnum > 0 and $section != $cm->sectionnum) { $activities[] = $thissection; $thissection = array(); } $section = $cm->sectionnum; $modname = strip_tags($cm->get_formatted_name()); if (core_text::strlen($modname) > 55) { $modname = core_text::substr($modname, 0, 50) . "..."; } if (!$cm->visible) { $modname = "(" . $modname . ")"; } $key = get_section_name($course, $cm->sectionnum); if (!isset($thissection[$key])) { $thissection[$key] = array(); } $thissection[$key][$cm->id] = $modname; if ($cm->id == $modid) { $selectedactivity = "{$cm->id}"; } } if (!empty($thissection)) { $activities[] = $thissection; } } if (has_capability('report/log:view', $sitecontext) && !$course->category) { $activities["site_errors"] = get_string("siteerrors"); if ($modid === "site_errors") { $selectedactivity = "site_errors"; } } $strftimedate = get_string("strftimedate"); $strftimedaydate = get_string("strftimedaydate"); asort($users); // Prepare the list of action options. $actions = array('view' => get_string('view'), 'add' => get_string('add'), 'update' => get_string('update'), 'delete' => get_string('delete'), '-view' => get_string('allchanges')); // Get all the possible dates // Note that we are keeping track of real (GMT) time and user time // User time is only used in displays - all calcs and passing is GMT $timenow = time(); // GMT // What day is it now for the user, and when is midnight that day (in GMT). $timemidnight = $today = usergetmidnight($timenow); // Put today up the top of the list $dates = array("0" => get_string('alldays'), "{$timemidnight}" => get_string("today") . ", " . userdate($timenow, $strftimedate)); if (!$course->startdate or $course->startdate > $timenow) { $course->startdate = $course->timecreated; } $numdates = 1; while ($timemidnight > $course->startdate and $numdates < 365) { $timemidnight = $timemidnight - 86400; $timenow = $timenow - 86400; $dates["{$timemidnight}"] = userdate($timenow, $strftimedaydate); $numdates++; } if ($selecteddate === "today") { $selecteddate = $today; } echo "<form class=\"logselectform\" action=\"{$CFG->wwwroot}/report/log/index.php\" method=\"get\">\n"; echo "<div>\n"; //invisible fieldset here breaks wrapping echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n"; echo "<input type=\"hidden\" name=\"showusers\" value=\"{$showusers}\" />\n"; echo "<input type=\"hidden\" name=\"showcourses\" value=\"{$showcourses}\" />\n"; if (has_capability('report/log:view', $sitecontext) && $showcourses) { $cid = empty($course->id) ? '1' : $course->id; echo html_writer::label(get_string('selectacoursesite'), 'menuhost_course', false, array('class' => 'accesshide')); echo html_writer::select($dropdown, "host_course", $hostid . '/' . $cid); } else { $courses = array(); $courses[$course->id] = get_course_display_name_for_list($course) . (empty($course->category) ? ' (' . get_string('site') . ') ' : ''); echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide')); echo html_writer::select($courses, "id", $course->id, false); if (has_capability('report/log:view', $sitecontext)) { $a = new stdClass(); $a->url = "{$CFG->wwwroot}/report/log/index.php?chooselog=0&group={$selectedgroup}&user={$selecteduser}" . "&id={$course->id}&date={$selecteddate}&modid={$selectedactivity}&showcourses=1&showusers={$showusers}"; print_string('logtoomanycourses', 'moodle', $a); } } if ($showgroups) { if ($cgroups = groups_get_all_groups($course->id)) { foreach ($cgroups as $cgroup) { $groups[$cgroup->id] = $cgroup->name; } } else { $groups = array(); } echo html_writer::label(get_string('selectagroup'), 'menugroup', false, array('class' => 'accesshide')); echo html_writer::select($groups, "group", $selectedgroup, get_string("allgroups")); } if ($showusers) { echo html_writer::label(get_string('participantslist'), 'menuuser', false, array('class' => 'accesshide')); echo html_writer::select($users, "user", $selecteduser, get_string("allparticipants")); } else { $users = array(); if (!empty($selecteduser)) { $user = $DB->get_record('user', array('id' => $selecteduser)); $users[$selecteduser] = fullname($user); } else { $users[0] = get_string('allparticipants'); } echo html_writer::label(get_string('participantslist'), 'menuuser', false, array('class' => 'accesshide')); echo html_writer::select($users, "user", $selecteduser, false); $a = new stdClass(); $a->url = "{$CFG->wwwroot}/report/log/index.php?chooselog=0&group={$selectedgroup}&user={$selecteduser}" . "&id={$course->id}&date={$selecteddate}&modid={$selectedactivity}&showusers=1&showcourses={$showcourses}"; print_string('logtoomanyusers', 'moodle', $a); } echo html_writer::label(get_string('date'), 'menudate', false, array('class' => 'accesshide')); echo html_writer::select($dates, "date", $selecteddate, false); echo html_writer::label(get_string('showreports'), 'menumodid', false, array('class' => 'accesshide')); echo html_writer::select($activities, "modid", $selectedactivity, get_string("allactivities")); echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide')); echo html_writer::select($actions, 'modaction', $modaction, get_string("allactions")); $logformats = array('showashtml' => get_string('displayonpage'), 'downloadascsv' => get_string('downloadtext'), 'downloadasods' => get_string('downloadods'), 'downloadasexcel' => get_string('downloadexcel')); echo html_writer::label(get_string('logsformat', 'report_log'), 'menulogformat', false, array('class' => 'accesshide')); echo html_writer::select($logformats, 'logformat', $logformat, false); echo '<input type="submit" value="' . get_string('gettheselogs') . '" />'; echo '</div>'; echo '</form>'; }
/** * get content */ public function get_content() { global $OUTPUT, $CFG; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; // get courses list in wich logged user was enrolled $courses = block_resources_get_all_resources(); if (!$courses) { $this->content->text .= 'There are no courses'; return $this->content; } // --------- cycle by courses foreach ($courses as $course) { if ($course->resources || $course->videoresources) { // render corse box $this->content->text .= $OUTPUT->box_start('coursebox', "course-{$course->id}") . html_writer::start_tag('div', array('class' => 'course_title')); $attributes = array('title' => $course->fullname); if ($course->id > 0) { if (empty($course->visible)) { $attributes['class'] = 'dimmed'; } $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id); $link = html_writer::link($courseurl, $coursefullname, $attributes); $this->content->text .= $OUTPUT->heading($link, 2, 'title'); } else { $this->content->text .= $this->output->heading(html_writer::link(new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id=' . $course->remoteid)), format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); } // render resources foreach ($course->resources as $resource) { /// --- Render one resource item $this->content->text .= html_writer::start_div('resource_item') . html_writer::start_div('resource_body') . html_writer::start_div('resource_title') . html_writer::link($resource->url, $resource->title, array('target' => '_blank', 'class' => 'resourcelink', 'data-objectid' => $resource->id)); $this->content->text .= html_writer::end_div(); // end of resource_title // render Author and source if (!empty($resource->author)) { $this->content->text .= html_writer::start_div('resource_metadata') . html_writer::tag('strong', 'Author') . ': ' . $resource->author . html_writer::end_div(); } if (!empty($resource->source)) { $this->content->text .= html_writer::start_div('resource_metadata') . html_writer::tag('strong', 'Source') . ': ' . $resource->source . html_writer::end_div(); } if (!empty($resource->avgrate)) { $this->content->text .= html_writer::start_div('resource_metadata') . html_writer::tag('strong', 'AVG rating') . ': ' . $resource->avgrate . html_writer::end_div(); } //echo html_writer::div($resource->description, 'resource_description'); $this->content->text .= html_writer::end_div(); // end of Resource body --- $this->content->text .= html_writer::end_div(); // end of Resource Item --- } // render videoresources foreach ($course->videoresources as $videoresource) { /// --- Render one resource item $url = new moodle_url("{$CFG->wwwroot}/mod/videoresource/view.php", array('id' => $videoresource->id)); $this->content->text .= html_writer::start_div('resource_item') . html_writer::start_div('resource_body') . html_writer::start_div('resource_title') . html_writer::link($url->out(false), $videoresource->name, array('target' => '_blank', 'class' => 'resourcelink', 'data-objectid' => $videoresource->id)); $this->content->text .= html_writer::end_div(); // end of resource_title //echo html_writer::div($resource->description, 'resource_description'); $this->content->text .= html_writer::end_div(); // end of Resource body --- $this->content->text .= html_writer::end_div(); // end of Resource Item --- } //$this->content->text .= $OUTPUT->box('', 'flush'); $this->content->text .= html_writer::end_tag('div'); $this->content->text .= $OUTPUT->box_end(); } } if (!empty($this->content->text)) { $this->content->text .= html_writer::link($CFG->wwwroot . '/blocks/resources/tocsv.php', 'Download list (CSV)'); } else { $this->content->text .= 'There are no resources'; //$this->content->text .= $OUTPUT->notification(get_string('no_resources', 'resourcelib'), 'redirectmessage'); } return $this->content; }
/** * Fill the table for displaying. * * @param bool $activitylink If this report link to the activity report or the user report. * @param bool $studentcoursesonly Only show courses that the user is a student of. */ public function fill_table($activitylink = false, $studentcoursesonly = false) { global $CFG, $DB, $OUTPUT, $USER; if ($studentcoursesonly && count($this->studentcourseids) == 0) { return false; } // Only show user's courses instead of all courses. if ($this->courses) { $coursesdata = $this->setup_courses_data($studentcoursesonly); foreach ($coursesdata as $coursedata) { $course = $coursedata['course']; $coursecontext = $coursedata['context']; $finalgrade = $coursedata['finalgrade']; $courseitem = $coursedata['courseitem']; $coursename = format_string(get_course_display_name_for_list($course), true, array('context' => $coursecontext)); // Link to the activity report version of the user grade report. if ($activitylink) { $courselink = html_writer::link(new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $this->user->id)), $coursename); } else { $courselink = html_writer::link(new moodle_url('/grade/report/user/index.php', array('id' => $course->id, 'userid' => $this->user->id)), $coursename); } $data = array($courselink, grade_format_gradevalue($finalgrade, $courseitem, true)); if ($this->showrank['any']) { if ($this->showrank[$course->id] && !is_null($finalgrade)) { $rank = $coursedata['rank']; $numusers = $coursedata['numusers']; $data[] = "{$rank}/{$numusers}"; } else { // No grade, no rank. // Or this course wants rank hidden. $data[] = '-'; } } $this->table->add_data($data); } return true; } else { echo $OUTPUT->notification(get_string('notenrolled', 'grades'), 'notifymessage'); return false; } }
function test_get_course_display_name_for_list() { global $CFG; $course = (object) array('shortname' => 'FROG101', 'fullname' => 'Introduction to pond life'); // Store config value in case other tests rely on it $oldcfg = $CFG->courselistshortnames; $CFG->courselistshortnames = 0; $this->assertEqual('Introduction to pond life', get_course_display_name_for_list($course)); $CFG->courselistshortnames = 1; $this->assertEqual('FROG101 Introduction to pond life', get_course_display_name_for_list($course)); $CFG->courselistshortnames = $oldcfg; }
/** * Build the HTML to display a single course in a filtered list * * @param object $course The course to display * @return string HTML to display a link to a course */ private function _print_single_course($course) { global $CFG, $USER; $dimmed = $course->visible ? '' : ' dimmed'; $linkcss = "fcl-course-link" . $dimmed; $new = ''; if ($this->fclconfig->showstatus) { if (isset($USER->lastcourseaccess[$course->id])) { if ($course->timemodified > $USER->lastcourseaccess[$course->id]) { if (!isset($USER->currentcourseaccess[$course->id])) { $new = html_writer::tag('i', '', array('class' => 'fa fa-star green' . $dimmed, 'title' => get_string('updated', 'block_filtered_course_list'), 'data-toggle' => "tooltip", 'data-content' => get_string('updated', 'block_filtered_course_list'), 'href' => '#')); } } } else { if (!isset($USER->currentcourseaccess[$course->id])) { $new = html_writer::tag('i', '', array('class' => 'fa fa-asterisk red' . $dimmed, 'title' => get_string('neverseen', 'block_filtered_course_list'), 'data-toggle' => "tooltip", 'data-content' => get_string('neverseen', 'block_filtered_course_list'), 'href' => '#')); } } } $html = html_writer::tag('li', $new . ' ' . html_writer::tag('a', get_course_display_name_for_list($course), array('href' => $CFG->wwwroot . '/course/view.php?id=' . $course->id, 'title' => format_string($course->shortname), 'class' => $linkcss))); return $html; }
/** * Returns blog info - cm, oublog * Also checks is a valid blog for import * (Throws exception on access error) * @param int $cmid * @param int $userid * @return array (cm id, oublog id, context id, blog name, course shortname) */ function oublog_import_getbloginfo($cmid, $userid = 0) { global $DB, $USER; if ($userid == 0) { $userid = $USER->id; } $bcourse = $DB->get_record_select('course', 'id = (SELECT course FROM {course_modules} WHERE id = ?)', array($cmid), '*', MUST_EXIST); $bmodinfo = get_fast_modinfo($bcourse, $userid); $bcm = $bmodinfo->get_cm($cmid); if ($bcm->modname !== 'oublog') { throw new moodle_exception('invalidcoursemodule', 'error'); } if (!($boublog = $DB->get_record('oublog', array('id' => $bcm->instance)))) { throw new moodle_exception('invalidcoursemodule', 'error'); } $bcontext = context_module::instance($bcm->id); $canview = $bcm->uservisible; if ($canview) { $canview = has_capability('mod/oublog:view', $bcontext, $userid); } if ($boublog->global) { // Ignore uservisible for global blog and only check cap. $canview = has_capability('mod/oublog:viewpersonal', context_system::instance(), $userid); } if (!$canview || !$boublog->global && $boublog->individual == OUBLOG_NO_INDIVIDUAL_BLOGS) { // Not allowed to get pages from selected blog. throw new moodle_exception('import_notallowed', 'oublog', '', oublog_get_displayname($boublog)); } if ($boublog->global) { $boublogname = $DB->get_field('oublog_instances', 'name', array('oublogid' => $boublog->id, 'userid' => $userid)); $shortname = ''; } else { $boublogname = $bcm->get_course()->shortname . ' ' . get_course_display_name_for_list($bcm->get_course()) . ' : ' . $bcm->get_formatted_name(); $shortname = $bcm->get_course()->shortname; } return array($bcm->id, $boublog->id, $bcontext->id, $boublogname, $shortname); }
/** * Returns localised visible name. * * @return string */ public function get_visible_name() { return $this->course->id == SITEID ? get_string('frontpage', 'admin') : format_string(get_course_display_name_for_list($this->course), true, array('context' => $this->context)); }
/** * Search courses following the specified criteria. * * @param string $criterianame Criteria name (search, modulelist (only admins), blocklist (only admins), tagid) * @param string $criteriavalue Criteria value * @param int $page Page number (for pagination) * @param int $perpage Items per page * @param array $requiredcapabilities Optional list of required capabilities (used to filter the list). * @param int $limittoenrolled Limit to only enrolled courses * @return array of course objects and warnings * @since Moodle 3.0 * @throws moodle_exception */ public static function search_courses($criterianame, $criteriavalue, $page = 0, $perpage = 0, $requiredcapabilities = array(), $limittoenrolled = 0) { global $CFG; require_once $CFG->libdir . '/coursecatlib.php'; $warnings = array(); $parameters = array('criterianame' => $criterianame, 'criteriavalue' => $criteriavalue, 'page' => $page, 'perpage' => $perpage, 'requiredcapabilities' => $requiredcapabilities); $params = self::validate_parameters(self::search_courses_parameters(), $parameters); self::validate_context(context_system::instance()); $allowedcriterianames = array('search', 'modulelist', 'blocklist', 'tagid'); if (!in_array($params['criterianame'], $allowedcriterianames)) { throw new invalid_parameter_exception('Invalid value for criterianame parameter (value: ' . $params['criterianame'] . '),' . 'allowed values are: ' . implode(',', $allowedcriterianames)); } if ($params['criterianame'] == 'modulelist' or $params['criterianame'] == 'blocklist') { require_capability('moodle/site:config', context_system::instance()); } $paramtype = array('search' => PARAM_RAW, 'modulelist' => PARAM_PLUGIN, 'blocklist' => PARAM_INT, 'tagid' => PARAM_INT); $params['criteriavalue'] = clean_param($params['criteriavalue'], $paramtype[$params['criterianame']]); // Prepare the search API options. $searchcriteria = array(); $searchcriteria[$params['criterianame']] = $params['criteriavalue']; $options = array(); if ($params['perpage'] != 0) { $offset = $params['page'] * $params['perpage']; $options = array('offset' => $offset, 'limit' => $params['perpage']); } // Search the courses. $courses = coursecat::search_courses($searchcriteria, $options, $params['requiredcapabilities']); $totalcount = coursecat::search_courses_count($searchcriteria, $options, $params['requiredcapabilities']); if (!empty($limittoenrolled)) { // Get the courses where the current user has access. $enrolled = enrol_get_my_courses(array('id', 'cacherev')); } $finalcourses = array(); $categoriescache = array(); foreach ($courses as $course) { if (!empty($limittoenrolled)) { // Filter out not enrolled courses. if (!isset($enrolled[$course->id])) { $totalcount--; continue; } } $coursecontext = context_course::instance($course->id); // Category information. if (!isset($categoriescache[$course->category])) { $categoriescache[$course->category] = coursecat::get($course->category); } $category = $categoriescache[$course->category]; // Retrieve course overfiew used files. $files = array(); foreach ($course->get_course_overviewfiles() as $file) { $fileurl = moodle_url::make_webservice_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename())->out(false); $files[] = array('filename' => $file->get_filename(), 'fileurl' => $fileurl, 'filesize' => $file->get_filesize()); } // Retrieve the course contacts, // we need here the users fullname since if we are not enrolled can be difficult to obtain them via other Web Services. $coursecontacts = array(); foreach ($course->get_course_contacts() as $contact) { $coursecontacts[] = array('id' => $contact['user']->id, 'fullname' => $contact['username']); } // Allowed enrolment methods (maybe we can self-enrol). $enroltypes = array(); $instances = enrol_get_instances($course->id, true); foreach ($instances as $instance) { $enroltypes[] = $instance->enrol; } // Format summary. list($summary, $summaryformat) = external_format_text($course->summary, $course->summaryformat, $coursecontext->id, 'course', 'summary', null); $displayname = get_course_display_name_for_list($course); $coursereturns = array(); $coursereturns['id'] = $course->id; $coursereturns['fullname'] = external_format_string($course->fullname, $coursecontext->id); $coursereturns['displayname'] = external_format_string($displayname, $coursecontext->id); $coursereturns['shortname'] = external_format_string($course->shortname, $coursecontext->id); $coursereturns['categoryid'] = $course->category; $coursereturns['categoryname'] = $category->name; $coursereturns['summary'] = $summary; $coursereturns['summaryformat'] = $summaryformat; $coursereturns['overviewfiles'] = $files; $coursereturns['contacts'] = $coursecontacts; $coursereturns['enrollmentmethods'] = $enroltypes; $finalcourses[] = $coursereturns; } return array('total' => $totalcount, 'courses' => $finalcourses, 'warnings' => $warnings); }
/** * Returns course name as it is configured to appear in courses lists formatted to course context * * @param course_in_list $course * @param array|stdClass $options additional formatting options * @return string */ public function get_course_formatted_name($course, $options = array()) { $options = (array) $options; if (!isset($options['context'])) { $options['context'] = context_course::instance($course->id); } $name = format_string(get_course_display_name_for_list($course), true, $options); if (!empty($this->searchcriteria['search'])) { $name = highlight($this->searchcriteria['search'], $name); } return $name; }
/** * This function is used to generate and display selector form * * @global stdClass $USER * @global stdClass $CFG * @global moodle_database $DB * @global core_renderer $OUTPUT * @global stdClass $SESSION * @uses CONTEXT_SYSTEM * @uses COURSE_MAX_COURSES_PER_DROPDOWN * @uses CONTEXT_COURSE * @uses SEPARATEGROUPS * @param stdClass $course course instance * @param int $selecteduser id of the selected user * @param string $selecteddate Date selected * @param string $modname course_module->id * @param string $modid number or 'site_errors' * @param string $modaction an action as recorded in the logs * @param int $selectedgroup Group to display * @param int $showcourses whether to show courses if we're over our limit. * @param int $showusers whether to show users if we're over our limit. * @param string $logformat Format of the logs (downloadascsv, showashtml, downloadasods, downloadasexcel) * @return void */ function report_log_print_selector_form($course, $selecteduser = 0, $selecteddate = 'today', $modname = "", $modid = 0, $modaction = '', $selectedgroup = -1, $showcourses = 0, $showusers = 0, $logformat = 'showashtml') { global $USER, $CFG, $DB, $OUTPUT, $SESSION; // first check to see if we can override showcourses and showusers $numcourses = $DB->count_records("course"); if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { $showcourses = 1; } $sitecontext = get_context_instance(CONTEXT_SYSTEM); $context = get_context_instance(CONTEXT_COURSE, $course->id); /// Setup for group handling. if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { $selectedgroup = -1; $showgroups = false; } else { if ($course->groupmode) { $showgroups = true; } else { $selectedgroup = 0; $showgroups = false; } } if ($selectedgroup === -1) { if (isset($SESSION->currentgroup[$course->id])) { $selectedgroup = $SESSION->currentgroup[$course->id]; } else { $selectedgroup = groups_get_all_groups($course->id, $USER->id); if (is_array($selectedgroup)) { $selectedgroup = array_shift(array_keys($selectedgroup)); $SESSION->currentgroup[$course->id] = $selectedgroup; } else { $selectedgroup = 0; } } } // Get all the possible users $users = array(); // Define limitfrom and limitnum for queries below // If $showusers is enabled... don't apply limitfrom and limitnum $limitfrom = empty($showusers) ? 0 : ''; $limitnum = empty($showusers) ? COURSE_MAX_USERS_PER_DROPDOWN + 1 : ''; $courseusers = get_enrolled_users($context, '', $selectedgroup, 'u.id, u.firstname, u.lastname', 'lastname ASC, firstname ASC', $limitfrom, $limitnum); if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) { $showusers = 1; } if ($showusers) { if ($courseusers) { foreach ($courseusers as $courseuser) { $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); } } $users[$CFG->siteguest] = get_string('guestuser'); } if (has_capability('report/log:view', $sitecontext) && $showcourses) { if ($ccc = $DB->get_records("course", null, "fullname", "id,shortname,fullname,category")) { foreach ($ccc as $cc) { if ($cc->category) { $courses["{$cc->id}"] = format_string(get_course_display_name_for_list($cc)); } else { $courses["{$cc->id}"] = format_string($cc->fullname) . ' (Site)'; } } } asort($courses); } $activities = array(); $selectedactivity = ""; /// Casting $course->modinfo to string prevents one notice when the field is null if ($modinfo = unserialize((string) $course->modinfo)) { $section = 0; $sections = get_all_sections($course->id); foreach ($modinfo as $mod) { if ($mod->mod == "label") { continue; } if ($mod->section > 0 and $section != $mod->section) { $activities["section/{$mod->section}"] = '--- ' . get_section_name($course, $sections[$mod->section]) . ' ---'; } $section = $mod->section; $mod->name = strip_tags(format_string($mod->name, true)); if (textlib::strlen($mod->name) > 55) { $mod->name = textlib::substr($mod->name, 0, 50) . "..."; } if (!$mod->visible) { $mod->name = "(" . $mod->name . ")"; } $activities["{$mod->cm}"] = $mod->name; if ($mod->cm == $modid) { $selectedactivity = "{$mod->cm}"; } } } if (has_capability('report/log:view', $sitecontext) && $course->id == SITEID) { $activities["site_errors"] = get_string("siteerrors"); if ($modid === "site_errors") { $selectedactivity = "site_errors"; } } $strftimedate = get_string("strftimedate"); $strftimedaydate = get_string("strftimedaydate"); asort($users); // Prepare the list of action options. $actions = array('view' => get_string('view'), 'add' => get_string('add'), 'update' => get_string('update'), 'delete' => get_string('delete'), '-view' => get_string('allchanges')); // Get all the possible dates // Note that we are keeping track of real (GMT) time and user time // User time is only used in displays - all calcs and passing is GMT $timenow = time(); // GMT // What day is it now for the user, and when is midnight that day (in GMT). $timemidnight = $today = usergetmidnight($timenow); // Put today up the top of the list $dates = array("{$timemidnight}" => get_string("today") . ", " . userdate($timenow, $strftimedate)); if (!$course->startdate or $course->startdate > $timenow) { $course->startdate = $course->timecreated; } $numdates = 1; while ($timemidnight > $course->startdate and $numdates < 365) { $timemidnight = $timemidnight - 86400; $timenow = $timenow - 86400; $dates["{$timemidnight}"] = userdate($timenow, $strftimedaydate); $numdates++; } if ($selecteddate == "today") { $selecteddate = $today; } echo "<form class=\"logselectform\" action=\"{$CFG->wwwroot}/report/log/index.php\" method=\"get\">\n"; echo "<div>\n"; echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n"; echo "<input type=\"hidden\" name=\"showusers\" value=\"{$showusers}\" />\n"; echo "<input type=\"hidden\" name=\"showcourses\" value=\"{$showcourses}\" />\n"; if (has_capability('report/log:view', $sitecontext) && $showcourses) { echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide')); echo html_writer::select($courses, "id", $course->id, false); } else { // echo '<input type="hidden" name="id" value="'.$course->id.'" />'; $courses = array(); $courses[$course->id] = get_course_display_name_for_list($course) . ($course->id == SITEID ? ' (' . get_string('site') . ') ' : ''); echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide')); echo html_writer::select($courses, "id", $course->id, false); if (has_capability('report/log:view', $sitecontext)) { $a = new stdClass(); $a->url = "{$CFG->wwwroot}/report/log/index.php?chooselog=0&group={$selectedgroup}&user={$selecteduser}" . "&id={$course->id}&date={$selecteddate}&modid={$selectedactivity}&showcourses=1&showusers={$showusers}"; print_string('logtoomanycourses', 'moodle', $a); } } if ($showgroups) { if ($cgroups = groups_get_all_groups($course->id)) { foreach ($cgroups as $cgroup) { $groups[$cgroup->id] = $cgroup->name; } } else { $groups = array(); } echo html_writer::label(get_string('selectagroup'), 'menugroup', false, array('class' => 'accesshide')); echo html_writer::select($groups, "group", $selectedgroup, get_string("allgroups")); } if ($showusers) { echo html_writer::label(get_string('selctauser'), 'menuuser', false, array('class' => 'accesshide')); echo html_writer::select($users, "user", $selecteduser, get_string("allparticipants")); } else { $users = array(); if (!empty($selecteduser)) { $user = $DB->get_record('user', array('id' => $selecteduser)); $users[$selecteduser] = fullname($user); } else { $users[0] = get_string('allparticipants'); } echo html_writer::label(get_string('selctauser'), 'menuuser', false, array('class' => 'accesshide')); echo html_writer::select($users, "user", $selecteduser, false); $a = new stdClass(); $a->url = "{$CFG->wwwroot}/report/log/index.php?chooselog=0&group={$selectedgroup}&user={$selecteduser}" . "&id={$course->id}&date={$selecteddate}&modid={$selectedactivity}&showusers=1&showcourses={$showcourses}"; print_string('logtoomanyusers', 'moodle', $a); } echo html_writer::label(get_string('date'), 'menudate', false, array('class' => 'accesshide')); echo html_writer::select($dates, "date", $selecteddate, get_string("alldays")); echo html_writer::label(get_string('activities'), 'menumodid', false, array('class' => 'accesshide')); echo html_writer::select($activities, "modid", $selectedactivity, get_string("allactivities")); echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide')); echo html_writer::select($actions, 'modaction', $modaction, get_string("allactions")); $logformats = array('showashtml' => get_string('displayonpage'), 'downloadascsv' => get_string('downloadtext'), 'downloadasods' => get_string('downloadods'), 'downloadasexcel' => get_string('downloadexcel')); echo html_writer::label(get_string('logsformat', 'report_log'), 'menulogformat', false, array('class' => 'accesshide')); echo html_writer::select($logformats, 'logformat', $logformat, false); echo '<input type="submit" value="' . get_string('gettheselogs') . '" />'; echo '</div>'; echo '</form>'; }
/** * Return the course information that is public (visible by every one) * * @param course_in_list $course course in list object * @param stdClass $coursecontext course context object * @return array the course information * @since Moodle 3.2 */ protected static function get_course_public_information(course_in_list $course, $coursecontext) { static $categoriescache = array(); // Category information. if (!array_key_exists($course->category, $categoriescache)) { $categoriescache[$course->category] = coursecat::get($course->category, IGNORE_MISSING); } $category = $categoriescache[$course->category]; // Retrieve course overview used files. $files = array(); foreach ($course->get_course_overviewfiles() as $file) { $fileurl = moodle_url::make_webservice_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename())->out(false); $files[] = array('filename' => $file->get_filename(), 'fileurl' => $fileurl, 'filesize' => $file->get_filesize(), 'filepath' => $file->get_filepath(), 'mimetype' => $file->get_mimetype(), 'timemodified' => $file->get_timemodified()); } // Retrieve the course contacts, // we need here the users fullname since if we are not enrolled can be difficult to obtain them via other Web Services. $coursecontacts = array(); foreach ($course->get_course_contacts() as $contact) { $coursecontacts[] = array('id' => $contact['user']->id, 'fullname' => $contact['username']); } // Allowed enrolment methods (maybe we can self-enrol). $enroltypes = array(); $instances = enrol_get_instances($course->id, true); foreach ($instances as $instance) { $enroltypes[] = $instance->enrol; } // Format summary. list($summary, $summaryformat) = external_format_text($course->summary, $course->summaryformat, $coursecontext->id, 'course', 'summary', null); $displayname = get_course_display_name_for_list($course); $coursereturns = array(); $coursereturns['id'] = $course->id; $coursereturns['fullname'] = external_format_string($course->fullname, $coursecontext->id); $coursereturns['displayname'] = external_format_string($displayname, $coursecontext->id); $coursereturns['shortname'] = external_format_string($course->shortname, $coursecontext->id); $coursereturns['categoryid'] = $course->category; $coursereturns['categoryname'] = $category == null ? '' : $category->name; $coursereturns['summary'] = $summary; $coursereturns['summaryformat'] = $summaryformat; $coursereturns['summaryfiles'] = external_util::get_area_files($coursecontext->id, 'course', 'summary', false, false); $coursereturns['overviewfiles'] = $files; $coursereturns['contacts'] = $coursecontacts; $coursereturns['enrollmentmethods'] = $enroltypes; return $coursereturns; }
/** * Sorts list of records by several fields * * @param array $records array of stdClass objects * @param array $sortfields assoc array where key is the field to sort and value is 1 for asc or -1 for desc * @return int */ protected static function sort_records(&$records, $sortfields) { if (empty($records)) { return; } // If sorting by course display name, calculate it (it may be fullname or shortname+fullname) if (array_key_exists('displayname', $sortfields)) { foreach ($records as $key => $record) { if (!isset($record->displayname)) { $records[$key]->displayname = get_course_display_name_for_list($record); } } } // sorting by one field - use collatorlib if (count($sortfields) == 1) { $property = key($sortfields); if (in_array($property, array('sortorder', 'id', 'visible', 'parent', 'depth'))) { $sortflag = collatorlib::SORT_NUMERIC; } else { if (in_array($property, array('idnumber', 'displayname', 'name', 'shortname', 'fullname'))) { $sortflag = collatorlib::SORT_STRING; } else { $sortflag = collatorlib::SORT_REGULAR; } } collatorlib::asort_objects_by_property($records, $property, $sortflag); if ($sortfields[$property] < 0) { $records = array_reverse($records, true); } return; } $records = coursecat_sortable_records::sort($records, $sortfields); }
/** * For the frontpage feedback returns the list of courses with at least one completed feedback * * @return array id=>name pairs of courses */ public function get_completed_courses() { global $DB; if ($this->get_feedback()->course != SITEID) { return []; } if ($this->allcourses !== null) { return $this->allcourses; } $courseselect = "SELECT fbc.courseid\n FROM {feedback_completed} fbc\n WHERE fbc.feedback = :feedbackid"; $ctxselect = context_helper::get_preload_record_columns_sql('ctx'); $sql = 'SELECT c.id, c.shortname, c.fullname, c.idnumber, c.visible, ' . $ctxselect . ' FROM {course} c JOIN {context} ctx ON c.id = ctx.instanceid AND ctx.contextlevel = :contextcourse WHERE c.id IN (' . $courseselect . ') ORDER BY c.sortorder'; $list = $DB->get_records_sql($sql, ['contextcourse' => CONTEXT_COURSE, 'feedbackid' => $this->get_feedback()->id]); $this->allcourses = array(); foreach ($list as $course) { context_helper::preload_from_record($course); if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { // Do not return courses that current user can not see. continue; } $label = get_course_display_name_for_list($course); $this->allcourses[$course->id] = $label; } return $this->allcourses; }
/** * Test get_courses */ public function test_get_courses() { global $DB; $this->resetAfterTest(true); $generatedcourses = array(); $coursedata['idnumber'] = 'idnumbercourse1'; $coursedata['fullname'] = 'Course 1 for PHPunit test'; $coursedata['summary'] = 'Course 1 description'; $coursedata['summaryformat'] = FORMAT_MOODLE; $course1 = self::getDataGenerator()->create_course($coursedata); $generatedcourses[$course1->id] = $course1; $course2 = self::getDataGenerator()->create_course(); $generatedcourses[$course2->id] = $course2; $course3 = self::getDataGenerator()->create_course(array('format' => 'topics')); $generatedcourses[$course3->id] = $course3; // Set the required capabilities by the external function. $context = context_system::instance(); $roleid = $this->assignUserCapability('moodle/course:view', $context->id); $this->assignUserCapability('moodle/course:update', context_course::instance($course1->id)->id, $roleid); $this->assignUserCapability('moodle/course:update', context_course::instance($course2->id)->id, $roleid); $this->assignUserCapability('moodle/course:update', context_course::instance($course3->id)->id, $roleid); $courses = core_course_external::get_courses(array('ids' => array($course1->id, $course2->id))); // We need to execute the return values cleaning process to simulate the web service server. $courses = external_api::clean_returnvalue(core_course_external::get_courses_returns(), $courses); // Check we retrieve the good total number of categories. $this->assertEquals(2, count($courses)); foreach ($courses as $course) { $dbcourse = $generatedcourses[$course['id']]; $this->assertEquals($course['idnumber'], $dbcourse->idnumber); $this->assertEquals($course['fullname'], $dbcourse->fullname); $this->assertEquals($course['displayname'], get_course_display_name_for_list($dbcourse)); // Summary was converted to the HTML format. $this->assertEquals($course['summary'], format_text($dbcourse->summary, FORMAT_MOODLE, array('para' => false))); $this->assertEquals($course['summaryformat'], FORMAT_HTML); $this->assertEquals($course['shortname'], $dbcourse->shortname); $this->assertEquals($course['categoryid'], $dbcourse->category); $this->assertEquals($course['format'], $dbcourse->format); $this->assertEquals($course['showgrades'], $dbcourse->showgrades); $this->assertEquals($course['newsitems'], $dbcourse->newsitems); $this->assertEquals($course['startdate'], $dbcourse->startdate); $this->assertEquals($course['numsections'], $dbcourse->numsections); $this->assertEquals($course['maxbytes'], $dbcourse->maxbytes); $this->assertEquals($course['showreports'], $dbcourse->showreports); $this->assertEquals($course['visible'], $dbcourse->visible); $this->assertEquals($course['hiddensections'], $dbcourse->hiddensections); $this->assertEquals($course['groupmode'], $dbcourse->groupmode); $this->assertEquals($course['groupmodeforce'], $dbcourse->groupmodeforce); $this->assertEquals($course['defaultgroupingid'], $dbcourse->defaultgroupingid); $this->assertEquals($course['completionnotify'], $dbcourse->completionnotify); $this->assertEquals($course['lang'], $dbcourse->lang); $this->assertEquals($course['forcetheme'], $dbcourse->theme); $this->assertEquals($course['enablecompletion'], $dbcourse->enablecompletion); if ($dbcourse->format === 'topics') { $this->assertEquals($course['courseformatoptions'], array(array('name' => 'numsections', 'value' => $dbcourse->numsections), array('name' => 'hiddensections', 'value' => $dbcourse->hiddensections), array('name' => 'coursedisplay', 'value' => $dbcourse->coursedisplay))); } } // Get all courses in the DB $courses = core_course_external::get_courses(array()); // We need to execute the return values cleaning process to simulate the web service server. $courses = external_api::clean_returnvalue(core_course_external::get_courses_returns(), $courses); $this->assertEquals($DB->count_records('course'), count($courses)); }
/** * Fill the table for displaying. * * @param bool $activitylink If this report link to the activity report or the user report. * @param bool $studentcoursesonly Only show courses that the user is a student of. */ public function fill_table($activitylink = false, $studentcoursesonly = false) { global $CFG, $DB, $OUTPUT, $USER; if ($studentcoursesonly && count($this->studentcourseids) == 0) { return false; } // Only show user's courses instead of all courses. if ($this->courses) { $numusers = $this->get_numusers(false); foreach ($this->courses as $course) { if (!$course->showgrades) { continue; } // If we are only showing student courses and this course isn't part of the group, then move on. if ($studentcoursesonly && !isset($this->studentcourseids[$course->id])) { continue; } $coursecontext = context_course::instance($course->id); if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) { // The course is hidden and the user isn't allowed to see it continue; } if (!has_capability('moodle/user:viewuseractivitiesreport', context_user::instance($this->user->id)) && ((!has_capability('moodle/grade:view', $coursecontext) || $this->user->id != $USER->id) && !has_capability('moodle/grade:viewall', $coursecontext))) { continue; } $coursename = format_string(get_course_display_name_for_list($course), true, array('context' => $coursecontext)); // Link to the activity report version of the user grade report. if ($activitylink) { $courselink = html_writer::link(new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $this->user->id)), $coursename); } else { $courselink = html_writer::link(new moodle_url('/grade/report/user/index.php', array('id' => $course->id, 'userid' => $this->user->id)), $coursename); } $canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext); // Get course grade_item $course_item = grade_item::fetch_course_item($course->id); // Get the stored grade $course_grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $this->user->id)); $course_grade->grade_item =& $course_item; $finalgrade = $course_grade->finalgrade; if (!$canviewhidden and !is_null($finalgrade)) { if ($course_grade->is_hidden()) { $finalgrade = null; } else { $adjustedgrade = $this->blank_hidden_total_and_adjust_bounds($course->id, $course_item, $finalgrade); // We temporarily adjust the view of this grade item - because the min and // max are affected by the hidden values in the aggregation. $finalgrade = $adjustedgrade['grade']; $course_item->grademax = $adjustedgrade['grademax']; $course_item->grademin = $adjustedgrade['grademin']; } } else { // We must use the rawgrademin / rawgrademax because it can be different for // each grade_grade when items are excluded from sum of grades. if (!is_null($finalgrade)) { $course_item->grademin = $course_grade->rawgrademin; $course_item->grademax = $course_grade->rawgrademax; } } $data = array($courselink, grade_format_gradevalue($finalgrade, $course_item, true)); if (!$this->showrank['any']) { //nothing to do } else { if ($this->showrank[$course->id] && !is_null($finalgrade)) { /// find the number of users with a higher grade /// please note this can not work if hidden grades involved :-( to be fixed in 2.0 $params = array($finalgrade, $course_item->id); $sql = "SELECT COUNT(DISTINCT(userid))\n FROM {grade_grades}\n WHERE finalgrade IS NOT NULL AND finalgrade > ?\n AND itemid = ?"; $rank = $DB->count_records_sql($sql, $params) + 1; $data[] = "{$rank}/{$numusers}"; } else { // No grade, no rank. // Or this course wants rank hidden. $data[] = '-'; } } $this->table->add_data($data); } return true; } else { echo $OUTPUT->notification(get_string('notenrolled', 'grades'), 'notifymessage'); return false; } }
/** * Returns the name of this course as it should be displayed within a list. * @return string */ public function get_formatted_name() { return format_string(get_course_display_name_for_list($this), true, $this->get_context()); }
/** * Return list of courses to show in selector. * * @return array list of courses. */ public function get_course_list() { global $DB, $SITE; $courses = array(); $sitecontext = context_system::instance(); // First check to see if we can override showcourses and showusers. $numcourses = $DB->count_records("course"); if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$this->showcourses) { $this->showcourses = 1; } // Check if course filter should be shown. if (has_capability('report/log:view', $sitecontext) && $this->showcourses) { if ($courserecords = $DB->get_records("course", null, "fullname", "id,shortname,fullname,category")) { foreach ($courserecords as $course) { if ($course->id == SITEID) { $courses[$course->id] = format_string($course->fullname) . ' (' . get_string('site') . ')'; } else { $courses[$course->id] = format_string(get_course_display_name_for_list($course)); } } } core_collator::asort($courses); } return $courses; }
$atlastpage = $page + 1 == ceil($totalcount / $perpage); } else { $atlastpage = true; } } else { $atfirstpage = true; $atlastpage = true; } foreach ($courses as $acourse) { $coursecontext = get_context_instance(CONTEXT_COURSE, $acourse->id); $count++; $up = $count > 1 || !$atfirstpage; $down = $count < $numcourses || !$atlastpage; $linkcss = $acourse->visible ? '' : ' class="dimmed" '; echo '<tr>'; $coursename = get_course_display_name_for_list($acourse); echo '<td><a ' . $linkcss . ' href="view.php?id=' . $acourse->id . '">' . format_string($coursename) . '</a></td>'; if ($editingon) { echo '<td>'; if (has_capability('moodle/course:update', $coursecontext)) { echo $OUTPUT->action_icon(new moodle_url('/course/edit.php', array('id' => $acourse->id, 'category' => $id, 'returnto' => 'category')), new pix_icon('t/edit', $strsettings)); } // role assignment link if (has_capability('moodle/course:enrolreview', $coursecontext)) { echo $OUTPUT->action_icon(new moodle_url('/enrol/users.php', array('id' => $acourse->id)), new pix_icon('i/users', get_string('enrolledusers', 'enrol'))); } if (can_delete_course($acourse->id)) { echo $OUTPUT->action_icon(new moodle_url('/course/delete.php', array('id' => $acourse->id)), new pix_icon('t/delete', $strdelete)); } // MDL-8885, users with no capability to view hidden courses, should not be able to lock themselves out if (has_capability('moodle/course:visibility', $coursecontext) && has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
/** * Construct contents of course_overview block * * @param array $courses list of courses in sorted order * @param array $overviews list of course overviews * @return string html to be displayed in course_overview block */ public function course_overview($courses, $overviews) { global $DB; $html = ''; $config = get_config('block_course_overview'); if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { global $CFG; require_once $CFG->libdir . '/coursecatlib.php'; } /*echo '<pre>'; print_r($courses);*/ $ismovingcourse = false; $courseordernumber = 0; $maxcourses = count($courses); $userediting = false; // Intialise string/icon etc if user is editing and courses > 1 if ($this->page->user_is_editing() && count($courses) > 1) { $userediting = true; $this->page->requires->js_init_call('M.block_course_overview.add_handles'); // Check if course is moving $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL); $movingcourseid = optional_param('courseid', 0, PARAM_INT); } /** * Indexador das categorias dos cursos * @author Cássio Queiroz <Cruzz> * @date 2015/12/26 */ $catids = array(); foreach ($courses as $key => $course) { $value = $DB->get_record_sql('SELECT id,name FROM {course_categories} WHERE id = ? ', array($course->category)); $catids[] = $value->id . '@' . $value->name; } $firstCat = explode("@", $catids[0]); $catids = array_unique($catids); // Render first movehere icon. if ($ismovingcourse) { // Remove movecourse param from url. $this->page->ensure_param_not_in_url('movecourse'); // Show moving course notice, so user knows what is being moved. $html .= $this->output->box_start('notice'); $a = new stdClass(); $a->fullname = $courses[$movingcourseid]->fullname; $a->cancellink = html_writer::link($this->page->url, get_string('cancel')); $html .= get_string('movingcourse', 'block_course_overview', $a); $html .= $this->output->box_end(); $moveurl = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid)); // Create move icon, so it can be used. $movetofirsticon = html_writer::empty_tag('img', array('src' => $this->output->pix_url('movehere'), 'alt' => get_string('movetofirst', 'block_course_overview', $courses[$movingcourseid]->fullname), 'title' => get_string('movehere'))); $moveurl = html_writer::link($moveurl, $movetofirsticon); $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } // @autor Cássio Queiroz <Cruzz> $html .= html_writer::start_tag('div', array('class' => 'cat_navigation')); $html .= html_writer::start_span('top-level') . 'Meus Cursos' . html_writer::end_span(); $html .= html_writer::start_tag('div', array('class' => 'cat_navs')); $piper = ''; foreach ($catids as $cor) { $name = explode('@', $cor); $html .= $piper . html_writer::start_span('allcat category-' . $name[0]) . $name[1] . html_writer::end_span(); $piper = ' | '; } $html .= html_writer::end_tag('div'); // END cat_navs $html .= html_writer::end_tag('div'); // END cat_navigation foreach ($courses as $key => $course) { // If moving course, then don't show course which needs to be moved. if ($ismovingcourse && $course->id == $movingcourseid) { continue; } $html .= html_writer::start_tag('div', array('class' => 'all cat_' . $course->category)); // @autor Cássio Queiroz <Cruzz> $html .= $this->output->box_start('coursebox', "course-{$course->id}"); $html .= html_writer::start_tag('div', array('class' => 'course_title')); // If user is editing, then add move icons. if ($userediting && !$ismovingcourse) { $moveicon = html_writer::empty_tag('img', array('src' => $this->pix_url('t/move')->out(false), 'alt' => get_string('movecourse', 'block_course_overview', $course->fullname), 'title' => get_string('move'))); $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id)); $moveurl = html_writer::link($moveurl, $moveicon); $html .= html_writer::tag('div', $moveurl, array('class' => 'move')); } // No need to pass title through s() here as it will be done automatically by html_writer. $attributes = array('title' => $course->fullname); if ($course->id > 0) { if (empty($course->visible)) { $attributes['class'] = 'dimmed'; } $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id); $link = html_writer::link($courseurl, $coursefullname, $attributes); $html .= $this->output->heading($link, 2, 'title'); } else { $html .= $this->output->heading(html_writer::link(new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id=' . $course->remoteid)), format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); } $html .= $this->output->box('', 'flush'); $html .= html_writer::end_tag('div'); // hide-div $html .= html_writer::end_tag('div'); if (!empty($config->showchildren) && $course->id > 0) { // List children here. if ($children = block_course_overview_get_child_shortnames($course->id)) { $html .= html_writer::tag('span', $children, array('class' => 'coursechildren')); } } // If user is moving courses, then down't show overview. if (isset($overviews[$course->id]) && !$ismovingcourse) { $html .= $this->activity_display($course->id, $overviews[$course->id]); } if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { // List category parent or categories path here. $currentcategory = coursecat::get($course->category, IGNORE_MISSING); if ($currentcategory !== null) { $html .= html_writer::start_tag('div', array('class' => 'categorypath')); if ($config->showcategories == BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH) { foreach ($currentcategory->get_parents() as $categoryid) { $category = coursecat::get($categoryid, IGNORE_MISSING); if ($category !== null) { $html .= $category->get_formatted_name() . ' / '; } } } $html .= $currentcategory->get_formatted_name(); $html .= html_writer::end_tag('div'); } } $html .= $this->output->box('', 'flush'); $html .= $this->output->box_end(); $courseordernumber++; if ($ismovingcourse) { $moveurl = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid)); $a = new stdClass(); $a->movingcoursename = $courses[$movingcourseid]->fullname; $a->currentcoursename = $course->fullname; $movehereicon = html_writer::empty_tag('img', array('src' => $this->output->pix_url('movehere'), 'alt' => get_string('moveafterhere', 'block_course_overview', $a), 'title' => get_string('movehere'))); $moveurl = html_writer::link($moveurl, $movehereicon); $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } } /** * Função jquery para mostrar os cursos de acordo com a categoria * @author Cássio Queiroz <Cruzz> * @date 2015/12/26 */ $html .= '<script type="text/javascript"> $(document).ready(function(){ $(".all").hide(); var last = $(".category-' . $firstCat[0] . '"); $(".cat_' . $firstCat[0] . '").fadeIn(); $(".category-' . $firstCat[0] . '").css("color","orange"); $(".allcat").click(function(){ if(typeof last === "undefined"){ last = $(this); } last.css("color","#656565"); last = $(this); $(".all").hide(); $(this).css("color","orange"); var name = $(this).attr("class").split("-"); $(".cat_"+name[1]).fadeIn(); }); }); </script> '; // Wrap course list in a div and return. return html_writer::tag('div', $html, array('class' => 'course_list')); }
/** * Returns human readable context identifier. * * @param boolean $withprefix whether to prefix the name of the context with Course * @param boolean $short whether to use the short name of the thing. * @return string the human readable context name. */ public function get_context_name($withprefix = true, $short = false) { global $DB; $name = ''; if ($this->_instanceid == SITEID) { $name = get_string('frontpage', 'admin'); } else { if ($course = $DB->get_record('course', array('id'=>$this->_instanceid))) { if ($withprefix){ $name = get_string('course').': '; } if ($short){ $name .= format_string($course->shortname, true, array('context' => $this)); } else { $name .= format_string(get_course_display_name_for_list($course)); } } } return $name; }
/** * Construct contents of course_overview block * * @param array $courses list of courses in sorted order * @param array $overviews list of course overviews * @return string html to be displayed in course_overview block */ public function course_overview($courses, $overviews) { $html = ''; $config = get_config('block_course_overview'); $ismovingcourse = false; $courseordernumber = 0; $maxcourses = count($courses); $userediting = false; // Intialise string/icon etc if user is editing and courses > 1 if ($this->page->user_is_editing() && count($courses) > 1) { $userediting = true; $this->page->requires->js_init_call('M.block_course_overview.add_handles'); // Check if course is moving $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL); $movingcourseid = optional_param('courseid', 0, PARAM_INT); } // Render first movehere icon. if ($ismovingcourse) { // Remove movecourse param from url. $this->page->ensure_param_not_in_url('movecourse'); // Show moving course notice, so user knows what is being moved. $html .= $this->output->box_start('notice'); $a = new stdClass(); $a->fullname = $courses[$movingcourseid]->fullname; $a->cancellink = html_writer::link($this->page->url, get_string('cancel')); $html .= get_string('movingcourse', 'block_course_overview', $a); $html .= $this->output->box_end(); $moveurl = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid)); // Create move icon, so it can be used. $movetofirsticon = html_writer::empty_tag('img', array('src' => $this->output->pix_url('movehere'), 'alt' => get_string('movetofirst', 'block_course_overview', $courses[$movingcourseid]->fullname), 'title' => get_string('movehere'))); $moveurl = html_writer::link($moveurl, $movetofirsticon); $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } $completedcourseshtml = ''; $inprogresscourseshtml = ''; $coursehtmlrecord = ''; foreach ($courses as $key => $course) { $coursehtmlrecord = ''; // If moving course, then don't show course which needs to be moved. if ($ismovingcourse && $course->id == $movingcourseid) { continue; } $coursehtmlrecord .= $this->output->box_start('coursebox', "course-{$course->id}"); $coursehtmlrecord .= html_writer::start_tag('div', array('class' => 'course_title')); // If user is editing, then add move icons. //GWL Display course image - Start global $CFG, $DB, $USER; $course = new course_in_list($course); //Getting progress percentage. $progress = get_course_progress_percentage($course, $USER); $completionstate = get_course_lesson_completionstate($course); $info = new completion_info($course); //GWL - Add this to add contion to generate certificate when instructor mark completed $completionstate = $info->is_course_complete($USER->id); //GWL - Add this to add contion to generate certificate when instructor mark completed // display course overview files $contentimages = $contentfiles = ''; foreach ($course->get_course_overviewfiles() as $file) { $isimage = $file->is_valid_image(); $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage); if ($isimage) { $contentimages .= html_writer::tag('div', html_writer::empty_tag('img', array('src' => $url)), array('class' => 'courseimage')); } else { $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle'); $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename')); $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon')); } } $content .= $contentimages . $contentfiles; $coursehtmlrecord .= $content; $attributes = array('title' => $course->fullname); if ($course->id > 0) { if (empty($course->visible)) { $attributes['class'] = 'dimmed'; } $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); $lession_id = get_course_lesson_id($course); if ($lession_id) { $courseurl = new moodle_url('/mod/lesson/view.php', array('id' => $lession_id)); } $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id); $link = html_writer::link($courseurl, $coursefullname, $attributes); if ($progress >= 100 || $completionstate == 1) { $coursehtmlrecord .= $this->output->heading($coursefullname, 2, 'title'); } else { $coursehtmlrecord .= $this->output->heading($link, 2, 'title'); } } else { $coursehtmlrecord .= $this->output->heading(html_writer::link(new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id=' . $course->remoteid)), format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); } $result = $DB->get_field("course", "summary", array("id" => $course->id)); $coursehtmlrecord .= $result; //GWL Display course image - END //GWL to get download certificate link if ($progress < 100 && !$completionstate) { $coursehtmlrecord .= '<div style=" background-color: #ccc; color: #fff; text-align: right; vertical-align: middle; height: 20px; border-radius: 10px; overflow: hidden; margin-bottom: 5px;"><div style="width: ' . $progress . '%; float: left; background-color: green; padding-right: 10px;">' . $progress . '%</div></div>'; } else { $certificates = get_coursemodules_in_course('iomadcertificate', $course->id); $certificatelink = '-'; if ($certificates) { $showcertificate = 1; foreach ($certificates as $certficate) { $modinfo = get_fast_modinfo($course->id); $cm = $modinfo->get_cm($certficate->id); if ($cm && $cm->uservisible) { $coursehtmlrecord .= '<div><a href="' . $CFG->wwwroot . '/mod/iomadcertificate/view.php?id=' . $certficate->id . '&action=get" class="pull-right" style="color:#f5811e;"> <i class="fa fa-cloud-download" style="color:#f5811e;" ></i> Download Certificate</a> </div>'; } } } } //GWL to get download certificate link // GWL - Course Status On Dashboard / if ($userediting && !$ismovingcourse) { $moveicon = html_writer::empty_tag('img', array('src' => $this->pix_url('t/move')->out(false), 'alt' => get_string('movecourse', 'block_course_overview', $course->fullname), 'title' => get_string('move'))); $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id)); $moveurl = html_writer::link($moveurl, $moveicon); $coursehtmlrecord .= html_writer::tag('div', $moveurl, array('class' => 'move')); } // No need to pass title through s() here as it will be done automatically by html_writer. $coursehtmlrecord .= $this->output->box('', 'flush'); $coursehtmlrecord .= html_writer::end_tag('div'); if (!empty($config->showchildren) && $course->id > 0) { // List children here. if ($children = block_course_overview_get_child_shortnames($course->id)) { $coursehtmlrecord .= html_writer::tag('span', $children, array('class' => 'coursechildren')); } } // If user is moving courses, then down't show overview. if (isset($overviews[$course->id]) && !$ismovingcourse) { $coursehtmlrecord .= $this->activity_display($course->id, $overviews[$course->id]); } $coursehtmlrecord .= $this->output->box('', 'flush'); $coursehtmlrecord .= $this->output->box_end(); $courseordernumber++; if ($ismovingcourse) { $moveurl = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid)); $a = new stdClass(); $a->movingcoursename = $courses[$movingcourseid]->fullname; $a->currentcoursename = $course->fullname; $movehereicon = html_writer::empty_tag('img', array('src' => $this->output->pix_url('movehere'), 'alt' => get_string('moveafterhere', 'block_course_overview', $a), 'title' => get_string('movehere'))); $moveurl = html_writer::link($moveurl, $movehereicon); $coursehtmlrecord .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } if ($progress >= 100 || $completionstate == 1) { $completedcourseshtml .= $coursehtmlrecord; } else { $inprogresscourseshtml .= $coursehtmlrecord; } } $html .= '<div class="inprogresscourse">In Progress Courses</div>'; $html .= $inprogresscourseshtml; $html .= '<div class="completecourse">Completed Courses</div>'; $html .= $completedcourseshtml; // Wrap course list in a div and return. return html_writer::tag('div', $html, array('class' => 'course_list')); }