Esempio n. 1
0
/**
 * Category is 0 (for all courses) or an object
 */
function print_courses($category)
{
    global $CFG, $OUTPUT;
    if (!is_object($category) && $category == 0) {
        $categories = get_child_categories(0);
        // Parent = 0   ie top-level categories only
        if (is_array($categories) && count($categories) == 1) {
            $category = array_shift($categories);
            $courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('summary', 'summaryformat'));
        } else {
            $courses = get_courses_wmanagers('all', 'c.sortorder ASC', array('summary', 'summaryformat'));
        }
        unset($categories);
    } else {
        $courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('summary', 'summaryformat'));
    }
    if ($courses) {
        echo html_writer::start_tag('ul', array('class' => 'unlist'));
        foreach ($courses as $course) {
            $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
            if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
                echo html_writer::start_tag('li');
                print_course($course);
                echo html_writer::end_tag('li');
            }
        }
        echo html_writer::end_tag('ul');
    } else {
        echo $OUTPUT->heading(get_string("nocoursesyet"));
        $context = get_context_instance(CONTEXT_SYSTEM);
        if (has_capability('moodle/course:create', $context)) {
            $options = array();
            if (!empty($category->id)) {
                $options['category'] = $category->id;
            } else {
                $options['category'] = $CFG->defaultrequestcategory;
            }
            echo html_writer::start_tag('div', array('class' => 'addcoursebutton'));
            echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
            echo html_writer::end_tag('div');
        }
    }
}
Esempio n. 2
0
function print_courses($category)
{
    /// Category is 0 (for all courses) or an object
    global $CFG;
    if (!is_object($category) && $category == 0) {
        $categories = get_child_categories(0);
        // Parent = 0   ie top-level categories only
        if (is_array($categories) && count($categories) == 1) {
            $category = array_shift($categories);
            $courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency'));
        } else {
            $courses = get_courses_wmanagers('all', 'c.sortorder ASC', array('password', 'summary', 'currency'));
        }
        unset($categories);
    } else {
        $courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency'));
    }
    if ($courses) {
        echo '<ul class="unlist">';
        foreach ($courses as $course) {
            if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', $course->context)) {
                echo '<li>';
                print_course($course);
                echo "</li>\n";
            }
        }
        echo "</ul>\n";
    } else {
        print_heading(get_string("nocoursesyet"));
        $context = get_context_instance(CONTEXT_SYSTEM);
        if (has_capability('moodle/course:create', $context)) {
            $options = array();
            $options['category'] = $category->id;
            echo '<div class="addcoursebutton">';
            print_single_button($CFG->wwwroot . '/course/edit.php', $options, get_string("addnewcourse"));
            echo '</div>';
        }
    }
}
Esempio n. 3
0
/**
 * Retrieve all dynamic files
 *
 * @return string[] The array of dynamic files
 */
function offline_get_dynamic_files()
{
    global $CFG, $COURSE, $USER, $DB;
    require_once $CFG->dirroot . '/course/lib.php';
    // Include homepage and accessible course pages
    $files = array('.', $CFG->wwwroot . '/', $CFG->wwwroot . '/index.php', $CFG->wwwroot . '/lib/offline/go_offline.js', $CFG->wwwroot . '/user/editadvanced.php?id=' . $USER->id);
    // get all accessible courses
    if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
        $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', array('summary'));
    } else {
        if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() or $DB->count_records('course') <= FRONTPAGECOURSELIMIT) {
            $categories = get_child_categories(0);
            if (is_array($categories) && count($categories) == 1) {
                $category = array_shift($categories);
                $courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency'));
            } else {
                $courses = get_courses_wmanagers('all', 'c.sortorder ASC', array('password', 'summary', 'currency'));
            }
            unset($categories);
        }
    }
    // make sure the course is visible and retrieve other modules and main course pages
    foreach ($courses as $course) {
        if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', $course->context)) {
            $files[] = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
            //Get all the module main pages
            foreach (get_list_of_plugins() as $module) {
                if ($module != 'label') {
                    $files[] = $CFG->wwwroot . '/mod/' . $module . '/index.php?id=' . $course->id;
                }
            }
            //Get all the relevant forums
            require_once $CFG->dirroot . '/mod/forum/lib.php';
            $forums = forum_get_readable_forums($USER->id, $course->id);
            foreach ($forums as $forum) {
                $files[] = $CFG->wwwroot . '/mod/forum/view.php?f=' . $forum->id;
            }
            $modinfo =& get_fast_modinfo($course);
            get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
            foreach ($mods as $mod) {
                if ($mod->modname == 'forum') {
                    $files[] = $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id;
                    $cm = get_coursemodule_from_id('forum', $mod->id);
                    $discussions = forum_get_discussions($cm);
                    foreach ($discussions as $d) {
                        $files[] = $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $d->discussion;
                    }
                }
            }
            //Get all the relevant assignments
            foreach ($modinfo->instances['assignment'] as $cm) {
                if (!$cm->uservisible) {
                    continue;
                }
                $files[] = $CFG->wwwroot . '/mod/assignment/view.php?id=' . $cm->id;
            }
        }
    }
    $files = str_replace('&amp;', '&', $files);
    return $files;
}
Esempio n. 4
0
/**
 * Print a list of all courses in selected category
 * Category is 0 (for all courses) or an object
 * @param int $category ID of selected category
 **/
function print_courses($category, $hidesitecourse = false)
{
    global $CFG;
    if (!is_object($category) && $category == 0) {
        $categories = get_child_categories(0);
        // Parent = 0   ie top-level categories only
        if (is_array($categories) && count($categories) == 1) {
            $category = array_shift($categories);
            $courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency', 'timecreated', 'enrolperiod'));
        } else {
            $courses = get_courses_wmanagers('all', 'c.sortorder ASC', array('password', 'summary', 'currency', 'timecreated', 'enrolperiod'));
        }
        unset($categories);
    } else {
        $courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency', 'timecreated', 'enrolperiod'));
    }
    if ($courses) {
        echo '<ul class="unlist">';
        foreach ($courses as $course) {
            if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', $course->context)) {
                echo '<li>';
                print_course($course);
                echo "</li>\n";
            }
        }
        echo "</ul>\n";
    } else {
        print_heading(get_string("nocoursesyet"));
        $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
        if (has_capability('moodle/course:create', $context)) {
            $options = array();
            $options['category'] = $category->id;
            echo '<div class="addcoursebutton">';
            // 17-07-2007 - kowy - novy kurz vznika pres konfigurator
            print_single_button($CFG->wwwroot . '/course/new_course.php', $options, get_string("addnewcourse"));
            echo '</div>';
        }
    }
}
<?php

require_once '../../config.php';
require_once 'lib/eip.php';
require_login();
$category = optional_param('category', '', PARAM_RAW);
$assign_course = optional_param('assign_course', 0, PARAM_INT);
$capabilitycourse = get_user_capability_course('moodle/role:assign');
$categorycourses = get_courses_wmanagers($category);
$capabilitycategorycourse = array();
foreach ($capabilitycourse as $cc) {
    //$capabilitycategorycourse[] = $categorycourses[$cc->id];
    if ($cc->id != SITEID) {
        if (array_key_exists($cc->id, $categorycourses)) {
            $std = $categorycourses[$cc->id];
            $capabilitycategorycourse[$cc->id] = $std->fullname;
        }
    }
}
if ($assign_course) {
    $context = get_context_instance(CONTEXT_COURSE, $assign_course);
    $assignableroles = get_assignable_roles($context, ROLENAME_BOTH);
    echo renderoptions($assignableroles);
} else {
    echo renderoptions($capabilitycategorycourse);
}