Beispiel #1
0
 private function _getGroupMembers($groupId)
 {
     global $CFG;
     require_once $CFG->libdir . '/grouplib.php';
     return groups_get_members($groupId);
     /* lib/grouplib.php */
 }
/**
 * Distributes students into groups randomly and creates a grouping with those 
 * groups.
 * 
 * You need to call groups_seed_random_number_generator() at some point in your 
 * script before calling this function. 
 * 
 * Note that this function does not distribute teachers into groups - this still 
 * needs to be done manually. 
 * 
 * @param int $courseid The id of the course that the grouping should belong to
 * @param int $nostudentspergroup The number of students to put in each group - 
 * this can be set to false if you prefer to specify the number of groups 
 * instead
 * @param int $nogroups The number of groups - this can be set to false if you 
 * prefer to specify the number of student in each group. If both are specified 
 * then $nostudentspergroup takes precedence. If neither is
 * specified then the function does nothing and returns false. 
 * @param boolean $distribevenly If $noofstudentspergroup is specified, then 
 * if this is set to true, any leftover students are distributed evenly among 
 * the groups, whereas if it is set to false then they are put in a separate 
 * group. 
 * @param object $groupsettings The default settings to give each group. 
 * This should contain prefix and defaultgroupdescription fields. The groups 
 * are named with the prefix followed by 1, 2, etc. and given the
 * default group description set. 
 * @param int $groupid If this is not set to false, then only students in the 
 * specified group are distributed into groups, not all the students enrolled on 
 * the course. 
 * @param boolean $alphabetical If this is set to true, then the students are 
 * not distributed randomly but in alphabetical order of last name. 
 * @return int The id of the grouping
 */
function groups_create_automatic_grouping($courseid, $nostudentspergroup, $nogroups, $distribevenly, $groupingsettings, $groupid = false, $alphabetical = false)
{
    if (!$nostudentspergroup and !$noteacherspergroup and !$nogroups) {
        $groupingid = false;
    } else {
        // Set $userids to the list of students that we want to put into groups
        // in the grouping
        if (!$groupid) {
            $users = get_course_students($courseid);
            $userids = groups_users_to_userids($users);
        } else {
            $userids = groups_get_members($groupid);
        }
        // Distribute the users into sets according to the parameters specified
        $userarrays = groups_distribute_in_random_sets($userids, $nostudentspergroup, $nogroups, $distribevenly, !$alphabetical);
        if (!$userarrays) {
            $groupingid = false;
        } else {
            // Create the grouping that the groups we create will go into
            $groupingid = groups_create_grouping($courseid, $groupingsettings);
            // Get the prefix for the names of each group and default group
            // description to give each group
            if (!$groupingsettings->prefix) {
                $prefix = get_string('defaultgroupprefix', 'groups');
            } else {
                $prefix = $groupingsettings->prefix;
            }
            if (!$groupingsettings->defaultgroupdescription) {
                $defaultgroupdescription = '';
            } else {
                $defaultgroupdescription = $groupingsettings->defaultgroupdescription;
            }
            // Now create a group for each set of students, add the group to the
            // grouping and then add the students
            $i = 1;
            foreach ($userarrays as $userids) {
                $groupsettings->name = $prefix . ' ' . $i;
                $groupsettings->description = $defaultgroupdescription;
                $i++;
                $groupid = groups_create_group($courseid, $groupsettings);
                $groupadded = groups_add_group_to_grouping($groupid, $groupingid);
                if (!$groupid or !$groupadded) {
                    $groupingid = false;
                } else {
                    if ($userids) {
                        foreach ($userids as $userid) {
                            $usersadded = groups_add_member($groupid, $userid);
                            // If unsuccessful just carry on I guess
                        }
                    }
                }
            }
        }
    }
    return $groupingid;
}
 function test_add_member()
 {
     // NOTE, interface change on add_member, remove_member.
     $this->assertTrue(groups_add_member($this->groupid, $this->userid));
     $this->assertTrue(groups_is_member($this->groupid, $this->userid));
     $this->assertTrue($userids = groups_get_members($this->groupid));
     //...
     $this->assertTrue($groupids = groups_get_groups_for_user($this->userid, $this->courseid));
     //...
     $this->assertTrue(1 == groups_count_group_members($this->groupid));
     //Utillib.
 }
/**
 * Count the number of open conversations in a given dialogue for a given user
 *  
 * @param   object  $dialogue
 * @param   object  $user
 * @param   bool    $viewall if true count all closed records, not just those where user is initator or receipient
 * @param   int     $groupid    filter conversations by recipients in the group specified
 * @return  int     count of the records found
 */
function dialogue_count_open($dialogue, $user, $viewall = false, $groupid = 0)
{
    if ($viewall) {
        $userwhere = '';
    } else {
        $userwhere = ' (userid=' . $user->id . ' OR recipientid=' . $user->id . ') AND ';
    }
    if ($groupid) {
        $members = groups_get_members($groupid, 'u.id');
        if ($members) {
            $list = '( ' . implode(', ', array_keys($members)) . ' )';
        } else {
            $list = '( 0 ) ';
        }
        $where = " ( userid IN {$list} OR recipientid IN {$list} ) AND {$userwhere} closed = 0";
    } else {
        $where = " {$userwhere} closed = 0";
    }
    return count_records_select('dialogue_conversations', "dialogueid = {$dialogue->id} AND {$where} ");
}
Beispiel #5
0
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once $CFG->libdir . '/formslib.php';
require_once $CFG->dirroot . '/local/forms.php';
$strheading = get_string('messagegroup', 'block_tao_team_groups');
$courseid = required_param('id', PARAM_INT);
$groupid = required_param('groupid', PARAM_INT);
if (!($COURSE = get_record('course', 'id', $courseid))) {
    error('Invalid course idnumber');
}
if (!empty($groupid) && !($group = get_record('groups', 'id', $groupid, 'courseid', $courseid))) {
    error('Invalid group id');
}
require_login();
print_header_simple($strheading, $strheading, build_navigation($strheading));
if (groups_is_member($groupid)) {
    $grpmembers = groups_get_members($groupid);
    if (count($grpmembers) > 1) {
        require_once $CFG->dirroot . '/local/forms.php';
        require_once $CFG->dirroot . '/message/lib.php';
        $messageform = new tao_group_message_send_form('', array('course' => $COURSE, 'group' => $group, 'count' => count($grpmembers) - 1));
        if ($data = $messageform->get_data()) {
            foreach ($grpmembers as $touser) {
                if ($touser->id != $USER->id) {
                    //don't send a message to yourself.
                    message_post_message($USER, $touser, $data->body, $data->format, 'direct');
                }
            }
            notify(get_string('groupmessagesent', 'block_tao_team_groups'), 'notifysuccess');
            print_continue($CFG->wwwroot . '/course/view.php?id=' . $COURSE->id);
        } else {
            if (!$messageform->is_cancelled()) {
Beispiel #6
0
function build_logs_array($course, $user = 0, $date = 0, $order = "l.time ASC", $limitfrom = '', $limitnum = '', $modname = "", $modid = 0, $modaction = "", $groupid = 0)
{
    global $DB, $SESSION, $USER;
    // It is assumed that $date is the GMT time of midnight for that day,
    // and so the next 86400 seconds worth of logs are printed.
    /// Setup for group handling.
    /// If the group mode is separate, and this user does not have editing privileges,
    /// then only the user's group can be viewed.
    if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
        if (isset($SESSION->currentgroup[$course->id])) {
            $groupid = $SESSION->currentgroup[$course->id];
        } else {
            $groupid = groups_get_all_groups($course->id, $USER->id);
            if (is_array($groupid)) {
                $groupid = array_shift(array_keys($groupid));
                $SESSION->currentgroup[$course->id] = $groupid;
            } else {
                $groupid = 0;
            }
        }
    } else {
        if (!$course->groupmode) {
            $groupid = 0;
        }
    }
    $joins = array();
    $params = array();
    if ($course->id != SITEID || $modid != 0) {
        $joins[] = "l.course = :courseid";
        $params['courseid'] = $course->id;
    }
    if ($modname) {
        $joins[] = "l.module = :modname";
        $params['modname'] = $modname;
    }
    if ('site_errors' === $modid) {
        $joins[] = "( l.action='error' OR l.action='infected' )";
    } else {
        if ($modid) {
            $joins[] = "l.cmid = :modid";
            $params['modid'] = $modid;
        }
    }
    if ($modaction) {
        $firstletter = substr($modaction, 0, 1);
        if ($firstletter == '-') {
            $joins[] = $DB->sql_like('l.action', ':modaction', false, true, true);
            $params['modaction'] = '%' . substr($modaction, 1) . '%';
        } else {
            $joins[] = $DB->sql_like('l.action', ':modaction', false);
            $params['modaction'] = '%' . $modaction . '%';
        }
    }
    /// Getting all members of a group.
    if ($groupid and !$user) {
        if ($gusers = groups_get_members($groupid)) {
            $gusers = array_keys($gusers);
            $joins[] = 'l.userid IN (' . implode(',', $gusers) . ')';
        } else {
            $joins[] = 'l.userid = 0';
            // No users in groups, so we want something that will always be false.
        }
    } else {
        if ($user) {
            $joins[] = "l.userid = :userid";
            $params['userid'] = $user;
        }
    }
    if ($date) {
        $enddate = $date + 86400;
        $joins[] = "l.time > :date AND l.time < :enddate";
        $params['date'] = $date;
        $params['enddate'] = $enddate;
    }
    $selector = implode(' AND ', $joins);
    $totalcount = 0;
    // Initialise
    $result = array();
    $result['logs'] = get_logs($selector, $params, $order, $limitfrom, $limitnum, $totalcount);
    $result['totalcount'] = $totalcount;
    return $result;
}
 /**
  * Return all members for a group
  *
  * @param array $groupids array of group ids
  * @return array with  group id keys containing arrays of user ids
  * @since Moodle 2.2
  */
 public static function get_group_members($groupids)
 {
     $members = array();
     $params = self::validate_parameters(self::get_group_members_parameters(), array('groupids' => $groupids));
     foreach ($params['groupids'] as $groupid) {
         // validate params
         $group = groups_get_group($groupid, 'id, courseid, name, enrolmentkey', MUST_EXIST);
         // now security checks
         $context = context_course::instance($group->courseid, IGNORE_MISSING);
         try {
             self::validate_context($context);
         } catch (Exception $e) {
             $exceptionparam = new stdClass();
             $exceptionparam->message = $e->getMessage();
             $exceptionparam->courseid = $group->courseid;
             throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
         }
         require_capability('moodle/course:managegroups', $context);
         $groupmembers = groups_get_members($group->id, 'u.id', 'lastname ASC, firstname ASC');
         $members[] = array('groupid' => $groupid, 'userids' => array_keys($groupmembers));
     }
     return $members;
 }
/**
 * Returns a list of issued certificates - sorted for report.
 *
 * @param int $certificateid
 * @param string $sort the sort order
 * @param bool $groupmode are we in group mode ?
 * @param stdClass $cm the course module
 * @param int $page offset
 * @param int $perpage total per page
 * @return stdClass the users
 */
function certificate_get_issues($certificateid, $sort = "ci.timecreated ASC", $groupmode, $cm, $page = 0, $perpage = 0)
{
    global $DB, $USER;
    $context = context_module::instance($cm->id);
    $conditionssql = '';
    $conditionsparams = array();
    // Get all users that can manage this certificate to exclude them from the report.
    $certmanagers = array_keys(get_users_by_capability($context, 'mod/certificate:manage', 'u.id'));
    $certmanagers = array_merge($certmanagers, array_keys(get_admins()));
    list($sql, $params) = $DB->get_in_or_equal($certmanagers, SQL_PARAMS_NAMED, 'cert');
    $conditionssql .= "AND NOT u.id {$sql} \n";
    $conditionsparams += $params;
    if ($groupmode) {
        $canaccessallgroups = has_capability('moodle/site:accessallgroups', $context);
        $currentgroup = groups_get_activity_group($cm);
        // If we are viewing all participants and the user does not have access to all groups then return nothing.
        if (!$currentgroup && !$canaccessallgroups) {
            return array();
        }
        if ($currentgroup) {
            if (!$canaccessallgroups) {
                // Guest users do not belong to any groups.
                if (isguestuser()) {
                    return array();
                }
                // Check that the user belongs to the group we are viewing.
                $usersgroups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid);
                if ($usersgroups) {
                    if (!isset($usersgroups[$currentgroup])) {
                        return array();
                    }
                } else {
                    // They belong to no group, so return an empty array.
                    return array();
                }
            }
            $groupusers = array_keys(groups_get_members($currentgroup, 'u.*'));
            if (empty($groupusers)) {
                return array();
            }
            list($sql, $params) = $DB->get_in_or_equal($groupusers, SQL_PARAMS_NAMED, 'grp');
            $conditionssql .= "AND u.id {$sql} ";
            $conditionsparams += $params;
        }
    }
    $page = (int) $page;
    $perpage = (int) $perpage;
    // Get all the users that have certificates issued, should only be one issue per user for a certificate
    $allparams = $conditionsparams + array('certificateid' => $certificateid);
    // The picture fields also include the name fields for the user.
    $picturefields = user_picture::fields('u', get_extra_user_fields($context));
    $users = $DB->get_records_sql("SELECT {$picturefields}, u.idnumber, ci.code, ci.timecreated\n                                     FROM {user} u\n                               INNER JOIN {certificate_issues} ci\n                                       ON u.id = ci.userid\n                                    WHERE u.deleted = 0\n                                      AND ci.certificateid = :certificateid {$conditionssql}\n                                 ORDER BY {$sort}", $allparams, $page * $perpage, $perpage);
    return $users;
}
Beispiel #9
0
/**
 * Returns a list of issued iomadcertificates - sorted for report.
 *
 * @param int $iomadcertificateid
 * @param string $sort the sort order
 * @param bool $groupmode are we in group mode ?
 * @param stdClass $cm the course module
 * @param int $page offset
 * @param int $perpage total per page
 * @return stdClass the users
 */
function iomadcertificate_get_issues($iomadcertificateid, $sort = "ci.timecreated ASC", $groupmode, $cm, $page = 0, $perpage = 0)
{
    global $CFG, $DB;
    // get all users that can manage this iomadcertificate to exclude them from the report.
    $context = context_module::instance($cm->id);
    $conditionssql = '';
    $conditionsparams = array();
    if ($certmanagers = array_keys(get_users_by_capability($context, 'mod/iomadcertificate:manage', 'u.id'))) {
        list($sql, $params) = $DB->get_in_or_equal($certmanagers, SQL_PARAMS_NAMED, 'cert');
        $conditionssql .= "AND NOT u.id {$sql} \n";
        $conditionsparams += $params;
    }
    $restricttogroup = false;
    if ($groupmode) {
        $currentgroup = groups_get_activity_group($cm);
        if ($currentgroup) {
            $restricttogroup = true;
            $groupusers = array_keys(groups_get_members($currentgroup, 'u.*'));
            if (empty($groupusers)) {
                return array();
            }
        }
    }
    $restricttogrouping = false;
    // if groupmembersonly used, remove users who are not in any group
    if (!empty($CFG->enablegroupings) and $cm->groupmembersonly) {
        if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
            $restricttogrouping = true;
        } else {
            return array();
        }
    }
    if ($restricttogroup || $restricttogrouping) {
        if ($restricttogroup) {
            $allowedusers = $groupusers;
        } else {
            if ($restricttogroup && $restricttogrouping) {
                $allowedusers = array_intersect($groupusers, $groupingusers);
            } else {
                $allowedusers = $groupingusers;
            }
        }
        list($sql, $params) = $DB->get_in_or_equal($allowedusers, SQL_PARAMS_NAMED, 'grp');
        $conditionssql .= "AND u.id {$sql} \n";
        $conditionsparams += $params;
    }
    $page = (int) $page;
    $perpage = (int) $perpage;
    // Get all the users that have iomadcertificates issued, should only be one issue per user for a iomadcertificate
    $allparams = $conditionsparams + array('iomadcertificateid' => $iomadcertificateid);
    $users = $DB->get_records_sql("SELECT u.*, ci.code, ci.timecreated\n                                   FROM {user} u\n                                   INNER JOIN {iomadcertificate_issues} ci\n                                   ON u.id = ci.userid\n                                   WHERE u.deleted = 0\n                                   AND ci.iomadcertificateid = :iomadcertificateid\n                                   {$conditionssql}\n                                   ORDER BY {$sort}", $allparams, $page * $perpage, $perpage);
    return $users;
}
Beispiel #10
0
 function get_group_members($group_id, $search = '')
 {
     $users = groups_get_members($group_id);
     $rdo = array();
     foreach ($users as $u) {
         if ($search) {
             if (stripos($u->username, $search) === false && stripos($u->firstname, $search) === false && stripos($u->lastname, $search) === false && stripos($u->idnumber, $search) === false) {
                 continue;
             }
         }
         $member['id'] = $u->id;
         $member['firstname'] = $u->firstname;
         $member['lastname'] = $u->lastname;
         $member['username'] = $u->username;
         $rdo[] = $member;
     }
     return $rdo;
 }
/**
 *
 *
 *
 */
function bookmarks_get_groupmembers($groups)
{
    $userids = array();
    foreach ($groups as $groupid) {
        $members = groups_get_members($groupid);
        foreach ($members as $member) {
            $userids[] = $member->id;
        }
    }
    return $userids;
}
Beispiel #12
0
 /**
  * Update grades in the gradebook.
  *
  * @param mixed $submission stdClass|null
  * @param mixed $grade stdClass|null
  * @return bool
  */
 protected function gradebook_item_update($submission = null, $grade = null)
 {
     global $CFG;
     require_once $CFG->dirroot . '/mod/assign/lib.php';
     // Do not push grade to gradebook if blind marking is active as
     // the gradebook would reveal the students.
     if ($this->is_blind_marking()) {
         return false;
     }
     // If marking workflow is enabled and grade is not released then remove any grade that may exist in the gradebook.
     if ($this->get_instance()->markingworkflow && !empty($grade) && $this->get_grading_status($grade->userid) != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
         // Remove the grade (if it exists) from the gradebook as it is not 'final'.
         $grade->grade = -1;
         $grade->feedbacktext = '';
     }
     if ($submission != null) {
         if ($submission->userid == 0) {
             // This is a group submission update.
             $team = groups_get_members($submission->groupid, 'u.id');
             foreach ($team as $member) {
                 $membersubmission = clone $submission;
                 $membersubmission->groupid = 0;
                 $membersubmission->userid = $member->id;
                 $this->gradebook_item_update($membersubmission, null);
             }
             return;
         }
         $gradebookgrade = $this->convert_submission_for_gradebook($submission);
     } else {
         $gradebookgrade = $this->convert_grade_for_gradebook($grade);
     }
     // Grading is disabled, return.
     if ($this->grading_disabled($gradebookgrade['userid'])) {
         return false;
     }
     $assign = clone $this->get_instance();
     $assign->cmidnumber = $this->get_course_module()->idnumber;
     // Set assign gradebook feedback plugin status (enabled and visible).
     $assign->gradefeedbackenabled = $this->is_gradebook_feedback_enabled();
     return assign_grade_item_update($assign, $gradebookgrade) == GRADE_UPDATE_OK;
 }
Beispiel #13
0
function build_logs_array($course, $user = 0, $date = 0, $order = "l.time ASC", $limitfrom = '', $limitnum = '', $modname = "", $modid = 0, $modaction = "", $groupid = 0)
{
    // It is assumed that $date is the GMT time of midnight for that day,
    // and so the next 86400 seconds worth of logs are printed.
    /// Setup for group handling.
    /// If the group mode is separate, and this user does not have editing privileges,
    /// then only the user's group can be viewed.
    if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
        $groupid = get_current_group($course->id);
    } else {
        if (!$course->groupmode) {
            $groupid = 0;
        }
    }
    $joins = array();
    if ($course->id != SITEID || $modid != 0) {
        $joins[] = "l.course='{$course->id}'";
    }
    if ($modname) {
        $joins[] = "l.module = '{$modname}'";
    }
    if ('site_errors' === $modid) {
        $joins[] = "( l.action='error' OR l.action='infected' )";
    } else {
        if ($modid) {
            $joins[] = "l.cmid = '{$modid}'";
        }
    }
    if ($modaction) {
        $firstletter = substr($modaction, 0, 1);
        if (preg_match('/[[:alpha:]]/', $firstletter)) {
            $joins[] = "lower(l.action) LIKE '%" . strtolower($modaction) . "%'";
        } else {
            if ($firstletter == '-') {
                $joins[] = "lower(l.action) NOT LIKE '%" . strtolower(substr($modaction, 1)) . "%'";
            }
        }
    }
    /// Getting all members of a group.
    if ($groupid and !$user) {
        if ($gusers = groups_get_members($groupid)) {
            $gusers = array_keys($gusers);
            $joins[] = 'l.userid IN (' . implode(',', $gusers) . ')';
        } else {
            $joins[] = 'l.userid = 0';
            // No users in groups, so we want something that will always be false.
        }
    } else {
        if ($user) {
            $joins[] = "l.userid = '{$user}'";
        }
    }
    if ($date) {
        $enddate = $date + 86400;
        $joins[] = "l.time > '{$date}' AND l.time < '{$enddate}'";
    }
    $selector = implode(' AND ', $joins);
    $totalcount = 0;
    // Initialise
    $result = array();
    $result['logs'] = get_logs($selector, $order, $limitfrom, $limitnum, $totalcount);
    $result['totalcount'] = $totalcount;
    return $result;
}
 /**
  * Query the reader. Store results in the object for use by build_table.
  *
  * @param int $pagesize size of page for paginated displayed table.
  * @param bool $useinitialsbar do you want to use the initials bar.
  */
 public function query_db($pagesize, $useinitialsbar = true)
 {
     global $DB;
     $joins = array();
     $params = array();
     // If we filter by user id and module id we also need to filter by crud and edulevel to ensure DB index is engaged.
     $useextendeddbindex = !$this->filterparams->logreader instanceof logstore_legacy\log\store && !empty($this->filterparams->userid) && !empty($this->filterparams->modid);
     $groupid = 0;
     if (!empty($this->filterparams->courseid) && $this->filterparams->courseid != SITEID) {
         if (!empty($this->filterparams->groupid)) {
             $groupid = $this->filterparams->groupid;
         }
         $joins[] = "courseid = :courseid";
         $params['courseid'] = $this->filterparams->courseid;
     }
     if (!empty($this->filterparams->siteerrors)) {
         $joins[] = "( action='error' OR action='infected' OR action='failed' )";
     }
     if (!empty($this->filterparams->modid)) {
         list($actionsql, $actionparams) = $this->get_cm_sql();
         $joins[] = $actionsql;
         $params = array_merge($params, $actionparams);
     }
     if (!empty($this->filterparams->action) || $useextendeddbindex) {
         list($actionsql, $actionparams) = $this->get_action_sql();
         $joins[] = $actionsql;
         $params = array_merge($params, $actionparams);
     }
     // Getting all members of a group.
     if ($groupid and empty($this->filterparams->userid)) {
         if ($gusers = groups_get_members($groupid)) {
             $gusers = array_keys($gusers);
             $joins[] = 'userid IN (' . implode(',', $gusers) . ')';
         } else {
             $joins[] = 'userid = 0';
             // No users in groups, so we want something that will always be false.
         }
     } else {
         if (!empty($this->filterparams->userid)) {
             $joins[] = "userid = :userid";
             $params['userid'] = $this->filterparams->userid;
         }
     }
     if (!empty($this->filterparams->date)) {
         $joins[] = "timecreated > :date AND timecreated < :enddate";
         $params['date'] = $this->filterparams->date;
         $params['enddate'] = $this->filterparams->date + DAYSECS;
         // Show logs only for the selected date.
     }
     if (isset($this->filterparams->edulevel) && $this->filterparams->edulevel >= 0) {
         $joins[] = "edulevel = :edulevel";
         $params['edulevel'] = $this->filterparams->edulevel;
     } else {
         if ($useextendeddbindex) {
             list($edulevelsql, $edulevelparams) = $DB->get_in_or_equal(array(\core\event\base::LEVEL_OTHER, \core\event\base::LEVEL_PARTICIPATING, \core\event\base::LEVEL_TEACHING), SQL_PARAMS_NAMED, 'edulevel');
             $joins[] = "edulevel " . $edulevelsql;
             $params = array_merge($params, $edulevelparams);
         }
     }
     if (!$this->filterparams->logreader instanceof logstore_legacy\log\store) {
         // Filter out anonymous actions, this is N/A for legacy log because it never stores them.
         $joins[] = "anonymous = 0";
     }
     $selector = implode(' AND ', $joins);
     if (!$this->is_downloading()) {
         $total = $this->filterparams->logreader->get_events_select_count($selector, $params);
         $this->pagesize($pagesize, $total);
     } else {
         $this->pageable(false);
     }
     // Get the users and course data.
     $this->rawdata = $this->filterparams->logreader->get_events_select_iterator($selector, $params, $this->filterparams->orderby, $this->get_page_start(), $this->get_page_size());
     // Update list of users which will be displayed on log page.
     $this->update_users_used();
     // Get the events. Same query than before; even if it is not likely, logs from new users
     // may be added since last query so we will need to work around later to prevent problems.
     // In almost most of the cases this will be better than having two opened recordsets.
     $this->rawdata = $this->filterparams->logreader->get_events_select_iterator($selector, $params, $this->filterparams->orderby, $this->get_page_start(), $this->get_page_size());
     // Set initial bars.
     if ($useinitialsbar && !$this->is_downloading()) {
         $this->initialbars($total > $pagesize);
     }
 }
Beispiel #15
0
/**
 * Get a set of dialogue conversations records for a given user
 * 
 * @param   object  $dialogue
 * @param   object  $user
 * @param   string  $condition to be included in WHERE clause to be used in sql
 * @param   string  $order by clause to be used in sql
 * @param   int     $groupid    of the group to filter conversations by (default: 0)
 * @return  array   recordset of conversations
 */
function dialogue_get_conversations($dialogue, $user, $condition = '', $order = '', $groupid = 0)
{
    global $CFG, $COURSE;
    if (!($cm = get_coursemodule_from_instance('dialogue', $dialogue->id, $COURSE->id))) {
        error('Course Module ID was incorrect');
    }
    if (!empty($condition)) {
        $condition = ' AND ' . $condition;
    }
    if (empty($order)) {
        $order = 'c.timemodified DESC';
    }
    if (has_capability('mod/dialogue:viewall', get_context_instance(CONTEXT_MODULE, $cm->id))) {
        $whereuser = '';
    } else {
        $whereuser = '******' . $user->id . ' OR c.recipientid = ' . $user->id . ') ';
    }
    // ULPGC ecastro enforce groups use
    if ($groupid) {
        $members = groups_get_members($groupid, 'u.id');
        if ($members) {
            $list = '( ' . implode(', ', array_keys($members)) . ' )';
        } else {
            $list = '( 0 ) ';
        }
        $whereuser .= " AND (c.userid IN {$list} OR c.recipientid IN {$list} )";
    }
    $sql = "SELECT c.*, COUNT(e.id) AS total, COUNT(r.id) as readings " . "FROM {$CFG->prefix}dialogue_conversations c " . "LEFT JOIN {$CFG->prefix}dialogue_entries e ON e.conversationid = c.id " . "LEFT JOIN {$CFG->prefix}dialogue_read r ON r.entryid = e.id AND r.userid = {$user->id} " . "WHERE c.dialogueid = {$dialogue->id} {$whereuser} {$condition} " . "GROUP BY c.id, c.userid, c.dialogueid, c.recipientid, c.lastid, c.lastrecipientid, c.timemodified, c.closed, c.seenon, c.ctype, c.format, c.subject, c.groupid, c.grouping " . "ORDER BY {$order} ";
    $conversations = get_records_sql($sql);
    return $conversations;
}
Beispiel #16
0
}
echo '</select>' . "\n";
echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="' . get_string('showmembersforgroup', 'group') . '" /></p>' . "\n";
echo '<p><input type="submit" ' . $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="' . get_string('editgroupsettings', 'group') . '" /></p>' . "\n";
echo '<p><input type="submit" ' . $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="' . get_string('deleteselectedgroup', 'group') . '" /></p>' . "\n";
echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="' . get_string('creategroup', 'group') . '" /></p>' . "\n";
echo '<p><input type="submit" name="act_showautocreategroupsform" id="showautocreategroupsform" value="' . get_string('autocreategroups', 'group') . '" /></p>' . "\n";
echo '</td>' . "\n";
echo '<td>' . "\n";
echo '<p><label for="members"><span id="memberslabel">' . get_string('membersofselectedgroup', 'group') . ' </span><span id="thegroup">&nbsp;</span></label></p>' . "\n";
//NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick.
echo '<select name="user" id="members" size="15" class="select"' . "\n";
echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">' . "\n";
$member_names = array();
if ($sel_groupid) {
    if ($members = groups_get_members($groupid)) {
        foreach ($members as $member) {
            $member_names[$member->id] = fullname($member, true);
        }
    }
}
if ($member_names) {
    // Put the groupings into a hash and sort them
    foreach ($member_names as $userid => $username) {
        echo "<option value=\"{$userid}\" title=\"{$username}\">{$username}</option>\n";
    }
} else {
    // Print an empty option to avoid the XHTML error of having an empty select element
    echo '<option>&nbsp;</option>';
}
echo '</select>' . "\n";
/**
 * Update workshopplus grades in the gradebook
 *
 * Needed by grade_update_mod_grades() in lib/gradelib.php
 *
 * @category grade
 * @param stdClass $workshopplus instance object with extra cmidnumber and modname property
 * @param int $userid        update grade of specific user only, 0 means all participants
 * @return void
 */
function workshopplus_update_grades(stdclass $workshopplus, $userid = 0)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/gradelib.php';
    $whereuser = $userid ? ' AND authorid = :userid' : '';
    $params = array('workshopplusid' => $workshopplus->id, 'userid' => $userid);
    $sql = 'SELECT authorid, grade, gradeover, gradeoverby, feedbackauthor, feedbackauthorformat, timemodified, timegraded
              FROM {workshopplus_submissions}
             WHERE workshopplusid = :workshopplusid AND example=0' . $whereuser;
    $records = $DB->get_records_sql($sql, $params);
    $submissiongrades = array();
    foreach ($records as $record) {
        $grade = new stdclass();
        $grade->userid = $record->authorid;
        if (!is_null($record->gradeover)) {
            $grade->rawgrade = grade_floatval($workshopplus->grade * $record->gradeover / 100);
            $grade->usermodified = $record->gradeoverby;
        } else {
            $grade->rawgrade = grade_floatval($workshopplus->grade * $record->grade / 100);
        }
        $grade->feedback = $record->feedbackauthor;
        $grade->feedbackformat = $record->feedbackauthorformat;
        $grade->datesubmitted = $record->timemodified;
        $grade->dategraded = $record->timegraded;
        $submissiongrades[$record->authorid] = $grade;
        ////// Find the groupmates and also update their records
        ////////////By Morteza
        /// find the group id of the current user
        $usergroups = groups_get_user_groups($workshopplus->course, $grade->userid);
        $currentgroupid = $usergroups[0][0];
        // Get the current group name from the group id.
        $currentgroupname = groups_get_group_name($currentgroupid);
        // loop over members of that group
        $groupmembers = groups_get_members($currentgroupid, $fields = 'u.*');
        /* Commenting out section for blind copy of grades
            * -- Sayantan - 28.04.2015
           foreach ($groupmembers as $memberid=>$member){                    
               if ($memberid != $grade->userid) {
                   $newgrade = clone $grade;
                   $newgrade->userid = $memberid;
                   $submissiongrades[$memberid] = $newgrade;
               }
           }
           */
        //////////end by Morteza
        /*
         * Begin: Change by Sayantan
         * Date: 28.04.2015
         */
        // Also think of scenario where author belonged to another group - Not possible unless students are
        // allowed to resubmit their solutions - have to think about this one
        // Check if this assignment has been graded previously (entry exists in grade_grades)
        //      no -> this is a new grading, simply copy grade of author to the group members
        //      yes -> this is a regrading
        $params = array('workshopplusid' => $workshopplus->id, 'userid' => $grade->userid);
        $sql = 'SELECT COUNT(1) AS cnt FROM moodle_grade_grades grades ' . 'INNER JOIN moodle_grade_items items ' . 'WHERE items.id = grades.itemid AND items.iteminstance = :workshopplusid AND grades.userid=:userid';
        $records = $DB->get_records_sql($sql, $params);
        $flag_re_grading = 0;
        foreach ($records as $record) {
            if ($record->cnt > 0) {
                // Check if records exist in grade_grades
                $flag_re_grading = 1;
                // If records exist in grade_grades then this is a regrading
            }
        }
        if ($flag_re_grading == 0) {
            // This is a new grading, hence copy grades
            foreach ($groupmembers as $memberid => $member) {
                if ($memberid != $grade->userid) {
                    $newgrade = clone $grade;
                    $newgrade->userid = $memberid;
                    $submissiongrades[$memberid] = $newgrade;
                }
            }
        } else {
            // This is a re grading, hence existing grades should not be overwritten
            //          + Check the time in which each member joined the group
            //          + If the time of joining group is later than time of previous grading then member was in a
            //          separate group when the initial grading was done and should get the grades he/she received
            //          in that group
            //          + If the member has no previous records - assign zero grade since this assignment was not
            //          done by that member (as he was not part of any group when the assignment was first graded)
            //
            foreach ($groupmembers as $memberid => $member) {
                if ($memberid != $grade->userid) {
                    // Check time at which $memberid joined the group
                    $joining_time = 0;
                    $params = array('userid' => $memberid);
                    $sql = 'SELECT timeadded FROM moodle_groups_members WHERE userid=:userid';
                    $records = $DB->get_records_sql($sql, $params);
                    foreach ($records as $record) {
                        $joining_time = $record->timeadded;
                    }
                    // Check time of previous grading
                    $grading_modified_time = 0;
                    $params = array('workshopplusid' => $workshopplus->id, 'userid' => $memberid);
                    $sql = 'SELECT grades.timemodified FROM moodle_grade_grades grades INNER JOIN moodle_grade_items items WHERE items.id = grades.itemid AND items.iteminstance=:workshopplusid AND grades.userid=:userid';
                    $records = $DB->get_records_sql($sql, $params);
                    // If no records are fetched then for the particular group member there exist no records in grades
                    // This means that when the previous grading was done this member was not part of any group
                    // and the grade assigned should be 0
                    if (sizeof($records) == 0) {
                        $newgrade = clone $grade;
                        $newgrade->userid = $memberid;
                        $grade->rawgrade = 0;
                        // Grade assigned to zero since this member was not present when previous grading was done
                        $submissiongrades[$memberid] = $newgrade;
                    } else {
                        foreach ($records as $record) {
                            $grading_modified_time = $record->timemodified;
                        }
                    }
                    // If records exist for the member in grades, and time of joining group is before time of previous grading
                    // then a simple copy of grades from the author's grades is okay
                    if (sizeof($records) < 0 && $grading_modified_time > $joining_time) {
                        $newgrade = clone $grade;
                        // Copy grade since member was in authors group earlier also
                        $newgrade->userid = $memberid;
                        $submissiongrades[$memberid] = $newgrade;
                    }
                    // If record exists for the member in grade but time of joining group is after time of last grading
                    // then we need to restore the previous grade that this member achieved
                    if (sizeof($records) < 0 && $grading_modified_time < $joining_time) {
                        // This member has already received a grade for this assignment
                        // but the member was in another group
                        // hence leave the previous grade untouched
                        // do not add this grade in the array $submissiongrades
                        // Thus in the grades table, the old grade for this member will remain unchanged
                        // Need to recalculate grades from the workshopplus submission of previous group
                        // the member belonged to
                        // Check the group history table
                        // Find a group with max(timeadded) < $grading_modified_time
                        $params = array('grading_modified_time' => $grading_modified_time, 'userid' => $memberid);
                        $sql = 'SELECT groupid FROM moodle_groups_members_history a WHERE userid=:userid AND timeadded=(SELECT MAX(timeadded) FROM moodle_groups_members_history b WHERE a.userid=b.userid AND a.groupid=b.groupid AND b.timeadded<:grading_modified_time)';
                        $records = $DB->get_records_sql($sql, $params);
                        // Find members of this group
                        foreach ($records as $record) {
                            $groupid = $records->groupid;
                        }
                        // loop over members of that group
                        $groupmembers = groups_get_members($groupid, $fields = 'u.*');
                        // Iterate over members to find submission for the given workshopplus id
                        foreach ($groupmembers as $oldmemberid => $oldmember) {
                            // Find submission for this group in workshopplus_submissions
                            $oldparams = array('workshopplusid' => $workshopplus->id, 'userid' => $oldmemberid);
                            $oldsql = 'SELECT authorid, grade, gradeover, gradeoverby, feedbackauthor, feedbackauthorformat, timemodified, timegraded FROM {workshopplus_submissions} WHERE workshopplusid = :workshopplusid AND example=0 AND authorid=:userid ORDER BY timemodified DESC';
                            $oldrecords = $DB->get_records_sql($oldsql, $oldparams);
                            // Break whenever a submission is found for a member
                            if (sizeof($records != 0)) {
                                // Copy grade for this user
                                $oldgrade = new stdclass();
                                $oldgrade->userid = $memberid;
                                if (!is_null($oldrecords->gradeover)) {
                                    $oldgrade->rawgrade = grade_floatval($workshopplus->grade * $oldrecords->gradeover / 100);
                                    $oldgrade->usermodified = $oldrecords->gradeoverby;
                                } else {
                                    $oldgrade->rawgrade = grade_floatval($workshopplus->grade * $oldrecords->grade / 100);
                                }
                                $oldgrade->feedback = $oldrecords->feedbackauthor;
                                $oldgrade->feedbackformat = $oldrecords->feedbackauthorformat;
                                $oldgrade->datesubmitted = $oldrecords->timemodified;
                                $oldgrade->dategraded = $oldrecords->timegraded;
                                $submissiongrades[$memberid] = $oldgrade;
                                break;
                            }
                        }
                    }
                }
            }
        }
        /*
         * End: Change by Sayantan
         * Date: 28.04.2015
         */
    }
    // Updating assessment grades -- only comment added -- no change to code
    $whereuser = $userid ? ' AND userid = :userid' : '';
    $params = array('workshopplusid' => $workshopplus->id, 'userid' => $userid);
    $sql = 'SELECT userid, gradinggrade, timegraded
              FROM {workshopplus_aggregations}
             WHERE workshopplusid = :workshopplusid' . $whereuser;
    $records = $DB->get_records_sql($sql, $params);
    $assessmentgrades = array();
    foreach ($records as $record) {
        $grade = new stdclass();
        $grade->userid = $record->userid;
        $grade->rawgrade = grade_floatval($workshopplus->gradinggrade * $record->gradinggrade / 100);
        $grade->dategraded = $record->timegraded;
        $assessmentgrades[$record->userid] = $grade;
    }
    workshopplus_grade_item_update($workshopplus, $submissiongrades, $assessmentgrades);
}
 protected function get_issued_certificate_users($sort = 'username', $groupmode = 0)
 {
     global $CFG, $DB;
     if ($sort == 'username') {
         $sort = $DB->sql_fullname() . ' ASC';
     } else {
         if ($sort == 'issuedate') {
             $sort = 'ci.timecreated ASC';
         } else {
             $sort = '';
         }
     }
     // get all users that can manage this certificate to exclude them from the report.
     $certmanagers = get_users_by_capability($this->context, 'mod/simplecertificate:manage', 'u.id');
     $issedusers = $DB->get_records_sql("SELECT u.*, ci.code, ci.timecreated \n            FROM {user} u INNER JOIN {simplecertificate_issues} ci ON u.id = ci.userid \n            WHERE u.deleted = 0 \n            AND ci.certificateid = :certificateid \n            AND timedeleted IS NULL \n            ORDER BY {$sort}", array('certificateid' => $this->get_instance()->id));
     // now exclude all the certmanagers.
     foreach ($issedusers as $id => $user) {
         if (!empty($certmanagers[$id])) {
             //exclude certmanagers.
             unset($issedusers[$id]);
         }
     }
     // if groupmembersonly used, remove users who are not in any group
     if (!empty($issedusers) and !empty($CFG->enablegroupings) and $this->coursemodule->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
             $issedusers = array_intersect($issedusers, array_keys($groupingusers));
         }
     }
     if ($groupmode) {
         $currentgroup = groups_get_activity_group($this->coursemodule);
         if ($currentgroup) {
             $groupusers = groups_get_members($currentgroup, 'u.*');
             if (empty($groupusers)) {
                 return array();
             }
             foreach ($issedusers as $id => $unused) {
                 if (empty($groupusers[$id])) {
                     // remove this user as it isn't in the group!
                     unset($issedusers[$id]);
                 }
             }
         }
     }
     return $issedusers;
 }
Beispiel #19
0
    public function wiki_print_subwiki_selector($wiki, $subwiki, $page, $pagetype = 'view') {
        global $CFG, $USER;
        require_once($CFG->dirroot . '/user/lib.php');
        switch ($pagetype) {
        case 'files':
            $baseurl = new moodle_url('/mod/wiki/files.php');
            break;
        case 'view':
        default:
            $baseurl = new moodle_url('/mod/wiki/view.php');
            break;
        }

        $cm = get_coursemodule_from_instance('wiki', $wiki->id);
        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
        // @TODO: A plenty of duplicated code below this lines.
        // Create private functions.
        switch (groups_get_activity_groupmode($cm)) {
        case NOGROUPS:
            if ($wiki->wikimode == 'collaborative') {
                // No need to print anything
                return;
            } else if ($wiki->wikimode == 'individual') {
                // We have private wikis here

                $view = has_capability('mod/wiki:viewpage', $context);
                $manage = has_capability('mod/wiki:managewiki', $context);

                // Only people with these capabilities can view all wikis
                if ($view && $manage) {
                    // @TODO: Print here a combo that contains all users.
                    $users = get_enrolled_users($context);
                    $options = array();
                    foreach ($users as $user) {
                        $options[$user->id] = fullname($user);
                    }

                    echo $this->output->container_start('wiki_right');
                    $params = array('wid' => $wiki->id, 'title' => $page->title);
                    if ($pagetype == 'files') {
                        $params['pageid'] = $page->id;
                    }
                    $baseurl->params($params);
                    $name = 'uid';
                    $selected = $subwiki->userid;
                    echo $this->output->single_select($baseurl, $name, $options, $selected);
                    echo $this->output->container_end();
                }
                return;
            } else {
                // error
                return;
            }
        case SEPARATEGROUPS:
            if ($wiki->wikimode == 'collaborative') {
                // We need to print a select to choose a course group

                $params = array('wid'=>$wiki->id, 'title'=>$page->title);
                if ($pagetype == 'files') {
                    $params['pageid'] = $page->id;
                }
                $baseurl->params($params);

                echo $this->output->container_start('wiki_right');
                groups_print_activity_menu($cm, $baseurl->out());
                echo $this->output->container_end();
                return;
            } else if ($wiki->wikimode == 'individual') {
                //  @TODO: Print here a combo that contains all users of that subwiki.
                $view = has_capability('mod/wiki:viewpage', $context);
                $manage = has_capability('mod/wiki:managewiki', $context);

                // Only people with these capabilities can view all wikis
                if ($view && $manage) {
                    $users = get_enrolled_users($context);
                    $options = array();
                    foreach ($users as $user) {
                        $groups = groups_get_all_groups($cm->course, $user->id);
                        if (!empty($groups)) {
                            foreach ($groups as $group) {
                                $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
                            }
                        } else {
                            $name = get_string('notingroup', 'wiki');
                            $options[0][$name]['0' . '-' . $user->id] = fullname($user);
                        }
                    }
                } else {
                    $group = groups_get_group($subwiki->groupid);
                    $users = groups_get_members($subwiki->groupid);
                    foreach ($users as $user) {
                        $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
                    }
                }
                echo $this->output->container_start('wiki_right');
                $params = array('wid' => $wiki->id, 'title' => $page->title);
                if ($pagetype == 'files') {
                    $params['pageid'] = $page->id;
                }
                $baseurl->params($params);
                $name = 'groupanduser';
                $selected = $subwiki->groupid . '-' . $subwiki->userid;
                echo $this->output->single_select($baseurl, $name, $options, $selected);
                echo $this->output->container_end();

                return;

            } else {
                // error
                return;
            }
        CASE VISIBLEGROUPS:
            if ($wiki->wikimode == 'collaborative') {
                // We need to print a select to choose a course group
                $params = array('wid'=>$wiki->id, 'title'=>urlencode($page->title));
                if ($pagetype == 'files') {
                    $params['pageid'] = $page->id;
                }
                $baseurl->params($params);

                echo $this->output->container_start('wiki_right');
                groups_print_activity_menu($cm, $baseurl->out());
                echo $this->output->container_end();
                return;

            } else if ($wiki->wikimode == 'individual') {
                $users = get_enrolled_users($context);
                $options = array();
                foreach ($users as $user) {
                    $groups = groups_get_all_groups($cm->course, $user->id);
                    if (!empty($groups)) {
                        foreach ($groups as $group) {
                            $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
                        }
                    } else {
                        $name = get_string('notingroup', 'wiki');
                        $options[0][$name]['0' . '-' . $user->id] = fullname($user);
                    }
                }

                echo $this->output->container_start('wiki_right');
                $params = array('wid' => $wiki->id, 'title' => $page->title);
                if ($pagetype == 'files') {
                    $params['pageid'] = $page->id;
                }
                $baseurl->params($params);
                $name = 'groupanduser';
                $selected = $subwiki->groupid . '-' . $subwiki->userid;
                echo $this->output->single_select($baseurl, $name, $options, $selected);
                echo $this->output->container_end();

                return;

            } else {
                // error
                return;
            }
        default:
            // error
            return;

        }

    }
Beispiel #20
0
    /**
     * Update grades in the gradebook.
     *
     * @param mixed $submission stdClass|null
     * @param mixed $grade stdClass|null
     * @return bool
     */
    protected function gradebook_item_update($submission=null, $grade=null) {
        global $CFG;

        require_once($CFG->dirroot.'/mod/assign/lib.php');
        // Do not push grade to gradebook if blind marking is active as
        // the gradebook would reveal the students.
        if ($this->is_blind_marking()) {
            return false;
        }
        if ($submission != null) {
            if ($submission->userid == 0) {
                // This is a group submission update.
                $team = groups_get_members($submission->groupid, 'u.id');

                foreach ($team as $member) {
                    $membersubmission = clone $submission;
                    $membersubmission->groupid = 0;
                    $membersubmission->userid = $member->id;
                    $this->gradebook_item_update($membersubmission, null);
                }
                return;
            }

            $gradebookgrade = $this->convert_submission_for_gradebook($submission);

        } else {
            $gradebookgrade = $this->convert_grade_for_gradebook($grade);
        }
        // Grading is disabled, return.
        if ($this->grading_disabled($gradebookgrade['userid'])) {
            return false;
        }
        $assign = clone $this->get_instance();
        $assign->cmidnumber = $this->get_course_module()->idnumber;

        return assign_grade_item_update($assign, $gradebookgrade);
    }
    /**
     * update grades in the gradebook
     *
     * @param mixed $submission stdClass|null
     * @param mixed $grade stdClass|null
     * @return bool
     */
    private function gradebook_item_update($submission=NULL, $grade=NULL) {

        // Do not push grade to gradebook if blind marking is active as the gradebook would reveal the students.
        if ($this->is_blind_marking()) {
            return false;
        }
        if ($submission != NULL) {
            if ($submission->userid == 0) {
                // This is a group submission update.
                $team = groups_get_members($submission->groupid, 'u.id');

                foreach ($team as $member) {
                    $submission->groupid = 0;
                    $submission->userid = $member->id;
                    $this->gradebook_item_update($submission, null);
                }
                return;
            }

            $gradebookgrade = $this->convert_submission_for_gradebook($submission);

        } else {
            $gradebookgrade = $this->convert_grade_for_gradebook($grade);
        }
        // Grading is disabled, return.
        if ($this->grading_disabled($gradebookgrade['userid'])) {
            return false;
        }
        $assign = clone $this->get_instance();
        $assign->cmidnumber = $this->get_course_module()->id;

        return assign_grade_item_update($assign, $gradebookgrade);
    }
Beispiel #22
0
/**
 * Gets the members of group that are enrolled on the course that the specified
 * module instance belongs to. 
 * @param int $cmid The id of the module instance
 * @param int $groupid The id of the group
 * @return array An array of the userids of the members. 
 */
function groups_m_get_members($cmid, $groupid)
{
    $userids = groups_get_members($groupid, $membertype);
    if (!$userids) {
        $memberids = false;
    } else {
        // Check if each user is enrolled on the course @@@ TO DO
    }
    return $memberids;
}
Beispiel #23
0
     redirect(new moodle_url('/group/members.php', array('group' => $groupids[0])));
     break;
     //UAIOPEN - se agrega la funcionalidad de unirse al grupo con envio de solicitudes
 //UAIOPEN - se agrega la funcionalidad de unirse al grupo con envio de solicitudes
 case 'joingroup':
     if (count($groupids) == 0 & count($groupids) > 1) {
         print_error('errorjoinone', 'group', $returnurl);
     }
     $joingroup = $groupids[0];
     redirect(new moodle_url('/group/join.php', array('courseid' => $courseid, 'group' => $joingroup)));
     break;
     //UAIOPEN - se agrega la funcionalidad de dejar el grupo
 //UAIOPEN - se agrega la funcionalidad de dejar el grupo
 case 'leavegroup':
     $leavegroup = $my_groupid;
     $members = groups_get_members($leavegroup);
     if (count($members) == 1) {
         groups_delete_group($leavegroup);
     } else {
         $member_group = $DB->get_records_sql('SELECT id,userid FROM {groups_members} WHERE groupid = ? and roleid = ? LIMIT 1', array($my_groupid, "2"));
         foreach ($member_group as $member_leader) {
             $member_new_leader = new stdClass();
             $member_new_leader->id = $member_leader->id;
             $member_new_leader->groupid = $leavegroup;
             $member_new_leader->leader_group = $member_leader->userid;
         }
         //UAIOPEN - actualiza el líder
         groups_update_leader($member_new_leader);
         //UAIOPEN - remueve al participante
         groups_remove_member($leavegroup, $USER->id);
     }
/**
 * Set a grade to a user or group for a given treasure hunt instance.
 * If the group identifier provided is not 0, the group is checked, else the user is checked.
 * 
 * @param stdClass $treasurehunt The treasurehunt instance.
 * @param int $groupid The identifier of group.
 * @param int $userid The identifier of user.
 * @return stdClass
 */
function treasurehunt_set_grade($treasurehunt, $groupid, $userid)
{
    if ($groupid == 0) {
        treasurehunt_update_grades($treasurehunt, $userid);
    } else {
        $userlist = groups_get_members($groupid);
        foreach ($userlist as $user) {
            treasurehunt_update_grades($treasurehunt, $user->id);
        }
    }
}
Beispiel #25
0
 /**
  * Returns IDs of the users who share group membership with the specified user.
  *
  * @param stdClass|cm_info $cm Course-module
  * @param int $userid User ID
  * @return array An array of ID of users.
  */
 public function get_shared_group_members($cm, $userid)
 {
     if (!isset($this->sharedgroupmembers[$userid])) {
         $this->sharedgroupmembers[$userid] = array();
         $groupsids = array_keys(groups_get_activity_allowed_groups($cm, $userid));
         foreach ($groupsids as $groupid) {
             $members = array_keys(groups_get_members($groupid, 'u.id'));
             $this->sharedgroupmembers[$userid] = array_merge($this->sharedgroupmembers[$userid], $members);
         }
     }
     return $this->sharedgroupmembers[$userid];
 }
/**
 * Run synchronization process
 *
 * @param progress_trace $trace
 * @param int|null $courseid or null for all courses
 * @return void
 */
function local_metagroups_sync(progress_trace $trace, $courseid = null)
{
    global $DB;
    if ($courseid !== null) {
        $courseids = array($courseid);
    } else {
        $courseids = local_metagroups_parent_courses();
    }
    foreach (array_unique($courseids) as $courseid) {
        $parent = get_course($courseid);
        // If parent course doesn't use groups, we can skip synchronization.
        if (groups_get_course_groupmode($parent) == NOGROUPS) {
            continue;
        }
        $trace->output($parent->fullname, 1);
        $children = local_metagroups_child_courses($parent->id);
        foreach ($children as $childid) {
            $child = get_course($childid);
            $trace->output($child->fullname, 2);
            $groups = groups_get_all_groups($child->id);
            foreach ($groups as $group) {
                if (!($metagroup = $DB->get_record('groups', array('courseid' => $parent->id, 'idnumber' => $group->id)))) {
                    $metagroup = new stdClass();
                    $metagroup->courseid = $parent->id;
                    $metagroup->idnumber = $group->id;
                    $metagroup->name = $group->name;
                    $metagroup->id = groups_create_group($metagroup, false, false);
                }
                $trace->output($metagroup->name, 3);
                $users = groups_get_members($group->id);
                foreach ($users as $user) {
                    groups_add_member($metagroup->id, $user->id, 'local_metagroups', $group->id);
                }
            }
        }
    }
}
/**
 * Returns a list of issued certificates - sorted for report.
 *
 * @param int $certificateid
 * @param string $sort the sort order
 * @param boolean $groupmode are we in group mode ?
 * @param stdClass $cm the course module
 */
function certificate_get_issues($certificateid, $sort = "ci.certdate ASC", $groupmode, $cm)
{
    global $CFG, $DB;
    // get all users that can manage this certificate to exclude them from the report.
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    $certmanagers = get_users_by_capability($context, 'mod/certificate:manage', 'u.id');
    // Get all the users that have certificates issued, first, create subsql
    // used in the main sql query, this is used so that we don't get an error
    // about the same u.id being returned multiple times due to being in the
    // certificate issues table multiple times.
    $subsql = "SELECT MAX(ci2.timecreated) as timecreated\n               FROM {certificate_issues} ci2\n               WHERE ci2.certificateid = :subsqlcertificateid\n               AND ci2.certdate > 0\n               AND ci2.userid = u.id";
    $users = $DB->get_records_sql("SELECT u.*, ci.code, ci.timecreated, ci.certdate, ci.studentname, ci.reportgrade\n                                   FROM {user} u\n                                   INNER JOIN {certificate_issues} ci\n                                   ON u.id = ci.userid\n                                   WHERE u.deleted = 0\n                                   AND ci.certificateid = :certificateid\n                                   AND ci.certdate > 0\n                                   AND ci.timecreated = ({$subsql})\n                                   ORDER BY {$sort}", array('certificateid' => $certificateid, 'subsqlcertificateid' => $certificateid));
    // now exclude all the certmanagers.
    foreach ($users as $id => $user) {
        if (isset($certmanagers[$id])) {
            //exclude certmanagers.
            unset($users[$id]);
        }
    }
    // if groupmembersonly used, remove users who are not in any group
    if (!empty($users) and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
        if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
            $users = array_intersect($users, array_keys($groupingusers));
        }
    }
    if (!$groupmode) {
        return $users;
    } else {
        $currentgroup = groups_get_activity_group($cm);
        if ($currentgroup) {
            $groupusers = groups_get_members($currentgroup, 'u.*');
            if (empty($groupusers)) {
                return array();
            }
            foreach ($groupusers as $id => $gpuser) {
                if (!isset($users[$id])) {
                    //remove this user as it isn't in the group!
                    unset($users[$id]);
                }
            }
        }
        return $users;
    }
}
Beispiel #28
0
$user_ids = '';
$users = array();
switch ($formdata['reportusers']) {
    case 'allusers':
        // anyone who has ever attempted this hotpot
        if ($records = get_records_select('hotpot_attempts', "hotpot={$hotpot->id}", '', 'id,userid')) {
            foreach ($records as $record) {
                $users[$record->userid] = 0;
                // "0" means user is NOT currently allowed to attempt this HotPot
            }
            unset($records);
        }
        break;
    case 'group':
        // group members
        if ($members = groups_get_members($formdata['reportgroupid'])) {
            foreach ($members as $memberid => $unused) {
                $users[$memberid] = 1;
                // "1" signifies currently recognized participant
            }
        }
        break;
    case 'allparticipants':
        // anyone currently allowed to attempt this HotPot
        if ($records = get_users_by_capability($modulecontext, 'mod/hotpot:attempt', 'u.id,u.id', 'u.id')) {
            foreach ($records as $record) {
                $users[$record->id] = 1;
                // "1" means user is allowed to do this HotPot
            }
            unset($records);
        }
Beispiel #29
0
 /**
  * Update grades in the gradebook.
  *
  * @param mixed $submission stdClass|null
  * @param mixed $grade stdClass|null
  * @return bool
  */
 protected function gradebook_item_update($submission = null, $grade = null)
 {
     // Do not push grade to gradebook if blind marking is active as
     // the gradebook would reveal the students.
     if ($this->is_blind_marking()) {
         return false;
     }
     // If marking workflow is enabled and grade is not released then don't send to gradebook yet.
     if ($this->get_instance()->markingworkflow && !empty($grade)) {
         $flags = $this->get_user_flags($grade->userid, false);
         if (empty($flags->workflowstate) || $flags->workflowstate != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
             return false;
         }
     }
     if ($submission != null) {
         if ($submission->userid == 0) {
             // This is a group submission update.
             $team = groups_get_members($submission->groupid, 'u.id');
             foreach ($team as $member) {
                 $membersubmission = clone $submission;
                 $membersubmission->groupid = 0;
                 $membersubmission->userid = $member->id;
                 $this->gradebook_item_update($membersubmission, null);
             }
             return;
         }
         $gradebookgrade = $this->convert_submission_for_gradebook($submission);
     } else {
         $gradebookgrade = $this->convert_grade_for_gradebook($grade);
     }
     // Grading is disabled, return.
     if ($this->grading_disabled($gradebookgrade['userid'])) {
         return false;
     }
     $assign = clone $this->get_instance();
     $assign->cmidnumber = $this->get_course_module()->idnumber;
     return assign_grade_item_update($assign, $gradebookgrade);
 }
Beispiel #30
0
    /**
     * Updates and creates the completion records in mdl_course_modules_completion.
     *
     * @param int $teamsubmission value of 0 or 1 to indicate whether this is a group activity
     * @param int $requireallteammemberssubmit value of 0 or 1 to indicate whether all group members must click Submit
     * @param obj $submission the submission
     * @param int $userid the user id
     * @param int $complete
     * @param obj $completion
     *
     * @return null
     */
    protected function update_activity_completion_records($teamsubmission,
                                                          $requireallteammemberssubmit,
                                                          $submission,
                                                          $userid,
                                                          $complete,
                                                          $completion) {

        if (($teamsubmission && $submission->groupid > 0 && !$requireallteammemberssubmit) ||
            ($teamsubmission && $submission->groupid > 0 && $requireallteammemberssubmit &&
             $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED)) {

            $members = groups_get_members($submission->groupid);

            foreach ($members as $member) {
                $completion->update_state($this->get_course_module(), $complete, $member->id);
            }
        } else {
            $completion->update_state($this->get_course_module(), $complete, $userid);
        }

        return;
    }