function list_activities($vplid)
 {
     global $DB;
     $list = array('' => '');
     $cn = $this->vpl->get_course()->shortname;
     //Low privilegies
     $courses = get_user_capability_course(VPL_VIEW_CAPABILITY, null, true, 'shortname');
     //Reorder courses by name similar to current
     usort($courses, function ($a, $b) use($cn) {
         $na = $a->shortname;
         $nb = $b->shortname;
         $da = levenshtein($na, $cn);
         $db = levenshtein($nb, $cn);
         if ($da != $db) {
             return $da < $db ? -1 : 1;
         }
         if ($na == $cn) {
             return -1;
         }
         if ($nb == $cn) {
             return 1;
         }
         if ($na != $nb) {
             return $na < $nb ? -1 : 1;
         }
         return 0;
     });
     foreach ($courses as $course) {
         $vpls = $DB->get_records(VPL, array('course' => $course->id));
         foreach ($vpls as $vplinstace) {
             if ($vplinstace->id == $vplid) {
                 continue;
             }
             $othervpl = new mod_vpl(false, $vplinstace->id);
             if (!$othervpl->get_course_module()) {
                 continue;
             }
             if ($othervpl->has_capability(VPL_SIMILARITY_CAPABILITY)) {
                 $list[$othervpl->get_course_module()->id] = $othervpl->get_course()->shortname . ' ' . $othervpl->get_printable_name();
             }
         }
         if (count($list) > 1000) {
             break;
             //Stop loading instances
         }
     }
     $list[''] = get_string('select');
     return $list;
 }
Пример #2
0
/**
 * Get a list of courses and also include 'Site' for site wide rules.
 *
 * @return array|bool Returns an array of courses or false if the user has no permission to subscribe to rules.
 */
function tool_monitor_get_user_courses()
{
    $orderby = 'visible DESC, sortorder ASC';
    $options = array();
    if (has_capability('tool/monitor:subscribe', context_system::instance())) {
        $options[0] = get_string('site');
    }
    if ($courses = get_user_capability_course('tool/monitor:subscribe', null, true, 'fullname, visible', $orderby)) {
        foreach ($courses as $course) {
            $coursectx = context_course::instance($course->id);
            if ($course->visible || has_capability('moodle/course:viewhiddencourses', $coursectx)) {
                $options[$course->id] = format_string($course->fullname, true, array('context' => $coursectx));
            }
        }
    }
    // If there are no courses and there is no site permission then return false.
    if (count($options) < 1) {
        return false;
    } else {
        return $options;
    }
}
Пример #3
0
// $Id: mod.php,v 1.9.2.3 2009/10/08 02:05:26 nicolasconnault Exp $
if (!defined('MOODLE_INTERNAL')) {
    die('Direct access to this script is forbidden.');
    ///  It must be included from a Moodle page
}
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->dirroot . '/backup/restorelib.php';
$syscontext = get_context_instance(CONTEXT_SYSTEM);
// if we're not a course creator , we can only import from our own courses.
if (has_capability('moodle/course:create', $syscontext)) {
    $creator = true;
}
$strimport = get_string("importdata");
$tcourseids = '';
if ($teachers = get_user_capability_course('moodle/course:update')) {
    foreach ($teachers as $teacher) {
        if ($teacher->id != $course->id && $teacher->id != SITEID) {
            $tcourseids .= $teacher->id . ',';
        }
    }
}
$taught_courses = array();
if (!empty($tcourseids)) {
    $tcourseids = substr($tcourseids, 0, -1);
    $taught_courses = get_records_list('course', 'id', $tcourseids, 'sortorder');
}
if (!empty($creator)) {
    $cat_courses = get_courses($course->category, $sort = "c.sortorder ASC", $fields = "c.id, c.fullname");
} else {
    $cat_courses = array();
Пример #4
0
/**
 * Returns the list of courses in which the user has permission to view the grade book
 *
 * Does not return the id of the current $COURSE and the site course (front page).
 *
 * @param int $userid The ID of user for which we want to get the list of courses. Defaults to
 * current $USER id.
 * @access public
 * @return array The list of course records
 */
function subcourse_available_courses($userid = null)
{
    global $COURSE, $USER, $DB;
    $courses = array();
    // to be returned
    if (empty($userid)) {
        $userid = $USER->id;
    }
    $fields = 'fullname,shortname,idnumber,category,visible,sortorder';
    $mycourses = get_user_capability_course('moodle/grade:viewall', $userid, true, $fields, 'sortorder');
    $existingsubcourses = $DB->get_records('subcourse', array('course' => $COURSE->id));
    if ($mycourses) {
        foreach ($mycourses as $mycourse) {
            if ($mycourse->id != $COURSE->id && $mycourse->id != SITEID) {
                foreach ($existingsubcourses as $existingsubcourse) {
                    if ($mycourse->id == $existingsubcourse->refcourse) {
                        continue 2;
                    }
                }
                $courses[] = $mycourse;
            }
        }
    }
    return $courses;
}
Пример #5
0
}
// This is the correct way to fill up $USER variable
complete_user_login($user);
if ($action === 'students') {
    if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
        emarking_json_error('Invalid course id');
    }
    $rs = emarking_get_students_for_printing($course->id);
    $results = array();
    foreach ($rs as $r) {
        $results[] = $r;
    }
    emarking_json_resultset($results);
} else {
    if ($action === 'courses') {
        $rs = get_user_capability_course($capability, $user->id);
        $results = array();
        foreach ($rs as $r) {
            $results[] = $r;
        }
        emarking_json_resultset($results);
    } else {
        if ($action === 'activities') {
            if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
                emarking_json_error('Invalid course id');
            }
            $rs = get_coursemodules_in_course('emarking', $course->id);
            $results = array();
            foreach ($rs as $r) {
                $results[] = $r;
            }
Пример #6
0
 /**
  * Get listing for a course folder.
  *
  * @param string $path Folder path.
  * @return array List of $list array and $path array.
  */
 protected function get_listing_course($path = '')
 {
     global $USER, $OUTPUT;
     $list = [];
     $breadcrumb = [['name' => $this->name, 'path' => '/'], ['name' => 'Courses', 'path' => '/courses/']];
     $reqcap = \local_o365\rest\sharepoint::get_course_site_required_capability();
     $courses = get_user_capability_course($reqcap, $USER->id, true, 'shortname');
     // Reindex courses array using course id.
     $coursesbyid = [];
     foreach ($courses as $i => $course) {
         $coursesbyid[$course->id] = $course;
         unset($courses[$i]);
     }
     unset($courses);
     if ($path === '/') {
         // Show available courses.
         foreach ($coursesbyid as $course) {
             $list[] = ['title' => $course->shortname, 'path' => '/courses/' . $course->id, 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'children' => []];
         }
     } else {
         $pathtrimmed = trim($path, '/');
         $pathparts = explode('/', $pathtrimmed);
         if (!is_numeric($pathparts[0])) {
             throw new \moodle_exception('errorbadpath', 'repository_office365');
         }
         $courseid = (int) $pathparts[0];
         unset($pathparts[0]);
         $relpath = !empty($pathparts) ? implode('/', $pathparts) : '';
         if (isset($coursesbyid[$courseid])) {
             if ($this->path_is_upload($path) === false) {
                 $sharepointclient = $this->get_sharepoint_apiclient();
                 if (!empty($sharepointclient)) {
                     $parentsiteuri = $sharepointclient->get_course_subsite_uri($coursesbyid[$courseid]->id);
                     $sharepointclient->set_site($parentsiteuri);
                     try {
                         $fullpath = !empty($relpath) ? '/' . $relpath : '/';
                         $contents = $sharepointclient->get_files($fullpath);
                         $list = $this->contents_api_response_to_list($contents, $path, 'sharepoint', $parentsiteuri);
                     } catch (\Exception $e) {
                         $list = [];
                     }
                 }
             }
             $curpath = '/courses/' . $courseid;
             $breadcrumb[] = ['name' => $coursesbyid[$courseid]->shortname, 'path' => $curpath];
             foreach ($pathparts as $pathpart) {
                 if (!empty($pathpart)) {
                     $curpath .= '/' . $pathpart;
                     $breadcrumb[] = ['name' => $pathpart, 'path' => $curpath];
                 }
             }
         }
     }
     return [$list, $breadcrumb];
 }
Пример #7
0
    $PAGE->set_context(context_system::instance());
} else {
    $pageurl->param('id', $courseid);
    $context = context_course::instance($course->id);
    $PAGE->set_context($context);
    require_course_login($course);
}
$PAGE->set_url($pageurl);
$PAGE->set_pagelayout('admin');
$PAGE->navbar->add($modulename, $pageurl);
$PAGE->set_title($modulename);
$PAGE->set_heading('');
// Course menu selector.
$courseselector = null;
// Display a list of course where the user has indexview capability.
if ($courses = get_user_capability_course('mod/dataform:indexview', null, true, 'fullname')) {
    $coursemenu = array();
    foreach ($courses as $crs) {
        $coursemenu[$crs->id] = $crs->fullname;
    }
    $select = new \single_select($pageurl, 'id', $coursemenu, $courseid, array(0 => get_string('choosedots')), 'index_jump');
    $select->set_label(get_string('course') . '&nbsp;');
    $courseselector = $OUTPUT->render($select);
}
echo $OUTPUT->header();
echo $courseselector;
// Without course id, display just the selector.
if (!$courseid) {
    echo $OUTPUT->footer();
    exit;
}
Пример #8
0
/**
 * returns a context in which the user can do restore.
 */
function local_get_one_of_my_power_contexts()
{
    if ($courseswithbackup = get_user_capability_course('moodle/restore:restorecourse')) {
        $oneof = array_shift($courseswithbackup);
        return context_course::instance($oneof->id);
    }
    return null;
}
Пример #9
0
 /**
  * Gets a list of courses where the current user can subscribe to rules as a dropdown.
  *
  * @return \single_select|bool returns the list of courses, or false if the select box
  *      should not be displayed.
  */
 public function get_user_courses_select()
 {
     global $DB;
     // If the number of courses on the site exceed the maximum drop down limit do not display the select box.
     $numcourses = $DB->count_records('course');
     if ($numcourses > COURSE_MAX_COURSES_PER_DROPDOWN) {
         return false;
     }
     $orderby = 'visible DESC, sortorder ASC';
     $options = array(0 => get_string('site'));
     if ($courses = get_user_capability_course('tool/monitor:subscribe', null, true, 'fullname', $orderby)) {
         foreach ($courses as $course) {
             $options[$course->id] = format_string($course->fullname, true, array('context' => \context_course::instance($course->id)));
         }
     }
     $url = new \moodle_url('/admin/tool/monitor/index.php');
     $select = new \single_select($url, 'courseid', $options, $this->courseid);
     $select->set_label(get_string('selectacourse', 'tool_monitor'));
     return $select;
 }
<?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);
}
Пример #11
0
/**
 * Returns the list of courses the grades can be taken from
 *
 * Returned are courses in which the user has permission to view the grade
 * book. Never returns the current course (as a course cannot be a subcourse of
 * itself) and the site course (the front page course). If the userid is not
 * passed, the current user is expected.
 *
 * @param int $userid Id of user for which we want to get the list of courses
 * @return array list of course records
 */
function subcourse_available_courses($userid = null)
{
    global $COURSE, $USER, $DB;
    $courses = array();
    // to be returned
    if (empty($userid)) {
        $userid = $USER->id;
    }
    $fields = 'fullname,shortname,idnumber,category,visible,sortorder';
    $mycourses = get_user_capability_course('moodle/grade:viewall', $userid, true, $fields, 'sortorder');
    if ($mycourses) {
        $ignorecourses = array($COURSE->id, SITEID);
        foreach ($mycourses as $mycourse) {
            if (in_array($mycourse->id, $ignorecourses)) {
                continue;
            }
            $courses[] = $mycourse;
        }
    }
    return $courses;
}