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


PHP groups_group_exists函数代码示例

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


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

示例1: groups_remove_member

/**
 * Deletes the link between the specified user and group.
 * @param int $groupid The group to delete the user from
 * @param int $userid The user to delete
 * @return boolean True if deletion was successful, false otherwise
 */
function groups_remove_member($groupid, $userid)
{
    if (!groups_group_exists($groupid)) {
        return false;
    }
    if (!groups_is_member($groupid, $userid)) {
        return true;
    }
    if (!delete_records('groups_members', 'groupid', $groupid, 'userid', $userid)) {
        return false;
    }
    //update group info
    set_field('groups', 'timemodified', time(), 'id', $groupid);
    return true;
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:21,代码来源:lib.php

示例2: groups_remove_member

/**
 * Deletes the link between the specified user and group.
 * @param int $groupid The group to delete the user from
 * @param int $userid The user to delete
 * @return boolean True if deletion was successful, false otherwise
 */
function groups_remove_member($groupid, $userid)
{
    if (!groups_group_exists($groupid)) {
        return false;
    }
    if (!groups_is_member($groupid, $userid)) {
        return true;
    }
    if (!delete_records('groups_members', 'groupid', $groupid, 'userid', $userid)) {
        return false;
    }
    //update group info
    set_field('groups', 'timemodified', time(), 'id', $groupid);
    //trigger groups events
    $eventdata = new object();
    $eventdata->groupid = $groupid;
    $eventdata->userid = $userid;
    events_trigger('groups_member_removed', $eventdata);
    return true;
}
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:26,代码来源:lib.php

示例3: groups_remove_member

/**
 * Deletes the link between the specified user and group.
 * @param int $groupid The group to delete the user from
 * @param int $userid The user to delete
 * @return boolean True if deletion was successful, false otherwise
 */
function groups_remove_member($groupid, $userid)
{
    global $DB;
    if (!$DB->record_exists('user', array('id' => $userid))) {
        throw new moodle_exception('useriddoesntexist');
    }
    if (!groups_group_exists($groupid)) {
        throw new moodle_exception('cannotaddmembergroupiddoesntexist');
    }
    if (!groups_is_member($groupid, $userid)) {
        return true;
    }
    $DB->delete_records('groups_members', array('groupid' => $groupid, 'userid' => $userid));
    //update group info
    $DB->set_field('groups', 'timemodified', time(), array('id' => $groupid));
    //trigger groups events
    $eventdata = new object();
    $eventdata->groupid = $groupid;
    $eventdata->userid = $userid;
    events_trigger('groups_member_removed', $eventdata);
    return true;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:28,代码来源:lib.php

示例4: report_ncccscensus_generate_report

/**
 * Performs the report function.
 *
 * @param array $formdata the form data
 * @param int $type the report type
 * @param string $saveto File to save the pdf report to.
 * @return bool False on failure
 * @uses $CFG, $DB
 */
function report_ncccscensus_generate_report($formdata, $type = REPORT_NCCCSCENSUS_ACTION_VIEW, $saveto = false)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/moodlelib.php';
    $reportname = 'report_ncccscensus';
    $cid = $formdata->id;
    // In case the form is hacked, set a default startdate to today at midnight.
    if (empty($formdata->startdate)) {
        $formdata->startdate = usergetmidnight(time(), get_user_timezone());
    }
    // In case the form is hacked, set a default enddate to today at midnight.
    if (empty($formdata->enddate)) {
        $formdata->enddate = $formdata->startdate;
    }
    // Advance enddate to tomorrow's midnight.
    $formdata->enddate += DAYSECS - 1;
    // This flag determines if we should display grouped users or not.
    $nogroups = isset($formdata->disablegroups) ? true : false;
    if ($nogroups) {
        $group = false;
    } else {
        // If group specified, do some validation.
        $group = isset($formdata->group) ? $formdata->group : false;
        // In case the form is hacked, the group could be invalid.
        if ($group === false || $group < 0) {
            throw new report_ncccscensus_exception('cannotfindgroup');
        }
        if ($group > 0) {
            // Validate the group ID.
            if (!groups_group_exists($group)) {
                throw new report_ncccscensus_exception('cannotfindgroup');
            }
            // Validate the group ID with respect to the course ID.
            $groupdata = groups_get_course_data($cid);
            $groupfound = false;
            foreach ($groupdata->groups as $groupobject) {
                if ($groupobject->id == $group) {
                    $groupfound = true;
                    break;
                }
            }
            if (!$groupfound) {
                throw new report_ncccscensus_exception('invalidgroupid');
            }
            // User could still hack form to view a group that they don't have the capability to see.
            $context = context_course::instance($cid);
            if (has_capability('moodle/site:accessallgroups', $context)) {
                $userid = 0;
            } else {
                if (has_capability('moodle/course:managegroups', $context)) {
                    $userid = $USER->id;
                } else {
                    $userid = false;
                }
            }
            if ($userid === false) {
                throw new report_ncccscensus_exception('invalidgroupid');
            }
            if ($userid != 0) {
                $grouprecs = groups_get_all_groups($course->id, $userid, 0, 'g.id, g.name');
                $groupnotfound = true;
                foreach ($grouprecs as $grouprec) {
                    if ($grouprec->id == $group) {
                        $groupnotfound = false;
                        break;
                    }
                }
                if ($groupnotfound) {
                    throw new report_ncccscensus_exception('invalidgroupid');
                }
            }
        }
    }
    $users = array();
    if ($nogroups) {
        $users = report_ncccscensus_get_users($cid, REPORT_NCCCSCENSUS_EXCLUDE_GROUP_MEMBERS);
    } else {
        if ($group > 0) {
            $users = report_ncccscensus_get_users($cid, $group);
        } else {
            $users = report_ncccscensus_get_users($cid);
        }
    }
    $results = report_ncccscensus_build_grades_array($cid, $users, $formdata->startdate, $formdata->enddate);
    if (empty($results)) {
        return false;
    }
    if ($type == REPORT_NCCCSCENSUS_ACTION_VIEW) {
        $headers = array('student' => get_string('studentfullnamehtml', $reportname));
        $showstudentid = report_ncccscensus_check_field_status('showstudentid', 'html');
    } else {
//.........这里部分代码省略.........
开发者ID:cbmegahan,项目名称:report_ncccscensus,代码行数:101,代码来源:lib.php

示例5: calendar_add_event_allowed

function calendar_add_event_allowed($event)
{
    global $USER;
    // can not be using guest account
    if (empty($USER->id) or $USER->username == 'guest') {
        return false;
    }
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    // if user has manageentries at site level, always return true
    if (has_capability('moodle/calendar:manageentries', $sitecontext)) {
        return true;
    }
    switch ($event->type) {
        case 'course':
            return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $event->courseid));
        case 'group':
            if (!groups_group_exists($event->groupid)) {
                //TODO:check.
                return false;
            }
            // this is ok because if you have this capability at course level, you should be able
            // to edit group calendar too
            // there is no need to check membership, because if you have this capability
            // you will have a role in this group context
            return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_GROUP, $event->groupid));
        case 'user':
            if ($event->userid == $USER->id) {
                return has_capability('moodle/calendar:manageownentries', $sitecontext);
            }
            //there is no 'break;' intentionally
        //there is no 'break;' intentionally
        case 'site':
            return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, SITEID));
        default:
            return false;
    }
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:37,代码来源:event.php

示例6: forum_cron


//.........这里部分代码省略.........
                    $userfrom = $users[$post->userid];
                } else {
                    if ($userfrom = get_record('user', 'id', $post->userid)) {
                        $users[$userfrom->id] = $userfrom;
                        // fetch only once, we can add it to user list, it will be skipped anyway
                    } else {
                        mtrace('Could not find user ' . $post->userid);
                        continue;
                    }
                }
                // setup global $COURSE properly - needed for roles and languages
                course_setup($course);
                // More environment
                // Fill caches
                if (!isset($userto->viewfullnames[$forum->id])) {
                    $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
                    $userto->viewfullnames[$forum->id] = has_capability('moodle/site:viewfullnames', $modcontext);
                }
                if (!isset($userto->canpost[$discussion->id])) {
                    $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
                    $userto->canpost[$discussion->id] = forum_user_can_post($forum, $discussion, $userto, $cm, $course, $modcontext);
                }
                if (!isset($userfrom->groups[$forum->id])) {
                    if (!isset($userfrom->groups)) {
                        $userfrom->groups = array();
                        $users[$userfrom->id]->groups = array();
                    }
                    $userfrom->groups[$forum->id] = groups_get_all_groups($course->id, $userfrom->id, $cm->groupingid);
                    $users[$userfrom->id]->groups[$forum->id] = $userfrom->groups[$forum->id];
                }
                // Make sure groups allow this user to see this email
                if ($discussion->groupid > 0 and $groupmode = groups_get_activity_groupmode($cm, $course)) {
                    // Groups are being used
                    if (!groups_group_exists($discussion->groupid)) {
                        // Can't find group
                        continue;
                        // Be safe and don't send it to anyone
                    }
                    if (!groups_is_member($discussion->groupid) and !has_capability('moodle/site:accessallgroups', $modcontext)) {
                        // do not send posts from other groups when in SEPARATEGROUPS or VISIBLEGROUPS
                        continue;
                    }
                }
                // Make sure we're allowed to see it...
                if (!forum_user_can_see_post($forum, $discussion, $post, NULL, $cm)) {
                    mtrace('user ' . $userto->id . ' can not see ' . $post->id);
                    continue;
                }
                // OK so we need to send the email.
                // Does the user want this post in a digest?  If so postpone it for now.
                if ($userto->maildigest > 0) {
                    // This user wants the mails to be in digest form
                    $queue = new object();
                    $queue->userid = $userto->id;
                    $queue->discussionid = $discussion->id;
                    $queue->postid = $post->id;
                    $queue->timemodified = $post->created;
                    if (!insert_record('forum_queue', $queue)) {
                        mtrace("Error: mod/forum/cron.php: Could not queue for digest mail for id {$post->id} to user {$userto->id} ({$userto->email}) .. not trying again.");
                    }
                    continue;
                }
                // Prepare to actually send the post now, and build up the content
                $cleanforumname = str_replace('"', "'", strip_tags(format_string($forum->name)));
                $userfrom->customheaders = array('Precedence: Bulk', 'List-Id: "' . $cleanforumname . '" <moodleforum' . $forum->id . '@' . $hostname . '>', 'List-Help: ' . $CFG->wwwroot . '/mod/forum/view.php?f=' . $forum->id, 'Message-ID: <moodlepost' . $post->id . '@' . $hostname . '>', 'In-Reply-To: <moodlepost' . $post->parent . '@' . $hostname . '>', 'References: <moodlepost' . $post->parent . '@' . $hostname . '>', 'X-Course-Id: ' . $course->id, 'X-Course-Name: ' . format_string($course->fullname, true));
                $postsubject = "{$course->shortname}: " . format_string($post->subject, true);
开发者ID:r007,项目名称:PMoodle,代码行数:67,代码来源:lib.php

示例7: calendar_edit_event_allowed

function calendar_edit_event_allowed($event)
{
    global $USER;
    // can not be using guest account
    if ($USER->username == "guest") {
        return false;
    }
    $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
    // if user has manageentries at site level, return true
    if (has_capability('moodle/calendar:manageentries', $sitecontext)) {
        return true;
    }
    // if groupid is set, it's definitely a group event
    if ($event->groupid) {
        //TODO:check.
        if (!groups_group_exists($event->groupid)) {
            return false;
        }
        // this is ok because if you have this capability at course level, you should be able
        // to edit group calendar too
        // there is no need to check membership, because if you have this capability
        // you will have a role in this group context
        return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_GROUP, $event->groupid));
    } else {
        if ($event->courseid) {
            // if groupid is not set, but course is set,
            // it's definiely a course event
            return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $event->courseid));
        } else {
            if ($event->userid && $event->userid == $USER->id) {
                // if course is not set, but userid id set, it's a user event
                return has_capability('moodle/calendar:manageownentries', $sitecontext);
            }
        }
    }
    return false;
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:37,代码来源:lib.php

示例8: forum_pluginfile

/**
 * Serves the forum attachments. Implements needed access control ;-)
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - justsend the file
 */
function forum_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
    global $CFG, $DB;

    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }

    require_course_login($course, true, $cm);

    $fileareas = array('attachment', 'post');
    if (!in_array($filearea, $fileareas)) {
        return false;
    }

    $postid = (int)array_shift($args);

    if (!$post = $DB->get_record('forum_posts', array('id'=>$postid))) {
        return false;
    }

    if (!$discussion = $DB->get_record('forum_discussions', array('id'=>$post->discussion))) {
        return false;
    }

    if (!$forum = $DB->get_record('forum', array('id'=>$cm->instance))) {
        return false;
    }

    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/$context->id/mod_forum/$filearea/$postid/$relativepath";
    if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
        return false;
    }

    // Make sure groups allow this user to see this file
    if ($discussion->groupid > 0 and $groupmode = groups_get_activity_groupmode($cm, $course)) {   // Groups are being used
        if (!groups_group_exists($discussion->groupid)) { // Can't find group
            return false;                           // Be safe and don't send it to anyone
        }

        if (!groups_is_member($discussion->groupid) and !has_capability('moodle/site:accessallgroups', $context)) {
            // do not send posts from other groups when in SEPARATEGROUPS or VISIBLEGROUPS
            return false;
        }
    }

    // Make sure we're allowed to see it...
    if (!forum_user_can_see_post($forum, $discussion, $post, NULL, $cm)) {
        return false;
    }


    // finally send the file
    send_stored_file($file, 0, 0, true); // download MUST be forced - security!
}
开发者ID:nfreear,项目名称:moodle,代码行数:67,代码来源:lib.php

示例9: wiki_get_subwiki_by_group_and_user_with_validation

/**
 * Utility function for getting a subwiki by group and user, validating that the user can view it.
 * If the subwiki doesn't exists in DB yet it'll have id -1.
 *
 * @param stdClass $wiki The wiki.
 * @param int $groupid Group ID. 0 means the subwiki doesn't use groups.
 * @param int $userid User ID. 0 means the subwiki doesn't use users.
 * @return stdClass Subwiki. If it doesn't exists in DB yet it'll have id -1. If the user can't view the
 *                  subwiki this function will return false.
 * @since  Moodle 3.1
 * @throws moodle_exception
 */
function wiki_get_subwiki_by_group_and_user_with_validation($wiki, $groupid, $userid)
{
    global $USER, $DB;
    // Get subwiki based on group and user.
    if (!($subwiki = wiki_get_subwiki_by_group($wiki->id, $groupid, $userid))) {
        // The subwiki doesn't exist.
        // Validate if user is valid.
        if ($userid != 0) {
            $user = core_user::get_user($userid, '*', MUST_EXIST);
            core_user::require_active_user($user);
        }
        // Validate that groupid is valid.
        if ($groupid != 0 && !groups_group_exists($groupid)) {
            throw new moodle_exception('cannotfindgroup', 'error');
        }
        // Valid data but subwiki not found. We'll simulate a subwiki object to check if the user would be able to see it
        // if it existed. If he's able to see it then we'll return an empty array because the subwiki has no pages.
        $subwiki = new stdClass();
        $subwiki->id = -1;
        $subwiki->wikiid = $wiki->id;
        $subwiki->userid = $userid;
        $subwiki->groupid = $groupid;
    }
    // Check that the user can view the subwiki. This function checks capabilities.
    if (!wiki_user_can_view($subwiki, $wiki)) {
        return false;
    }
    return $subwiki;
}
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:41,代码来源:locallib.php

示例10: role_assign

/**
 * This function makes a role-assignment (a role for a user or group in a particular context)
 * @param $roleid - the role of the id
 * @param $userid - userid
 * @param $groupid - group id
 * @param $contextid - id of the context
 * @param $timestart - time this assignment becomes effective
 * @param $timeend - time this assignemnt ceases to be effective
 * @uses $USER
 * @return id - new id of the assigment
 */
function role_assign($roleid, $userid, $groupid, $contextid, $timestart = 0, $timeend = 0, $hidden = 0, $enrol = 'manual', $timemodified = '')
{
    global $USER, $CFG;
    debugging("Assign roleid {$roleid} userid {$userid} contextid {$contextid}", DEBUG_DEVELOPER);
    /// Do some data validation
    if (empty($roleid)) {
        debugging('Role ID not provided');
        return false;
    }
    if (empty($userid) && empty($groupid)) {
        debugging('Either userid or groupid must be provided');
        return false;
    }
    if ($userid && !record_exists('user', 'id', $userid)) {
        debugging('User ID ' . intval($userid) . ' does not exist!');
        return false;
    }
    if ($groupid && !groups_group_exists($groupid)) {
        debugging('Group ID ' . intval($groupid) . ' does not exist!');
        return false;
    }
    if (!($context = get_context_instance_by_id($contextid))) {
        debugging('Context ID ' . intval($contextid) . ' does not exist!');
        return false;
    }
    if ($timestart and $timeend and $timestart > $timeend) {
        debugging('The end time can not be earlier than the start time');
        return false;
    }
    if (!$timemodified) {
        $timemodified = time();
    }
    /// Check for existing entry
    if ($userid) {
        $ra = get_record('role_assignments', 'roleid', $roleid, 'contextid', $context->id, 'userid', $userid);
    } else {
        $ra = get_record('role_assignments', 'roleid', $roleid, 'contextid', $context->id, 'groupid', $groupid);
    }
    $newra = new object();
    if (empty($ra)) {
        // Create a new entry
        $newra->roleid = $roleid;
        $newra->contextid = $context->id;
        $newra->userid = $userid;
        $newra->hidden = $hidden;
        $newra->enrol = $enrol;
        /// Always round timestart downto 100 secs to help DBs to use their own caching algorithms
        /// by repeating queries with the same exact parameters in a 100 secs time window
        $newra->timestart = round($timestart, -2);
        $newra->timeend = $timeend;
        $newra->timemodified = $timemodified;
        $newra->modifierid = empty($USER->id) ? 0 : $USER->id;
        $success = insert_record('role_assignments', $newra);
    } else {
        // We already have one, just update it
        $newra->id = $ra->id;
        $newra->hidden = $hidden;
        $newra->enrol = $enrol;
        /// Always round timestart downto 100 secs to help DBs to use their own caching algorithms
        /// by repeating queries with the same exact parameters in a 100 secs time window
        $newra->timestart = round($timestart, -2);
        $newra->timeend = $timeend;
        $newra->timemodified = $timemodified;
        $newra->modifierid = empty($USER->id) ? 0 : $USER->id;
        $success = update_record('role_assignments', $newra);
    }
    if ($success) {
        /// Role was assigned, so do some other things
        /// If the user is the current user, then reload the capabilities too.
        if (!empty($USER->id) && $USER->id == $userid) {
            load_all_capabilities();
        }
        /// Ask all the modules if anything needs to be done for this user
        if ($mods = get_list_of_plugins('mod')) {
            foreach ($mods as $mod) {
                include_once $CFG->dirroot . '/mod/' . $mod . '/lib.php';
                $functionname = $mod . '_role_assign';
                if (function_exists($functionname)) {
                    $functionname($userid, $context, $roleid);
                }
            }
        }
    }
    /// now handle metacourse role assignments if in course context
    if ($success and $context->contextlevel == CONTEXT_COURSE) {
        if ($parents = get_records('course_meta', 'child_course', $context->instanceid)) {
            foreach ($parents as $parent) {
                sync_metacourse($parent->parent_course);
            }
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:101,代码来源:accesslib.php

示例11: exercise_list_unassessed_student_submissions

function exercise_list_unassessed_student_submissions($exercise, $user)
{
    // list the student submissions not assessed by the teacher
    global $CFG;
    $timenow = time();
    if (!($course = get_record("course", "id", $exercise->course))) {
        error("Course is misconfigured");
    }
    if (!($cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id))) {
        error("Course Module ID was incorrect");
    }
    $table->head = array(get_string("title", "exercise"), get_string("submittedby", "exercise"), get_string("submitted", "exercise"), get_string("action", "exercise"), get_string("comment", "exercise"));
    $table->align = array("left", "left", "left", "left", "left");
    $table->size = array("*", "*", "*", "*", "*");
    $table->cellpadding = 2;
    $table->cellspacing = 0;
    // get all the submissions, oldest first, youngest last
    // exercise_get_student_submissions is group aware
    $groupid = get_current_group($course->id);
    if ($groupid) {
        if (!groups_group_exists($groupid)) {
            error("List unassessed student submissions: group not found");
        }
        print_heading(get_string("studentsubmissionsforassessment", "exercise", $group->name));
    }
    if ($submissions = exercise_get_student_submissions($exercise, "time", $groupid)) {
        foreach ($submissions as $submission) {
            // only consider "cold" submissions
            if ($submission->timecreated < $timenow - $CFG->maxeditingtime) {
                $comment = "";
                // see if student has already submitted
                $submissionowner = get_record("user", "id", $submission->userid);
                if (exercise_count_user_submissions($exercise, $submissionowner) == 1) {
                    // it's the student's first submission
                    // see if there are no cold assessments for this submission
                    if (!exercise_count_assessments($submission)) {
                        // now see if the teacher has already assessed this submission
                        $warm = false;
                        if ($assessments = get_records("exercise_assessments", "submissionid", $submission->id)) {
                            foreach ($assessments as $assessment) {
                                if (isteacher($course->id, $assessment->userid)) {
                                    if ($assessment->timecreated > $timenow - $CFG->maxeditingtime) {
                                        $warm = true;
                                    }
                                    break;
                                    // no need to look further
                                }
                            }
                        }
                        // get their assessment
                        if ($assessments = exercise_get_user_assessments($exercise, $submissionowner)) {
                            foreach ($assessments as $assessment) {
                                $studentassessment = $assessment;
                                break;
                                // there should only be one!
                            }
                            $timegap = get_string("ago", "exercise", format_time($submission->timecreated - $timenow));
                            if ($submission->late) {
                                $timegap = "<font color=\"red\">" . $timegap . "</font>";
                            }
                            if ($warm) {
                                // last chance salon
                                $action = "<a href=\"assessments.php?action=teacherassessment&amp;id={$cm->id}&amp;aid={$studentassessment->id}&amp;sid={$submission->id}\">" . get_string("edit", "exercise") . "</a>";
                                $table->data[] = array(exercise_print_submission_title($exercise, $submission), fullname($submissionowner), $timegap, $action, $comment);
                            } else {
                                $action = "<a href=\"assessments.php?action=teacherassessment&amp;id={$cm->id}&amp;aid={$studentassessment->id}&amp;sid={$submission->id}\">" . get_string("assess", "exercise") . "</a>";
                                $table->data[] = array(exercise_print_submission_title($exercise, $submission), fullname($submissionowner), $timegap, $action, $comment);
                            }
                        } else {
                            // there's no student assessment, odd!!
                        }
                    }
                } else {
                    $teacherassessed = false;
                    $warm = false;
                    if ($assessments = get_records("exercise_assessments", "submissionid", $submission->id)) {
                        foreach ($assessments as $assessment) {
                            if (isteacher($course->id, $assessment->userid)) {
                                $teacherassessed = true;
                                if (!($teacher = get_record("user", "id", $assessment->userid))) {
                                    error("List unassessed student submissions: teacher record not found");
                                }
                                $comment = get_string("resubmissionfor", "exercise", fullname($teacher));
                                if ($assessment->timecreated > $timenow - $CFG->maxeditingtime) {
                                    $warm = true;
                                }
                                break;
                                // no need to look further
                            }
                        }
                    }
                    if ($teacherassessed and $warm) {
                        // last chance salon
                        $action = "<a href=\"assessments.php?action=assessresubmission&amp;id={$cm->id}&amp;sid={$submission->id}\">" . get_string("edit", "exercise") . "</a>";
                        $timegap = get_string("ago", "exercise", format_time($submission->timecreated - $timenow));
                        if ($submission->late) {
                            $timegap = "<font color=\"red\">" . $timegap . "</font>";
                        }
                        $table->data[] = array(exercise_print_submission_title($exercise, $submission), fullname($submissionowner), $timegap, $action, $comment);
                    }
//.........这里部分代码省略.........
开发者ID:r007,项目名称:PMoodle,代码行数:101,代码来源:locallib.php

示例12: error

if (!($cm = get_coursemodule_from_instance('chat', $chat->id, $course->id))) {
    error('Course Module ID was incorrect');
}
require_login($course->id, false, $cm);
if (isguest()) {
    error('Guest does not have access to chat rooms');
}
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
    print_header();
    notice(get_string("activityiscurrentlyhidden"));
}
/// Check to see if groups are being used here
if ($groupmode = groupmode($course, $cm)) {
    // Groups are being used
    if ($groupid = get_and_set_current_group($course, $groupmode, $groupid)) {
        if (!groups_group_exists($groupid)) {
            error("That group (id {$groupid}) doesn't exist!");
        }
        $groupname = ': ' . $group->name;
    } else {
        $groupname = ': ' . get_string('allparticipants');
    }
} else {
    $groupid = 0;
    $groupname = '';
}
$strchat = get_string('modulename', 'chat');
// must be before current_language() in chat_login_user() to force course language!!!
if (!($chat_sid = chat_login_user($chat->id, 'sockets', $groupid, $course))) {
    error('Could not log in to chat room!!');
}
开发者ID:veritech,项目名称:pare-project,代码行数:31,代码来源:index.php

示例13: validation

 /**
  *
  */
 public function validation($params)
 {
     global $DB, $USER;
     // Check the component is mod_dataform.
     if ($params['component'] != 'mod_dataform') {
         throw new rating_exception('invalidcomponent');
     }
     $ownentry = $params['rateduserid'] == $USER->id;
     if ($ownentry) {
         // You can't rate your own entries unless you have the capability.
         if (!has_capability('dataformfield/ratingmdl:ownrate', $params['context'])) {
             throw new rating_exception('nopermissiontorate');
         }
     } else {
         // You can't rate other entries unless you have the capability.
         if (!has_capability('dataformfield/ratingmdl:anyrate', $params['context'])) {
             throw new rating_exception('nopermissiontorate');
         }
     }
     // If the supplied context doesnt match the item's context.
     if ($params['context']->id != $this->df->context->id) {
         throw new rating_exception('invalidcontext');
     }
     // Check the ratingarea is entry or activity.
     if ($params['ratingarea'] != $this->name) {
         throw new rating_exception('invalidratingarea');
     }
     // Vaildate entry scale and rating range.
     if ($params['scaleid'] != $this->_scaleid) {
         throw new rating_exception('invalidscaleid');
     }
     // Upper limit.
     if ($this->_scaleid < 0) {
         // Its a custom scale.
         $scalerecord = $DB->get_record('scale', array('id' => -$this->_scaleid));
         if ($scalerecord) {
             $scalearray = explode(',', $scalerecord->scale);
             if ($params['rating'] > count($scalearray)) {
                 throw new rating_exception('invalidnum');
             }
         } else {
             throw new rating_exception('invalidscaleid');
         }
     } else {
         if ($params['rating'] > $this->_scaleid) {
             // If its numeric and submitted rating is above maximum.
             throw new rating_exception('invalidnum');
         }
     }
     // Lower limit.
     if ($params['rating'] < 0 and $params['rating'] != RATING_UNSET_RATING) {
         throw new rating_exception('invalidnum');
     }
     // Make sure groups allow this user to see the item they're rating.
     $groupid = $this->df->currentgroup;
     if ($groupid > 0 and $groupmode = groups_get_activity_groupmode($this->df->cm, $this->df->course)) {
         // Groups are being used.
         if (!groups_group_exists($groupid)) {
             // Can't find group.
             throw new rating_exception('cannotfindgroup');
         }
         if (!groups_is_member($groupid) and !has_capability('moodle/site:accessallgroups', $this->df->context)) {
             // Do not allow rating of posts from other groups when in SEPARATEGROUPS or VISIBLEGROUPS.
             throw new rating_exception('notmemberofgroup');
         }
     }
     return true;
 }
开发者ID:vaenda,项目名称:moodle-mod_dataform,代码行数:71,代码来源:ratingmdl.php

示例14: get_subwiki_pages

 /**
  * Returns the list of pages from a specific subwiki.
  *
  * @param int $wikiid The wiki instance ID.
  * @param int $groupid The group ID. If not defined, use current group.
  * @param int $userid The user ID. If not defined, use current user.
  * @param array $options Several options like sort by, sort direction, ...
  * @return array Containing a list of warnings and a list of pages.
  * @since Moodle 3.1
  */
 public static function get_subwiki_pages($wikiid, $groupid = -1, $userid = 0, $options = array())
 {
     global $USER, $DB;
     $returnedpages = array();
     $warnings = array();
     $params = self::validate_parameters(self::get_subwiki_pages_parameters(), array('wikiid' => $wikiid, 'groupid' => $groupid, 'userid' => $userid, 'options' => $options));
     // Get wiki instance.
     if (!($wiki = wiki_get_wiki($params['wikiid']))) {
         throw new moodle_exception('incorrectwikiid', 'wiki');
     }
     list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     // Determine group.
     $groupmode = groups_get_activity_groupmode($cm);
     if ($groupmode == NOGROUPS) {
         $groupid = 0;
     } else {
         if ($params['groupid'] == -1) {
             // Use current group.
             $groupid = groups_get_activity_group($cm);
             $groupid = !empty($groupid) ? $groupid : 0;
         } else {
             $groupid = $params['groupid'];
         }
     }
     // Determine user.
     if ($wiki->wikimode == 'collaborative') {
         // Collaborative wikis don't use userid in subwikis.
         $userid = 0;
     } else {
         if (empty($params['userid'])) {
             // Use current user.
             $userid = $USER->id;
         } else {
             $userid = $params['userid'];
         }
     }
     // Get subwiki based on group and user.
     if (!($subwiki = wiki_get_subwiki_by_group($cm->instance, $groupid, $userid))) {
         // The subwiki doesn't exist.
         // Validate if user is valid.
         if ($userid != 0 && $userid != $USER->id && !($user = $DB->get_record('user', array('id' => $userid)))) {
             throw new moodle_exception('invaliduserid', 'error');
         }
         // Validate that groupid is valid.
         if ($groupid != 0 && !groups_group_exists($groupid)) {
             throw new moodle_exception('cannotfindgroup', 'error');
         }
         // Valid data but subwiki not found. We'll simulate a subwiki object to check if the user would be able to see it
         // if it existed. If he's able to see it then we'll return an empty array because the subwiki has no pages.
         $subwiki = new stdClass();
         $subwiki->wikiid = $wiki->id;
         $subwiki->userid = $userid;
         $subwiki->groupid = $groupid;
         // Check that the user can view the subwiki. This function checks capabilities.
         if (!wiki_user_can_view($subwiki, $wiki)) {
             throw new moodle_exception('cannotviewpage', 'wiki');
         }
     } else {
         // Check that the user can view the subwiki. This function checks capabilities.
         if (!wiki_user_can_view($subwiki, $wiki)) {
             throw new moodle_exception('cannotviewpage', 'wiki');
         }
         // Set sort param.
         $options = $params['options'];
         if (!empty($options['sortby'])) {
             if ($options['sortdirection'] != 'ASC' && $options['sortdirection'] != 'DESC') {
                 // Invalid sort direction. Use default.
                 $options['sortdirection'] = 'ASC';
             }
             $sort = $options['sortby'] . ' ' . $options['sortdirection'];
         }
         $pages = wiki_get_page_list($subwiki->id, $sort);
         $caneditpages = wiki_user_can_edit($subwiki);
         $firstpage = wiki_get_first_page($subwiki->id);
         foreach ($pages as $page) {
             $retpage = array('id' => $page->id, 'subwikiid' => $page->subwikiid, 'title' => external_format_string($page->title, $context->id), 'timecreated' => $page->timecreated, 'timemodified' => $page->timemodified, 'timerendered' => $page->timerendered, 'userid' => $page->userid, 'pageviews' => $page->pageviews, 'readonly' => $page->readonly, 'caneditpage' => $caneditpages, 'firstpage' => $page->id == $firstpage->id);
             if ($options['includecontent']) {
                 // Refresh page cached content if needed.
                 if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
                     if ($content = wiki_refresh_cachedcontent($page)) {
                         $page = $content['page'];
                     }
                 }
                 list($retpage['cachedcontent'], $retpage['contentformat']) = external_format_text($page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id);
             }
             $returnedpages[] = $retpage;
         }
     }
//.........这里部分代码省略.........
开发者ID:rushi963,项目名称:moodle,代码行数:101,代码来源:external.php

示例15: role_assign

/**
 * This function makes a role-assignment (a role for a user or group in a particular context)
 * @param $roleid - the role of the id
 * @param $userid - userid
 * @param $groupid - group id
 * @param $contextid - id of the context
 * @param $timestart - time this assignment becomes effective
 * @param $timeend - time this assignemnt ceases to be effective
 * @uses $USER
 * @return id - new id of the assigment
 */
function role_assign($roleid, $userid, $groupid, $contextid, $timestart = 0, $timeend = 0, $hidden = 0, $enrol = 'manual', $timemodified = '')
{
    global $USER, $CFG, $DB;
    /// Do some data validation
    if (empty($roleid)) {
        debugging('Role ID not provided');
        return false;
    }
    if (empty($userid) && empty($groupid)) {
        debugging('Either userid or groupid must be provided');
        return false;
    }
    if ($userid && !$DB->record_exists('user', array('id' => $userid))) {
        debugging('User ID ' . intval($userid) . ' does not exist!');
        return false;
    }
    if ($groupid && !groups_group_exists($groupid)) {
        debugging('Group ID ' . intval($groupid) . ' does not exist!');
        return false;
    }
    if (!($context = get_context_instance_by_id($contextid))) {
        debugging('Context ID ' . intval($contextid) . ' does not exist!');
        return false;
    }
    if ($timestart and $timeend and $timestart > $timeend) {
        debugging('The end time can not be earlier than the start time');
        return false;
    }
    if (!$timemodified) {
        $timemodified = time();
    }
    /// Check for existing entry
    if ($userid) {
        $ra = $DB->get_record('role_assignments', array('roleid' => $roleid, 'contextid' => $context->id, 'userid' => $userid));
    } else {
        $ra = $DB->get_record('role_assignments', array('roleid' => $roleid, 'contextid' => $context->id, 'groupid' => $groupid));
    }
    if (empty($ra)) {
        // Create a new entry
        $ra = new object();
        $ra->roleid = $roleid;
        $ra->contextid = $context->id;
        $ra->userid = $userid;
        $ra->hidden = $hidden;
        $ra->enrol = $enrol;
        /// Always round timestart downto 100 secs to help DBs to use their own caching algorithms
        /// by repeating queries with the same exact parameters in a 100 secs time window
        $ra->timestart = round($timestart, -2);
        $ra->timeend = $timeend;
        $ra->timemodified = $timemodified;
        $ra->modifierid = empty($USER->id) ? 0 : $USER->id;
        if (!($ra->id = $DB->insert_record('role_assignments', $ra))) {
            return false;
        }
    } else {
        // We already have one, just update it
        $ra->id = $ra->id;
        $ra->hidden = $hidden;
        $ra->enrol = $enrol;
        /// Always round timestart downto 100 secs to help DBs to use their own caching algorithms
        /// by repeating queries with the same exact parameters in a 100 secs time window
        $ra->timestart = round($timestart, -2);
        $ra->timeend = $timeend;
        $ra->timemodified = $timemodified;
        $ra->modifierid = empty($USER->id) ? 0 : $USER->id;
        if (!$DB->update_record('role_assignments', $ra)) {
            return false;
        }
    }
    /// mark context as dirty - modules might use has_capability() in xxx_role_assing()
    /// again expensive, but needed
    mark_context_dirty($context->path);
    if (!empty($USER->id) && $USER->id == $userid) {
        /// If the user is the current user, then do full reload of capabilities too.
        load_all_capabilities();
    }
    /// Ask all the modules if anything needs to be done for this user
    if ($mods = get_list_of_plugins('mod')) {
        foreach ($mods as $mod) {
            include_once $CFG->dirroot . '/mod/' . $mod . '/lib.php';
            $functionname = $mod . '_role_assign';
            if (function_exists($functionname)) {
                $functionname($userid, $context, $roleid);
            }
        }
    }
    /// now handle metacourse role assignments if in course context
    if ($context->contextlevel == CONTEXT_COURSE) {
        if ($parents = $DB->get_records('course_meta', array('child_course' => $context->instanceid))) {
//.........这里部分代码省略.........
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:101,代码来源:accesslib.php


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