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;
}
/**
* 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;
//.........这里部分代码省略.........
开发者ID:numbas,项目名称:moodle,代码行数:101,代码来源:lib.php
示例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;
}
//.........这里部分代码省略.........
开发者ID:nuckey,项目名称:moodle,代码行数:101,代码来源:lib.php
示例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;
}
/**
* 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);
}
/**
* 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;
}
请发表评论