本文整理汇总了PHP中groups_has_membership函数的典型用法代码示例。如果您正苦于以下问题:PHP groups_has_membership函数的具体用法?PHP groups_has_membership怎么用?PHP groups_has_membership使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了groups_has_membership函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: questionnaire_extend_settings_navigation
/**
* Adds module specific settings to the settings block
*
* @param settings_navigation $settings The settings navigation object
* @param navigation_node $questionnairenode The node to add module settings to
*/
function questionnaire_extend_settings_navigation(settings_navigation $settings, navigation_node $questionnairenode)
{
global $PAGE, $DB, $USER, $CFG;
$individualresponse = optional_param('individualresponse', false, PARAM_INT);
$rid = optional_param('rid', false, PARAM_INT);
// Response id.
$currentgroupid = optional_param('group', 0, PARAM_INT);
// Group id.
require_once $CFG->dirroot . '/mod/questionnaire/questionnaire.class.php';
$context = $PAGE->cm->context;
$cmid = $PAGE->cm->id;
$cm = $PAGE->cm;
$course = $PAGE->course;
if (!($questionnaire = $DB->get_record("questionnaire", array("id" => $cm->instance)))) {
print_error('invalidcoursemodule');
}
$courseid = $course->id;
$questionnaire = new questionnaire(0, $questionnaire, $course, $cm);
if ($survey = $DB->get_record('questionnaire_survey', array('id' => $questionnaire->sid))) {
$owner = trim($survey->owner) == trim($courseid);
} else {
$survey = false;
$owner = true;
}
// We want to add these new nodes after the Edit settings node, and before the
// Locally assigned roles node. Of course, both of those are controlled by capabilities.
$keys = $questionnairenode->get_children_key_list();
$beforekey = null;
$i = array_search('modedit', $keys);
if ($i === false and array_key_exists(0, $keys)) {
$beforekey = $keys[0];
} else {
if (array_key_exists($i + 1, $keys)) {
$beforekey = $keys[$i + 1];
}
}
if (has_capability('mod/questionnaire:manage', $context) && $owner) {
$url = '/mod/questionnaire/qsettings.php';
$node = navigation_node::create(get_string('advancedsettings'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'advancedsettings', new pix_icon('t/edit', ''));
$questionnairenode->add_node($node, $beforekey);
}
if (has_capability('mod/questionnaire:editquestions', $context) && $owner) {
$url = '/mod/questionnaire/questions.php';
$node = navigation_node::create(get_string('questions', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'questions', new pix_icon('t/edit', ''));
$questionnairenode->add_node($node, $beforekey);
}
if (has_capability('mod/questionnaire:preview', $context) && $owner) {
$url = '/mod/questionnaire/preview.php';
$node = navigation_node::create(get_string('preview_label', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'preview', new pix_icon('t/preview', ''));
$questionnairenode->add_node($node, $beforekey);
}
if ($questionnaire->user_can_take($USER->id)) {
$url = '/mod/questionnaire/complete.php';
$node = navigation_node::create(get_string('answerquestions', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, '', new pix_icon('i/info', 'answerquestions'));
$questionnairenode->add_node($node, $beforekey);
}
$usernumresp = $questionnaire->count_submissions($USER->id);
if ($questionnaire->capabilities->readownresponses && $usernumresp > 0) {
$url = '/mod/questionnaire/myreport.php';
$node = navigation_node::create(get_string('yourresponses', 'questionnaire'), new moodle_url($url, array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary')), navigation_node::TYPE_SETTING, null, 'yourresponses');
$myreportnode = $questionnairenode->add_node($node, $beforekey);
$summary = $myreportnode->add(get_string('summary', 'questionnaire'), new moodle_url('/mod/questionnaire/myreport.php', array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary')));
$byresponsenode = $myreportnode->add(get_string('viewbyresponse', 'questionnaire'), new moodle_url('/mod/questionnaire/myreport.php', array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 1, 'action' => 'vresp')));
$allmyresponsesnode = $myreportnode->add(get_string('myresponses', 'questionnaire'), new moodle_url('/mod/questionnaire/myreport.php', array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'vall')));
if ($questionnaire->capabilities->downloadresponses) {
$downloadmyresponsesnode = $myreportnode->add(get_string('downloadtext'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'user' => $USER->id, 'action' => 'dwnpg', 'group' => $currentgroupid)));
}
}
$numresp = $questionnaire->count_submissions();
// Number of responses in currently selected group (or all participants etc.).
if (isset($SESSION->questionnaire->numselectedresps)) {
$numselectedresps = $SESSION->questionnaire->numselectedresps;
} else {
$numselectedresps = $numresp;
}
// If questionnaire is set to separate groups, prevent user who is not member of any group
// to view All responses.
$canviewgroups = true;
$groupmode = groups_get_activity_groupmode($cm, $course);
if ($groupmode == 1) {
$canviewgroups = groups_has_membership($cm, $USER->id);
}
if ($questionnaire->capabilities->readallresponseanytime && $numresp > 0 && $owner && $numselectedresps > 0 || $questionnaire->capabilities->readallresponses && $numresp > 0 && $canviewgroups && ($questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_ALWAYS || $questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENCLOSED && $questionnaire->is_closed() || $questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENANSWERED && $usernumresp > 0) && $questionnaire->is_survey_owner()) {
$url = '/mod/questionnaire/report.php';
$node = navigation_node::create(get_string('viewallresponses', 'questionnaire'), new moodle_url($url, array('instance' => $questionnaire->id, 'action' => 'vall')), navigation_node::TYPE_SETTING, null, 'vall');
$reportnode = $questionnairenode->add_node($node, $beforekey);
if ($questionnaire->capabilities->viewsingleresponse) {
$summarynode = $reportnode->add(get_string('summary', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall')));
} else {
$summarynode = $reportnode;
}
$defaultordernode = $summarynode->add(get_string('order_default', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall', 'group' => $currentgroupid)));
$ascendingordernode = $summarynode->add(get_string('order_ascending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallasort', 'group' => $currentgroupid)));
$descendingordernode = $summarynode->add(get_string('order_descending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallarsort', 'group' => $currentgroupid)));
//.........这里部分代码省略.........
示例2: can_view_all_responses
public function can_view_all_responses($usernumresp = null)
{
global $USER, $DB, $SESSION;
if ($owner = $DB->get_field('questionnaire_survey', 'owner', array('id' => $this->sid))) {
$owner = trim($owner) == trim($this->course->id);
} else {
$owner = true;
}
$numresp = $this->count_submissions();
if ($usernumresp === null) {
$usernumresp = $questionnaire->count_submissions($USER->id);
}
// Number of Responses in currently selected group (or all participants etc.).
if (isset($SESSION->questionnaire->numselectedresps)) {
$numselectedresps = $SESSION->questionnaire->numselectedresps;
} else {
$numselectedresps = $numresp;
}
// If questionnaire is set to separate groups, prevent user who is not member of any group
// to view All responses.
$canviewgroups = true;
$groupmode = groups_get_activity_groupmode($this->cm, $this->course);
if ($groupmode == 1) {
$canviewgroups = groups_has_membership($this->cm, $USER->id);
}
$canviewallgroups = has_capability('moodle/site:accessallgroups', $this->context);
return ($canviewallgroups || $canviewgroups && $this->capabilities->readallresponseanytime) && $numresp > 0 && $owner && $numselectedresps > 0 || $this->capabilities->readallresponses && $numresp > 0 && $canviewgroups && ($this->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_ALWAYS || $this->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENCLOSED && $this->is_closed() || $this->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENANSWERED && $usernumresp > 0) && $this->is_survey_owner();
}
示例3: get_graders
/**
* Returns a list of teachers that should be grading given submission.
*
* @param int $userid The submission to grade
* @return array
*/
protected function get_graders($userid)
{
// Potential graders should be active users only.
$potentialgraders = get_enrolled_users($this->context, "mod/assign:grade", null, 'u.*', null, null, null, true);
$graders = array();
if (groups_get_activity_groupmode($this->get_course_module()) == SEPARATEGROUPS) {
if ($groups = groups_get_all_groups($this->get_course()->id, $userid)) {
foreach ($groups as $group) {
foreach ($potentialgraders as $grader) {
if ($grader->id == $userid) {
// Do not send self.
continue;
}
if (groups_is_member($group->id, $grader->id)) {
$graders[$grader->id] = $grader;
}
}
}
} else {
// User not in group, try to find graders without group.
foreach ($potentialgraders as $grader) {
if ($grader->id == $userid) {
// Do not send self.
continue;
}
if (!groups_has_membership($this->get_course_module(), $grader->id)) {
$graders[$grader->id] = $grader;
}
}
}
} else {
foreach ($potentialgraders as $grader) {
if ($grader->id == $userid) {
// Do not send self.
continue;
}
// Must be enrolled.
if (is_enrolled($this->get_course_context(), $grader->id)) {
$graders[$grader->id] = $grader;
}
}
}
return $graders;
}
示例4: groups_course_module_visible
/**
* Determine if a course module is currently visible to a user
*
* $USER If $userid is null, use the global object.
*
* @global object
* @global object
* @param int $cm The course module
* @param int $userid The user to check against the group.
* @return boolean True if the user can view the course module, false otherwise.
*/
function groups_course_module_visible($cm, $userid = null)
{
global $CFG, $USER;
if (empty($userid)) {
$userid = $USER->id;
}
if (empty($CFG->enablegroupmembersonly)) {
return true;
}
if (empty($cm->groupmembersonly)) {
return true;
}
if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id), $userid) or groups_has_membership($cm, $userid)) {
return true;
}
return false;
}
示例5: get_graders
/**
* Returns a list of teachers that should be grading given submission
*
* @param int $userid
* @return array
*/
private function get_graders($userid) {
//potential graders
$potentialgraders = get_enrolled_users($this->context, "mod/assign:grade");
$graders = array();
if (groups_get_activity_groupmode($this->get_course_module()) == SEPARATEGROUPS) { // Separate groups are being used
if ($groups = groups_get_all_groups($this->get_course()->id, $userid)) { // Try to find all groups
foreach ($groups as $group) {
foreach ($potentialgraders as $grader) {
if ($grader->id == $userid) {
continue; // do not send self
}
if (groups_is_member($group->id, $grader->id)) {
$graders[$grader->id] = $grader;
}
}
}
} else {
// user not in group, try to find graders without group
foreach ($potentialgraders as $grader) {
if ($grader->id == $userid) {
continue; // do not send self
}
if (!groups_has_membership($this->get_course_module(), $grader->id)) {
$graders[$grader->id] = $grader;
}
}
}
} else {
foreach ($potentialgraders as $grader) {
if ($grader->id == $userid) {
continue; // do not send self
}
// must be enrolled
if (is_enrolled($this->get_course_context(), $grader->id)) {
$graders[$grader->id] = $grader;
}
}
}
return $graders;
}
示例6: htmlspecialchars
echo '<a href="' . $CFG->wwwroot . htmlspecialchars('/mod/questionnaire/myreport.php?' . $argstr) . '">' . $titletext . '</a>';
echo $OUTPUT->box_end();
}
if ($survey = $DB->get_record('questionnaire_survey', array('id' => $questionnaire->sid))) {
$owner = trim($survey->owner) == trim($course->id);
} else {
$survey = false;
$owner = true;
}
$numresp = $questionnaire->count_submissions();
// Number of Responses in currently selected group (or all participants etc.).
if (isset($SESSION->questionnaire->numselectedresps)) {
$numselectedresps = $SESSION->questionnaire->numselectedresps;
} else {
$numselectedresps = $numresp;
}
// If questionnaire is set to separate groups, prevent user who is not member of any group
// to view All responses.
$canviewgroups = true;
$groupmode = groups_get_activity_groupmode($cm, $course);
if ($groupmode == 1) {
$canviewgroups = groups_has_membership($cm, $USER->id);
}
$canviewallgroups = has_capability('moodle/site:accessallgroups', $context);
if (($canviewallgroups || $canviewgroups && $questionnaire->capabilities->readallresponseanytime) && $numresp > 0 && $owner && $numselectedresps > 0 || $questionnaire->capabilities->readallresponses && $numresp > 0 && $canviewgroups && ($questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_ALWAYS || $questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENCLOSED && $questionnaire->is_closed() || $questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENANSWERED && $usernumresp > 0) && $questionnaire->is_survey_owner()) {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
$argstr = 'instance=' . $questionnaire->id . '&group=' . $currentgroupid;
echo '<a href="' . $CFG->wwwroot . htmlspecialchars('/mod/questionnaire/report.php?' . $argstr) . '">' . get_string('viewallresponses', 'questionnaire') . '</a>';
echo $OUTPUT->box_end();
}
echo $OUTPUT->footer();
示例7: require_login
//.........这里部分代码省略.........
}
}
/// Check that the user account is properly set up
if (user_not_fully_set_up($USER)) {
$SESSION->wantsurl = $FULLME;
redirect($CFG->wwwroot . '/user/edit.php?id=' . $USER->id . '&course=' . SITEID);
}
/// Make sure current IP matches the one for this session (if required)
if (!empty($CFG->tracksessionip)) {
if ($USER->sessionIP != md5(getremoteaddr())) {
print_error('sessionipnomatch', 'error');
}
}
/// Make sure the USER has a sesskey set up. Used for checking script parameters.
sesskey();
// Check that the user has agreed to a site policy if there is one
if (!empty($CFG->sitepolicy)) {
if (!$USER->policyagreed) {
$SESSION->wantsurl = $FULLME;
redirect($CFG->wwwroot . '/user/policy.php');
}
}
// Fetch the system context, we are going to use it a lot.
$sysctx = get_context_instance(CONTEXT_SYSTEM);
/// If the site is currently under maintenance, then print a message
if (!has_capability('moodle/site:config', $sysctx)) {
if (file_exists($CFG->dataroot . '/' . SITEID . '/maintenance.html')) {
print_maintenance_message();
exit;
}
}
/// groupmembersonly access control
if (!empty($CFG->enablegroupings) and $cm and $cm->groupmembersonly and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
if (isguestuser() or !groups_has_membership($cm)) {
print_error('groupmembersonlyerror', 'group', $CFG->wwwroot . '/course/view.php?id=' . $cm->course);
}
}
// Fetch the course context, and prefetch its child contexts
if (!isset($COURSE->context)) {
if (!($COURSE->context = get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
print_error('nocontext');
}
}
if (!empty($cm) && !isset($cm->context)) {
if (!($cm->context = get_context_instance(CONTEXT_MODULE, $cm->id))) {
print_error('nocontext');
}
}
if ($COURSE->id == SITEID) {
/// Eliminate hidden site activities straight away
if (!empty($cm) && !$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $cm->context)) {
redirect($CFG->wwwroot, get_string('activityiscurrentlyhidden'));
}
user_accesstime_log($COURSE->id);
/// Access granted, update lastaccess times
return;
} else {
/// Check if the user can be in a particular course
if (empty($USER->access['rsw'][$COURSE->context->path])) {
//
// MDL-13900 - If the course or the parent category are hidden
// and the user hasn't the 'course:viewhiddencourses' capability, prevent access
//
if (!($COURSE->visible && course_parent_visible($COURSE)) && !has_capability('moodle/course:viewhiddencourses', $COURSE->context)) {
print_header_simple();
notice(get_string('coursehidden'), $CFG->wwwroot . '/');
示例8: moodle_url
$groupurl = new moodle_url('/group/overview.php', array('id' => $cm->course));
$overridedeleteurl = new moodle_url('/mod/quiz/overridedelete.php');
$overrideediturl = new moodle_url('/mod/quiz/overrideedit.php');
$hasinactive = false;
// Whether there are any inactive overrides.
foreach ($overrides as $override) {
$fields = array();
$values = array();
$active = true;
// Check for inactive overrides.
if (!$groupmode) {
if (!has_capability('mod/quiz:attempt', $context, $override->userid)) {
// User not allowed to take the quiz.
$active = false;
} else {
if (!empty($CFG->enablegroupmembersonly) && $cm->groupmembersonly && !groups_has_membership($cm, $override->userid)) {
// User does not belong to the current grouping.
$active = false;
}
}
}
// Format timeopen.
if (isset($override->timeopen)) {
$fields[] = get_string('quizopens', 'quiz');
$values[] = $override->timeopen > 0 ? userdate($override->timeopen) : get_string('noopen', 'quiz');
}
// Format timeclose.
if (isset($override->timeclose)) {
$fields[] = get_string('quizcloses', 'quiz');
$values[] = $override->timeclose > 0 ? userdate($override->timeclose) : get_string('noclose', 'quiz');
}
示例9: hotpot_is_visible
function hotpot_is_visible(&$cm)
{
global $CFG, $COURSE;
// check grouping
$modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
if (empty($CFG->enablegroupings) || empty($cm->groupmembersonly) || has_capability('moodle/site:accessallgroups', $modulecontext)) {
// groupings not applicable
} else {
if (!isguestuser() && groups_has_membership($cm)) {
// user is in one of the groups in the allowed grouping
} else {
// user is not in the required grouping and does not have sufficiently privileges to view this hotpot activity
return false;
}
}
// check if user can view hidden activities
if (isset($COURSE->context)) {
$coursecontext =& $COURSE->context;
} else {
$coursecontext = get_context_instance(CONTEXT_COURSE, $cm->course);
}
if (has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
return true;
// user can view hidden activities
}
if (!isset($cm->sectionvisible)) {
if (!($section = get_record('course_sections', 'id', $cm->section))) {
error('Course module record contains invalid section');
}
$cm->sectionvisible = $section->visible;
}
if (empty($cm->sectionvisible)) {
$visible = HOTPOT_NO;
} else {
$visible = HOTPOT_YES;
if (empty($cm->visible)) {
if ($chain = hotpot_get_chain($cm)) {
$startofchain = array_shift($chain);
$visible = $startofchain->visible;
}
}
}
return $visible;
}
示例10: grouptool_extend_navigation
/**
* Extends the global navigation tree by adding grouptool nodes if there is a relevant content
*
* This can be called by an AJAX request so do not rely on $PAGE as it might not be set up properly.
*
* @param navigation_node $navref Object representing the nav tree node of the grouptool mod instance
* @param stdClass $course course object
* @param stdClass $module module object
* @param cm_info $cm cousre module info object
*/
function grouptool_extend_navigation(navigation_node $navref, stdClass $course, stdClass $module, cm_info $cm)
{
global $DB;
$context = context_module::instance($cm->id);
$creategrps = has_capability('mod/grouptool:create_groups', $context);
$creategrpgs = has_capability('mod/grouptool:create_groupings', $context);
$admingrps = has_capability('mod/grouptool:administrate_groups', $context);
if ($creategrps || $creategrpgs || $admingrps) {
if ($creategrps && ($admingrps || $creategrpgs)) {
$admin = $navref->add(get_string('administration', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'administration')));
$admin->add(get_string('group_administration', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'group_admin')));
$admin->add(get_string('group_creation', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'group_creation')));
} else {
if ($creategrps) {
$navref->add(get_string('group_creation', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'group_creation')));
} else {
if ($creategrpgs || $admingrps) {
$navref->add(get_string('group_administration', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'group_admin')));
}
}
}
}
if (has_capability('mod/grouptool:grade', $context) || has_capability('mod/grouptool:grade_own_group', $context)) {
$navref->add(get_string('grading', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'grading')));
}
// Groupmode?
$gmok = true;
if (groups_get_activity_groupmode($cm, $course) != NOGROUPS) {
$gmok = $gmok && groups_has_membership($cm);
}
$gt = $DB->get_record('grouptool', array('id' => $cm->instance));
$regopen = $gt->allow_reg && ($gt->timedue == 0 || time() < $gt->timedue) && $gt->timeavailable < time();
if (has_capability('mod/grouptool:register_students', $context) || $regopen && $gmok && has_capability('mod/grouptool:register', $context)) {
$tmp = $navref->add(get_string('selfregistration', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'selfregistration')));
}
if (has_capability('mod/grouptool:register_students', $context)) {
$navref->add(get_string('import', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'import')));
}
if (has_capability('mod/grouptool:view_regs_course_view', $context) && has_capability('mod/grouptool:view_regs_group_view', $context)) {
$userstab = $navref->add(get_string('users_tab', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'overview')));
$userstab->add(get_string('overview_tab', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'overview')));
$userstab->add(get_string('userlist_tab', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'userlist')));
} else {
if (has_capability('mod/grouptool:view_regs_group_view', $context)) {
$navref->add(get_string('users_tab', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'overview')));
} else {
if (has_capability('mod/grouptool:view_regs_course_view', $context)) {
$navref->add(get_string('users_tab', 'grouptool'), new moodle_url('/mod/grouptool/view.php', array('id' => $cm->id, 'tab' => 'userlist')));
}
}
}
$navref->nodetype = navigation_node::NODETYPE_BRANCH;
}
示例11: foreach
$hasinactive = false; // Whether there are any inactive overrides.
foreach ($overrides as $override) {
$fields = array();
$values = array();
$active = true;
// Check for inactive overrides.
if (!$groupmode) {
if (!has_capability('mod/quiz:attempt', $context, $override->userid)) {
// User not allowed to take the quiz.
$active = false;
} else if (!empty($CFG->enablegroupmembersonly) && $cm->groupmembersonly &&
!groups_has_membership($cm, $override->userid)) {
// User does not belong to the current grouping.
$active = false;
}
}
// Format timeopen.
if (isset($override->timeopen)) {
$fields[] = get_string('quizopens', 'quiz');
$values[] = $override->timeopen > 0 ?
userdate($override->timeopen) : get_string('noopen', 'quiz');
}
// Format timeclose.
if (isset($override->timeclose)) {
$fields[] = get_string('quizcloses', 'quiz');
示例12: array
$currentsessiongroupid = -1;
}
// all members of any group
$sql = "SELECT R.id, R.survey_id, R.submitted, R.username\n FROM " . $CFG->prefix . "questionnaire_response R,\n " . $CFG->prefix . "groups_members GM\n WHERE R.survey_id=" . $sid . " AND\n R.complete='y' AND\n GM.groupid>0 AND\n R.username=GM.userid\n ORDER BY R.id";
if (!($respsallgroupmembers = get_records_sql($sql))) {
$respsallgroupmembers = array();
}
$SESSION->questionnaire->numrespsallgroupmembers = count($respsallgroupmembers);
// not members of any group
$sql = "SELECT R.id, R.survey_id, R.submitted, R.username, U.id AS user\n FROM " . $CFG->prefix . "questionnaire_response R,\n " . $CFG->prefix . "user U\n WHERE R.survey_id=" . $sid . " AND\n R.complete='y' AND\n R.username=U.id\n ORDER BY user";
if (!($respsnongroupmembers = get_records_sql($sql))) {
$respsnongroupmembers = array();
}
foreach ($respsnongroupmembers as $resp => $key) {
$userid = $key->user;
if (groups_has_membership($cm, $userid)) {
unset($respsnongroupmembers[$resp]);
}
}
if (!$respsnongroupmembers) {
$respsnongroupmembers = array();
}
$SESSION->questionnaire->numrespsnongroupmembers = count($respsnongroupmembers);
// current group members
$sql = "SELECT R.id, R.survey_id, R.submitted, R.username\n FROM " . $CFG->prefix . "questionnaire_response R,\n " . $CFG->prefix . "groups_members GM\n WHERE R.survey_id=" . $sid . " AND\n R.complete='y' AND\n GM.groupid=" . $currentgroupid . " AND\n R.username=GM.userid\n ORDER BY R.id";
if (!($currentgroupresps = get_records_sql($sql))) {
$currentgroupresps = array();
}
$SESSION->questionnaire->numcurrentgroupresps = count($currentgroupresps);
} else {
//groupmode = separate groups but user is not member of any group
示例13: require_login
//.........这里部分代码省略.........
// cache ok
} else {
if (is_enrolled($coursecontext, $USER, '', true)) {
// active participants may always access
// TODO: refactor this into some new function
$now = time();
$sql = "SELECT MAX(ue.timeend)\n FROM {user_enrolments} ue\n JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)\n JOIN {user} u ON u.id = ue.userid\n WHERE ue.userid = :userid AND ue.status = :active AND e.status = :enabled AND u.deleted = 0\n AND ue.timestart < :now1 AND (ue.timeend = 0 OR ue.timeend > :now2)";
$params = array('enabled' => ENROL_INSTANCE_ENABLED, 'active' => ENROL_USER_ACTIVE, 'userid' => $USER->id, 'courseid' => $coursecontext->instanceid, 'now1' => $now, 'now2' => $now);
$until = $DB->get_field_sql($sql, $params);
if (!$until or $until > time() + ENROL_REQUIRE_LOGIN_CACHE_PERIOD) {
$until = time() + ENROL_REQUIRE_LOGIN_CACHE_PERIOD;
}
$USER->enrol['enrolled'][$course->id] = $until;
$access = true;
// remove traces of previous temp guest access
$USER->access = remove_temp_roles($coursecontext, $USER->access);
} else {
$instances = $DB->get_records('enrol', array('courseid' => $course->id, 'status' => ENROL_INSTANCE_ENABLED), 'sortorder, id ASC');
$enrols = enrol_get_plugins(true);
// first ask all enabled enrol instances in course if they want to auto enrol user
foreach ($instances as $instance) {
if (!isset($enrols[$instance->enrol])) {
continue;
}
// Get a duration for the guestaccess, a timestamp in the future or false.
$until = $enrols[$instance->enrol]->try_autoenrol($instance);
if ($until !== false) {
$USER->enrol['enrolled'][$course->id] = $until;
$USER->access = remove_temp_roles($coursecontext, $USER->access);
$access = true;
break;
}
}
// if not enrolled yet try to gain temporary guest access
if (!$access) {
foreach ($instances as $instance) {
if (!isset($enrols[$instance->enrol])) {
continue;
}
// Get a duration for the guestaccess, a timestamp in the future or false.
$until = $enrols[$instance->enrol]->try_guestaccess($instance);
if ($until !== false) {
$USER->enrol['tempguest'][$course->id] = $until;
$access = true;
break;
}
}
}
}
}
}
if (!$access) {
if ($preventredirect) {
throw new require_login_exception('Not enrolled');
}
$SESSION->wantsurl = $FULLME;
redirect($CFG->wwwroot . '/enrol/index.php?id=' . $course->id);
}
}
// test visibility
if ($cm && !$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $cmcontext)) {
if ($preventredirect) {
throw new require_login_exception('Activity is hidden');
}
redirect($CFG->wwwroot, get_string('activityiscurrentlyhidden'));
}
// groupmembersonly access control
if (!empty($CFG->enablegroupmembersonly) and $cm and $cm->groupmembersonly and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
if (isguestuser() or !groups_has_membership($cm)) {
if ($preventredirect) {
throw new require_login_exception('Not member of a group');
}
print_error('groupmembersonlyerror', 'group', $CFG->wwwroot . '/course/view.php?id=' . $cm->course);
}
}
// Conditional activity access control
if (!empty($CFG->enableavailability) and $cm) {
// TODO: this is going to work with login-as-user, sorry!
// We cache conditional access in session
if (!isset($SESSION->conditionaccessok)) {
$SESSION->conditionaccessok = array();
}
// If you have been allowed into the module once then you are allowed
// in for rest of session, no need to do conditional checks
if (!array_key_exists($cm->id, $SESSION->conditionaccessok)) {
// Get condition info (does a query for the availability table)
require_once $CFG->libdir . '/conditionlib.php';
$ci = new condition_info($cm, CONDITION_MISSING_EXTRATABLE);
// Check condition for user (this will do a query if the availability
// information depends on grade or completion information)
if ($ci->is_available($junk) || has_capability('moodle/course:viewhiddenactivities', $cmcontext)) {
$SESSION->conditionaccessok[$cm->id] = true;
} else {
print_error('activityiscurrentlyhidden');
}
}
}
// Finally access granted, update lastaccess times
user_accesstime_log($course->id);
}
示例14: generate_csv
//.........这里部分代码省略.........
} else {
if ($userid) {
// download CSV for one user's own responses'
$sql = "SELECT R.id, R.survey_id, R.submitted, R.username\n FROM " . $CFG->prefix . "questionnaire_response R\n WHERE R.survey_id='{$this->survey->id}' AND\n R.complete='y' AND\n R.username='{$userid}'\n ORDER BY R.id";
if (!($records = get_records_sql($sql))) {
$records = array();
}
} else {
// download CSV for all participants (or groups if enabled)
if ($groupid == -1) {
// all participants
$sql = "SELECT R.id, R.survey_id, R.submitted, R.username\n FROM " . $CFG->prefix . "questionnaire_response R\n WHERE R.survey_id='{$this->survey->id}' AND\n R.complete='y'\n ORDER BY R.id";
} else {
if ($groupid == -2) {
// all members of any group
$sql = "SELECT R.id, R.survey_id, R.submitted, R.username\n FROM " . $CFG->prefix . "questionnaire_response R,\n " . $CFG->prefix . "groups_members GM\n WHERE R.survey_id='{$this->survey->id}' AND\n R.complete='y' AND\n GM.groupid>0 AND\n R.username=GM.userid\n ORDER BY R.id";
} else {
if ($groupid == -3) {
// not members of any group
$sql = "SELECT R.id, R.survey_id, R.submitted, U.id AS username\n FROM " . $CFG->prefix . "questionnaire_response R,\n " . $CFG->prefix . "user U\n WHERE R.survey_id='{$this->survey->id}' AND\n R.complete='y' AND\n R.username=U.id\n ORDER BY username";
} else {
// members of a specific group
$sql = "SELECT R.id, R.survey_id, R.submitted, R.username\n FROM " . $CFG->prefix . "questionnaire_response R,\n " . $CFG->prefix . "groups_members GM\n WHERE R.survey_id='{$this->survey->id}' AND\n R.complete='y' AND\n GM.groupid=" . $groupid . " AND\n R.username=GM.userid\n ORDER BY R.id";
}
}
}
if (!($records = get_records_sql($sql))) {
$records = array();
}
if ($groupid == -3) {
// members of no group
foreach ($records as $row => $key) {
$userid = $key->username;
if (groups_has_membership($this->cm, $userid)) {
unset($records[$row]);
}
}
}
}
}
$isanonymous = $this->respondenttype == 'anonymous';
foreach ($records as $record) {
// get the response
$response = $this->response_select_name($record->id);
$qid = $record->id;
//JR for better compabitility & readability with Excel
$submitted = date(get_string('strfdateformatcsv', 'questionnaire'), $record->submitted);
$institution = '';
$department = '';
$username = $record->username;
if ($user = get_record('user', 'id', $username)) {
$institution = $user->institution;
$department = $user->department;
}
if ($isanonymous) {
$username = get_string('anonymous', 'questionnaire');
}
/// Moodle:
// Get the course name that this questionnaire belongs to.
if ($survey->realm != 'public') {
$courseid = $this->course->id;
$coursename = $this->course->fullname;
} else {
/// For a public questionnaire, look for the course that used it.
$sql = 'SELECT q.id, q.course, c.fullname ' . 'FROM ' . $CFG->prefix . 'questionnaire q, ' . $CFG->prefix . 'questionnaire_attempts qa, ' . $CFG->prefix . 'course c ' . 'WHERE qa.rid = ' . $qid . ' AND q.id = qa.qid AND c.id = q.course';
if ($record = get_record_sql($sql)) {
示例15: questionnaire_extend_settings_navigation
//.........这里部分代码省略.........
$keys = $questionnairenode->get_children_key_list();
$beforekey = null;
$i = array_search('modedit', $keys);
if ($i === false && array_key_exists(0, $keys)) {
$beforekey = $keys[0];
} else {
if (array_key_exists($i + 1, $keys)) {
$beforekey = $keys[$i + 1];
}
}
if (has_capability('mod/questionnaire:manage', $context) && $owner) {
$url = '/mod/questionnaire/qsettings.php';
$node = navigation_node::create(get_string('advancedsettings'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'advancedsettings', new pix_icon('t/edit', ''));
$questionnairenode->add_node($node, $beforekey);
}
if (has_capability('mod/questionnaire:editquestions', $context) && $owner) {
$url = '/mod/questionnaire/questions.php';
$node = navigation_node::create(get_string('questions', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'questions', new pix_icon('t/edit', ''));
$questionnairenode->add_node($node, $beforekey);
}
if (has_capability('mod/questionnaire:preview', $context)) {
$url = '/mod/questionnaire/preview.php';
$node = navigation_node::create(get_string('preview_label', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'preview', new pix_icon('t/preview', ''));
$questionnairenode->add_node($node, $beforekey);
}
if ($questionnaire->user_can_take($USER->id)) {
$url = '/mod/questionnaire/complete.php';
if ($questionnaire->user_has_saved_response($USER->id)) {
$args = ['id' => $cmid, 'resume' => 1];
$text = get_string('resumesurvey', 'questionnaire');
} else {
$args = ['id' => $cmid];
$text = get_string('answerquestions', 'questionnaire');
}
$node = navigation_node::create($text, new moodle_url($url, $args), navigation_node::TYPE_SETTING, null, '', new pix_icon('i/info', 'answerquestions'));
$questionnairenode->add_node($node, $beforekey);
}
$usernumresp = $questionnaire->count_submissions($USER->id);
if ($questionnaire->capabilities->readownresponses && $usernumresp > 0) {
$url = '/mod/questionnaire/myreport.php';
if ($usernumresp > 1) {
$urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary', 'group' => $currentgroupid);
$node = navigation_node::create(get_string('yourresponses', 'questionnaire'), new moodle_url($url, $urlargs), navigation_node::TYPE_SETTING, null, 'yourresponses');
$myreportnode = $questionnairenode->add_node($node, $beforekey);
$urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary', 'group' => $currentgroupid);
$myreportnode->add(get_string('summary', 'questionnaire'), new moodle_url($url, $urlargs));
$urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 1, 'action' => 'vresp', 'group' => $currentgroupid);
$byresponsenode = $myreportnode->add(get_string('viewindividualresponse', 'questionnaire'), new moodle_url($url, $urlargs));
$urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'vall', 'group' => $currentgroupid);
$myreportnode->add(get_string('myresponses', 'questionnaire'), new moodle_url($url, $urlargs));
if ($questionnaire->capabilities->downloadresponses) {
$urlargs = array('instance' => $questionnaire->id, 'user' => $USER->id, 'action' => 'dwnpg', 'group' => $currentgroupid);
$myreportnode->add(get_string('downloadtext'), new moodle_url('/mod/questionnaire/report.php', $urlargs));
}
} else {
$urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 1, 'action' => 'vresp', 'group' => $currentgroupid);
$node = navigation_node::create(get_string('yourresponse', 'questionnaire'), new moodle_url($url, $urlargs), navigation_node::TYPE_SETTING, null, 'yourresponse');
$myreportnode = $questionnairenode->add_node($node, $beforekey);
}
}
// If questionnaire is set to separate groups, prevent user who is not member of any group
// and is not a non-editing teacher to view All responses.
if ($questionnaire->can_view_all_responses($usernumresp)) {
$url = '/mod/questionnaire/report.php';
$node = navigation_node::create(get_string('viewallresponses', 'questionnaire'), new moodle_url($url, array('instance' => $questionnaire->id, 'action' => 'vall')), navigation_node::TYPE_SETTING, null, 'vall');
$reportnode = $questionnairenode->add_node($node, $beforekey);
if ($questionnaire->capabilities->viewsingleresponse) {
$summarynode = $reportnode->add(get_string('summary', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall')));
} else {
$summarynode = $reportnode;
}
$summarynode->add(get_string('order_default', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall', 'group' => $currentgroupid)));
$summarynode->add(get_string('order_ascending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallasort', 'group' => $currentgroupid)));
$summarynode->add(get_string('order_descending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallarsort', 'group' => $currentgroupid)));
if ($questionnaire->capabilities->deleteresponses) {
$summarynode->add(get_string('deleteallresponses', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'delallresp', 'group' => $currentgroupid)));
}
if ($questionnaire->capabilities->downloadresponses) {
$summarynode->add(get_string('downloadtextformat', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'dwnpg', 'group' => $currentgroupid)));
}
if ($questionnaire->capabilities->viewsingleresponse) {
$byresponsenode = $reportnode->add(get_string('viewbyresponse', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vresp', 'byresponse' => 1, 'group' => $currentgroupid)));
$byresponsenode->add(get_string('view', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vresp', 'byresponse' => 1, 'group' => $currentgroupid)));
if ($individualresponse) {
$byresponsenode->add(get_string('deleteresp', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'dresp', 'byresponse' => 1, 'rid' => $rid, 'group' => $currentgroupid, 'individualresponse' => 1)));
}
}
}
$canviewgroups = true;
$groupmode = groups_get_activity_groupmode($cm, $course);
if ($groupmode == 1) {
$canviewgroups = groups_has_membership($cm, $USER->id);
}
$canviewallgroups = has_capability('moodle/site:accessallgroups', $context);
if ($questionnaire->capabilities->viewsingleresponse && ($canviewallgroups || $canviewgroups)) {
$url = '/mod/questionnaire/show_nonrespondents.php';
$node = navigation_node::create(get_string('show_nonrespondents', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'nonrespondents');
$questionnairenode->add_node($node, $beforekey);
}
}