当前位置: 首页>>代码示例>>PHP>>正文


PHP groups_get_course_groupmode函数代码示例

本文整理汇总了PHP中groups_get_course_groupmode函数的典型用法代码示例。如果您正苦于以下问题:PHP groups_get_course_groupmode函数的具体用法?PHP groups_get_course_groupmode怎么用?PHP groups_get_course_groupmode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了groups_get_course_groupmode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: group_created

 /**
  * Group created
  *
  * @param \core\event\group_created $event
  * @return void
  */
 public static function group_created(\core\event\group_created $event)
 {
     global $DB;
     $group = $event->get_record_snapshot('groups', $event->objectid);
     $courseids = local_metagroups_parent_courses($group->courseid);
     foreach ($courseids as $courseid) {
         $course = get_course($courseid);
         // If parent course doesn't use groups, we can skip synchronization.
         if (groups_get_course_groupmode($course) == NOGROUPS) {
             continue;
         }
         if (!$DB->record_exists('groups', array('courseid' => $course->id, 'idnumber' => $group->id))) {
             $metagroup = new \stdClass();
             $metagroup->courseid = $course->id;
             $metagroup->idnumber = $group->id;
             $metagroup->name = $group->name;
             groups_create_group($metagroup, false, false);
         }
     }
 }
开发者ID:stanta,项目名称:moodle-local_metagroups,代码行数:26,代码来源:observers.php

示例2: display_filemanager_link

 /**
  *
  * @uses $CFG
  * @uses $USER
  */
 function display_filemanager_link()
 {
     global $CFG, $USER;
     if (!($course = get_record('course', 'id', $this->instance->pageid))) {
         error("Course ID is incorrect");
     }
     $coursecontext = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
     $canmanagegroups = has_capability('block/file_manager:canmanagegroups', $coursecontext);
     $this->content->items[] = "<a title=\"" . get_string('msgfilemanager', 'block_file_manager') . "\" href=\"{$CFG->wwwroot}/blocks/file_manager/view.php?id={$this->instance->pageid}&groupid=0\">" . get_string('myfiles', 'block_file_manager') . "</a>";
     $this->content->icons[] = "<img src=\"{$CFG->pixpath}/i/files.gif\" alt=\"\" />";
     // If the user is member of any group of this course, links for each group in which he belongs must be displayed
     $groupmode = groups_get_course_groupmode($course);
     $groupsarray = array();
     switch ($groupmode) {
         case NOGROUPS:
             // Nothing to display
             break;
         case SEPARATEGROUPS:
             if ($canmanagegroups) {
                 // Displays all groups because of super rights
                 $groupsarray = groups_get_all_groups($this->instance->pageid);
             } else {
                 // Display only links for groups in which the user is member
                 $groupsarray = groups_get_all_groups($this->instance->pageid, $USER->id);
             }
             break;
         case VISIBLEGROUPS:
             // Display a link for all groups
             $groupsarray = groups_get_all_groups($this->instance->pageid);
             break;
     }
     // Displays group links if user in a group.
     if (is_array($groupsarray)) {
         foreach ($groupsarray as $groupid => $value) {
             $this->content->items[] = "<a title=\"" . get_string('msgfilemanagergroup', 'block_file_manager') . "\" href=\"{$CFG->wwwroot}/blocks/file_manager/view.php?id={$this->instance->pageid}&groupid={$groupid}\">" . groups_get_group_name($groupid) . "</a>";
             $this->content->icons[] = "<img src=\"{$CFG->pixpath}/i/files.gif\" alt=\"\" />";
         }
     }
 }
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:44,代码来源:block_file_manager.php

示例3: local_metagroups_sync

/**
 * 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);
                }
            }
        }
    }
}
开发者ID:stanta,项目名称:moodle-local_metagroups,代码行数:44,代码来源:locallib.php

示例4: get_enrolled_users


//.........这里部分代码省略.........
                 $groupid = (int) $option['value'];
                 break;
             case 'onlyactive':
                 $onlyactive = !empty($option['value']);
                 break;
             case 'userfields':
                 $thefields = explode(',', $option['value']);
                 foreach ($thefields as $f) {
                     $userfields[] = clean_param($f, PARAM_ALPHANUMEXT);
                 }
                 break;
             case 'limitfrom':
                 $limitfrom = clean_param($option['value'], PARAM_INT);
                 break;
             case 'limitnumber':
                 $limitnumber = clean_param($option['value'], PARAM_INT);
                 break;
             case 'sortby':
                 $sortallowedvalues = array('id', 'firstname', 'lastname', 'siteorder');
                 if (!in_array($option['value'], $sortallowedvalues)) {
                     throw new invalid_parameter_exception('Invalid value for sortby parameter (value: ' . $option['value'] . '),' . 'allowed values are: ' . implode(',', $sortallowedvalues));
                 }
                 if ($option['value'] == 'siteorder') {
                     list($sortby, $sortparams) = users_order_by_sql('us');
                 } else {
                     $sortby = 'us.' . $option['value'];
                 }
                 break;
             case 'sortdirection':
                 $sortdirection = strtoupper($option['value']);
                 $directionallowedvalues = array('ASC', 'DESC');
                 if (!in_array($sortdirection, $directionallowedvalues)) {
                     throw new invalid_parameter_exception('Invalid value for sortdirection parameter
                     (value: ' . $sortdirection . '),' . 'allowed values are: ' . implode(',', $directionallowedvalues));
                 }
                 break;
         }
     }
     $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
     $coursecontext = context_course::instance($courseid, IGNORE_MISSING);
     if ($courseid == SITEID) {
         $context = context_system::instance();
     } else {
         $context = $coursecontext;
     }
     try {
         self::validate_context($context);
     } catch (Exception $e) {
         $exceptionparam = new stdClass();
         $exceptionparam->message = $e->getMessage();
         $exceptionparam->courseid = $params['courseid'];
         throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
     }
     if ($courseid == SITEID) {
         require_capability('moodle/site:viewparticipants', $context);
     } else {
         require_capability('moodle/course:viewparticipants', $context);
     }
     // to overwrite this parameter, you need role:review capability
     if ($withcapability) {
         require_capability('moodle/role:review', $coursecontext);
     }
     // need accessallgroups capability if you want to overwrite this option
     if (!empty($groupid) && !groups_is_member($groupid)) {
         require_capability('moodle/site:accessallgroups', $coursecontext);
     }
     // to overwrite this option, you need course:enrolereview permission
     if ($onlyactive) {
         require_capability('moodle/course:enrolreview', $coursecontext);
     }
     list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext, $withcapability, $groupid, $onlyactive);
     $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
     $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
     $enrolledparams['contextlevel'] = CONTEXT_USER;
     $groupjoin = '';
     if (empty($groupid) && groups_get_course_groupmode($course) == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $coursecontext)) {
         // Filter by groups the user can view.
         $usergroups = groups_get_user_groups($course->id);
         if (!empty($usergroups['0'])) {
             list($groupsql, $groupparams) = $DB->get_in_or_equal($usergroups['0'], SQL_PARAMS_NAMED);
             $groupjoin = "JOIN {groups_members} gm ON (u.id = gm.userid AND gm.groupid {$groupsql})";
             $enrolledparams = array_merge($enrolledparams, $groupparams);
         } else {
             // User doesn't belong to any group, so he can't see any user. Return an empty array.
             return array();
         }
     }
     $sql = "SELECT us.*\n                  FROM {user} us\n                  JOIN (\n                      SELECT DISTINCT u.id {$ctxselect}\n                        FROM {user} u {$ctxjoin} {$groupjoin}\n                       WHERE u.id IN ({$enrolledsql})\n                  ) q ON q.id = us.id\n                ORDER BY {$sortby} {$sortdirection}";
     $enrolledparams = array_merge($enrolledparams, $sortparams);
     $enrolledusers = $DB->get_recordset_sql($sql, $enrolledparams, $limitfrom, $limitnumber);
     $users = array();
     foreach ($enrolledusers as $user) {
         context_helper::preload_from_record($user);
         if ($userdetails = user_get_user_details($user, $course, $userfields)) {
             $users[] = $userdetails;
         }
     }
     $enrolledusers->close();
     return $users;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:externallib.php

示例5: setup_groups

 /**
  * Sets up this object's group variables, mainly to restrict the selection of users to display.
  */
 protected function setup_groups()
 {
     /// find out current groups mode
     if ($this->groupmode = groups_get_course_groupmode($this->course)) {
         $this->currentgroup = groups_get_course_group($this->course, true);
         $this->group_selector = groups_print_course_menu($this->course, $this->pbarurl, true);
         if ($this->groupmode == SEPARATEGROUPS and !$this->currentgroup and !has_capability('moodle/site:accessallgroups', $this->context)) {
             $this->currentgroup = -2;
             // means can not access any groups at all
         }
         if ($this->currentgroup) {
             $this->groupsql = " JOIN {groups_members} gm ON gm.userid = u.id ";
             $this->groupwheresql = " AND gm.groupid = :gr_grpid ";
             $this->groupwheresql_params = array('gr_grpid' => $this->currentgroup);
         }
     }
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:20,代码来源:lib.php

示例6: clean_param

        } else {
            echo $OUTPUT->header();
            $PAGE->navbar->add($struser);
            echo $OUTPUT->heading(get_string('notenrolledprofile'));
        }
        $referer = clean_param($_SERVER['HTTP_REFERER'], PARAM_LOCALURL);
        if (!empty($referer)) {
            echo $OUTPUT->continue_button($referer);
        }
        echo $OUTPUT->footer();
        exit;
    }

    // If groups are in use and enforced throughout the course, then make sure we can meet in at least one course level group.
    // Except when we are a parent, in which case we would not be in any group.
    if (groups_get_course_groupmode($course) == SEPARATEGROUPS
            and $course->groupmodeforce
            and !has_capability('moodle/site:accessallgroups', $coursecontext)
            and !has_capability('moodle/site:accessallgroups', $coursecontext, $user->id)
            and !$isparent) {
        if (!isloggedin() or isguestuser()) {
            // Do not use require_login() here because we might have already used require_login($course).
            redirect(get_login_url());
        }
        $mygroups = array_keys(groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid, 'g.id, g.name'));
        $usergroups = array_keys(groups_get_all_groups($course->id, $user->id, $course->defaultgroupingid, 'g.id, g.name'));
        if (!array_intersect($mygroups, $usergroups)) {
            print_error("groupnotamember", '', "../course/view.php?id=$course->id");
        }
    }
}
开发者ID:educacionbe,项目名称:cursos,代码行数:31,代码来源:view.php

示例7: redirect

            echo $OUTPUT->header();
            echo $OUTPUT->heading(get_string('notenrolled', '', $fullname));
        } else {
            echo $OUTPUT->header();
            $PAGE->navbar->add($struser);
            echo $OUTPUT->heading(get_string('notenrolledprofile'));
        }
        if (!empty($_SERVER['HTTP_REFERER'])) {
            echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']);
        }
        echo $OUTPUT->footer();
        exit;
    }

    // If groups are in use and enforced throughout the course, then make sure we can meet in at least one course level group
    if (groups_get_course_groupmode($course) == SEPARATEGROUPS and $course->groupmodeforce
      and !has_capability('moodle/site:accessallgroups', $coursecontext) and !has_capability('moodle/site:accessallgroups', $coursecontext, $user->id)) {
        if (!isloggedin() or isguestuser()) {
            // do not use require_login() here because we might have already used require_login($course)
            redirect(get_login_url());
        }
        $mygroups = array_keys(groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid, 'g.id, g.name'));
        $usergroups = array_keys(groups_get_all_groups($course->id, $user->id, $course->defaultgroupingid, 'g.id, g.name'));
        if (!array_intersect($mygroups, $usergroups)) {
            print_error("groupnotamember", '', "../course/view.php?id=$course->id");
        }
    }
}


/// We've established they can see the user's name at least, so what about the rest?
开发者ID:nfreear,项目名称:moodle,代码行数:31,代码来源:view.php

示例8: redirect

            $PAGE->navbar->add($fullname);
            echo $OUTPUT->header();
            echo $OUTPUT->heading(get_string('notenrolled', '', $fullname));
        } else {
            echo $OUTPUT->header();
            $PAGE->navbar->add($struser);
            echo $OUTPUT->heading(get_string('notenrolledprofile'));
        }
        if (!empty($_SERVER['HTTP_REFERER'])) {
            echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']);
        }
        echo $OUTPUT->footer();
        exit;
    }
    // If groups are in use and enforced throughout the course, then make sure we can meet in at least one course level group
    if (groups_get_course_groupmode($course) == SEPARATEGROUPS and $course->groupmodeforce and !has_capability('moodle/site:accessallgroups', $coursecontext) and !has_capability('moodle/site:accessallgroups', $coursecontext, $user->id)) {
        if (!isloggedin() or isguestuser()) {
            // do not use require_login() here because we might have already used require_login($course)
            redirect(get_login_url());
        }
        $mygroups = array_keys(groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid, 'g.id, g.name'));
        $usergroups = array_keys(groups_get_all_groups($course->id, $user->id, $course->defaultgroupingid, 'g.id, g.name'));
        if (!array_intersect($mygroups, $usergroups)) {
            print_error("groupnotamember", '', "../course/view.php?id={$course->id}");
        }
    }
}
/// We've established they can see the user's name at least, so what about the rest?
if (!$currentuser) {
    $PAGE->navigation->extend_for_user($user);
    if ($node = $PAGE->settingsnav->get('userviewingsettings' . $user->id)) {
开发者ID:vuchannguyen,项目名称:web,代码行数:31,代码来源:view.php

示例9: generate_user_settings

 /**
  * This function gets called by {@link settings_navigation::load_user_settings()} and actually works out
  * what can be shown/done
  *
  * @param int $courseid The current course' id
  * @param int $userid The user id to load for
  * @param string $gstitle The string to pass to get_string for the branch title
  * @return navigation_node|false
  */
 protected function generate_user_settings($courseid, $userid, $gstitle = 'usercurrentsettings')
 {
     global $DB, $CFG, $USER, $SITE;
     if ($courseid != $SITE->id) {
         if (!empty($this->page->course->id) && $this->page->course->id == $courseid) {
             $course = $this->page->course;
         } else {
             $select = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT c.*, {$select}\n                          FROM {course} c\n                          JOIN {context} ctx ON c.id = ctx.instanceid\n                         WHERE c.id = :courseid AND ctx.contextlevel = :contextlevel";
             $params = array('courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
             $course = $DB->get_record_sql($sql, $params, MUST_EXIST);
             context_helper::preload_from_record($course);
         }
     } else {
         $course = $SITE;
     }
     $coursecontext = context_course::instance($course->id);
     // Course context
     $systemcontext = context_system::instance();
     $currentuser = $USER->id == $userid;
     if ($currentuser) {
         $user = $USER;
         $usercontext = context_user::instance($user->id);
         // User context
     } else {
         $select = context_helper::get_preload_record_columns_sql('ctx');
         $sql = "SELECT u.*, {$select}\n                      FROM {user} u\n                      JOIN {context} ctx ON u.id = ctx.instanceid\n                     WHERE u.id = :userid AND ctx.contextlevel = :contextlevel";
         $params = array('userid' => $userid, 'contextlevel' => CONTEXT_USER);
         $user = $DB->get_record_sql($sql, $params, IGNORE_MISSING);
         if (!$user) {
             return false;
         }
         context_helper::preload_from_record($user);
         // Check that the user can view the profile
         $usercontext = context_user::instance($user->id);
         // User context
         $canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
         if ($course->id == $SITE->id) {
             if ($CFG->forceloginforprofiles && !has_coursecontact_role($user->id) && !$canviewuser) {
                 // Reduce possibility of "browsing" userbase at site level
                 // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
                 return false;
             }
         } else {
             $canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext);
             $userisenrolled = is_enrolled($coursecontext, $user->id, '', true);
             if (!$canviewusercourse && !$canviewuser || !$userisenrolled) {
                 return false;
             }
             $canaccessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
             if (!$canaccessallgroups && groups_get_course_groupmode($course) == SEPARATEGROUPS && !$canviewuser) {
                 // If groups are in use, make sure we can see that group (MDL-45874). That does not apply to parents.
                 if ($courseid == $this->page->course->id) {
                     $mygroups = get_fast_modinfo($this->page->course)->groups;
                 } else {
                     $mygroups = groups_get_user_groups($courseid);
                 }
                 $usergroups = groups_get_user_groups($courseid, $userid);
                 if (!array_intersect_key($mygroups[0], $usergroups[0])) {
                     return false;
                 }
             }
         }
     }
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
     $key = $gstitle;
     $prefurl = new moodle_url('/user/preferences.php');
     if ($gstitle != 'usercurrentsettings') {
         $key .= $userid;
         $prefurl->param('userid', $userid);
     }
     // Add a user setting branch.
     if ($gstitle == 'usercurrentsettings') {
         $dashboard = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_CONTAINER, null, 'dashboard');
         // This should be set to false as we don't want to show this to the user. It's only for generating the correct
         // breadcrumb.
         $dashboard->display = false;
         if (get_home_page() == HOMEPAGE_MY) {
             $dashboard->mainnavonly = true;
         }
         $iscurrentuser = $user->id == $USER->id;
         $baseargs = array('id' => $user->id);
         if ($course->id != $SITE->id && !$iscurrentuser) {
             $baseargs['course'] = $course->id;
             $issitecourse = false;
         } else {
             // Load all categories and get the context for the system.
             $issitecourse = true;
         }
         // Add the user profile to the dashboard.
         $profilenode = $dashboard->add(get_string('profile'), new moodle_url('/user/profile.php', array('id' => $user->id)), self::TYPE_SETTING, null, 'myprofile');
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:navigationlib.php

示例10: print_groupmode_setting

/**
 * Print groupmode form element on module setup forms in mod/.../mod.html
 */
function print_groupmode_setting($form, $course = NULL)
{
    if (empty($course)) {
        if (!($course = get_record('course', 'id', $form->course))) {
            error("This course doesn't exist");
        }
    }
    if ($form->coursemodule) {
        if (!($cm = get_record('course_modules', 'id', $form->coursemodule))) {
            error("This course module doesn't exist");
        }
        $groupmode = groups_get_activity_groupmode($cm);
    } else {
        $cm = null;
        $groupmode = groups_get_course_groupmode($course);
    }
    if ($course->groupmode or !$course->groupmodeforce) {
        echo '<tr valign="top">';
        echo '<td align="right"><b>' . get_string('groupmode') . ':</b></td>';
        echo '<td align="left">';
        $choices = array();
        $choices[NOGROUPS] = get_string('groupsnone');
        $choices[SEPARATEGROUPS] = get_string('groupsseparate');
        $choices[VISIBLEGROUPS] = get_string('groupsvisible');
        choose_from_menu($choices, 'groupmode', $groupmode, '', '', 0, false, $course->groupmodeforce);
        helpbutton('groupmode', get_string('groupmode'));
        echo '</td></tr>';
    }
}
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:32,代码来源:lib.php

示例11: file_pluginfile


//.........这里部分代码省略.........
                                            }
                                        }
                                        $filename = array_pop($args);
                                        $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
                                        if (!($file = $fs->get_file($context->id, $component, $filearea, 0, $filepath, $filename)) or $file->is_directory()) {
                                            send_file_not_found();
                                        }
                                        \core\session\manager::write_close();
                                        // Unlock session during file serving.
                                        send_stored_file($file, 0, 0, true, array('preview' => $preview));
                                        // must force download - security!
                                    } else {
                                        if ($filearea === 'profile' and $context->contextlevel == CONTEXT_COURSE) {
                                            $userid = (int) array_shift($args);
                                            $usercontext = context_user::instance($userid);
                                            if ($CFG->forcelogin) {
                                                require_login();
                                            }
                                            if (!empty($CFG->forceloginforprofiles)) {
                                                require_login();
                                                if (isguestuser()) {
                                                    print_error('noguest');
                                                }
                                                //TODO: review this logic of user profile access prevention
                                                if (!has_coursecontact_role($userid) and !has_capability('moodle/user:viewdetails', $usercontext)) {
                                                    print_error('usernotavailable');
                                                }
                                                if (!has_capability('moodle/user:viewdetails', $context) && !has_capability('moodle/user:viewdetails', $usercontext)) {
                                                    print_error('cannotviewprofile');
                                                }
                                                if (!is_enrolled($context, $userid)) {
                                                    print_error('notenrolledprofile');
                                                }
                                                if (groups_get_course_groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
                                                    print_error('groupnotamember');
                                                }
                                            }
                                            $filename = array_pop($args);
                                            $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
                                            if (!($file = $fs->get_file($usercontext->id, 'user', 'profile', 0, $filepath, $filename)) or $file->is_directory()) {
                                                send_file_not_found();
                                            }
                                            \core\session\manager::write_close();
                                            // Unlock session during file serving.
                                            send_stored_file($file, 0, 0, true, array('preview' => $preview));
                                            // must force download - security!
                                        } else {
                                            if ($filearea === 'backup' and $context->contextlevel == CONTEXT_USER) {
                                                require_login();
                                                if (isguestuser()) {
                                                    send_file_not_found();
                                                }
                                                $userid = $context->instanceid;
                                                if ($USER->id != $userid) {
                                                    send_file_not_found();
                                                }
                                                $filename = array_pop($args);
                                                $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
                                                if (!($file = $fs->get_file($context->id, 'user', 'backup', 0, $filepath, $filename)) or $file->is_directory()) {
                                                    send_file_not_found();
                                                }
                                                \core\session\manager::write_close();
                                                // Unlock session during file serving.
                                                send_stored_file($file, 0, 0, true, array('preview' => $preview));
                                                // must force download - security!
                                            } else {
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:67,代码来源:filelib.php

示例12: get_contacts

 /**
  * Return a list of current user contacts
  * This function checks if the current user can send messages to all the users or only to managers
  *
  * @param int $group Group to filter
  * @param string $fi Firstname initial to filter
  * @param string $li Lastname initial to filter
  * @param int $roleid Role id to filter
  * @return array Array of contacts
  */
 public function get_contacts($group, $fi, $li, $roleid)
 {
     global $DB, $OUTPUT, $SESSION, $USER;
     if (!$this->cansend) {
         return array();
     }
     // Cache (see refresh cache bellow)
     $hash = "-{$group}-{$fi}-{$li}-{$roleid}-";
     if (isset($SESSION->jmailcache->contacts[$this->course->id][$hash])) {
         // Problem when sending messages to new users.
         //return $SESSION->jmailcache->contacts[$this->course->id][$hash];
     }
     if (!$this->globalinbox) {
         if (!has_capability('moodle/course:viewparticipants', $this->context)) {
             return array();
         }
     }
     $groupmode = groups_get_course_groupmode($this->course);
     // Groups are being used
     $currentgroup = groups_get_course_group($this->course, true);
     if (!$currentgroup) {
         // To make some other functions work better later
         $currentgroup = NULL;
     }
     $this->isseparategroups = ($this->course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $this->context));
     if ($this->isseparategroups and !$currentgroup) {
         return array();
     }
     $capability = null;
     // Users without cansendtoall capability cand send only to managers
     // Managers are those who can send to all messages
     if (!$this->cansendtoall and $this->cansendtomanagers) {
         $capability = "block/jmail:sendtoall";
     }
     list($esql, $params) = get_enrolled_sql($this->context, $capability, $currentgroup, true);
     $joins = array("FROM {user} u");
     $wheres = array();
     $select = "SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt, u.email";
     $joins[] = "JOIN ({$esql}) e ON e.id = u.id";
     // course enrolled users only
     $params['courseid'] = $this->course->id;
     // performance hacks - we preload user contexts together with accounts
     list($ccselect, $ccjoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
     $select .= $ccselect;
     $joins[] = $ccjoin;
     if ($roleid) {
         $contextlist = get_related_contexts_string($this->context);
         $wheres[] = "u.id IN (SELECT userid FROM {role_assignments} WHERE roleid = :roleid AND contextid {$contextlist})";
         $params['roleid'] = $roleid;
     }
     if ($fi) {
         $wheres[] = $DB->sql_like('firstname', ':search1', false, false);
         $params['search1'] = "{$fi}%";
     }
     if ($li) {
         $wheres[] = $DB->sql_like('lastname', ':search2', false, false);
         $params['search2'] = "{$li}%";
     }
     if (!empty($this->config->filterfield)) {
         $wheres[] = "u." . $this->config->filterfield . " = :filterfield";
         $params['filterfield'] = $USER->{$this->config->filterfield};
     }
     $from = implode("\n", $joins);
     if ($wheres) {
         $where = "WHERE " . implode(" AND ", $wheres);
     } else {
         $where = "";
     }
     $sort = '';
     $start = '';
     $end = '';
     $userlist = $DB->get_records_sql("{$select} {$from} {$where} {$sort}", $params, $start, $end);
     if ($userlist) {
         foreach ($userlist as $key => $u) {
             $userlist[$key]->fullname = fullname($u);
             $userlist[$key]->profileimage = $OUTPUT->user_picture($u);
             unset($userlist[$key]->email);
         }
     }
     $SESSION->jmailcache->contacts[$this->course->id][$hash] = $userlist;
     return $userlist;
 }
开发者ID:borrown,项目名称:moodle-block_jmail,代码行数:92,代码来源:block_jmail_mailbox.class.php

示例13: generate_user_settings

 /**
  * This function gets called by {@link settings_navigation::load_user_settings()} and actually works out
  * what can be shown/done
  *
  * @param int $courseid The current course' id
  * @param int $userid The user id to load for
  * @param string $gstitle The string to pass to get_string for the branch title
  * @return navigation_node|false
  */
 protected function generate_user_settings($courseid, $userid, $gstitle = 'usercurrentsettings')
 {
     global $DB, $CFG, $USER, $SITE;
     if ($courseid != $SITE->id) {
         if (!empty($this->page->course->id) && $this->page->course->id == $courseid) {
             $course = $this->page->course;
         } else {
             $select = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT c.*, {$select}\n                          FROM {course} c\n                          JOIN {context} ctx ON c.id = ctx.instanceid\n                         WHERE c.id = :courseid AND ctx.contextlevel = :contextlevel";
             $params = array('courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
             $course = $DB->get_record_sql($sql, $params, MUST_EXIST);
             context_helper::preload_from_record($course);
         }
     } else {
         $course = $SITE;
     }
     $coursecontext = context_course::instance($course->id);
     // Course context
     $systemcontext = context_system::instance();
     $currentuser = $USER->id == $userid;
     if ($currentuser) {
         $user = $USER;
         $usercontext = context_user::instance($user->id);
         // User context
     } else {
         $select = context_helper::get_preload_record_columns_sql('ctx');
         $sql = "SELECT u.*, {$select}\n                      FROM {user} u\n                      JOIN {context} ctx ON u.id = ctx.instanceid\n                     WHERE u.id = :userid AND ctx.contextlevel = :contextlevel";
         $params = array('userid' => $userid, 'contextlevel' => CONTEXT_USER);
         $user = $DB->get_record_sql($sql, $params, IGNORE_MISSING);
         if (!$user) {
             return false;
         }
         context_helper::preload_from_record($user);
         // Check that the user can view the profile
         $usercontext = context_user::instance($user->id);
         // User context
         $canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
         if ($course->id == $SITE->id) {
             if ($CFG->forceloginforprofiles && !has_coursecontact_role($user->id) && !$canviewuser) {
                 // Reduce possibility of "browsing" userbase at site level
                 // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
                 return false;
             }
         } else {
             $canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext);
             $userisenrolled = is_enrolled($coursecontext, $user->id);
             if (!$canviewusercourse && !$canviewuser || !$userisenrolled) {
                 return false;
             }
             $canaccessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
             if (!$canaccessallgroups && groups_get_course_groupmode($course) == SEPARATEGROUPS && !$canviewuser) {
                 // If groups are in use, make sure we can see that group (MDL-45874). That does not apply to parents.
                 if ($courseid == $this->page->course->id) {
                     $mygroups = get_fast_modinfo($this->page->course)->groups;
                 } else {
                     $mygroups = groups_get_user_groups($courseid);
                 }
                 $usergroups = groups_get_user_groups($courseid, $userid);
                 if (!array_intersect_key($mygroups[0], $usergroups[0])) {
                     return false;
                 }
             }
         }
     }
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
     $key = $gstitle;
     if ($gstitle != 'usercurrentsettings') {
         $key .= $userid;
     }
     // Add a user setting branch
     $usersetting = $this->add(get_string($gstitle, 'moodle', $fullname), null, self::TYPE_CONTAINER, null, $key);
     $usersetting->id = 'usersettings';
     if ($this->page->context->contextlevel == CONTEXT_USER && $this->page->context->instanceid == $user->id) {
         // Automatically start by making it active
         $usersetting->make_active();
     }
     // Check if the user has been deleted
     if ($user->deleted) {
         if (!has_capability('moodle/user:update', $coursecontext)) {
             // We can't edit the user so just show the user deleted message
             $usersetting->add(get_string('userdeleted'), null, self::TYPE_SETTING);
         } else {
             // We can edit the user so show the user deleted message and link it to the profile
             if ($course->id == $SITE->id) {
                 $profileurl = new moodle_url('/user/profile.php', array('id' => $user->id));
             } else {
                 $profileurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
             }
             $usersetting->add(get_string('userdeleted'), $profileurl, self::TYPE_SETTING);
         }
         return true;
//.........这里部分代码省略.........
开发者ID:adonm,项目名称:learning,代码行数:101,代码来源:navigationlib.php

示例14: get_group_list

 /**
  * Return list of groups.
  *
  * @return array list of groups.
  */
 public function get_group_list()
 {
     // No groups for system.
     if (empty($this->course)) {
         return array();
     }
     $context = context_course::instance($this->course->id);
     $groups = array();
     $groupmode = groups_get_course_groupmode($this->course);
     if ($groupmode == VISIBLEGROUPS || ($groupmode == SEPARATEGROUPS and has_capability('moodle/site:accessallgroups', $context))) {
         // Get all groups.
         if ($cgroups = groups_get_all_groups($this->course->id)) {
             foreach ($cgroups as $cgroup) {
                 $groups[$cgroup->id] = $cgroup->name;
             }
         }
     }
     return $groups;
 }
开发者ID:sirromas,项目名称:lms,代码行数:24,代码来源:renderable.php

示例15: setup_groups

 /**
  * Sets up this object's group variables, mainly to restrict the selection of users to display.
  */
 function setup_groups()
 {
     global $CFG;
     /// find out current groups mode
     if ($this->groupmode = groups_get_course_groupmode($this->course)) {
         $this->currentgroup = groups_get_course_group($this->course, true);
         $this->group_selector = groups_print_course_menu($this->course, $this->pbarurl, true);
         if ($this->groupmode == SEPARATEGROUPS and !$this->currentgroup and !has_capability('moodle/site:accessallgroups', $this->context)) {
             $this->currentgroup = -2;
             // means can not accesss any groups at all
         }
         if ($this->currentgroup) {
             $this->groupsql = " JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id ";
             $this->groupwheresql = " AND gm.groupid = {$this->currentgroup} ";
         }
     }
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:20,代码来源:lib.php


注:本文中的groups_get_course_groupmode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。