本文整理汇总了PHP中get_enrolled_users函数的典型用法代码示例。如果您正苦于以下问题:PHP get_enrolled_users函数的具体用法?PHP get_enrolled_users怎么用?PHP get_enrolled_users使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_enrolled_users函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: blended_get_users_by_type
/**
* Find the list of users and get a list with the ids of students and a list of non-students
* @param type $context_course
* @return array(array($studentIds), array($non_studentIds), array($activeids), array($user_records))
*/
function blended_get_users_by_type($context_course)
{
// Get users with gradable roles
global $CFG;
$gradable_roles = $CFG->gradebookroles;
$roles = explode(',', $gradable_roles);
$students = array();
foreach ($roles as $roleid) {
$users_in_role = get_role_users($roleid, $context_course);
$ids = array_keys($users_in_role);
$students = array_merge($students, $ids);
$students = array_unique($students);
}
// get enrolled users
$user_records = get_enrolled_users($context_course, '', 0, '*');
$users = array_keys($user_records);
$non_students = array_diff($users, $students);
// select active userids
$activeids = array();
global $DB;
list($select, $params) = $DB->get_in_or_equal($students);
$select = "userid {$select}";
$select .= " AND courseid = ?";
$params[] = (int) $context_course->instanceid;
$last_accesses = $DB->get_records_select('user_lastaccess', $select, $params);
foreach ($last_accesses as $record) {
$activeids[] = $record->userid;
}
return array($students, $non_students, $activeids, $user_records);
}
示例2: game_showusers
function game_showusers($game)
{
global $CFG, $USER;
$users = array();
$context = get_context_instance(CONTEXT_COURSE, $game->course);
if ($courseusers = get_enrolled_users($context)) {
foreach ($courseusers as $courseuser) {
$users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context));
}
}
if ($guest = guest_user()) {
$users[$guest->id] = fullname($guest);
}
?>
<script type="text/javascript">
function onselectuser()
{
window.location.href = "<?php
echo $CFG->wwwroot . '/mod/game/showanswers.php?q=' . $game->id . '&userid=';
?>
" + document.getElementById('menuuser').value;
}
</script>
<?php
//choose_from_menu($users, 'user', $USER->id, get_string("allparticipants"), 'javascript:onselectuser();');
//function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
// $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
// $id='', $listbox=false, $multiple=false, $class='')
$attributes = 'onchange="javascript:onselectuser();"';
$name = 'user';
$id = 'menu' . $name;
$class = 'menu' . $name;
$class = 'select ' . $class;
/// Add 'select' selector always
$nothing = get_string("allparticipants");
$nothingvalue = '0';
$options = $users;
$selected = optional_param('userid', $USER->id, PARAM_INT);
$output = '<select id="' . $id . '" class="' . $class . '" name="' . $name . '" ' . $attributes . '>' . "\n";
$output .= ' <option value="' . s($nothingvalue) . '"' . "\n";
if ($nothingvalue === $selected) {
$output .= ' selected="selected"';
}
$output .= '>' . $nothing . '</option>' . "\n";
if (!empty($options)) {
foreach ($options as $value => $label) {
$output .= ' <option value="' . s($value) . '"';
if ((string) $value == (string) $selected || is_array($selected) && in_array($value, $selected)) {
$output .= ' selected="selected"';
}
if ($label === '') {
$output .= '>' . $value . '</option>' . "\n";
} else {
$output .= '>' . $label . '</option>' . "\n";
}
}
}
echo $output . '</select>' . "\n";
}
示例3: __construct
/**
* Constructor.
*
* @param string $uniqueid Unique ID.
* @param int $courseid Course ID.
* @param int $groupid Group ID.
*/
public function __construct($uniqueid, $courseid, $groupid)
{
global $DB, $PAGE;
parent::__construct($uniqueid);
// Block XP stuff.
$this->xpmanager = block_xp_manager::get($courseid);
$this->xpoutput = $PAGE->get_renderer('block_xp');
$context = context_course::instance($courseid);
// Define columns.
$this->define_columns(array('userpic', 'fullname', 'lvl', 'xp', 'progress', 'actions'));
$this->define_headers(array('', get_string('fullname'), get_string('level', 'block_xp'), get_string('xp', 'block_xp'), get_string('progress', 'block_xp'), ''));
// Get all the users that are enrolled and can earn XP.
$ids = array();
$users = get_enrolled_users($context, 'block/xp:earnxp', $groupid);
foreach ($users as $user) {
$ids[$user->id] = $user->id;
}
unset($users);
// Get the users which might not be enrolled or are revoked the permission, but still should
// be displayed in the report for the teachers' benefit. We need to filter out the users which
// are not a member of the group though.
if (empty($groupid)) {
$sql = 'SELECT userid FROM {block_xp} WHERE courseid = :courseid';
$params = array('courseid' => $courseid);
} else {
$sql = 'SELECT b.userid
FROM {block_xp} b
JOIN {groups_members} gm
ON b.userid = gm.userid
AND gm.groupid = :groupid
WHERE courseid = :courseid';
$params = array('courseid' => $courseid, 'groupid' => $groupid);
}
$entries = $DB->get_recordset_sql($sql, $params);
foreach ($entries as $entry) {
$ids[$entry->userid] = $entry->userid;
}
$entries->close();
list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param', true, null);
// Define SQL.
$this->sql = new stdClass();
$this->sql->fields = user_picture::fields('u') . ', COALESCE(x.lvl, 1) AS lvl, x.xp, ' . context_helper::get_preload_record_columns_sql('ctx');
$this->sql->from = "{user} u\n JOIN {context} ctx\n ON ctx.instanceid = u.id\n AND ctx.contextlevel = :contextlevel\n LEFT JOIN {block_xp} x\n ON (x.userid = u.id AND x.courseid = :courseid)";
$this->sql->where = "u.id {$insql}";
$this->sql->params = array_merge($inparams, array('courseid' => $courseid, 'contextlevel' => CONTEXT_USER));
// Define various table settings.
$this->sortable(true, 'lvl', SORT_DESC);
$this->no_sorting('userpic');
$this->no_sorting('progress');
$this->collapsible(false);
}
示例4: definition
/**
* Defines forms elements
*/
public function definition()
{
global $COURSE, $DB, $CFG;
$criteria = $this->_customdata['criteria'];
$context = $this->_customdata['context'];
$cmid = $this->_customdata['id'];
$emarking = $this->_customdata['emarking'];
$action = $this->_customdata['action'];
$totalpages = $this->_customdata['totalpages'];
$mform = $this->_form;
// Add header.
$mform->addElement('header', 'general', $action === 'addmarkers' ? get_string('assignmarkerstocriteria', 'mod_emarking') : get_string('assignpagestocriteria', 'mod_emarking'));
// Hide course module id.
$mform->addElement('hidden', 'id', $cmid);
$mform->setType('id', PARAM_INT);
// Hide action.
$mform->addElement('hidden', 'action', $action);
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('html', '<table class="addmarkerstable"><tr><td>');
if ($action === "addmarkers") {
// Array of motives for regrading.
$markers = get_enrolled_users($context, 'mod/assign:grade');
$chkmarkers = array();
foreach ($markers as $marker) {
$chkmarkers[$marker->id] = $marker->firstname . " " . $marker->lastname;
}
$select = $mform->addElement('select', 'datamarkers', get_string('markers', 'mod_emarking'), $chkmarkers, null);
$select->setMultiple(true);
} else {
$chkpages = array();
for ($i = 1; $i <= $totalpages; $i++) {
$chkpages[$i] = get_string('page', 'mod_emarking') . " " . $i;
}
$select = $mform->addElement('select', 'datapages', core_text::strtotitle(get_string('pages', 'mod_emarking')), $chkpages, null);
$select->setMultiple(true);
}
$criteriaitems = array();
foreach ($criteria as $criterion) {
$criteriaitems[$criterion['id']] = $criterion['description'];
}
$mform->addElement('html', '</td><td>');
if ($action === "addmarkers") {
$select = $mform->addElement('select', 'criteriamarkers', get_string('criteria', 'mod_emarking'), $criteriaitems, null);
} else {
$select = $mform->addElement('select', 'criteriapages', get_string('criteria', 'mod_emarking'), $criteriaitems, null);
}
$select->setMultiple(true);
$mform->addElement('html', '</td></tr></table>');
// Add action buttons.
$this->add_action_buttons();
}
示例5: definition
function definition()
{
$courseid = optional_param('courseid', 0, PARAM_INT);
$mform =& $this->_form;
$context = context_course::instance($courseid);
$mform->addElement('hidden', 'courseid', $courseid);
$mform->setType('courseid', PARAM_INT);
$users = get_enrolled_users($context);
foreach ($users as $user) {
$mform->addElement('advcheckbox', 'usersids[]', $user->firstname . ' ' . $user->lastname, ' email: ' . $user->email, array('group' => 1), array(0, $user->id));
//$mform->setDefault('usersids', $user->id);
}
$buttons = array();
$buttons[] =& $mform->createElement('submit', 'send', get_string('email_send', 'block_configurable_reports'));
$buttons[] =& $mform->createElement('cancel');
$mform->addGroup($buttons, 'buttons', get_string('actions'), array(' '), false);
}
示例6: definition
/**
* Defines forms elements
*/
public function definition()
{
global $COURSE, $DB, $CFG;
$criteria = $this->_customdata['criteria'];
$context = $this->_customdata['context'];
$cmid = $this->_customdata['id'];
$emarking = $this->_customdata['emarking'];
$mform = $this->_form;
// Add header
$mform->addElement('header', 'general', get_string('assignmarkerstocriteria', 'mod_emarking'));
// Hide course module id
$mform->addElement('hidden', 'id', $cmid);
$mform->setType('id', PARAM_INT);
// Array of motives for regrading
$markers = get_enrolled_users($context, 'mod/assign:grade');
foreach ($criteria as $criterion) {
$chkmarkers = array();
foreach ($markers as $marker) {
$chkmarkers[] = $mform->createElement('checkbox', 'assign-' . $criterion['id'] . '-' . $marker->id, null, $marker->firstname . " " . $marker->lastname);
}
// Add markers group as checkboxes
$mform->addGroup($chkmarkers, 'markers-' . $criterion['id'], $criterion['description'], array('<br />'), false);
$mform->addRule('markers-' . $criterion['id'], get_string('required'), 'required', null, 'client');
$mform->setType('markers-' . $criterion['id'], PARAM_INT);
}
if (isset($emarking->totalpages) && $emarking->totalpages > 0) {
// Add header
$mform->addElement('header', 'general', ucfirst(get_string('assignpagestocriteria', 'mod_emarking')));
foreach ($criteria as $criterion) {
$chkpages = array();
for ($i = 1; $i <= $emarking->totalpages; $i++) {
$chkpages[] = $mform->createElement('checkbox', 'page-' . $criterion['id'] . '-' . $i, null, get_string('page', 'mod_emarking') . " " . $i);
}
// Add pages group as checkboxes
$mform->addGroup($chkpages, 'pages-' . $criterion['id'], $criterion['description'], array('<br />'), false);
$mform->addRule('pages-' . $criterion['id'], get_string('required'), 'required', null, 'client');
$mform->setType('pages-' . $criterion['id'], PARAM_INT);
}
}
// Add action buttons
$this->add_action_buttons();
}
示例7: block_print_user_table
function block_print_user_table($blockid, $courseid, $skillmax, $return = false)
{
$context = context_course::instance($courseid);
$userfields = 'u.id, u.firstname, u.lastname';
$userlist = get_enrolled_users($context, 'block/skill_bars:viewpages', 0, $userfields);
$skillslist = get_course_skills($courseid);
$headers = array('User');
foreach ($skillslist as $skill) {
$headers[] = $skill->name;
}
$showlist = new html_table();
$showlist->head = $headers;
$showlistdata = array();
foreach ($userlist as $user) {
$fullname = $user->firstname . " " . $user->lastname;
$skills = get_user_skills($user->id, $courseid);
$record = array();
if (count($skills)) {
$url = new moodle_url('/blocks/skill_bars/update.php', array('blockid' => $blockid, 'courseid' => $courseid, 'userid' => $user->id));
$link = html_writer::link($url, $fullname);
$record[] = $link;
foreach ($skills as $skill) {
$record[] = get_skillbar_icon($skill->points, $skillmax);
}
} else {
$record[] = $fullname;
foreach ($skillslist as $skill) {
$record[] = '';
}
}
$showlistdata[] = $record;
}
$showlist->data = $showlistdata;
if ($return) {
return html_writer::table($showlist);
} else {
echo html_writer::table($showlist);
}
}
示例8: definition
public function definition()
{
global $COURSE;
$context = context_course::instance($COURSE->id);
$namefields = get_all_user_name_fields(true, 'u');
$students = get_enrolled_users($context, 'mod/attendance:canbelisted', 0, 'u.id,' . $namefields . ',u.email', 'u.lastname, u.firstname', 0, 0, true);
$partarray = array();
foreach ($students as $student) {
$partarray[$student->id] = fullname($student) . ' (' . $student->email . ')';
}
$mform = $this->_form;
$description = $this->_customdata['description'];
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'userid', 0);
$mform->setType('userid', PARAM_INT);
$mform->addElement('header', 'attheader', get_string('tempusermerge', 'attendance'));
$mform->addElement('static', 'description', get_string('tempuser', 'attendance'), $description);
$mform->addElement('select', 'participant', get_string('participant', 'attendance'), $partarray);
$mform->addElement('static', 'requiredentries', '', get_string('requiredentries', 'attendance'));
$mform->addHelpButton('requiredentries', 'requiredentry', 'attendance');
$this->add_action_buttons(true, get_string('mergeuser', 'attendance'));
}
示例9: __construct
/**
* Constructor.
*
* @param string $uniqueid Unique ID.
*/
public function __construct($uniqueid, $courseid)
{
global $DB, $PAGE;
parent::__construct($uniqueid);
// Block XP stuff.
$this->xpmanager = block_xp_manager::get($courseid);
$this->xpoutput = $PAGE->get_renderer('block_xp');
$context = context_course::instance($courseid);
// Define columns.
$this->define_columns(array('userpic', 'fullname', 'lvl', 'xp', 'progress', 'actions'));
$this->define_headers(array('', get_string('fullname'), get_string('level', 'block_xp'), get_string('xp', 'block_xp'), get_string('progress', 'block_xp'), ''));
// Get the relevant user IDs, users enrolled or users with XP.
// This might be a performance issue at some point.
$ids = array();
$users = get_enrolled_users($context, 'block/xp:earnxp');
foreach ($users as $user) {
$ids[$user->id] = $user->id;
}
unset($users);
$entries = $DB->get_recordset_sql('SELECT userid FROM {block_xp} WHERE courseid = :courseid', array('courseid' => $courseid));
foreach ($entries as $entry) {
$ids[$entry->userid] = $entry->userid;
}
$entries->close();
list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param', true, null);
// Define SQL.
$this->sql = new stdClass();
$this->sql->fields = user_picture::fields('u') . ', x.lvl, x.xp';
$this->sql->from = "{user} u LEFT JOIN {block_xp} x ON (x.userid = u.id AND x.courseid = :courseid)";
$this->sql->where = "u.id {$insql}";
$this->sql->params = array_merge($inparams, array('courseid' => $courseid));
// Define various table settings.
$this->sortable(true, 'lvl', SORT_DESC);
$this->no_sorting('userpic');
$this->no_sorting('progress');
$this->collapsible(false);
}
示例10: get_content
function get_content()
{
global $CFG, $OUTPUT;
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass();
$this->content->footer = '';
if (empty($this->instance)) {
$this->content->text = '';
return $this->content;
}
// user/index.php expect course context, so get one if page has module context.
$currentcontext = $this->page->context->get_course_context(false);
if (!empty($this->config->text)) {
$this->content->text = $this->config->text;
}
$this->content->text = 'No Hangout';
if (empty($currentcontext)) {
return $this->content;
}
if ($this->page->course->id == SITEID) {
$this->context->text .= "site context";
}
$users = get_enrolled_users($currentcontext);
$usersemails = '';
foreach ($users as $user) {
$usersemails .= "{ id : '{$user->email}', invite_type : 'EMAIL' },";
}
$this->content->text = "<script src=\"https://apis.google.com/js/platform.js\" async defer></script>\n <g:hangout render=\"createhangout\" invites=\"[{$usersemails}]\"></g:hangout>";
$this->content->text .= '<br><a href= "' . $CFG->wwwroot . '/blocks/google_hangout/select_users.php?courseid=' . $this->page->course->id . '" alt="Select users">Hangout with selected users</a>';
if (!empty($this->config->text)) {
$this->content->text .= $this->config->text;
}
return $this->content;
}
示例11: show_add_tii_tutors_form
/**
* Show a form with a dropdown box to allow tutors who are enrolled in Moodle
* on this course to be added to this course in Turnitin
*
* @global type $CFG
* @global type $OUTPUT
* @param obj $cm course module data
* @param array $tutors tutors who are currently enrolled with Turnitin
* @return output
*/
public function show_add_tii_tutors_form($cm, $tutors)
{
global $CFG, $OUTPUT;
$moodletutors = get_enrolled_users(context_module::instance($cm->id), 'mod/turnitintooltwo:grade', 0, 'u.id');
// Populate elements array which will generate the form elements
// Each element is in following format: (type, name, label, helptext (minus _help), options (if select).
$elements = array();
$elements[] = array('header', 'add_tii_tutors', get_string('turnitintutorsadd', 'turnitintooltwo'));
$options = array();
foreach ($moodletutors as $k => $v) {
$availabletutor = new turnitintooltwo_user($v->id, "Instructor", false, "site", false);
if (array_key_exists($availabletutor->id, $tutors)) {
unset($moodletutors[$k]);
} else {
$options[$availabletutor->id] = $availabletutor->fullname . ' (' . $availabletutor->email . ')';
}
}
if (count($options) == 0) {
$elements[] = array('static', 'turnitintutors', get_string('turnitintutors', 'turnitintooltwo') . ": ", '', get_string('turnitintutorsallenrolled', 'turnitintooltwo'));
$customdata["hide_submit"] = true;
} else {
$elements[] = array('select', 'turnitintutors', get_string('turnitintutors', 'turnitintooltwo'), '', $options);
$elements[] = array('hidden', 'action', 'addtutor');
$customdata["show_cancel"] = false;
$customdata["submit_label"] = get_string('turnitintutorsadd', 'turnitintooltwo');
}
$customdata["elements"] = $elements;
$form = new turnitintooltwo_form($CFG->wwwroot . '/mod/turnitintooltwo/view.php' . '?id=' . $cm->id . '&do=tutors', $customdata);
$output = $OUTPUT->box($form->display(), 'generalbox boxaligncenter', 'general');
return $output;
}
示例12: get_submissions
/**
* Returns submissions by part (and unsubmitted users if appropriate)
*
* @global type $DB
* @global type $USER
* @param object $cm course module object
* @param int $partid specific part id, includes all if 0
* @param int $userid specific user id, includes all if 0
* @param int $submissionsonly flag to include/remove non submitted students from results
* @return array of submissions by part
*/
public function get_submissions($cm, $partid = 0, $userid = 0, $submissionsonly = 0)
{
global $DB, $USER;
// If no part id is specified then get them all.
$sql = " turnitintooltwoid = ? ";
$sqlparams = array($this->id);
if ($partid == 0) {
$parts = $this->get_parts();
} else {
$part = $this->get_part_details($partid);
$parts[$partid] = $part;
$sql .= " AND submission_part = ? ";
$sqlparams[] = $partid;
}
$context = context_module::instance($cm->id);
$istutor = has_capability('mod/turnitintooltwo:grade', $context);
// If logged in as instructor then get for all users.
$allnamefields = get_all_user_name_fields();
if ($istutor && $userid == 0) {
$users = get_enrolled_users($context, 'mod/turnitintooltwo:submit', groups_get_activity_group($cm), 'u.id, ' . implode($allnamefields, ', '));
$users = !$users ? array() : $users;
} else {
if ($istutor) {
$user = $DB->get_record('user', array('id' => $userid), 'id, ' . implode($allnamefields, ', '));
$users = array($userid => $user);
$sql .= " AND userid = ? ";
$sqlparams[] = $userid;
} else {
$users = array($USER->id => $USER);
$sql .= " AND userid = ? ";
$sqlparams[] = $USER->id;
}
}
// Populate the submissions array to show all users for all parts.
$submissions = array();
foreach ($parts as $part) {
$submissions[$part->id] = array();
foreach ($users as $user) {
$emptysubmission = new stdClass();
$emptysubmission->userid = $user->id;
$emptysubmission->firstname = $user->firstname;
$emptysubmission->lastname = $user->lastname;
$emptysubmission->fullname = fullname($user);
$emptysubmission->submission_unanon = 0;
$emptysubmission->nmoodle = 0;
if ($submissionsonly == 0) {
$submissions[$part->id][$user->id] = $emptysubmission;
}
}
}
// Get submissions that were made where a moodle userid is known.
// Contains moodle users both enrolled or not enrolled.
if ($submissionsdata = $DB->get_records_select("turnitintooltwo_submissions", " userid != 0 AND " . $sql, $sqlparams)) {
foreach ($submissionsdata as $submission) {
$user = new turnitintooltwo_user($submission->userid, 'Learner', false);
$submission->firstname = $user->firstname;
$submission->lastname = $user->lastname;
$submission->fullname = $user->fullname;
$submission->tii_user_id = $user->tii_user_id;
$submission->nmoodle = 0;
if (isset($users[$user->id])) {
// User is a moodle user ie in array from moodle user call above.
$submissions[$submission->submission_part][$user->id] = $submission;
} else {
if (groups_get_activity_group($cm) == 0) {
// User is not a moodle user ie not in array from moodle user call above and group list is set to all users.
$submission->nmoodle = 1;
$submissions[$submission->submission_part][$user->id] = $submission;
}
}
}
}
// Now get submissions that were made by a non moodle students.
// These are unknown to moodle possibly non-enrolled on turnitin.
// Possibly real but not yet linked Turnitin users. If group list is set do not get these non group users.
if ($submissionsdata = $DB->get_records_select("turnitintooltwo_submissions", " userid = 0 AND " . $sql, $sqlparams) and groups_get_activity_group($cm) == 0) {
foreach ($submissionsdata as $submission) {
$submission->nmoodle = 1;
$submission->userid = $submission->submission_nmuserid;
$submission->firstname = $submission->submission_nmfirstname;
$submission->lastname = $submission->submission_nmlastname;
$submissions[$submission->submission_part][$submission->userid] = $submission;
}
}
return $submissions;
}
示例13: definition
function definition()
{
global $CFG, $COURSE, $USER;
$mform =& $this->_form;
$context = context_course::instance($COURSE->id);
$modinfo = get_fast_modinfo($COURSE);
$sections = get_all_sections($COURSE->id);
$mform->addElement('header', 'filters', get_string('managefilters'));
//TODO: add better string
$groupoptions = array();
if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
// limited group access
$groups = groups_get_user_groups($COURSE->id);
$allgroups = groups_get_all_groups($COURSE->id);
if (!empty($groups[$COURSE->defaultgroupingid])) {
foreach ($groups[$COURSE->defaultgroupingid] as $groupid) {
$groupoptions[$groupid] = format_string($allgroups[$groupid]->name, true, array('context' => $context));
}
}
} else {
$groupoptions = array('0' => get_string('allgroups'));
if (has_capability('moodle/site:accessallgroups', $context)) {
// user can see all groups
$allgroups = groups_get_all_groups($COURSE->id);
} else {
// user can see course level groups
$allgroups = groups_get_all_groups($COURSE->id, 0, $COURSE->defaultgroupingid);
}
foreach ($allgroups as $group) {
$groupoptions[$group->id] = format_string($group->name, true, array('context' => $context));
}
}
if ($COURSE->id == SITEID) {
$viewparticipants = has_capability('moodle/site:viewparticipants', context_system::instance());
} else {
$viewparticipants = has_capability('moodle/course:viewparticipants', $context);
}
if ($viewparticipants) {
$viewfullnames = has_capability('moodle/site:viewfullnames', context_course::instance($COURSE->id));
$options = array();
$options[0] = get_string('allparticipants');
$options[$CFG->siteguest] = get_string('guestuser');
if (isset($groupoptions[0])) {
// can see all enrolled users
if ($enrolled = get_enrolled_users($context, null, 0, user_picture::fields('u'))) {
foreach ($enrolled as $euser) {
$options[$euser->id] = fullname($euser, $viewfullnames);
}
}
} else {
// can see users from some groups only
foreach ($groupoptions as $groupid => $unused) {
if ($enrolled = get_enrolled_users($context, null, $groupid, user_picture::fields('u'))) {
foreach ($enrolled as $euser) {
if (!array_key_exists($euser->id, $options)) {
$options[$euser->id] = fullname($euser, $viewfullnames);
}
}
}
}
}
$mform->addElement('select', 'user', get_string('participants'), $options);
$mform->setAdvanced('user');
}
$sectiontitle = get_string('sectionname', 'format_' . $COURSE->format);
$options = array('' => get_string('allactivities'));
$modsused = array();
foreach ($modinfo->cms as $cm) {
if (!$cm->uservisible) {
continue;
}
$modsused[$cm->modname] = true;
}
foreach ($modsused as $modname => $unused) {
$libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
if (!file_exists($libfile)) {
unset($modsused[$modname]);
continue;
}
include_once $libfile;
$libfunction = $modname . "_get_recent_mod_activity";
if (!function_exists($libfunction)) {
unset($modsused[$modname]);
continue;
}
$options["mod/{$modname}"] = get_string('allmods', '', get_string('modulenameplural', $modname));
}
foreach ($modinfo->sections as $section => $cmids) {
$options["section/{$section}"] = "-- " . get_section_name($COURSE, $sections[$section]) . " --";
foreach ($cmids as $cmid) {
$cm = $modinfo->cms[$cmid];
if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
continue;
}
$options[$cm->id] = format_string($cm->name);
}
}
$mform->addElement('select', 'modid', get_string('activities'), $options);
$mform->setAdvanced('modid');
if ($groupoptions) {
//.........这里部分代码省略.........
示例14: display_submission
/**
* Display a single submission, ready for grading on a popup window
*
* This default method prints the teacher info and submissioncomment box at the top and
* the student info and submission at the bottom.
* This method also fetches the necessary data in order to be able to
* provide a "Next submission" button.
* Calls preprocess_submission() to give assignment type plug-ins a chance
* to process submissions before they are graded
* This method gets its arguments from the page parameters userid and offset
*
* @global object
* @global object
* @param string $extra_javascript
*/
function display_submission($offset=-1,$userid =-1, $display=true) {
global $CFG, $DB, $PAGE, $OUTPUT;
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once("$CFG->dirroot/repository/lib.php");
if ($userid==-1) {
$userid = required_param('userid', PARAM_INT);
}
if ($offset==-1) {
$offset = required_param('offset', PARAM_INT);//offset for where to start looking for student.
}
$filter = optional_param('filter', 0, PARAM_INT);
if (!$user = $DB->get_record('user', array('id'=>$userid))) {
print_error('nousers');
}
if (!$submission = $this->get_submission($user->id)) {
$submission = $this->prepare_new_submission($userid);
}
if ($submission->timemodified > $submission->timemarked) {
$subtype = 'assignmentnew';
} else {
$subtype = 'assignmentold';
}
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array($user->id));
$gradingdisabled = $grading_info->items[0]->grades[$userid]->locked || $grading_info->items[0]->grades[$userid]->overridden;
/// construct SQL, using current offset to find the data of the next student
$course = $this->course;
$assignment = $this->assignment;
$cm = $this->cm;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// Get all ppl that can submit assignments
$currentgroup = groups_get_activity_group($cm);
$users = get_enrolled_users($context, 'mod/assignment:view', $currentgroup, 'u.id');
if ($users) {
$users = array_keys($users);
// if groupmembersonly used, remove users who are not in any group
if (!empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
$users = array_intersect($users, array_keys($groupingusers));
}
}
}
$nextid = 0;
$where = '';
if($filter == 'submitted') {
$where .= 's.timemodified > 0 AND ';
} else if($filter == 'requiregrading') {
$where .= 's.timemarked < s.timemodified AND ';
}
if ($users) {
$userfields = user_picture::fields('u', array('lastaccess'));
$select = "SELECT $userfields,
s.id AS submissionid, s.grade, s.submissioncomment,
s.timemodified, s.timemarked,
COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ";
$sql = 'FROM {user} u '.
'LEFT JOIN {assignment_submissions} s ON u.id = s.userid
AND s.assignment = '.$this->assignment->id.' '.
'WHERE '.$where.'u.id IN ('.implode(',', $users).') ';
if ($sort = flexible_table::get_sort_for_table('mod-assignment-submissions')) {
$sort = 'ORDER BY '.$sort.' ';
}
$auser = $DB->get_records_sql($select.$sql.$sort, null, $offset, 2);
if (is_array($auser) && count($auser)>1) {
$nextuser = next($auser);
/// Calculate user status
$nextuser->status = ($nextuser->timemarked > 0) && ($nextuser->timemarked >= $nextuser->timemodified);
$nextid = $nextuser->id;
}
}
if ($submission->teacher) {
$teacher = $DB->get_record('user', array('id'=>$submission->teacher));
} else {
global $USER;
//.........这里部分代码省略.........
示例15: assign_print_overview
/**
* Print an overview of all assignments
* for the courses.
*
* @param mixed $courses The list of courses to print the overview for
* @param array $htmlarray The array of html to return
*/
function assign_print_overview($courses, &$htmlarray)
{
global $USER, $CFG, $DB;
if (empty($courses) || !is_array($courses) || count($courses) == 0) {
return array();
}
if (!($assignments = get_all_instances_in_courses('assign', $courses))) {
return;
}
$assignmentids = array();
// Do assignment_base::isopen() here without loading the whole thing for speed
foreach ($assignments as $key => $assignment) {
$time = time();
$isopen = false;
if ($assignment->duedate) {
$duedate = false;
if ($assignment->cutoffdate) {
$duedate = $assignment->cutoffdate;
}
if ($duedate) {
$isopen = $assignment->allowsubmissionsfromdate <= $time && $time <= $duedate;
} else {
$isopen = $assignment->allowsubmissionsfromdate <= $time;
}
}
if ($isopen) {
$assignmentids[] = $assignment->id;
}
}
if (empty($assignmentids)) {
// no assignments to look at - we're done
return true;
}
$strduedate = get_string('duedate', 'assign');
$strcutoffdate = get_string('nosubmissionsacceptedafter', 'assign');
$strnolatesubmissions = get_string('nolatesubmissions', 'assign');
$strduedateno = get_string('duedateno', 'assign');
$strduedateno = get_string('duedateno', 'assign');
$strgraded = get_string('graded', 'assign');
$strnotgradedyet = get_string('notgradedyet', 'assign');
$strnotsubmittedyet = get_string('notsubmittedyet', 'assign');
$strsubmitted = get_string('submitted', 'assign');
$strassignment = get_string('modulename', 'assign');
$strreviewed = get_string('reviewed', 'assign');
// NOTE: we do all possible database work here *outside* of the loop to ensure this scales
//
list($sqlassignmentids, $assignmentidparams) = $DB->get_in_or_equal($assignmentids);
// build up and array of unmarked submissions indexed by assignment id/ userid
// for use where the user has grading rights on assignment
$rs = $DB->get_recordset_sql("SELECT s.assignment as assignment, s.userid as userid, s.id as id, s.status as status, g.timemodified as timegraded\n FROM {assign_submission} s LEFT JOIN {assign_grades} g ON s.userid = g.userid and s.assignment = g.assignment\n WHERE g.timemodified = 0 OR s.timemodified > g.timemodified\n AND s.assignment {$sqlassignmentids}", $assignmentidparams);
$unmarkedsubmissions = array();
foreach ($rs as $rd) {
$unmarkedsubmissions[$rd->assignment][$rd->userid] = $rd->id;
}
$rs->close();
// get all user submissions, indexed by assignment id
$mysubmissions = $DB->get_records_sql("SELECT a.id AS assignment, a.nosubmissions AS nosubmissions, g.timemodified AS timemarked, g.grader AS grader, g.grade AS grade, s.status AS status\n FROM {assign} a LEFT JOIN {assign_grades} g ON g.assignment = a.id AND g.userid = ? LEFT JOIN {assign_submission} s ON s.assignment = a.id AND s.userid = ?\n AND a.id {$sqlassignmentids}", array_merge(array($USER->id, $USER->id), $assignmentidparams));
foreach ($assignments as $assignment) {
// Do not show assignments that are not open
if (!in_array($assignment->id, $assignmentids)) {
continue;
}
$str = '<div class="assign overview"><div class="name">' . $strassignment . ': ' . '<a ' . ($assignment->visible ? '' : ' class="dimmed"') . 'title="' . $strassignment . '" href="' . $CFG->wwwroot . '/mod/assign/view.php?id=' . $assignment->coursemodule . '">' . format_string($assignment->name) . '</a></div>';
if ($assignment->duedate) {
$str .= '<div class="info">' . $strduedate . ': ' . userdate($assignment->duedate) . '</div>';
} else {
$str .= '<div class="info">' . $strduedateno . '</div>';
}
if ($assignment->cutoffdate) {
if ($assignment->cutoffdate == $assignment->duedate) {
$str .= '<div class="info">' . $strnolatesubmissions . '</div>';
} else {
$str .= '<div class="info">' . $strcutoffdate . ': ' . userdate($assignment->cutoffdate) . '</div>';
}
}
$context = context_module::instance($assignment->coursemodule);
if (has_capability('mod/assign:grade', $context)) {
// count how many people can submit
$submissions = 0;
// init
if ($students = get_enrolled_users($context, 'mod/assign:view', 0, 'u.id')) {
foreach ($students as $student) {
if (isset($unmarkedsubmissions[$assignment->id][$student->id])) {
$submissions++;
}
}
}
if ($submissions) {
$link = new moodle_url('/mod/assign/view.php', array('id' => $assignment->coursemodule, 'action' => 'grading'));
$str .= '<div class="details"><a href="' . $link . '">' . get_string('submissionsnotgraded', 'assign', $submissions) . '</a></div>';
}
}
if (has_capability('mod/assign:submit', $context)) {
//.........这里部分代码省略.........