/** * checks if a user has a myoverride capability somewhere, so he might be My Moodle * exampted. */ function local_has_myoverride_somewhere() { global $USER, $CFG; // TODO : explore caps for a moodle/local:overridemy positive answer. if ($hassome = local_my_has_capability_somewhere('local/my:overridemy', false, false, true, CONTEXT_COURSE . ',' . CONTEXT_COURSECAT . ',' . CONTEXT_SYSTEM)) { return true; } /* * ADDED : on special configuration check positive response of an override driver * that could come from having some profile field marked */ if (@$CFG->specialprofilefieldmyoverridedrivers) { $drivers = "'" . str_replace(',', "','", $CFG->specialprofilefieldmyoverridedrivers) . "'"; if ($myprofiledriverfields = $DB->get_records_select('user_info_field', " shortname IN ('{$drivers}') ")) { foreach ($myprofiledriverfields as $f) { if ($driverdata = $DB->get_record('user_info_data', array('fieldid' => $f->id, 'userid' => $USER->id))) { if ($driverdata->data == 1) { return true; } } } } } return false; }
/** * Prints the "classical" "My Courses" area */ function local_my_print_authored_courses(&$excludedcourses, &$courseareacourses) { global $OUTPUT, $CFG, $DB; $debug = 0; $myauthcourses = local_get_my_authoring_courses(); // Post 2.5. include_once $CFG->dirroot . '/lib/coursecatlib.php'; $mycatlist = coursecat::make_categories_list('moodle/course:create'); if (!empty($excludedcourses)) { foreach (array_keys($excludedcourses) as $cid) { if ($debug) { echo "rejected authored {$cid} as excluded</br/>"; } unset($myauthcourses[$cid]); } } $str = ''; $hascontent = false; if (!empty($mycatlist) || !empty($myauthcourses)) { $str .= '<div class="block block_my_authored_courses">'; $str .= '<div class="header">'; $str .= '<div class="title">'; $str .= '<h2>' . get_string('myauthoringcourses', 'local_my') . '</h2>'; $str .= '</div>'; $str .= '</div>'; $str .= '<div class="content">'; $hascontent = true; } if (!empty($mycatlist)) { $levels = CONTEXT_COURSE . ',' . CONTEXT_COURSECAT; $cancreate = local_my_has_capability_somewhere('moodle/course:create', false, false, true, $levels); $catids = array_keys($mycatlist); $firstcatid = array_shift($catids); $button0 = ''; $button1 = ''; $button2 = ''; $button3 = ''; if ($cancreate) { $params = array('view' => 'courses', 'categoryid' => $firstcatid); $label = get_string('managemycourses', 'local_my'); $button0 = $OUTPUT->single_button(new moodle_url('/course/management.php', $params), $label); $label = get_string('newcourse', 'local_my'); $button1 = $OUTPUT->single_button(new moodle_url('/local/my/create_course.php'), $label); if (is_dir($CFG->dirroot . '/local/coursetemplates')) { $config = get_config('local_coursetemplates'); if ($config->enabled && $config->templatecategory) { $params = array('category' => $config->templatecategory, 'visible' => 1); if ($DB->count_records('course', $params)) { $buttonurl = new moodle_url('/local/coursetemplates/index.php'); $button2 = $OUTPUT->single_button($buttonurl, get_string('newcoursefromtemplate', 'local_my')); } } } // Need fetch a context where user has effective capability. $powercontext = local_get_one_of_my_power_contexts(); if ($powercontext) { $params = array('contextid' => $powercontext->id); $buttonurl = new moodle_url('/backup/restorefile.php', $params); $button3 = $OUTPUT->single_button($buttonurl, get_string('restorecourse', 'local_my')); } } $str .= '<div class="right-button course-creation-buttons">' . $button0 . ' ' . $button1 . ' ' . $button2 . ' ' . $button3 . '</div>'; } if (!empty($myauthcourses)) { $str .= '<table id="myauthoredcourselist" width="100%" class="generaltable courselist">'; $str .= '<tr valign="top"><td>'; if (count($myauthcourses) < 0 + @$config->maxoverviewedlistsize) { $str .= local_print_course_overview($myauthcourses, true, array('gaugewidth' => 0, 'gaugeheight' => 0)); } else { if (count($myauthcourses) < 0 + @$config->maxuncategorizedlistsize) { // Solve a performance issue for people having wide access to courses. $options = array('noheading' => true, 'withcats' => false, 'nocompletion' => true, 'gaugewidth' => 0, 'gaugeheight' => 0); } else { // Solve a performance issue for people having wide access to courses. $options = array('noheading' => true, 'withcats' => true, 'nocompletion' => true, 'gaugewidth' => 0, 'gaugeheight' => 0); } $str .= local_my_print_courses('myauthcourses', $myauthcourses, $options, true); } $str .= '</td></tr>'; $str .= '</table>'; if ($debug) { foreach ($myauthcourses as $ac) { echo "exclude authored {$ac->id} as authored <br/>"; } } $excludedcourses = $excludedcourses + $myauthcourses; } if ($hascontent) { $str .= '</div>'; $str .= '</div>'; } return $str; }