本文整理汇总了PHP中groups_get_activity_groupmode函数的典型用法代码示例。如果您正苦于以下问题:PHP groups_get_activity_groupmode函数的具体用法?PHP groups_get_activity_groupmode怎么用?PHP groups_get_activity_groupmode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了groups_get_activity_groupmode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: definition
function definition()
{
global $CFG, $USER;
$mform =& $this->_form;
$course = $this->_customdata['course'];
$cm = $this->_customdata['cm'];
$modcontext = $this->_customdata['modcontext'];
$mform->addElement('header', 'general', get_string('export', 'quiz'));
$mform->setHelpButton('general', array('export', get_string('export', 'quiz'), 'attforblock'));
$groupmode = groups_get_activity_groupmode($cm);
$groups = groups_get_activity_allowed_groups($cm, $USER->id);
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
$grouplist[0] = get_string('allparticipants');
}
if ($groups) {
foreach ($groups as $group) {
$grouplist[$group->id] = $group->name;
}
}
$mform->addElement('select', 'group', get_string('group'), $grouplist);
$ident = array();
$ident[] =& MoodleQuickForm::createElement('checkbox', 'id', '', get_string('studentid', 'attforblock'));
$ident[] =& MoodleQuickForm::createElement('checkbox', 'uname', '', get_string('username'));
$mform->addGroup($ident, 'ident', get_string('identifyby', 'attforblock'), array('<br />'), true);
$mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true));
$mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attforblock'), get_string('yes'));
$mform->addElement('date_selector', 'sessionenddate', get_string('endofperiod', 'attforblock'));
$mform->disabledIf('sessionenddate', 'includenottaken', 'notchecked');
$mform->addElement('select', 'format', get_string('format'), array('excel' => get_string('downloadexcel', 'attforblock'), 'ooo' => get_string('downloadooo', 'attforblock'), 'text' => get_string('downloadtext', 'attforblock')));
// buttons
$submit_string = get_string('ok');
$this->add_action_buttons(false, $submit_string);
$mform->addElement('hidden', 'id', $cm->id);
// $mform->addElement('hidden', 'action', 'add');
}
示例2: load_from_record
/**
* Create a scheduler instance from the database.
*/
protected static function load_from_record($id, stdClass $coursemodule)
{
$scheduler = new scheduler_instance();
$scheduler->load($id);
$scheduler->cm = $coursemodule;
$scheduler->groupmode = groups_get_activity_groupmode($coursemodule);
return $scheduler;
}
示例3: get_current_group
/**
* Get the current group for the user user looking at the report.
*
* @param object $cm the course_module information.
* @param object $coures the course settings.
* @param context $context the quiz context.
* @return int the current group id, if applicable. 0 for all users,
* NO_GROUPS_ALLOWED if the user cannot see any group.
*/
public function get_current_group($cm, $course, $context)
{
$groupmode = groups_get_activity_groupmode($cm, $course);
$currentgroup = groups_get_activity_group($cm, true);
if ($groupmode == SEPARATEGROUPS && !$currentgroup && !has_capability('moodle/site:accessallgroups', $context)) {
$currentgroup = self::NO_GROUPS_ALLOWED;
}
return $currentgroup;
}
示例4: definition
/**
* Definition of the setting form elements
*/
public function definition() {
$mform = $this->_form;
$workshop = $this->_customdata['workshop'];
$plugindefaults = get_config('workshopallocation_random');
$mform->addElement('header', 'randomallocationsettings', get_string('allocationsettings', 'workshopallocation_random'));
$gmode = groups_get_activity_groupmode($workshop->cm, $workshop->course);
switch ($gmode) {
case NOGROUPS:
$grouplabel = get_string('groupsnone', 'group');
break;
case VISIBLEGROUPS:
$grouplabel = get_string('groupsvisible', 'group');
break;
case SEPARATEGROUPS:
$grouplabel = get_string('groupsseparate', 'group');
break;
}
$mform->addElement('static', 'groupmode', get_string('groupmode', 'group'), $grouplabel);
$options_numper = array(
workshop_random_allocator_setting::NUMPER_SUBMISSION => get_string('numperauthor', 'workshopallocation_random'),
workshop_random_allocator_setting::NUMPER_REVIEWER => get_string('numperreviewer', 'workshopallocation_random')
);
$grpnumofreviews = array();
$grpnumofreviews[] = $mform->createElement('select', 'numofreviews', '',
workshop_random_allocator::available_numofreviews_list());
$mform->setDefault('numofreviews', $plugindefaults->numofreviews);
$grpnumofreviews[] = $mform->createElement('select', 'numper', '', $options_numper);
$mform->setDefault('numper', workshop_random_allocator_setting::NUMPER_SUBMISSION);
$mform->addGroup($grpnumofreviews, 'grpnumofreviews', get_string('numofreviews', 'workshopallocation_random'),
array(' '), false);
if (VISIBLEGROUPS == $gmode) {
$mform->addElement('checkbox', 'excludesamegroup', get_string('excludesamegroup', 'workshopallocation_random'));
$mform->setDefault('excludesamegroup', 0);
} else {
$mform->addElement('hidden', 'excludesamegroup', 0);
}
$mform->addElement('checkbox', 'removecurrent', get_string('removecurrentallocations', 'workshopallocation_random'));
$mform->setDefault('removecurrent', 0);
$mform->addElement('checkbox', 'assesswosubmission', get_string('assesswosubmission', 'workshopallocation_random'));
$mform->setDefault('assesswosubmission', 0);
if (empty($workshop->useselfassessment)) {
$mform->addElement('static', 'addselfassessment', get_string('addselfassessment', 'workshopallocation_random'),
get_string('selfassessmentdisabled', 'workshop'));
} else {
$mform->addElement('checkbox', 'addselfassessment', get_string('addselfassessment', 'workshopallocation_random'));
}
$this->add_action_buttons();
}
示例5: __construct
public function __construct($recordorid, $options = array())
{
global $USER;
parent::__construct($recordorid, $options);
$this->cm = get_coursemodule_from_instance('mediagallery', $this->record->id);
if (!empty($this->cm)) {
$this->context = \context_module::instance($this->cm->id);
$this->options['currentgroup'] = groups_get_activity_group($this->cm, true);
$this->options['groupmode'] = groups_get_activity_groupmode($this->cm);
$this->options['groups'] = groups_get_all_groups($this->cm->course, $USER->id, $this->cm->groupingid);
}
}
示例6: certificate_get_teachers
/**
* Returns a list of teachers by group
* for sending email alerts to teachers
*
* @param stdClass $certificate
* @param stdClass $user
* @param stdClass $course
* @param stdClass $cm
* @return array the teacher array
*/
function certificate_get_teachers($certificate, $user, $course, $cm)
{
global $USER;
$context = context_module::instance($cm->id);
$potteachers = get_users_by_capability($context, 'mod/certificate:manage', '', '', '', '', '', '', false, false);
if (empty($potteachers)) {
return array();
}
$teachers = array();
if (groups_get_activity_groupmode($cm, $course) == SEPARATEGROUPS) {
// Separate groups are being used
if ($groups = groups_get_all_groups($course->id, $user->id)) {
// Try to find all groups
foreach ($groups as $group) {
foreach ($potteachers as $t) {
if ($t->id == $user->id) {
continue;
// do not send self
}
if (groups_is_member($group->id, $t->id)) {
$teachers[$t->id] = $t;
}
}
}
} else {
// user not in group, try to find teachers without group
foreach ($potteachers as $t) {
if ($t->id == $USER->id) {
continue;
// do not send self
}
if (!groups_get_all_groups($course->id, $t->id)) {
//ugly hack
$teachers[$t->id] = $t;
}
}
}
} else {
foreach ($potteachers as $t) {
if ($t->id == $USER->id) {
continue;
// do not send self
}
$teachers[$t->id] = $t;
}
}
return $teachers;
}
示例7: scheduler_migrate_groupmode
function scheduler_migrate_groupmode($sid)
{
global $DB;
$globalenable = (bool) get_config('mod_scheduler', 'groupscheduling');
$cm = get_coursemodule_from_instance('scheduler', $sid, 0, false, IGNORE_MISSING);
if ($cm) {
if (groups_get_activity_groupmode($cm) > 0 && $globalenable) {
$g = $cm->groupingid;
} else {
$g = -1;
}
$DB->set_field('scheduler', 'bookingrouping', $g, array('id' => $sid));
$DB->set_field('course_modules', 'groupmode', 0, array('id' => $cm->id));
$DB->set_field('course_modules', 'groupingid', 0, array('id' => $cm->id));
}
}
示例8: definition
/**
* Called to define this moodle form
*
* @return void
*/
public function definition()
{
global $USER;
$mform =& $this->_form;
$course = $this->_customdata['course'];
$cm = $this->_customdata['cm'];
$modcontext = $this->_customdata['modcontext'];
$mform->addElement('header', 'general', get_string('export', 'attendance'));
$groupmode = groups_get_activity_groupmode($cm, $course);
$groups = groups_get_activity_allowed_groups($cm, $USER->id);
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
$grouplist[0] = get_string('allparticipants');
}
if ($groups) {
foreach ($groups as $group) {
$grouplist[$group->id] = $group->name;
}
}
$mform->addElement('select', 'group', get_string('group'), $grouplist);
$ident = array();
$ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attendance'));
$ident[] =& $mform->createElement('checkbox', 'uname', '', get_string('username'));
$optional = array('idnumber', 'institution', 'department');
foreach ($optional as $opt) {
$ident[] =& $mform->createElement('checkbox', $opt, '', get_string($opt));
$mform->setType($opt, PARAM_NOTAGS);
}
$mform->addGroup($ident, 'ident', get_string('identifyby', 'attendance'), array('<br />'), true);
$mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true));
$mform->setType('id', PARAM_INT);
$mform->setType('uname', PARAM_INT);
$mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes'));
$mform->setDefault('includeallsessions', true);
$mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attendance'), get_string('yes'));
$mform->addElement('checkbox', 'includeremarks', get_string('includeremarks', 'attendance'), get_string('yes'));
$mform->addElement('date_selector', 'sessionstartdate', get_string('startofperiod', 'attendance'));
$mform->setDefault('sessionstartdate', $course->startdate);
$mform->disabledIf('sessionstartdate', 'includeallsessions', 'checked');
$mform->addElement('date_selector', 'sessionenddate', get_string('endofperiod', 'attendance'));
$mform->disabledIf('sessionenddate', 'includeallsessions', 'checked');
$mform->addElement('select', 'format', get_string('format'), array('excel' => get_string('downloadexcel', 'attendance'), 'ooo' => get_string('downloadooo', 'attendance'), 'text' => get_string('downloadtext', 'attendance')));
$submit_string = get_string('ok');
$this->add_action_buttons(false, $submit_string);
$mform->addElement('hidden', 'id', $cm->id);
}
示例9: display
/**
* Displays the full report
*
* @param \stdClass $scorm full SCORM object
* @param \stdClass $cm - full course_module object
* @param \stdClass $course - full course object
* @param string $download - type of download being requested
*/
public function display($scorm, $cm, $course, $download)
{
global $DB, $OUTPUT, $PAGE;
if ($groupmode = groups_get_activity_groupmode($cm)) {
// Groups are being used.
groups_print_activity_menu($cm, new \moodle_url($PAGE->url));
}
if ($scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id')) {
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$imageurl = new \moodle_url('/mod/scorm/report/graphs/graph.php', array('scoid' => $sco->id));
$graphname = $sco->title;
echo $OUTPUT->heading($graphname, 3);
echo \html_writer::tag('div', \html_writer::empty_tag('img', array('src' => $imageurl, 'alt' => $graphname)), array('class' => 'graph'));
}
}
}
}
示例10: login_user
/**
* Log the current user into a chat room in the given chat.
*
* @param int $chatid the chat instance id
* @param int $groupid the user group id
* @return array of warnings and the chat unique session id
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function login_user($chatid, $groupid = 0)
{
global $DB;
$params = self::validate_parameters(self::login_user_parameters(), array('chatid' => $chatid, 'groupid' => $groupid));
$warnings = array();
// Request and permission validation.
$chat = $DB->get_record('chat', array('id' => $params['chatid']), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($chat, 'chat');
$context = context_module::instance($cm->id);
self::validate_context($context);
require_capability('mod/chat:chat', $context);
if (!empty($params['groupid'])) {
$groupid = $params['groupid'];
// Determine is the group is visible to user.
if (!groups_group_visible($groupid, $course, $cm)) {
throw new moodle_exception('notingroup');
}
} else {
// Check to see if groups are being used here.
if ($groupmode = groups_get_activity_groupmode($cm)) {
$groupid = groups_get_activity_group($cm);
// Determine is the group is visible to user (this is particullary for the group 0).
if (!groups_group_visible($groupid, $course, $cm)) {
throw new moodle_exception('notingroup');
}
} else {
$groupid = 0;
}
}
// Get the unique chat session id.
// Since we are going to use the chat via Web Service requests we set the ajax version (since it's the most similar).
if (!($chatsid = chat_login_user($chat->id, 'ajax', $groupid, $course))) {
throw moodle_exception('cantlogin', 'chat');
}
$result = array();
$result['chatsid'] = $chatsid;
$result['warnings'] = $warnings;
return $result;
}
示例11: display
//.........这里部分代码省略.........
}
} else {
if (optional_param('regrade', 0, PARAM_BOOL) && confirm_sesskey()) {
if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts($quiz, false, $groupstudents, $attemptids);
redirect($reporturl->out(false, $displayoptions));
}
}
}
}
if ($regradeall && confirm_sesskey()) {
require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts($quiz, false, $groupstudents);
redirect($reporturl->out(false, $displayoptions), '', 5);
} else {
if ($regradealldry && confirm_sesskey()) {
require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts($quiz, true, $groupstudents);
redirect($reporturl->out(false, $displayoptions), '', 5);
} else {
if ($regradealldrydo && confirm_sesskey()) {
require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts_needing_it($quiz, $groupstudents);
redirect($reporturl->out(false, $displayoptions), '', 5);
}
}
}
// Start output.
if (!$table->is_downloading()) {
// Only print headers if not asked to download data
$this->print_header_and_tabs($cm, $course, $quiz, 'overview');
}
if ($groupmode = groups_get_activity_groupmode($cm)) {
// Groups are being used
if (!$table->is_downloading()) {
groups_print_activity_menu($cm, $reporturl->out(true, $displayoptions));
}
}
// Print information on the number of existing attempts
if (!$table->is_downloading()) {
//do not print notices when downloading
if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
}
}
$hasquestions = quiz_questions_in_quiz($quiz->questions);
if (!$table->is_downloading()) {
if (!$hasquestions) {
echo quiz_no_questions_message($quiz, $cm, $this->context);
} else {
if (!$students) {
echo $OUTPUT->notification(get_string('nostudentsyet'));
} else {
if ($currentgroup && !$groupstudents) {
echo $OUTPUT->notification(get_string('nostudentsingroup'));
}
}
}
// Print display options
$mform->display();
}
$hasstudents = $students && (!$currentgroup || $groupstudents);
if ($hasquestions && ($hasstudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)) {
// Construct the SQL
$fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid, ';
示例12: has_capability
$canallocate = has_capability('mod/workshop:allocate', $workshop->context);
$canpublish = has_capability('mod/workshop:publishsubmissions', $workshop->context);
$canoverride = ($workshop->phase == workshop::PHASE_EVALUATION and has_capability('mod/workshop:overridegrades', $workshop->context));
$userassessment = $workshop->get_assessment_of_submission_by_user($submission->id, $USER->id);
$isreviewer = !empty($userassessment);
$editable = ($cansubmit and $ownsubmission);
$ispublished = ($workshop->phase == workshop::PHASE_CLOSED and $submission->published == 1 and has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context));
if (empty($submission->id) and !$workshop->creating_submission_allowed($USER->id)) {
$editable = false;
}
if ($submission->id and !$workshop->modifying_submission_allowed($USER->id)) {
$editable = false;
}
if ($canviewall) {
// check this flag against the group membership yet
if (groups_get_activity_groupmode($workshop->cm) == SEPARATEGROUPS) {
// user must have accessallgroups or share at least one group with the submission author
if (!has_capability('moodle/site:accessallgroups', $workshop->context)) {
$usersgroups = groups_get_activity_allowed_groups($workshop->cm);
$authorsgroups = groups_get_all_groups($workshop->course->id, $submission->authorid, $workshop->cm->groupingid, 'g.id');
$sharedgroups = array_intersect_key($usersgroups, $authorsgroups);
if (empty($sharedgroups)) {
$canviewall = false;
}
}
}
}
if ($editable and $workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_SUBMISSION and !has_capability('mod/workshop:manageexamples', $workshop->context)) {
// check that all required examples have been assessed by the user
$examples = $workshop->get_examples_for_reviewer($USER->id);
foreach ($examples as $exampleid => $example) {
示例13: forum_get_posts_by_user
//.........这里部分代码省略.........
// DB caching friendly
$now = round(time(), -2);
// For each course to search we want to find the forums the user has posted in
// and providing the current user can access the forum create a search condition
// for the forum to get the requested users posts.
foreach ($return->courses as $course) {
// Now we need to get the forums
$modinfo = get_fast_modinfo($course);
if (empty($modinfo->instances['forum'])) {
// hmmm, no forums? well at least its easy... skip!
continue;
}
// Iterate
foreach ($modinfo->get_instances_of('forum') as $forumid => $cm) {
if (!$cm->uservisible or !isset($forums[$forumid])) {
continue;
}
// Get the forum in question
$forum = $forums[$forumid];
// This is needed for functionality later on in the forum code....
$forum->cm = $cm;
// Check that either the current user can view the forum, or that the
// current user has capabilities over the requested user and the requested
// user can view the discussion
if (!has_capability('mod/forum:viewdiscussion', $cm->context) && !($hascapsonuser && has_capability('mod/forum:viewdiscussion', $cm->context, $user->id))) {
continue;
}
// This will contain forum specific where clauses
$forumsearchselect = array();
if (!$iscurrentuser && !$hascapsonuser) {
// Make sure we check group access
if (groups_get_activity_groupmode($cm, $course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $cm->context)) {
$groups = $modinfo->get_groups($cm->groupingid);
$groups[] = -1;
list($groupid_sql, $groupid_params) = $DB->get_in_or_equal($groups, SQL_PARAMS_NAMED, 'grps'.$forumid.'_');
$forumsearchparams = array_merge($forumsearchparams, $groupid_params);
$forumsearchselect[] = "d.groupid $groupid_sql";
}
// hidden timed discussions
if (!empty($CFG->forum_enabletimedposts) && !has_capability('mod/forum:viewhiddentimedposts', $cm->context)) {
$forumsearchselect[] = "(d.userid = :userid{$forumid} OR (d.timestart < :timestart{$forumid} AND (d.timeend = 0 OR d.timeend > :timeend{$forumid})))";
$forumsearchparams['userid'.$forumid] = $user->id;
$forumsearchparams['timestart'.$forumid] = $now;
$forumsearchparams['timeend'.$forumid] = $now;
}
// qanda access
if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $cm->context)) {
// We need to check whether the user has posted in the qanda forum.
$discussionspostedin = forum_discussions_user_has_posted_in($forum->id, $user->id);
if (!empty($discussionspostedin)) {
$forumonlydiscussions = array(); // Holds discussion ids for the discussions the user is allowed to see in this forum.
foreach ($discussionspostedin as $d) {
$forumonlydiscussions[] = $d->id;
}
list($discussionid_sql, $discussionid_params) = $DB->get_in_or_equal($forumonlydiscussions, SQL_PARAMS_NAMED, 'qanda'.$forumid.'_');
$forumsearchparams = array_merge($forumsearchparams, $discussionid_params);
$forumsearchselect[] = "(d.id $discussionid_sql OR p.parent = 0)";
} else {
$forumsearchselect[] = "p.parent = 0";
}
}
示例14: chat_print_recent_activity
/**
* Given a course and a date, prints a summary of all chat rooms past and present
* This function is called from course/lib.php: print_recent_activity()
*
* @global object
* @global object
* @global object
* @param object $course
* @param array $viewfullnames
* @param int|string $timestart Timestamp
* @return bool
*/
function chat_print_recent_activity($course, $viewfullnames, $timestart)
{
global $CFG, $USER, $DB, $OUTPUT;
// this is approximate only, but it is really fast ;-)
$timeout = $CFG->chat_old_ping * 10;
if (!($mcms = $DB->get_records_sql("SELECT cm.id, MAX(chm.timestamp) AS lasttime\n FROM {course_modules} cm\n JOIN {modules} md ON md.id = cm.module\n JOIN {chat} ch ON ch.id = cm.instance\n JOIN {chat_messages} chm ON chm.chatid = ch.id\n WHERE chm.timestamp > ? AND ch.course = ? AND md.name = 'chat'\n GROUP BY cm.id\n ORDER BY lasttime ASC", array($timestart, $course->id)))) {
return false;
}
$past = array();
$current = array();
$modinfo =& get_fast_modinfo($course);
// reference needed because we might load the groups
foreach ($mcms as $cmid => $mcm) {
if (!array_key_exists($cmid, $modinfo->cms)) {
continue;
}
$cm = $modinfo->cms[$cmid];
$cm->lasttime = $mcm->lasttime;
if (!$modinfo->cms[$cm->id]->uservisible) {
continue;
}
if (groups_get_activity_groupmode($cm) != SEPARATEGROUPS or has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
if ($timeout > time() - $cm->lasttime) {
$current[] = $cm;
} else {
$past[] = $cm;
}
continue;
}
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id);
// load all my groups and cache it in modinfo
}
// verify groups in separate mode
if (!($mygroupids = $modinfo->groups[$cm->groupingid])) {
continue;
}
// ok, last post was not for my group - we have to query db to get last message from one of my groups
// only minor problem is that the order will not be correct
$mygroupids = implode(',', $mygroupids);
$cm->mygroupids = $mygroupids;
if (!($mcm = $DB->get_record_sql("SELECT cm.id, MAX(chm.timestamp) AS lasttime\n FROM {course_modules} cm\n JOIN {chat} ch ON ch.id = cm.instance\n JOIN {chat_messages_current} chm ON chm.chatid = ch.id\n WHERE chm.timestamp > ? AND cm.id = ? AND\n (chm.groupid IN ({$mygroupids}) OR chm.groupid = 0)\n GROUP BY cm.id", array($timestart, $cm->id)))) {
continue;
}
$cm->lasttime = $mcm->lasttime;
if ($timeout > time() - $cm->lasttime) {
$current[] = $cm;
} else {
$past[] = $cm;
}
}
if (!$past and !$current) {
return false;
}
$strftimerecent = get_string('strftimerecent');
if ($past) {
echo $OUTPUT->heading(get_string("pastchats", 'chat') . ':');
foreach ($past as $cm) {
$link = $CFG->wwwroot . '/mod/chat/view.php?id=' . $cm->id;
$date = userdate($cm->lasttime, $strftimerecent);
echo '<div class="head"><div class="date">' . $date . '</div></div>';
echo '<div class="info"><a href="' . $link . '">' . format_string($cm->name, true) . '</a></div>';
}
}
if ($current) {
echo $OUTPUT->heading(get_string("currentchats", 'chat') . ':');
$oldest = floor((time() - $CFG->chat_old_ping) / 10) * 10;
// better db caching
$timeold = time() - $CFG->chat_old_ping;
$timeold = floor($timeold / 10) * 10;
// better db caching
$timeoldext = time() - $CFG->chat_old_ping * 10;
// JSless gui_basic needs much longer timeouts
$timeoldext = floor($timeoldext / 10) * 10;
// better db caching
$params = array('timeold' => $timeold, 'timeoldext' => $timeoldext, 'cmid' => $cm->id);
$timeout = "AND (chu.version<>'basic' AND chu.lastping>:timeold) OR (chu.version='basic' AND chu.lastping>:timeoldext)";
foreach ($current as $cm) {
//count users first
if (isset($cm->mygroupids)) {
$groupselect = "AND (chu.groupid IN ({$cm->mygroupids}) OR chu.groupid = 0)";
} else {
$groupselect = "";
}
if (!($users = $DB->get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email, u.picture\n FROM {course_modules} cm\n JOIN {chat} ch ON ch.id = cm.instance\n JOIN {chat_users} chu ON chu.chatid = ch.id\n JOIN {user} u ON u.id = chu.userid\n WHERE cm.id = :cmid {$timeout} {$groupselect}\n GROUP BY u.id, u.firstname, u.lastname, u.email, u.picture", $params))) {
}
$link = $CFG->wwwroot . '/mod/chat/view.php?id=' . $cm->id;
$date = userdate($cm->lasttime, $strftimerecent);
//.........这里部分代码省略.........
示例15: quiz_send_notification_emails
/**
* Takes a bunch of information to format into an email and send
* to the specified recipient.
*
* @param object $course the course
* @param object $quiz the quiz
* @param object $attempt this attempt just finished
* @param object $context the quiz context
* @param object $cm the coursemodule for this quiz
*
* @return int number of emails sent
*/
function quiz_send_notification_emails($course, $quiz, $attempt, $context, $cm)
{
global $CFG, $USER;
// we will count goods and bads for error logging
$emailresult = array('good' => 0, 'block' => 0, 'fail' => 0);
// do nothing if required objects not present
if (empty($course) or empty($quiz) or empty($attempt) or empty($context)) {
debugging('quiz_send_notification_emails: Email(s) not sent due to program error.', DEBUG_DEVELOPER);
return $emailresult['fail'];
}
// check for confirmation required
$sendconfirm = false;
$notifyexcludeusers = '';
if (has_capability('mod/quiz:emailconfirmsubmission', $context, NULL, false)) {
// exclude from notify emails later
$notifyexcludeusers = $USER->id;
// send the email
$sendconfirm = true;
}
// check for notifications required
$notifyfields = 'u.id, u.username, u.firstname, u.lastname, u.email, u.emailstop, u.lang, u.timezone, u.mailformat, u.maildisplay';
$groups = groups_get_all_groups($course->id, $USER->id);
if (is_array($groups) && count($groups) > 0) {
$groups = array_keys($groups);
} else {
if (groups_get_activity_groupmode($cm, $course) != NOGROUPS) {
// If the user is not in a group, and the quiz is set to group mode,
// then set $gropus to a non-existant id so that only users with
// 'moodle/site:accessallgroups' get notified.
$groups = -1;
} else {
$groups = '';
}
}
$userstonotify = get_users_by_capability($context, 'mod/quiz:emailnotifysubmission', $notifyfields, '', '', '', $groups, $notifyexcludeusers, false, false, true);
// if something to send, then build $a
if (!empty($userstonotify) or $sendconfirm) {
$a = new stdClass();
// course info
$a->coursename = $course->fullname;
$a->courseshortname = $course->shortname;
// quiz info
$a->quizname = $quiz->name;
$a->quizreporturl = $CFG->wwwroot . '/mod/quiz/report.php?q=' . $quiz->id;
$a->quizreportlink = '<a href="' . $a->quizreporturl . '">' . format_string($quiz->name) . ' report</a>';
$a->quizreviewurl = $CFG->wwwroot . '/mod/quiz/review.php?attempt=' . $attempt->id;
$a->quizreviewlink = '<a href="' . $a->quizreviewurl . '">' . format_string($quiz->name) . ' review</a>';
$a->quizurl = $CFG->wwwroot . '/mod/quiz/view.php?q=' . $quiz->id;
$a->quizlink = '<a href="' . $a->quizurl . '">' . format_string($quiz->name) . '</a>';
// attempt info
$a->submissiontime = userdate($attempt->timefinish);
$a->timetaken = format_time($attempt->timefinish - $attempt->timestart);
// student who sat the quiz info
$a->studentidnumber = $USER->idnumber;
$a->studentname = fullname($USER);
$a->studentusername = $USER->username;
}
// send confirmation if required
if ($sendconfirm) {
// send the email and update stats
switch (quiz_send_confirmation($a)) {
case true:
$emailresult['good']++;
break;
case false:
$emailresult['fail']++;
break;
case 'emailstop':
$emailresult['block']++;
break;
}
}
// send notifications if required
if (!empty($userstonotify)) {
// loop through recipients and send an email to each and update stats
foreach ($userstonotify as $recipient) {
switch (quiz_send_notification($recipient, $a)) {
case true:
$emailresult['good']++;
break;
case false:
$emailresult['fail']++;
break;
case 'emailstop':
$emailresult['block']++;
break;
}
}
//.........这里部分代码省略.........