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


PHP groups_get_grouping_members函数代码示例

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


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

示例1: display_submission

 function display_submission($extra_javascript = '')
 {
     global $CFG;
     require_once $CFG->libdir . '/gradelib.php';
     require_once $CFG->libdir . '/tablelib.php';
     $userid = required_param('userid', PARAM_INT);
     $offset = required_param('offset', PARAM_INT);
     //offset for where to start looking for student.
     if (!($user = get_record('user', 'id', $userid))) {
         error('No such user!');
     }
     if (!($submission = $this->get_submission($user->id))) {
         $submission = $this->prepare_new_submission($userid);
     }
     if ($submission->timemodified > $submission->timemarked) {
         $subtype = 'assignmentnew';
     } else {
         $subtype = 'assignmentold';
     }
     // Get the criteria
     $criteriaList = get_records_list('assignment_criteria', 'assignment', $this->assignment->id, 'ordernumber');
     $numberOfCriteria = 0;
     if (is_array($criteriaList)) {
         $criteriaList = array_values($criteriaList);
         $numberOfCriteria = count($criteriaList);
     }
     $reviews = $this->get_reviews_of_student($user->id);
     $numberOfReviewsOfThisStudent = 0;
     if (is_array($reviews)) {
         $numberOfReviewsOfThisStudent = count($reviews);
     }
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array($user->id));
     $disabled = $grading_info->items[0]->grades[$userid]->locked || $grading_info->items[0]->grades[$userid]->overridden;
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     /// Get all ppl that can submit assignments
     $currentgroup = groups_get_activity_group($cm);
     if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
         $users = array_keys($users);
     }
     // if groupmembersonly used, remove users who are not in any group
     if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
     $nextid = 0;
     if ($users) {
         $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
                           s.id AS submissionid, s.grade, s.submissioncomment,
                           s.timecreated as submitted, s.timemarked as timemarked ';
         $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'assignment_submissions s ON u.id = s.userid
                                                                   AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE u.id IN (' . implode(',', $users) . ') ';
         $sort = 'ORDER BY COALESCE(submitted,2147483647) ASC, submissionid ASC, u.lastname ASC';
         // if ($sort = flexible_table::get_sql_sort('mod-assignment-submissions')) {
         // $sort = 'ORDER BY '.$sort.' ';
         // }
         if (($auser = get_records_sql($select . $sql . $sort, $offset + 1, 1)) !== false) {
             $nextuser = array_shift($auser);
             // Calculate user status
             if ($nextuser && $nextuser->submitted) {
                 $nextuser->status = $nextuser->timemarked > 0;
                 $nextid = $nextuser->id;
             }
         }
     }
     print_header(get_string('feedback', 'assignment') . ':' . fullname($user, true) . ':' . format_string($this->assignment->name));
     // Print any extra javascript needed for saveandnext
     print $extra_javascript;
     // Some javascript to help with setting up >.>
     echo '<script type="text/javascript">' . "\n";
     echo 'function setNext(){' . "\n";
     echo 'document.getElementById(\'submitform\').mode.value=\'next\';' . "\n";
     echo 'document.getElementById(\'submitform\').userid.value="' . $nextid . '";' . "\n";
     echo '}' . "\n";
     echo 'function saveNext(){' . "\n";
     echo 'document.getElementById(\'submitform\').mode.value=\'saveandnext\';' . "\n";
     echo 'document.getElementById(\'submitform\').userid.value="' . $nextid . '";' . "\n";
     echo 'document.getElementById(\'submitform\').saveuserid.value="' . $userid . '";' . "\n";
     //        echo 'document.getElementById(\'submitform\').menuindex.value = document.getElementById(\'submitform\').grade.selectedIndex;'."\n";
     echo '}' . "\n";
     echo 'function setSavePrev(){' . "\n";
     echo 'document.getElementById(\'submitform\').savePrev.value=\'1\';' . "\n";
     echo '}' . "\n";
     echo '</script>' . "\n";
     require_once $CFG->dirroot . '/mod/assignment/type/peerreview/' . self::STYLES_FILE;
     echo '<table cellspacing="0" class="feedback ' . $subtype . '" style="width:99%;">';
     // Start of student info row
     echo '<tr>';
     echo '<td class="picture user">';
     print_user_picture($user, $this->course->id, $user->picture);
     echo '</td>';
     echo '<td class="topic">';
     echo '<div class="from">';
     echo '<div class="fullname">' . fullname($user, true) . '</div>';
     if ($submission->timemodified) {
         echo '<div class="time">' . get_string('submitted', 'assignment_peerreview') . ': ' . userdate($submission->timecreated) . $this->display_lateness($submission->timecreated) . '</div>';
     }
//.........这里部分代码省略.........
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:assignment.class.php

示例2: plagiarismSimilarities

 function plagiarismSimilarities($id)
 {
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $currentgroup = groups_get_activity_group($cm);
     if ($users = get_users_by_capability($this->context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
         $users = array_keys($users);
     }
     // if groupmembersonly used, remove users who are not in any group
     if ($users and !empty($this->cfg->enablegroupings) and $cm->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
     $similarities = get_records('plagiarismdetector_similarities', 'plagiarismid', $id);
     $userssim = array();
     $arrsim;
     $arrusers = array();
     foreach ($similarities as $sim) {
         $userssim[] = $sim->user1;
         $userssim[] = $sim->user2;
         if (!isset($arrsim[$sim->user1])) {
             $arrsim[$sim->user1] = array();
         }
         if (!isset($arrsim[$sim->user2])) {
             $arrsim[$sim->user2] = array();
         }
         $arrsim[$sim->user1][$sim->user2] = new stdClass();
         $arrsim[$sim->user1][$sim->user2]->similarity = $sim->similarity;
         $arrsim[$sim->user1][$sim->user2]->confirmed = $sim->confirmed;
         $arrsim[$sim->user1][$sim->user2]->id = $sim->id;
         $arrsim[$sim->user2][$sim->user1] = $arrsim[$sim->user1][$sim->user2];
         $id = $sim->user1;
         $usa = new stdClass();
         $usa->firstname = $id;
         $usa->lastname = '(false)';
         $usa->id = $id;
         $arrusers[$id] = $usa;
     }
     $userssim = array_unique($userssim);
     $users = array_intersect($users, $userssim);
     $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt ';
     $sql = 'FROM ' . $this->cfg->prefix . 'user u ' . 'WHERE u.id IN (' . implode(',', $users) . ') ';
     $infousers = get_records_sql($select . $sql);
     foreach ($infousers as $us) {
         $id = $us->id;
         $arrusers[$id] = $us;
     }
     $ret = new stdClass();
     $ret->users = $arrusers;
     $ret->similarities = $arrsim;
     return $ret;
 }
开发者ID:syrusakbary,项目名称:PlagiarismDetector_Mod-Moodle,代码行数:54,代码来源:lib.php

示例3: array_keys

if ($meeting->sessiontype == 0) {
    $course_users = $DB->get_records_sql("select u.id from {role_assignments} ra, {context} con, {course} c, {user} u where ra.userid=u.id and ra.contextid=con.id and con.instanceid=c.id and c.id=" . $meeting->course);
    //$course_users = $DB->get_records_sql("select u.id from mdl_role_assignments ra, mdl_context con, mdl_course c, mdl_user u where ra.userid=u.id and ra.contextid=con.id and con.instanceid=c.id and c.id=" . $meeting->course);
    $userids = array_keys($course_users);
} else {
    if ($meeting->sessiontype == 1) {
        $userids = explode(',', $meeting->nonchairlist);
    } else {
        if ($meeting->sessiontype == 2) {
            //This will get all the people in the course
            $course_users = $DB->get_records_sql("select u.id from {role_assignments} ra, {context} con, {course} c, {user} u where ra.userid=u.id and ra.contextid=con.id and con.instanceid=c.id and c.id=" . $meeting->course);
            //$course_users = $DB->get_records_sql("select u.id from mdl_role_assignments ra, mdl_context con, mdl_course c, mdl_user u where ra.userid=u.id and ra.contextid=con.id and con.instanceid=c.id and c.id=" . $meeting->course);
            $userids = array_keys($course_users);
        } else {
            if ($meeting->sessiontype == 3) {
                $userids = array_keys(groups_get_grouping_members($meeting->groupingid, 'distinct u.id', 'u.id'));
            }
        }
    }
}
/// Only care about non-moderators of the activity.
if ($meeting->sessiontype == 1) {
    $userids = implode(', ', $userids);
} else {
    if ($moderators = get_users_by_capability($context, 'mod/elluminate:moderatemeeting', 'u.id', '', '', '', '', '', false)) {
        $userids = implode(', ', array_diff($userids, array_keys($moderators)));
    } else {
        $userids = implode(', ', $userids);
    }
}
$select = 'SELECT u.id, u.firstname, u.lastname ';
开发者ID:nadavkav,项目名称:Moodle2-Hebrew-plugins,代码行数:31,代码来源:attendance.php

示例4: display_submissions

 /**
  *  Display all the submissions ready for grading
  */
 function display_submissions($message = '')
 {
     global $CFG, $db, $USER;
     require_once $CFG->libdir . '/gradelib.php';
     /* first we check to see if the form has just been submitted
      * to request user_preference updates
      */
     if (isset($_POST['updatepref'])) {
         $perpage = optional_param('perpage', 10, PARAM_INT);
         $perpage = $perpage <= 0 ? 10 : $perpage;
         set_user_preference('assignment_perpage', $perpage);
         set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
     }
     /* next we get perpage and quickgrade (allow quick grade) params
      * from database
      */
     $perpage = get_user_preferences('assignment_perpage', 10);
     $quickgrade = get_user_preferences('assignment_quickgrade', 0);
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
     if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
         $uses_outcomes = true;
     } else {
         $uses_outcomes = false;
     }
     $teacherattempts = true;
     /// Temporary measure
     $page = optional_param('page', 0, PARAM_INT);
     $strsaveallfeedback = get_string('saveallfeedback', 'assignment');
     /// Some shortcuts to make the code read better
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $tabindex = 1;
     //tabindex for quick grading tabbing; Not working for dropdowns yet
     add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
     $navlinks = array();
     $navlinks[] = array('name' => $this->strassignments, 'link' => "index.php?id={$course->id}", 'type' => 'activity');
     $navlinks[] = array('name' => format_string($this->assignment->name, true), 'link' => "view.php?a={$this->assignment->id}", 'type' => 'activityinstance');
     $navlinks[] = array('name' => $this->strsubmissions, 'link' => '', 'type' => 'title');
     $navigation = build_navigation($navlinks);
     print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
     if (!empty($message)) {
         echo $message;
         // display messages here if any
     }
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     /// find out current groups mode
     $groupmode = groups_get_activity_groupmode($cm);
     $currentgroup = groups_get_activity_group($cm, true);
     groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id);
     /// Get all ppl that are allowed to submit assignments
     $users = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', $currentgroup, '', false);
     $users = array_keys($users);
     if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
         $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id');
         $users = array_intersect($users, array_keys($groupingusers));
     }
     $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
     if ($uses_outcomes) {
         $tablecolumns[] = 'outcome';
         // no sorting based on outcomes column
     }
     $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified') . ' (' . $course->student . ')', get_string('lastmodified') . ' (' . $course->teacher . ')', get_string('status'), get_string('finalgrade', 'grades'));
     if ($uses_outcomes) {
         $tableheaders[] = get_string('outcome', 'grades');
     }
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-assignment-submissions');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;currentgroup=' . $currentgroup);
     $table->sortable(true, 'lastname');
     //sorted by lastname by default
     $table->collapsible(true);
     $table->initialbars(true);
     $table->column_suppress('picture');
     $table->column_suppress('fullname');
     $table->column_class('picture', 'picture');
     $table->column_class('fullname', 'fullname');
     $table->column_class('grade', 'grade');
     $table->column_class('submissioncomment', 'comment');
     $table->column_class('timemodified', 'timemodified');
     $table->column_class('timemarked', 'timemarked');
     $table->column_class('status', 'status');
     $table->column_class('finalgrade', 'finalgrade');
     if ($uses_outcomes) {
         $table->column_class('outcome', 'outcome');
     }
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'submissions');
     $table->set_attribute('width', '90%');
     //$table->set_attribute('align', 'center');
     $table->no_sorting('finalgrade');
     $table->no_sorting('outcome');
     // Start working -- this is necessary as soon as the niceties are over
     $table->setup();
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:101,代码来源:lib.php

示例5: iomadcertificate_get_issues

/**
 * Returns a list of issued iomadcertificates - sorted for report.
 *
 * @param int $iomadcertificateid
 * @param string $sort the sort order
 * @param bool $groupmode are we in group mode ?
 * @param stdClass $cm the course module
 * @param int $page offset
 * @param int $perpage total per page
 * @return stdClass the users
 */
function iomadcertificate_get_issues($iomadcertificateid, $sort = "ci.timecreated ASC", $groupmode, $cm, $page = 0, $perpage = 0)
{
    global $CFG, $DB;
    // get all users that can manage this iomadcertificate to exclude them from the report.
    $context = context_module::instance($cm->id);
    $conditionssql = '';
    $conditionsparams = array();
    if ($certmanagers = array_keys(get_users_by_capability($context, 'mod/iomadcertificate:manage', 'u.id'))) {
        list($sql, $params) = $DB->get_in_or_equal($certmanagers, SQL_PARAMS_NAMED, 'cert');
        $conditionssql .= "AND NOT u.id {$sql} \n";
        $conditionsparams += $params;
    }
    $restricttogroup = false;
    if ($groupmode) {
        $currentgroup = groups_get_activity_group($cm);
        if ($currentgroup) {
            $restricttogroup = true;
            $groupusers = array_keys(groups_get_members($currentgroup, 'u.*'));
            if (empty($groupusers)) {
                return array();
            }
        }
    }
    $restricttogrouping = false;
    // if groupmembersonly used, remove users who are not in any group
    if (!empty($CFG->enablegroupings) and $cm->groupmembersonly) {
        if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
            $restricttogrouping = true;
        } else {
            return array();
        }
    }
    if ($restricttogroup || $restricttogrouping) {
        if ($restricttogroup) {
            $allowedusers = $groupusers;
        } else {
            if ($restricttogroup && $restricttogrouping) {
                $allowedusers = array_intersect($groupusers, $groupingusers);
            } else {
                $allowedusers = $groupingusers;
            }
        }
        list($sql, $params) = $DB->get_in_or_equal($allowedusers, SQL_PARAMS_NAMED, 'grp');
        $conditionssql .= "AND u.id {$sql} \n";
        $conditionsparams += $params;
    }
    $page = (int) $page;
    $perpage = (int) $perpage;
    // Get all the users that have iomadcertificates issued, should only be one issue per user for a iomadcertificate
    $allparams = $conditionsparams + array('iomadcertificateid' => $iomadcertificateid);
    $users = $DB->get_records_sql("SELECT u.*, ci.code, ci.timecreated\n                                   FROM {user} u\n                                   INNER JOIN {iomadcertificate_issues} ci\n                                   ON u.id = ci.userid\n                                   WHERE u.deleted = 0\n                                   AND ci.iomadcertificateid = :iomadcertificateid\n                                   {$conditionssql}\n                                   ORDER BY {$sort}", $allparams, $page * $perpage, $perpage);
    return $users;
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:64,代码来源:lib.php

示例6: display_submissions

 /**
  *  Display all the submissions ready for grading
  *
  * @global object
  * @global object
  * @global object
  * @global object
  * @param string $message
  * @return bool|void
  */
 function display_submissions($message = '')
 {
     global $CFG, $DB, $USER, $DB, $OUTPUT;
     require_once $CFG->libdir . '/gradelib.php';
     /* first we check to see if the form has just been submitted
      * to request user_preference updates
      */
     if (isset($_POST['updatepref'])) {
         $perpage = optional_param('perpage', 10, PARAM_INT);
         $perpage = $perpage <= 0 ? 10 : $perpage;
         set_user_preference('assignment_perpage', $perpage);
         set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
     }
     /* next we get perpage and quickgrade (allow quick grade) params
      * from database
      */
     $perpage = get_user_preferences('assignment_perpage', 10);
     $quickgrade = get_user_preferences('assignment_quickgrade', 0);
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
     if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
         $uses_outcomes = true;
     } else {
         $uses_outcomes = false;
     }
     $page = optional_param('page', 0, PARAM_INT);
     $strsaveallfeedback = get_string('saveallfeedback', 'assignment');
     /// Some shortcuts to make the code read better
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $tabindex = 1;
     //tabindex for quick grading tabbing; Not working for dropdowns yet
     add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->cm->id, $this->assignment->id, $this->cm->id);
     $navigation = build_navigation($this->strsubmissions, $this->cm);
     print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
     $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
     if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
         echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">' . get_string('seeallcoursegrades', 'grades') . '</a></div>';
     }
     if (!empty($message)) {
         echo $message;
         // display messages here if any
     }
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     /// Check to see if groups are being used in this assignment
     /// find out current groups mode
     $groupmode = groups_get_activity_groupmode($cm);
     $currentgroup = groups_get_activity_group($cm, true);
     groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id);
     /// Get all ppl that are allowed to submit assignments
     if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
         $users = array_keys($users);
     }
     // if groupmembersonly used, remove users who are not in any group
     if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
     $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
     if ($uses_outcomes) {
         $tablecolumns[] = 'outcome';
         // no sorting based on outcomes column
     }
     $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified') . ' (' . get_string('submission', 'assignment') . ')', get_string('lastmodified') . ' (' . get_string('grade') . ')', get_string('status'), get_string('finalgrade', 'grades'));
     if ($uses_outcomes) {
         $tableheaders[] = get_string('outcome', 'grades');
     }
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-assignment-submissions');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;currentgroup=' . $currentgroup);
     $table->sortable(true, 'lastname');
     //sorted by lastname by default
     $table->collapsible(true);
     $table->initialbars(true);
     $table->column_suppress('picture');
     $table->column_suppress('fullname');
     $table->column_class('picture', 'picture');
     $table->column_class('fullname', 'fullname');
     $table->column_class('grade', 'grade');
     $table->column_class('submissioncomment', 'comment');
     $table->column_class('timemodified', 'timemodified');
     $table->column_class('timemarked', 'timemarked');
     $table->column_class('status', 'status');
     $table->column_class('finalgrade', 'finalgrade');
     if ($uses_outcomes) {
         $table->column_class('outcome', 'outcome');
     }
//.........这里部分代码省略.........
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:lib.php

示例7: geogebra_view_results

function geogebra_view_results($geogebra, $context, $cm, $course, $action)
{
    global $CFG, $DB, $OUTPUT, $PAGE, $USER;
    if ($action == 'submitgrade') {
        // Upgrade submitted grade
        $grade = optional_param('grade', '', PARAM_INT);
        $gradecomment = optional_param_array('comment_editor', '', PARAM_RAW);
        $attemptid = optional_param('attemptid', '', PARAM_INT);
        $attempt = geogebra_get_attempt($attemptid);
        parse_str($attempt->vars, $parsedvars);
        $parsedvars['grade'] = $grade;
        $attempt->vars = http_build_query($parsedvars, '', '&');
        geogebra_update_attempt($attemptid, $attempt->vars, GEOGEBRA_UPDATE_TEACHER, $gradecomment['text']);
    }
    // Show students list with their results
    require_once $CFG->libdir . '/gradelib.php';
    $perpage = optional_param('perpage', 10, PARAM_INT);
    $perpage = $perpage <= 0 ? 10 : $perpage;
    $page = optional_param('page', 0, PARAM_INT);
    // Find out current groups mode
    $groupmode = groups_get_activity_groupmode($cm);
    $currentgroup = groups_get_activity_group($cm, true);
    // Get all ppl that are allowed to submit geogebra
    list($esql, $params) = get_enrolled_sql($context, 'mod/geogebra:submit', $currentgroup);
    $sql = "SELECT u.id FROM {user} u " . "LEFT JOIN ({$esql}) eu ON eu.id=u.id " . "WHERE u.deleted = 0 AND eu.id=u.id ";
    $users = $DB->get_records_sql($sql, $params);
    if (!empty($users)) {
        $users = array_keys($users);
    }
    // If groupmembersonly used, remove users who are not in any group
    if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
        if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
            $users = array_intersect($users, array_keys($groupingusers));
        }
    }
    // TODO: Review to show all users information
    if (!empty($users)) {
        // Create results table
        $extrafields = get_extra_user_fields($context);
        $tablecolumns = array_merge(array('picture', 'fullname'), $extrafields, array('attempts', 'duration', 'grade', 'comment', 'datestudent', 'dateteacher', 'status'));
        $extrafieldnames = array();
        foreach ($extrafields as $field) {
            $extrafieldnames[] = get_user_field_name($field);
        }
        $tableheaders = array_merge(array('', get_string('fullnameuser')), $extrafieldnames, array(get_string('attempts', 'geogebra'), get_string('duration', 'geogebra'), get_string('grade'), get_string('comment', 'geogebra'), get_string('lastmodifiedsubmission', 'geogebra'), get_string('lastmodifiedgrade', 'geogebra'), get_string('status', 'geogebra')));
        require_once $CFG->libdir . '/tablelib.php';
        $table = new flexible_table('mod-geogebra-results');
        $table->define_columns($tablecolumns);
        $table->define_headers($tableheaders);
        $table->define_baseurl($CFG->wwwroot . '/mod/geogebra/report.php?id=' . $cm->id . '&amp;currentgroup=' . $currentgroup);
        $table->sortable(true, 'lastname');
        // Sorted by lastname by default
        $table->collapsible(true);
        $table->initialbars(true);
        $table->column_suppress('picture');
        $table->column_suppress('fullname');
        $table->column_class('picture', 'picture');
        $table->column_class('fullname', 'fullname');
        foreach ($extrafields as $field) {
            $table->column_class($field, $field);
        }
        $table->set_attribute('cellspacing', '0');
        $table->set_attribute('id', 'attempts');
        $table->set_attribute('class', 'results generaltable generalbox');
        $table->set_attribute('width', '100%');
        $table->no_sorting('attempts');
        $table->no_sorting('duration');
        $table->no_sorting('grade');
        $table->no_sorting('comment');
        $table->no_sorting('datestudent');
        $table->no_sorting('dateteacher');
        $table->no_sorting('status');
        // Start working -- this is necessary as soon as the niceties are over
        $table->setup();
        // Construct the SQL
        list($where, $params) = $table->get_sql_where();
        if ($where) {
            $where .= ' AND ';
        }
        if ($sort = $table->get_sql_sort()) {
            $sort = ' ORDER BY ' . $sort;
        }
        $ufields = user_picture::fields('u', $extrafields);
        $select = "SELECT {$ufields} ";
        $sql = 'FROM {user} u WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') ';
        $ausers = $DB->get_records_sql($select . $sql . $sort, $params, $table->get_page_start(), $table->get_page_size());
        $table->pagesize($perpage, count($users));
        $offset = $page * $perpage;
        // Offset used to calculate index of student in that particular query, needed for the pop up to know who's next
        if ($ausers !== false) {
            // $grading_info = grade_get_grades($course->id, 'mod', 'geogebra', $geogebra->id, array_keys($ausers));
            foreach ($ausers as $auser) {
                $picture = $OUTPUT->user_picture($auser);
                $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&amp;course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $context)) . '</a>';
                $row = array($picture, $userlink);
                $extradata = array();
                foreach ($extrafields as $field) {
                    $extradata[] = $auser->{$field};
                }
                $row += $extradata;
//.........这里部分代码省略.........
开发者ID:ninelanterns,项目名称:moodle-mod_geogebra,代码行数:101,代码来源:locallib.php

示例8: get_sql_filter

 /**
  * get_sql_filter
  *
  * @param xxx $data
  * @return xxx
  */
 function get_sql_filter($data)
 {
     global $DB, $hotpot;
     $filter = '';
     $params = array();
     if (($value = $data['value']) && ($operator = $data['operator'])) {
         $userids = array();
         if (substr($value, 0, 5) == 'group') {
             if (substr($value, 5, 3) == 'ing') {
                 $gids = groups_get_all_groupings($hotpot->course->id);
                 $gid = intval(substr($value, 8));
                 if ($gids && array_key_exists($gid, $gids) && ($members = groups_get_grouping_members($gid))) {
                     $userids = array_keys($members);
                 }
             } else {
                 $gids = groups_get_all_groups($hotpot->course->id);
                 $gid = intval(substr($value, 5));
                 if ($gids && array_key_exists($gid, $gids) && ($members = groups_get_members($gid))) {
                     $userids = array_keys($members);
                 }
             }
         }
         if (count($userids)) {
             switch ($operator) {
                 case 1:
                     // is equal to
                     list($filter, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, '', true);
                     break;
                 case 2:
                     // isn't equal to
                     list($filter, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, '', false);
                     break;
             }
             if ($filter) {
                 $filter = 'id ' . $filter;
             }
         }
     }
     // no userids found
     return array($filter, $params);
 }
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:47,代码来源:userfiltering.php

示例9: certificate_get_issues

function certificate_get_issues($certificate, $user, $sort = "u.studentname ASC", $groupmode, $cm)
{
    global $CFG;
    //get all users that can manage this certificate to exclude them from the report.
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    $certmanagers = get_users_by_capability($context, 'mod/certificate:manage', 'u.id');
    //get all the users that have certificates issued.
    $users = get_records_sql("SELECT u.*,u.picture, s.code, s.timecreated, s.certdate, s.studentname, s.reportgrade\n                              FROM {$CFG->prefix}certificate_issues s,\n                                   {$CFG->prefix}user u\n                             WHERE s.certificateid = '{$certificate}'\n                               AND s.userid = u.id\n                               AND s.certdate > 0\n                             ORDER BY {$sort}");
    //now exclude all the certmanagers.
    foreach ($users as $id => $user) {
        if (isset($certmanagers[$id])) {
            //exclude certmanagers.
            unset($users[$id]);
        }
    }
    // if groupmembersonly used, remove users who are not in any group
    if (!empty($users) and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
        if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
            $users = array_intersect($users, array_keys($groupingusers));
        }
    }
    if (!$groupmode) {
        return $users;
    } else {
        $currentgroup = groups_get_activity_group($cm);
        if ($currentgroup) {
            $groupusers = groups_get_members($currentgroup, 'u.*');
            if (empty($groupusers)) {
                return array();
            }
            foreach ($groupusers as $id => $gpuser) {
                if (!isset($users[$id])) {
                    //remove this user as it isn't in the group!
                    unset($users[$id]);
                }
            }
        }
        return $users;
    }
}
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:40,代码来源:lib.php

示例10: get_gradebook_users

 /**
  * Returns a list of users by gradebook roles.
  */
 public function get_gradebook_users(array $userids = null)
 {
     global $DB, $CFG;
     // Must have gradebook roles.
     if (empty($CFG->gradebookroles)) {
         return null;
     }
     $gradebookroles = explode(", ", $CFG->gradebookroles);
     if (!($df = $this->df)) {
         return;
     }
     if (!empty($CFG->enablegroupings) and $df->cm->groupmembersonly) {
         $groupingsusers = groups_get_grouping_members($df->cm->groupingid, 'u.id', 'u.id');
         $gusers = $groupingsusers ? array_keys($groupingsusers) : null;
     }
     if (!empty($userids)) {
         if (!empty($gusers)) {
             $gusers = array_intersect($userids, $gusers);
         } else {
             $gusers = $userids;
         }
     }
     $roleusers = array();
     if (isset($gusers)) {
         if (!empty($gusers)) {
             list($inuids, $params) = $DB->get_in_or_equal($gusers, SQL_PARAMS_NAMED, 'u');
             foreach ($gradebookroles as $roleid) {
                 $roleusers = $roleusers + get_role_users($roleid, $df->context, true, user_picture::fields('u'), 'u.lastname ASC', true, $df->currentgroup, '', '', "u.id {$inuids}", $params);
             }
         }
     } else {
         foreach ($gradebookroles as $roleid) {
             $roleusers = $roleusers + get_role_users($roleid, $df->context, true, user_picture::fields('u'), 'u.lastname ASC', true, $df->currentgroup);
         }
     }
     return $roleusers;
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:40,代码来源:grade_manager.php

示例11: display_member_marking_window

 /**
  * display a marking popup window for teachers marking a team member's submission
  * teacher can not reverse student submission to draft.
  * @param $extra_javascript
  */
 function display_member_marking_window($extra_javascript)
 {
     global $CFG;
     require_once $CFG->libdir . '/gradelib.php';
     require_once $CFG->libdir . '/tablelib.php';
     $userid = required_param('userid', PARAM_INT);
     $offset = required_param('offset', PARAM_INT);
     //offset for where to start looking for student.
     if (!($user = get_record('user', 'id', $userid))) {
         error('No such user!');
     }
     if (!($submission = $this->get_submission($user->id))) {
         $submission = $this->prepare_new_submission($userid);
     }
     if ($submission->timemodified > $submission->timemarked) {
         $subtype = 'assignmentnew';
     } else {
         $subtype = 'assignmentold';
     }
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array($user->id));
     $disabled = $grading_info->items[0]->grades[$userid]->locked || $grading_info->items[0]->grades[$userid]->overridden;
     /// construct SQL, using current offset to find the data of the next student
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     /// Get all ppl that can submit assignments
     $currentgroup = groups_get_activity_group($cm);
     if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
         $users = array_keys($users);
     }
     // if groupmembersonly used, remove users who are not in any group
     if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
     $nextid = 0;
     if ($users) {
         $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
                           s.id AS submissionid, s.grade, s.submissioncomment,
                           s.timemodified, s.timemarked,
                           COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
         $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'assignment_submissions s ON u.id = s.userid
                                                                   AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE u.id IN (' . implode(',', $users) . ') ';
         if ($sort = flexible_table::get_sql_sort('mod-assignment-submissions')) {
             $sort = 'ORDER BY ' . $sort . ' ';
         }
         if (($auser = get_records_sql($select . $sql . $sort, $offset + 1, 1)) !== false) {
             $nextuser = array_shift($auser);
             /// Calculate user status
             $nextuser->status = $nextuser->timemarked > 0 && $nextuser->timemarked >= $nextuser->timemodified;
             $nextid = $nextuser->id;
         }
     }
     print_header(get_string('feedback', 'assignment') . ':' . fullname($user, true) . ':' . format_string($this->assignment->name));
     /// Print any extra javascript needed for saveandnext
     echo $extra_javascript;
     ///SOme javascript to help with setting up >.>
     echo '<script type="text/javascript">' . "\n";
     echo 'function setNext(){' . "\n";
     echo 'document.getElementById(\'submitform\').mode.value=\'next\';' . "\n";
     echo 'document.getElementById(\'submitform\').userid.value="' . $nextid . '";' . "\n";
     echo '}' . "\n";
     echo 'function saveNext(){' . "\n";
     echo 'document.getElementById(\'submitform\').mode.value=\'saveandnext\';' . "\n";
     echo 'document.getElementById(\'submitform\').userid.value="' . $nextid . '";' . "\n";
     echo 'document.getElementById(\'submitform\').saveuserid.value="' . $userid . '";' . "\n";
     echo 'document.getElementById(\'submitform\').menuindex.value = document.getElementById(\'submitform\').grade.selectedIndex;' . "\n";
     echo '}' . "\n";
     echo '</script>' . "\n";
     echo '<table cellspacing="0" class="feedback ' . $subtype . '" >';
     ///Start of teacher info row
     echo '<tr>';
     echo '<td class="picture teacher">';
     if ($submission->teacher) {
         $teacher = get_record('user', 'id', $submission->teacher);
     } else {
         global $USER;
         $teacher = $USER;
     }
     print_user_picture($teacher, $this->course->id, $teacher->picture);
     echo '</td>';
     echo '<td class="content">';
     echo '<form id="submitform" action="submissions.php" method="post">';
     echo '<div>';
     // xhtml compatibility - invisiblefieldset was breaking layout here
     echo '<input type="hidden" name="offset" value="' . ($offset + 1) . '" />';
     echo '<input type="hidden" name="userid" value="' . $userid . '" />';
     echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />';
     echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
     echo '<input type="hidden" name="mode" value="grade" />';
     echo '<input type="hidden" name="menuindex" value="0" />';
     //selected menu index
     //new hidden field, initialized to -1.
//.........这里部分代码省略.........
开发者ID:ruddj,项目名称:Moodle-2.0-Team-Assignment,代码行数:101,代码来源:assignment.class.php

示例12: display_submission

 /**
  *  Display a single submission, ready for grading on a popup window
  * Justin: I just lifted this from assignments/lib.php because  I needed to show the conversation entries properly.beneath the feedback form.
  * This default method prints the teacher info and submissioncomment box at the top and
  * the student info and submission at the bottom.
  * This method also fetches the necessary data in order to be able to
  * provide a "Next submission" button.
  * Calls preprocess_submission() to give assignment type plug-ins a chance
  * to process submissions before they are graded
  * This method gets its arguments from the page parameters userid and offset
  */
 function display_submission($extra_javascript = '')
 {
     global $CFG;
     require_once $CFG->libdir . '/gradelib.php';
     require_once $CFG->libdir . '/tablelib.php';
     $userid = required_param('userid', PARAM_INT);
     $offset = required_param('offset', PARAM_INT);
     //offset for where to start looking for student.
     if (!($user = get_record('user', 'id', $userid))) {
         error('No such user!');
     }
     if (!($submission = $this->get_submission($user->id))) {
         $submission = $this->prepare_new_submission($userid);
     }
     if ($submission->timemodified > $submission->timemarked) {
         $subtype = 'assignmentnew';
     } else {
         $subtype = 'assignmentold';
     }
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array($user->id));
     $disabled = $grading_info->items[0]->grades[$userid]->locked || $grading_info->items[0]->grades[$userid]->overridden;
     /// construct SQL, using current offset to find the data of the next student
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     /// Get all ppl that can submit assignments
     $currentgroup = groups_get_activity_group($cm);
     if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
         $users = array_keys($users);
     }
     // if groupmembersonly used, remove users who are not in any group
     if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
     $nextid = 0;
     if ($users) {
         $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
                           s.id AS submissionid, s.grade, s.submissioncomment,
                           s.timemodified, s.timemarked,
                           COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
         $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'assignment_submissions s ON u.id = s.userid
                                                                   AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE u.id IN (' . implode(',', $users) . ') ';
         if ($sort = flexible_table::get_sql_sort('mod-assignment-submissions')) {
             $sort = 'ORDER BY ' . $sort . ' ';
         }
         if (($auser = get_records_sql($select . $sql . $sort, $offset + 1, 1)) !== false) {
             $nextuser = array_shift($auser);
             /// Calculate user status
             $nextuser->status = $nextuser->timemarked > 0 && $nextuser->timemarked >= $nextuser->timemodified;
             $nextid = $nextuser->id;
         }
     }
     print_header(get_string('feedback', 'assignment') . ':' . fullname($user, true) . ':' . format_string($this->assignment->name));
     /// Print any extra javascript needed for saveandnext
     echo $extra_javascript;
     ///SOme javascript to help with setting up >.>
     echo '<script type="text/javascript">' . "\n";
     echo 'function setNext(){' . "\n";
     echo 'document.getElementById(\'submitform\').mode.value=\'next\';' . "\n";
     echo 'document.getElementById(\'submitform\').userid.value="' . $nextid . '";' . "\n";
     echo '}' . "\n";
     echo 'function saveNext(){' . "\n";
     echo 'document.getElementById(\'submitform\').mode.value=\'saveandnext\';' . "\n";
     echo 'document.getElementById(\'submitform\').userid.value="' . $nextid . '";' . "\n";
     echo 'document.getElementById(\'submitform\').saveuserid.value="' . $userid . '";' . "\n";
     echo 'document.getElementById(\'submitform\').menuindex.value = document.getElementById(\'submitform\').grade.selectedIndex;' . "\n";
     echo '}' . "\n";
     echo '</script>' . "\n";
     echo '<table cellspacing="0" class="feedback ' . $subtype . '" >';
     ///Start of teacher info row
     echo '<tr>';
     echo '<td class="picture teacher">';
     //Edited by justin 20081003: otherwise regardlss of which teacher is logged in ,
     //first teacher to write in journal would be shown,
     //if ($submission->teacher) {
     if (false) {
         $teacher = get_record('user', 'id', $submission->teacher);
     } else {
         global $USER;
         $teacher = $USER;
     }
     print_user_picture($teacher, $this->course->id, $teacher->picture);
     echo '</td>';
     echo '<td class="content">';
     echo '<form id="submitform" action="submissions.php" method="post">';
     echo '<div>';
//.........这里部分代码省略.........
开发者ID:laiello,项目名称:poodll,代码行数:101,代码来源:assignment.class.php

示例13: count_real_submissions

 function count_real_submissions($groupid = 0)
 {
     global $CFG;
     $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     // this is all the users with this capability set, in this context or higher
     if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $groupid, '', false)) {
         $users = array_keys($users);
     }
     // if groupmembersonly used, remove users who are not in any group
     if ($users and !empty($CFG->enablegroupings) and $this->cm->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($this->cm->groupingid, 'u.id', 'u.id')) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
     if (empty($users)) {
         return 0;
     }
     $userlists = implode(',', $users);
     // Count the number of assignments that have been submitted and for
     // which a response file has been generated (ie data2 = 'responded',
     // not 'submitted')
     $markedcount = count_records_sql("SELECT COUNT('x')\n                                FROM {$CFG->prefix}assignment_submissions\n                                WHERE assignment = {$this->cm->instance} AND\n                                data2 = '" . ASSIGNMENT_UPLOADPDF_STATUS_RESPONDED . "' AND\n                                userid IN ({$userlists})");
     // Count the number of assignments that have been submitted, but for
     // which a response file has not been generated (ie data2 = 'submitted',
     // not 'responded')
     $unmarkedcount = count_records_sql("SELECT COUNT('x')\n                                FROM {$CFG->prefix}assignment_submissions\n                                WHERE assignment = {$this->cm->instance} AND\n                                data2 = '" . ASSIGNMENT_UPLOADPDF_STATUS_SUBMITTED . "' AND\n                                userid IN ({$userlists})");
     $totalcount = $markedcount + $unmarkedcount;
     if ($unmarkedcount) {
         return "{$totalcount}({$unmarkedcount})";
     } else {
         return $totalcount;
     }
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:33,代码来源:assignment.class.php

示例14: get_context_instance

/// Determine if the current user can participate in this meeting.
$participant = false;
if ($elluminate->sessiontype == 1) {
    $mctx = get_context_instance(CONTEXT_MODULE, $cm->id);
    //Checks to see if the user is a participant in the private meeting
    if (elluminate_is_participant_in_meeting($elluminate, $USER->id)) {
        //then checks to make sure that the user role has the privilege to join a meeting
        $participant = $canjoinmeeting;
    }
} else {
    if ($elluminate->sessiontype == 3) {
        if ($accessallgroups) {
            $participant = $canjoinmeeting;
        } else {
            $isvaliduser = false;
            $groupingusers = groups_get_grouping_members($elluminate->groupingid);
            foreach ($groupingusers as $groupinguser) {
                if (!$isvaliduser) {
                    if ($groupinguser->id == $USER->id) {
                        $isvaliduser = true;
                    }
                    if ($elluminate->creator == $USER->id) {
                        $isvaliduser = true;
                    }
                }
            }
            if ($isvaliduser) {
                $participant = $canjoinmeeting;
            }
        }
    } else {
开发者ID:nadavkav,项目名称:Moodle2-Hebrew-plugins,代码行数:31,代码来源:view.php

示例15: download_zip

 /**
  * Creates a zip of all uploaded files and sends a zip to the browser
  * @param unknown $users false => empty zip, true all users, array files from users in array
  */
 public function download_zip($users = array())
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/filelib.php';
     $context = $this->get_context();
     $cm = $this->get_coursemodule();
     $conditions = array();
     $conditions['publication'] = $this->get_instance()->id;
     $filesforzipping = array();
     $fs = get_file_storage();
     $filearea = 'attachment';
     // Find out current groups mode.
     $groupmode = groups_get_activity_groupmode($this->get_coursemodule());
     $currentgroup = groups_get_activity_group($this->get_coursemodule(), true);
     // Get group name for filename.
     $groupname = '';
     // Get all ppl that are allowed to submit assignments.
     list($esql, $params) = get_enrolled_sql($context, 'mod/publication:view', $currentgroup);
     $showall = false;
     if (has_capability('mod/publication:approve', $context) || has_capability('mod/publication:grantextension', $context)) {
         $showall = true;
     }
     if (is_array($users) && count($users) > 0) {
         $customusers = " and u.id IN (" . implode($users, ', ') . ") ";
     } else {
         if ($users == false) {
             $customusers = " AND 1=2 ";
         }
     }
     if ($showall) {
         $sql = 'SELECT u.id FROM {user} u ' . 'LEFT JOIN (' . $esql . ') eu ON eu.id=u.id ' . 'WHERE u.deleted = 0 AND eu.id=u.id ' . $customusers;
     } else {
         $sql = 'SELECT u.id FROM {user} u ' . 'LEFT JOIN (' . $esql . ') eu ON eu.id=u.id ' . 'LEFT JOIN {publication_file} files ON (u.id = files.userid) ' . 'WHERE u.deleted = 0 AND eu.id=u.id ' . $customusers . 'AND files.publication = ' . $this->get_instance()->id . ' ';
         if ($this->get_instance()->mode == PUBLICATION_MODE_UPLOAD) {
             // Mode upload.
             if ($this->get_instance()->obtainteacherapproval) {
                 // Need teacher approval.
                 $where = 'files.teacherapproval = 1';
             } else {
                 // No need for teacher approval.
                 // Teacher only hasnt rejected.
                 $where = '(files.teacherapproval = 1 OR files.teacherapproval IS NULL)';
             }
         } else {
             // Mode import.
             if (!$this->get_instance()->obtainstudentapproval) {
                 // No need to ask student and teacher has approved.
                 $where = 'files.teacherapproval = 1';
             } else {
                 // Student and teacher have approved.
                 $where = 'files.teacherapproval = 1 AND files.studentapproval = 1';
             }
         }
         $sql .= 'AND ' . $where . ' ';
         $sql .= 'GROUP BY u.id';
     }
     $users = $DB->get_records_sql($sql, $params);
     if (!empty($users)) {
         $users = array_keys($users);
     }
     // If groupmembersonly used, remove users who are not in any group.
     if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
     $filename = str_replace(' ', '_', clean_filename($this->course->shortname . '-' . $this->get_instance()->name . '-' . $groupname . $this->get_instance()->id . '.zip'));
     // Name of new zip file.
     $userfields = get_all_user_name_fields();
     $userfields['id'] = 'id';
     $userfields['username'] = 'username';
     $userfields = implode(', ', $userfields);
     $viewfullnames = has_capability('moodle/site:viewfullnames', $this->context);
     // Get all files from each user.
     foreach ($users as $uploader) {
         $auserid = $uploader;
         $conditions['userid'] = $uploader;
         $records = $DB->get_records('publication_file', $conditions);
         $aassignid = $auserid;
         // Get name of this assignment for use in the file names.
         // Get user firstname/lastname.
         $auser = $DB->get_record('user', array('id' => $auserid), $userfields);
         foreach ($records as $record) {
             if (has_capability('mod/publication:approve', $this->get_context()) || $this->has_filepermission($record->fileid)) {
                 // Is teacher or file is public.
                 $file = $fs->get_file_by_id($record->fileid);
                 // Get files new name.
                 $fileext = strstr($file->get_filename(), '.');
                 $fileoriginal = str_replace($fileext, '', $file->get_filename());
                 $fileforzipname = clean_filename(($viewfullnames ? fullname($auser) : '') . '_' . $fileoriginal . '_' . $auserid . $fileext);
                 // Save file name to array for zipping.
                 $filesforzipping[$fileforzipname] = $file;
             }
         }
     }
     // End of foreach.
//.........这里部分代码省略.........
开发者ID:Kathrin84,项目名称:moodle-mod_publication,代码行数:101,代码来源:locallib.php


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