本文整理汇总了PHP中groups_get_user_groups函数的典型用法代码示例。如果您正苦于以下问题:PHP groups_get_user_groups函数的具体用法?PHP groups_get_user_groups怎么用?PHP groups_get_user_groups使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了groups_get_user_groups函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: report_data
public function report_data($visualreport)
{
$data = array();
$data['header'] = array();
$data['header']['student'] = 'student';
$data['header']['grade'] = 'grade';
$data['header']['item'] = 'item';
$data['header']['group'] = 'group';
foreach ($visualreport->grades as $itemkey => $itemgrades) {
foreach ($itemgrades as $studentkey => $studentdata) {
if ($studentdata != null && $studentdata->finalgrade != null) {
foreach (groups_get_user_groups($visualreport->courseid, $studentkey) as $grouping) {
if (count($grouping) > 0) {
foreach ($grouping as $group) {
$data[$studentkey . '-' . $itemkey . '-' . $group]['student'] = $visualreport->users[$studentkey]->firstname . ' ' . $visualreport->users[$studentkey]->lastname;
$data[$studentkey . '-' . $itemkey . '-' . $group]['grade'] = $studentdata->standardise_score($studentdata->finalgrade, $visualreport->gtree->items[$itemkey]->grademin, $visualreport->gtree->items[$itemkey]->grademax, 0, 100);
$data[$studentkey . '-' . $itemkey . '-' . $group]['item'] = $visualreport->gtree->items[$itemkey]->get_name();
$data[$studentkey . '-' . $itemkey . '-' . $group]['group'] = groups_get_group_name($group);
}
} else {
$data[$studentkey . '-' . $itemkey . '-ng']['student'] = $visualreport->users[$studentkey]->firstname . ' ' . $visualreport->users[$studentkey]->lastname;
$data[$studentkey . '-' . $itemkey . '-ng']['grade'] = $studentdata->standardise_score($studentdata->finalgrade, $visualreport->gtree->items[$itemkey]->grademin, $visualreport->gtree->items[$itemkey]->grademax, 0, 100);
$data[$studentkey . '-' . $itemkey . '-ng']['item'] = $visualreport->gtree->items[$itemkey]->get_name();
$data[$studentkey . '-' . $itemkey . '-ng']['group'] = get_string('nogroup', 'gradereport_visual');
}
}
}
}
}
return $data;
}
示例2: _getUserCourseGroupings
private function _getUserCourseGroupings($userId, $courseId)
{
global $CFG;
require_once $CFG->dirroot . '/group/lib.php';
return groups_get_user_groups($courseId, $userId);
/* group/lib.php */
}
示例3: report_data
public function report_data($visualreport)
{
$data = array();
$data['header'] = array();
$data['header']['grade'] = 'grade';
$data['header']['item'] = 'item';
$data['header']['group'] = 'group';
$count = array();
foreach ($visualreport->grades as $itemkey => $itemgrades) {
foreach ($itemgrades as $studentkey => $studentdata) {
if ($studentdata != null && $studentdata->finalgrade != null) {
foreach (groups_get_user_groups($visualreport->courseid, $studentkey) as $grouping) {
if (count($grouping) > 0) {
foreach ($grouping as $group) {
if (!isset($data[$itemkey . '-' . $group])) {
$data[$itemkey . '-' . $group] = array();
$data[$itemkey . '-' . $group]['grade'] = $studentdata->standardise_score($studentdata->finalgrade, $visualreport->gtree->items[$itemkey]->grademin, $visualreport->gtree->items[$itemkey]->grademax, 0, 100);
$data[$itemkey . '-' . $group]['item'] = $visualreport->gtree->items[$itemkey]->get_name();
$data[$itemkey . '-' . $group]['group'] = groups_get_group_name($group);
$count[$itemkey . '-' . $group] = 1;
} else {
$data[$itemkey . '-' . $group]['grade'] += $studentdata->standardise_score($studentdata->finalgrade, $visualreport->gtree->items[$itemkey]->grademin, $visualreport->gtree->items[$itemkey]->grademax, 0, 100);
$count[$itemkey . '-' . $group]++;
}
}
} else {
if (!isset($data[$itemkey . '-ng'])) {
$data[$itemkey . '-ng'] = array();
$data[$itemkey . '-ng']['grade'] = $studentdata->standardise_score($studentdata->finalgrade, $visualreport->gtree->items[$itemkey]->grademin, $visualreport->gtree->items[$itemkey]->grademax, 0, 100);
$data[$itemkey . '-ng']['item'] = $visualreport->gtree->items[$itemkey]->get_name();
$data[$itemkey . '-ng']['group'] = get_string('nogroup', 'gradereport_visual');
$count[$itemkey . '-ng'] = 1;
} else {
$data[$itemkey . '-ng']['grade'] += $studentdata->standardise_score($studentdata->finalgrade, $visualreport->gtree->items[$itemkey]->grademin, $visualreport->gtree->items[$itemkey]->grademax, 0, 100);
$count[$itemkey . '-ng']++;
}
}
if (!isset($data[$itemkey . '-ag'])) {
$data[$itemkey . '-ag'] = array();
$data[$itemkey . '-ag']['grade'] = $studentdata->standardise_score($studentdata->finalgrade, $visualreport->gtree->items[$itemkey]->grademin, $visualreport->gtree->items[$itemkey]->grademax, 0, 100);
$data[$itemkey . '-ag']['item'] = $visualreport->gtree->items[$itemkey]->get_name();
$data[$itemkey . '-ag']['group'] = get_string('allgroups', 'gradereport_visual');
$count[$itemkey . '-ag'] = 1;
} else {
$data[$itemkey . '-ag']['grade'] += $studentdata->standardise_score($studentdata->finalgrade, $visualreport->gtree->items[$itemkey]->grademin, $visualreport->gtree->items[$itemkey]->grademax, 0, 100);
$count[$itemkey . '-ag']++;
}
}
}
}
}
foreach ($data as $key => $row) {
if ($key != 'header') {
$data[$key]['grade'] /= $count[$key];
}
}
return $data;
}
示例4: bp_em_group_events_build_sql_conditions
function bp_em_group_events_build_sql_conditions($conditions, $args)
{
if (!empty($args['group']) && is_numeric($args['group'])) {
$conditions['group'] = "( `group_id`={$args['group']} )";
} elseif ($args['group'] == 'my') {
$groups = groups_get_user_groups(get_current_user_id());
if (count($groups) > 0) {
$conditions['group'] = "( `group_id` IN (" . implode(',', $groups['groups']) . ") )";
}
}
return $conditions;
}
示例5: bp_em_group_events_build_sql_conditions
function bp_em_group_events_build_sql_conditions($conditions, $args)
{
if (!empty($args['group']) && is_numeric($args['group'])) {
$conditions['group'] = "( `group_id`={$args['group']} )";
} elseif (!empty($args['group']) && $args['group'] == 'my') {
$groups = groups_get_user_groups(get_current_user_id());
if (count($groups) > 0) {
$conditions['group'] = "( `group_id` IN (" . implode(',', $groups['groups']) . ") )";
}
}
//deal with private groups and events
if (is_user_logged_in()) {
global $wpdb;
//find out what private groups they belong to, and don't show private group events not in their memberships
$group_ids = BP_Groups_Member::get_group_ids(get_current_user_id());
if ($group_ids['total'] > 0) {
$conditions['group_privacy'] = "(`event_private`=0 OR (`event_private`=1 AND (`group_id` IS NULL OR `group_id` = 0)) OR (`event_private`=1 AND `group_id` IN (" . implode(',', $group_ids['groups']) . ")))";
} else {
//find out what private groups they belong to, and don't show private group events not in their memberships
$conditions['group_privacy'] = "(`event_private`=0 OR (`event_private`=1 AND (`group_id` IS NULL OR `group_id` = 0)))";
}
}
return $conditions;
}
示例6: forum_tp_count_forum_unread_posts
/**
* Returns the count of records for the provided user and forum and [optionally] group.
*
* @global object
* @global object
* @global object
* @param object $cm
* @param object $course
* @return int
*/
function forum_tp_count_forum_unread_posts($cm, $course) {
global $CFG, $USER, $DB;
static $readcache = array();
$forumid = $cm->instance;
if (!isset($readcache[$course->id])) {
$readcache[$course->id] = array();
if ($counts = forum_tp_get_course_unread_posts($USER->id, $course->id)) {
foreach ($counts as $count) {
$readcache[$course->id][$count->id] = $count->unread;
}
}
}
if (empty($readcache[$course->id][$forumid])) {
// no need to check group mode ;-)
return 0;
}
$groupmode = groups_get_activity_groupmode($cm, $course);
if ($groupmode != SEPARATEGROUPS) {
return $readcache[$course->id][$forumid];
}
if (has_capability('moodle/site:accessallgroups', context_module::instance($cm->id))) {
return $readcache[$course->id][$forumid];
}
require_once($CFG->dirroot.'/course/lib.php');
$modinfo = get_fast_modinfo($course);
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id, $USER->id);
}
$mygroups = $modinfo->groups[$cm->groupingid];
// add all groups posts
if (empty($mygroups)) {
$mygroups = array(-1=>-1);
} else {
$mygroups[-1] = -1;
}
list ($groups_sql, $groups_params) = $DB->get_in_or_equal($mygroups);
$now = round(time(), -2); // db cache friendliness
$cutoffdate = $now - ($CFG->forum_oldpostdays*24*60*60);
$params = array($USER->id, $forumid, $cutoffdate);
if (!empty($CFG->forum_enabletimedposts)) {
$timedsql = "AND d.timestart < ? AND (d.timeend = 0 OR d.timeend > ?)";
$params[] = $now;
$params[] = $now;
} else {
$timedsql = "";
}
$params = array_merge($params, $groups_params);
$sql = "SELECT COUNT(p.id)
FROM {forum_posts} p
JOIN {forum_discussions} d ON p.discussion = d.id
LEFT JOIN {forum_read} r ON (r.postid = p.id AND r.userid = ?)
WHERE d.forum = ?
AND p.modified >= ? AND r.id is NULL
$timedsql
AND d.groupid $groups_sql";
return $DB->get_field_sql($sql, $params);
}
示例7: feedback_get_recent_mod_activity
/**
* Returns all users who has completed a specified feedback since a given time
* many thanks to Manolescu Dorel, who contributed these two functions
*
* @global object
* @global object
* @global object
* @global object
* @uses CONTEXT_MODULE
* @param array $activities Passed by reference
* @param int $index Passed by reference
* @param int $timemodified Timestamp
* @param int $courseid
* @param int $cmid
* @param int $userid
* @param int $groupid
* @return void
*/
function feedback_get_recent_mod_activity(&$activities, &$index,
$timemodified, $courseid,
$cmid, $userid="", $groupid="") {
global $CFG, $COURSE, $USER, $DB;
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$course = $DB->get_record('course', array('id'=>$courseid));
}
$modinfo = get_fast_modinfo($course);
$cm = $modinfo->cms[$cmid];
$sqlargs = array();
//TODO: user user_picture::fields;
$sql = " SELECT fk . * , fc . * , u.firstname, u.lastname, u.email, u.picture, u.email
FROM {feedback_completed} fc
JOIN {feedback} fk ON fk.id = fc.feedback
JOIN {user} u ON u.id = fc.userid ";
if ($groupid) {
$sql .= " JOIN {groups_members} gm ON gm.userid=u.id ";
}
$sql .= " WHERE fc.timemodified > ? AND fk.id = ? ";
$sqlargs[] = $timemodified;
$sqlargs[] = $cm->instace;
if ($userid) {
$sql .= " AND u.id = ? ";
$sqlargs[] = $userid;
}
if ($groupid) {
$sql .= " AND gm.groupid = ? ";
$sqlargs[] = $groupid;
}
if (!$feedbackitems = $DB->get_records_sql($sql, $sqlargs)) {
return;
}
$cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);
$groupmode = groups_get_activity_groupmode($cm, $course);
if (is_null($modinfo->groups)) {
// load all my groups and cache it in modinfo
$modinfo->groups = groups_get_user_groups($course->id);
}
$aname = format_string($cm->name, true);
foreach ($feedbackitems as $feedbackitem) {
if ($feedbackitem->userid != $USER->id) {
if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
$usersgroups = groups_get_all_groups($course->id,
$feedbackitem->userid,
$cm->groupingid);
if (!is_array($usersgroups)) {
continue;
}
$usersgroups = array_keys($usersgroups);
$intersect = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
if (empty($intersect)) {
continue;
}
}
}
$tmpactivity = new stdClass();
$tmpactivity->type = 'feedback';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->sectionnum= $cm->sectionnum;
$tmpactivity->timestamp = $feedbackitem->timemodified;
//.........这里部分代码省略.........
示例8: assignment_get_recent_mod_activity
/**
* Returns all assignments since a given time in specified forum.
*/
function assignment_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) {
global $CFG, $COURSE, $USER, $DB;
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$course = $DB->get_record('course', array('id'=>$courseid));
}
$modinfo =& get_fast_modinfo($course);
$cm = $modinfo->cms[$cmid];
$params = array();
if ($userid) {
$userselect = "AND u.id = :userid";
$params['userid'] = $userid;
} else {
$userselect = "";
}
if ($groupid) {
$groupselect = "AND gm.groupid = :groupid";
$groupjoin = "JOIN {groups_members} gm ON gm.userid=u.id";
$params['groupid'] = $groupid;
} else {
$groupselect = "";
$groupjoin = "";
}
$params['cminstance'] = $cm->instance;
$params['timestart'] = $timestart;
$userfields = user_picture::fields('u', null, 'userid');
if (!$submissions = $DB->get_records_sql("SELECT asb.id, asb.timemodified,
$userfields
FROM {assignment_submissions} asb
JOIN {assignment} a ON a.id = asb.assignment
JOIN {user} u ON u.id = asb.userid
$groupjoin
WHERE asb.timemodified > :timestart AND a.id = :cminstance
$userselect $groupselect
ORDER BY asb.timemodified ASC", $params)) {
return;
}
$groupmode = groups_get_activity_groupmode($cm, $course);
$cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
$grader = has_capability('moodle/grade:viewall', $cm_context);
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
}
$show = array();
foreach($submissions as $submission) {
if ($submission->userid == $USER->id) {
$show[] = $submission;
continue;
}
// the act of submitting of assignment may be considered private - only graders will see it if specified
if (empty($CFG->assignment_showrecentsubmissions)) {
if (!$grader) {
continue;
}
}
if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
if (isguestuser()) {
// shortcut - guest user does not belong into any group
continue;
}
// this will be slow - show only users that share group with me in this cm
if (empty($modinfo->groups[$cm->id])) {
continue;
}
$usersgroups = groups_get_all_groups($course->id, $cm->userid, $cm->groupingid);
if (is_array($usersgroups)) {
$usersgroups = array_keys($usersgroups);
$intersect = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
if (empty($intersect)) {
continue;
}
}
}
$show[] = $submission;
}
if (empty($show)) {
return;
}
//.........这里部分代码省略.........
示例9: assignment_get_recent_mod_activity
/**
* Returns all assignments since a given time in specified forum.
*/
function assignment_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid = 0, $groupid = 0)
{
global $CFG, $COURSE, $USER;
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $courseid);
}
$modinfo =& get_fast_modinfo($course);
$cm = $modinfo->cms[$cmid];
if ($userid) {
$userselect = "AND u.id = {$userid}";
} else {
$userselect = "";
}
if ($groupid) {
$groupselect = "AND gm.groupid = {$groupid}";
$groupjoin = "JOIN {$CFG->prefix}groups_members gm ON gm.userid=u.id";
} else {
$groupselect = "";
$groupjoin = "";
}
if (!($submissions = get_records_sql("SELECT asb.id, asb.timemodified, asb.userid,\n u.firstname, u.lastname, u.email, u.picture\n FROM {$CFG->prefix}assignment_submissions asb\n JOIN {$CFG->prefix}assignment a ON a.id = asb.assignment\n JOIN {$CFG->prefix}user u ON u.id = asb.userid\n {$groupjoin}\n WHERE asb.timemodified > {$timestart} AND a.id = {$cm->instance}\n {$userselect} {$groupselect}\n ORDER BY asb.timemodified ASC"))) {
return;
}
$groupmode = groups_get_activity_groupmode($cm, $course);
$cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
$grader = has_capability('moodle/grade:viewall', $cm_context);
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id);
// load all my groups and cache it in modinfo
}
$show = array();
foreach ($submissions as $submission) {
if ($submission->userid == $USER->id) {
$show[] = $submission;
continue;
}
// the act of submitting of assignment may be considered private - only graders will see it if specified
if (empty($CFG->assignment_showrecentsubmissions)) {
if (!$grader) {
continue;
}
}
if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
if (isguestuser()) {
// shortcut - guest user does not belong into any group
continue;
}
// this will be slow - show only users that share group with me in this cm
if (empty($modinfo->groups[$cm->id])) {
continue;
}
$usersgroups = groups_get_all_groups($course->id, $cm->userid, $cm->groupingid);
if (is_array($usersgroups)) {
$usersgroups = array_keys($usersgroups);
$interset = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
if (empty($intersect)) {
continue;
}
}
}
$show[] = $submission;
}
if (empty($show)) {
return;
}
if ($grader) {
require_once $CFG->libdir . '/gradelib.php';
$userids = array();
foreach ($show as $id => $submission) {
$userids[] = $submission->userid;
}
$grades = grade_get_grades($courseid, 'mod', 'assignment', $cm->instance, $userids);
}
$aname = format_string($cm->name, true);
foreach ($show as $submission) {
$tmpactivity = new object();
$tmpactivity->type = 'assignment';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->sectionnum = $cm->sectionnum;
$tmpactivity->timestamp = $submission->timemodified;
if ($grader) {
$tmpactivity->grade = $grades->items[0]->grades[$submission->userid]->str_long_grade;
}
$tmpactivity->user->userid = $submission->userid;
$tmpactivity->user->fullname = fullname($submission, $viewfullnames);
$tmpactivity->user->picture = $submission->picture;
$activities[$index++] = $tmpactivity;
}
return;
}
示例10: calendar_set_filters
/**
* Returns the courses to load events for, the
*
* @param array $courseeventsfrom An array of courses to load calendar events for
* @param bool $ignorefilters specify the use of filters, false is set as default
* @return array An array of courses, groups, and user to load calendar events for based upon filters
*/
function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false)
{
global $USER, $CFG, $DB;
// For backwards compatability we have to check whether the courses array contains
// just id's in which case we need to load course objects.
$coursestoload = array();
foreach ($courseeventsfrom as $id => $something) {
if (!is_object($something)) {
$coursestoload[] = $id;
unset($courseeventsfrom[$id]);
}
}
if (!empty($coursestoload)) {
// TODO remove this in 2.2
debugging('calendar_set_filters now preferes an array of course objects with preloaded contexts', DEBUG_DEVELOPER);
$courseeventsfrom = array_merge($courseeventsfrom, $DB->get_records_list('course', 'id', $coursestoload));
}
$courses = array();
$user = false;
$group = false;
// capabilities that allow seeing group events from all groups
// TODO: rewrite so that moodle/calendar:manageentries is not necessary here
$allgroupscaps = array('moodle/site:accessallgroups', 'moodle/calendar:manageentries');
$isloggedin = isloggedin();
if ($ignorefilters || calendar_show_event_type(CALENDAR_EVENT_COURSE)) {
$courses = array_keys($courseeventsfrom);
}
if ($ignorefilters || calendar_show_event_type(CALENDAR_EVENT_GLOBAL)) {
$courses[] = SITEID;
}
$courses = array_unique($courses);
sort($courses);
if (!empty($courses) && in_array(SITEID, $courses)) {
// Sort courses for consistent colour highlighting
// Effectively ignoring SITEID as setting as last course id
$key = array_search(SITEID, $courses);
unset($courses[$key]);
$courses[] = SITEID;
}
if ($ignorefilters || $isloggedin && calendar_show_event_type(CALENDAR_EVENT_USER)) {
$user = $USER->id;
}
if (!empty($courseeventsfrom) && (calendar_show_event_type(CALENDAR_EVENT_GROUP) || $ignorefilters)) {
if (count($courseeventsfrom) == 1) {
$course = reset($courseeventsfrom);
if (has_any_capability($allgroupscaps, context_course::instance($course->id))) {
$coursegroups = groups_get_all_groups($course->id, 0, 0, 'g.id');
$group = array_keys($coursegroups);
}
}
if ($group === false) {
if (!empty($CFG->calendar_adminseesall) && has_any_capability($allgroupscaps, context_system::instance())) {
$group = true;
} else {
if ($isloggedin) {
$groupids = array();
// We already have the courses to examine in $courses
// For each course...
foreach ($courseeventsfrom as $courseid => $course) {
// If the user is an editing teacher in there,
if (!empty($USER->groupmember[$course->id])) {
// We've already cached the users groups for this course so we can just use that
$groupids = array_merge($groupids, $USER->groupmember[$course->id]);
} else {
if ($course->groupmode != NOGROUPS || !$course->groupmodeforce) {
// If this course has groups, show events from all of those related to the current user
$coursegroups = groups_get_user_groups($course->id, $USER->id);
$groupids = array_merge($groupids, $coursegroups['0']);
}
}
}
if (!empty($groupids)) {
$group = $groupids;
}
}
}
}
}
if (empty($courses)) {
$courses = false;
}
return array($courses, $group, $user);
}
示例11: process_data
/**
* Processes the data sent by the form (grades and feedbacks).
* Caller is reposible for all access control checks
* @param array $data form submission (with magic quotes)
* @return array empty array if success, array of warnings if something fails.
*/
function process_data($data)
{
$warnings = array();
$separategroups = false;
$mygroups = array();
if ($this->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $this->context)) {
$separategroups = true;
$mygroups = groups_get_user_groups($this->course->id);
$mygroups = $mygroups[0];
// ignore groupings
// reorder the groups fro better perf bellow
$current = array_search($this->currentgroup, $mygroups);
if ($current !== false) {
unset($mygroups[$current]);
array_unshift($mygroups, $this->currentgroup);
}
}
// always initialize all arrays
$queue = array();
foreach ($data as $varname => $postedvalue) {
$needsupdate = false;
// skip, not a grade nor feedback
if (strpos($varname, 'grade') === 0) {
$data_type = 'grade';
} else {
if (strpos($varname, 'feedback') === 0) {
$data_type = 'feedback';
} else {
continue;
}
}
$gradeinfo = explode("_", $varname);
$userid = clean_param($gradeinfo[1], PARAM_INT);
$itemid = clean_param($gradeinfo[2], PARAM_INT);
$oldvalue = $data->{'old' . $varname};
// was change requested?
if ($oldvalue == $postedvalue) {
// string comparison
continue;
}
if (!($grade_item = grade_item::fetch(array('id' => $itemid, 'courseid' => $this->courseid)))) {
// we must verify course id here!
error('Incorrect grade item id');
}
// Pre-process grade
if ($data_type == 'grade') {
$feedback = false;
$feedbackformat = false;
if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
if ($postedvalue == -1) {
// -1 means no grade
$finalgrade = null;
} else {
$finalgrade = $postedvalue;
}
} else {
$finalgrade = unformat_float($postedvalue);
}
$errorstr = '';
// Warn if the grade is out of bounds.
if (is_null($finalgrade)) {
// ok
} else {
$bounded = $grade_item->bounded_grade($finalgrade);
if ($bounded > $finalgrade) {
$errorstr = 'lessthanmin';
} else {
if ($bounded < $finalgrade) {
$errorstr = 'morethanmax';
}
}
}
if ($errorstr) {
$user = get_record('user', 'id', $userid, '', '', '', '', 'id, firstname, lastname');
$gradestr = new object();
$gradestr->username = fullname($user);
$gradestr->itemname = $grade_item->get_name();
$warnings[] = get_string($errorstr, 'grades', $gradestr);
}
} else {
if ($data_type == 'feedback') {
$finalgrade = false;
$trimmed = trim($postedvalue);
if (empty($trimmed)) {
$feedback = NULL;
} else {
$feedback = stripslashes($postedvalue);
}
}
}
// group access control
if ($separategroups) {
// note: we can not use $this->currentgroup because it would fail badly
// when having two browser windows each with different group
//.........这里部分代码省略.........
示例12: override_exists
/**
* Returns user override
*
* Algorithm: For each assign setting, if there is a matching user-specific override,
* then use that otherwise, if there are group-specific overrides, return the most
* lenient combination of them. If neither applies, leave the assign setting unchanged.
*
* @param int $userid The userid.
* @return override if exist
*/
public function override_exists($userid) {
global $DB;
// Check for user override.
$override = $DB->get_record('assign_overrides', array('assignid' => $this->get_instance()->id, 'userid' => $userid));
if (!$override) {
$override = new stdClass();
$override->duedate = null;
$override->cutoffdate = null;
$override->allowsubmissionsfromdate = null;
}
// Check for group overrides.
$groupings = groups_get_user_groups($this->get_instance()->course, $userid);
if (!empty($groupings[0])) {
// Select all overrides that apply to the User's groups.
list($extra, $params) = $DB->get_in_or_equal(array_values($groupings[0]));
$sql = "SELECT * FROM {assign_overrides}
WHERE groupid $extra AND assignid = ?";
$params[] = $this->get_instance()->id;
$records = $DB->get_records_sql($sql, $params);
// Combine the overrides.
$duedates = array();
$cutoffdates = array();
$allowsubmissionsfromdates = array();
foreach ($records as $gpoverride) {
if (isset($gpoverride->duedate)) {
$duedates[] = $gpoverride->duedate;
}
if (isset($gpoverride->cutoffdate)) {
$cutoffdates[] = $gpoverride->cutoffdate;
}
if (isset($gpoverride->allowsubmissionsfromdate)) {
$allowsubmissionsfromdates[] = $gpoverride->allowsubmissionsfromdate;
}
}
// If there is a user override for a setting, ignore the group override.
if (is_null($override->allowsubmissionsfromdate) && count($allowsubmissionsfromdates)) {
$override->allowsubmissionsfromdate = min($allowsubmissionsfromdates);
}
if (is_null($override->cutoffdate) && count($cutoffdates)) {
if (in_array(0, $cutoffdates)) {
$override->cutoffdate = 0;
} else {
$override->cutoffdate = max($cutoffdates);
}
}
if (is_null($override->duedate) && count($duedates)) {
if (in_array(0, $duedates)) {
$override->duedate = 0;
} else {
$override->duedate = max($duedates);
}
}
}
return $override;
}
示例13: widget
function widget($args, $instance)
{
global $bp;
//only show widget to logged in users
if (!is_user_logged_in()) {
return;
}
//get the groups the user is part of
$results = groups_get_user_groups(get_current_user_id());
//don't show widget if user doesn't have any groups
if ($results['total'] == 0) {
return;
}
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? sprintf(__('Recent %s from your Groups', 'bp-group-documents'), $this->bp_group_documents_name) : sanitize_text_field($instance['title']));
echo $before_widget . $before_title . $title . $after_title;
do_action('bp_group_documents_usergroups_widget_before_html');
$document_list = BP_Group_Documents::get_list_for_usergroups_widget(absint($instance['num_items']), (bool) $instance['featured']);
if ($document_list && count($document_list) >= 1) {
echo '<ul id="bp-group-documents-usergroups" class="bp-group-documents-list">';
foreach ($document_list as $item) {
$document = new BP_Group_Documents($item['id']);
$group = new BP_Groups_Group($document->group_id);
echo '<li>';
if (get_option('bp_group_documents_display_icons')) {
$document->icon();
}
?>
<a class="bp-group-documents-title" id="group-document-link-<?php
echo $document->id;
?>
"
href="<?php
$document->url();
?>
" target="_blank">
<?php
echo $document->name;
?>
</a>
<?php
echo sprintf(__('posted in %s', 'bp-group-documents'), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>');
echo '</li>';
}
echo '</ul>';
} else {
echo '<div class="widget-error">' . sprintf(__('There are no %s to display.', 'bp-group-documents'), $this->bp_group_documents_name) . '</div></p>';
}
echo $after_widget;
}
示例14: array
<?php
global $EM_Event;
if (!function_exists('bp_is_active') || !bp_is_active('groups')) {
return false;
}
$user_groups = array();
$group_data = groups_get_user_groups(get_current_user_id());
if (!is_super_admin()) {
foreach ($group_data['groups'] as $group_id) {
if (groups_is_user_admin(get_current_user_id(), $group_id)) {
$user_groups[] = groups_get_group(array('group_id' => $group_id));
}
}
$group_count = count($user_groups);
} else {
$groups = groups_get_groups(array('show_hidden' => true, 'per_page' => 0));
$user_groups = $groups['groups'];
$group_count = $groups['total'];
}
if (count($user_groups) > 0) {
?>
<p>
<select name="group_id">
<option value=""><?php
_e('Not a Group Event', 'dbem');
?>
</option>
<?php
//in case user isn't a group mod, but can edit other users' events
if (!empty($EM_Event->group_id) && !in_array($EM_Event->group_id, $group_data['groups'])) {
示例15: quiz_get_recent_mod_activity
/**
* Returns all quiz graded users since a given time for specified quiz
*/
function quiz_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid = 0, $groupid = 0)
{
global $CFG, $COURSE, $USER;
require_once 'locallib.php';
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $courseid);
}
$modinfo =& get_fast_modinfo($course);
$cm = $modinfo->cms[$cmid];
$quiz = get_record('quiz', 'id', $cm->instance);
if ($userid) {
$userselect = "AND u.id = {$userid}";
} else {
$userselect = '';
}
if ($groupid) {
$groupselect = "AND gm.groupid = {$groupid}";
$groupjoin = "JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id";
} else {
$groupselect = '';
$groupjoin = '';
}
if (!($attempts = get_records_sql("\n SELECT qa.*,\n u.firstname, u.lastname, u.email, u.picture, u.imagealt\n FROM {$CFG->prefix}quiz_attempts qa\n JOIN {$CFG->prefix}user u ON u.id = qa.userid\n {$groupjoin}\n WHERE qa.timefinish > {$timestart}\n AND qa.quiz = {$quiz->id}\n AND qa.preview = 0\n {$userselect}\n {$groupselect}\n ORDER BY qa.timefinish ASC"))) {
return;
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$accessallgroups = has_capability('moodle/site:accessallgroups', $context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
$grader = has_capability('mod/quiz:viewreports', $context);
$groupmode = groups_get_activity_groupmode($cm, $course);
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id);
// load all my groups and cache it in modinfo
}
$hasgrades = $quiz->grade != 0 && $quiz->sumgrades != 0;
$usersgroups = null;
$aname = format_string($cm->name, true);
foreach ($attempts as $attempt) {
if ($attempt->userid != $USER->id) {
if (!$grader) {
// Grade permission required
continue;
}
if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
if (is_null($usersgroups)) {
$usersgroups = groups_get_all_groups($course->id, $attempt->userid, $cm->groupingid);
if (is_array($usersgroups)) {
$usersgroups = array_keys($usersgroups);
} else {
$usersgroups = array();
}
}
if (!array_intersect($usersgroups, $modinfo->groups[$cm->id])) {
continue;
}
}
}
$options = quiz_get_reviewoptions($quiz, $attempt, $context);
$tmpactivity = new stdClass();
$tmpactivity->type = 'quiz';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->sectionnum = $cm->sectionnum;
$tmpactivity->timestamp = $attempt->timefinish;
$tmpactivity->content->attemptid = $attempt->id;
$tmpactivity->content->attempt = $attempt->attempt;
if ($hasgrades && $options->scores) {
$tmpactivity->content->sumgrades = round($attempt->sumgrades, $quiz->decimalpoints);
$tmpactivity->content->maxgrade = round($quiz->sumgrades, $quiz->decimalpoints);
} else {
$tmpactivity->content->sumgrades = null;
$tmpactivity->content->maxgrade = null;
}
$tmpactivity->user->userid = $attempt->userid;
$tmpactivity->user->fullname = fullname($attempt, $viewfullnames);
$tmpactivity->user->picture = $attempt->picture;
$tmpactivity->user->imagealt = $attempt->imagealt;
$activities[$index++] = $tmpactivity;
}
return;
}