/**
* Function to display a teacher's available exams. This uses all the
* courses that a teacher is enrolled in and checks which course has
* exams related to it. Shows the exam, the date and adds a
*/
function display_exams_list()
{
global $DB, $CFG, $USER;
$IP_Address = $tableName = 'Exams';
$user_table = 'user';
$table = new html_table();
$table->head = array('Course', 'Date', 'Navigation');
$table->tablealign = 'center';
$table->width = '100%';
$user_courses = enrol_get_users_courses($USER->id, true, '*', 'visible DESC,sortorder ASC');
/**
* Checks the teachers courses with available tests and if exists add to the main page.
*/
foreach ($user_courses as $uc) {
$rec = $DB->get_records_sql('SELECT booklet_id, year_semester_origin
FROM {mem_booklet_data}
WHERE course_id=?', array(intval($uc->id)));
$row_info = array();
if (count($rec) > 0) {
$row = new html_table_row(array($uc->fullname, current($rec)->year_semester_origin, '<div style="text-align: center"><a href=' . $CFG->wwwroot . '/local/memplugin/grid.php?course_id=' . intval($uc->id) . '>' . get_string('startmarking', 'local_memplugin') . '</a></div>'));
$table->data[] = $row;
}
}
echo html_writer::table($table);
}
public function get_content() {
global $DB;
if ($this->content !== null) {
return $this->content;
}
global $CFG, $USER, $PAGE;
$this->content = new stdClass();
require_once($CFG->dirroot.'/blocks/queries/lib.php');
require_once($CFG->dirroot.'/blocks/queries/commentform.php');
require_once($CFG->dirroot.'/blocks/queries/queries_form.php');
//query to enrol users courses particulars
$courses = enrol_get_users_courses($USER->id);
//calling function for if login user instructor or not
$instructorlogin = block_queries_getrole_user($courses,'instructor');
//calling function for if login user registrar or not
$registrarlogin = block_queries_getrole_user($courses,'registrar');
//calling function for if login user student or not
$studentlogin = block_queries_getrole_user($courses,'student');
/************calling function for getting data to the logged in user*************/
$this->content->text = block_queries_display_view($USER,$instructorlogin,$registrarlogin,$studentlogin);
$this->content->footer = '';
$this->page->requires->js('/blocks/queries/js/commentform_popup.js');
// Return the content object
return $this->content;
}
/**
* Get list of courses user is enrolled in (only active enrolments are returned).
* Please note the current user must be able to access the course, otherwise the course is not included.
*
* @param int $userid
* @return array of courses
*/
public static function get_users_courses($userid)
{
global $USER, $DB;
// Do basic automatic PARAM checks on incoming data, using params description
// If any problems are found then exceptions are thrown with helpful error messages
$params = self::validate_parameters(self::get_users_courses_parameters(), array('userid' => $userid));
$courses = enrol_get_users_courses($params['userid'], true, 'id, shortname, fullname, idnumber, visible');
$result = array();
foreach ($courses as $course) {
$context = context_course::instance($course->id, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
// current user can not access this course, sorry we can not disclose who is enrolled in this course!
continue;
}
if ($userid != $USER->id and !has_capability('moodle/course:viewparticipants', $context)) {
// we need capability to view participants
continue;
}
list($enrolledsqlselect, $enrolledparams) = get_enrolled_sql($context);
$enrolledsql = "SELECT COUNT(*) FROM ({$enrolledsqlselect}) AS enrolleduserids";
$enrolledusercount = $DB->count_records_sql($enrolledsql, $enrolledparams);
$result[] = array('id' => $course->id, 'shortname' => $course->shortname, 'fullname' => $course->fullname, 'idnumber' => $course->idnumber, 'visible' => $course->visible, 'enrolledusercount' => $enrolledusercount);
}
return $result;
}
function definition()
{
global $CFG, $DB, $USER;
$mform = $this->_form;
$attributes_heading = 'size="24"';
$attributes_radio_text = 'size="11"';
//General Section.
$mform->addElement('header', 'general', get_string('genheader', 'local_memplugin'));
//Get list of logged in user's enrolled courses and display as checkboxes.
$user_courses = enrol_get_users_courses($USER->id, true, '*', 'visible DESC,sortorder ASC');
$select_course_array = array();
$select_course_array[0] = '';
// Add a blank space to the select box.
$selectgroup = array();
//TODO Remove below Select code for checkboxes instead of dropdown
foreach ($user_courses as $uc) {
$select_course_array[$uc->id] = $uc->fullname;
}
$selectgroup[] = $mform->createElement('select', 'coursechoices', get_string('sectionheader', 'local_memplugin'), $select_course_array);
$mform->addElement('group', 'courseselect', get_string('courses', 'local_memplugin'), $selectgroup, array('<br>'), false);
//TODO For now we can only handle one course section but uncomment the following and get rid of the above
//Selection items to make it checkboxes again.
/*
foreach ($user_courses as $uc){
$courses_group[] =& $mform->createElement('advcheckbox', 'courseboxes['.$uc->id.']', null, $uc->fullname, array('group'=>0),array(0,1));
}
$mform->addElement('group', 'courseselect', get_string('courses', 'local_memplugin'), $courses_group, array('<br>'), false);
*/
$mform->addElement('header', 'fileheader', get_string('file', 'local_memplugin'));
//Switch to a filepicker for now until we figure out how it works.
//$mform->addElement('filemanager', 'files', get_string('exambatch', 'local_memplugin'), null, array('accepted_types' => 'image/png'));
$mform->addElement('filepicker', 'userfile', get_string('exambatch', 'local_memplugin'), null, array('accepted_types' => 'application/zip'));
$mform->closeHeaderBefore('buttonar');
$buttonarray = array();
//$buttonarray[] =& $mform->createElement('submit','savebutton', get_string('savebutton', 'local_memplugin'));
$buttonarray[] =& $mform->createElement('submit', 'markbutton', get_string('markbutton', 'local_memplugin'));
$buttonarray[] =& $mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
}
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
* @param int $userid
* @param object $gpr grade plugin return tracking object
* @param string $context
*/
public function __construct($userid, $gpr, $context)
{
global $CFG, $COURSE, $DB;
parent::__construct($COURSE->id, $gpr, $context);
// Get the user (for full name).
$this->user = $DB->get_record('user', array('id' => $userid));
// Load the user's courses.
$this->courses = enrol_get_users_courses($this->user->id, false, 'id, shortname, showgrades');
$this->showrank = array();
$this->showrank['any'] = false;
$this->showtotalsifcontainhidden = array();
$this->studentcourseids = array();
$this->teachercourses = array();
$roleids = explode(',', get_config('moodle', 'gradebookroles'));
if ($this->courses) {
foreach ($this->courses as $course) {
$this->showrank[$course->id] = grade_get_setting($course->id, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
if ($this->showrank[$course->id]) {
$this->showrank['any'] = true;
}
$this->showtotalsifcontainhidden[$course->id] = grade_get_setting($course->id, 'report_overview_showtotalsifcontainhidden', $CFG->grade_report_overview_showtotalsifcontainhidden);
$coursecontext = context_course::instance($course->id);
foreach ($roleids as $roleid) {
if (user_has_role_assignment($userid, $roleid, $coursecontext->id)) {
$this->studentcourseids[$course->id] = $course->id;
// We only need to check if one of the roleids has been assigned.
break;
}
}
if (has_capability('moodle/grade:viewall', $coursecontext, $userid)) {
$this->teachercourses[$course->id] = $course;
}
}
}
// base url for sorting by first/last name
$this->baseurl = $CFG->wwwroot . '/grade/overview/index.php?id=' . $userid;
$this->pbarurl = $this->baseurl;
$this->setup_table();
}
开发者ID:grug,项目名称:moodle,代码行数:45,代码来源:lib.php
示例11: count_unread_and_courses_messages
/**
* Returns unread messages count and courses
* @return array
*/
public static function count_unread_and_courses_messages($userid = '0')
{
global $DB, $USER;
//Parameter validation
//REQUIRED
$params = self::validate_parameters(self::count_unread_messages_parameters(), array('userid' => $userid));
//Context validation
//OPTIONAL but in most web service it should present
$context = get_context_instance(CONTEXT_USER, $USER->id);
self::validate_context($context);
//Capability checking
//OPTIONAL but in most web service it should present
if (!has_capability('moodle/user:viewdetails', $context)) {
throw new moodle_exception('cannotviewprofile');
}
$messagecount = $DB->count_records_select('message', 'useridto=' . (int) $userid);
$courses = enrol_get_users_courses($params['userid'], true, 'id, shortname, fullname, idnumber, visible');
$result = array('messagecount' => $messagecount, 'courses' => array());
foreach ($courses as $course) {
$context = context_course::instance($course->id, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
// current user can not access this course, sorry we can not disclose who is enrolled in this course!
continue;
}
if ($userid != $USER->id and !has_capability('moodle/course:viewparticipants', $context)) {
// we need capability to view participants
continue;
}
list($enrolledsqlselect, $enrolledparams) = get_enrolled_sql($context);
$enrolledsql = "SELECT COUNT('x') FROM ({$enrolledsqlselect}) enrolleduserids";
$enrolledusercount = $DB->count_records_sql($enrolledsql, $enrolledparams);
$result['courses'][] = array('id' => $course->id, 'shortname' => $course->shortname, 'fullname' => $course->fullname, 'idnumber' => $course->idnumber, 'visible' => $course->visible, 'enrolledusercount' => $enrolledusercount);
}
return $result;
}
/**
* Get list of courses user is enrolled in (only active enrolments are returned).
*
* Please note the current user must be able to access the course, otherwise the course is not included.
*
* @param int $userid
* @return array of courses
*/
public static function get_users_courses($userid)
{
global $USER;
// Do basic automatic PARAM checks on incoming data, using params description
// If any problems are found then exceptions are thrown with helpful error messages
$params = self::validate_parameters(self::get_users_courses_parameters(), array('userid' => $userid));
$courses = enrol_get_users_courses($params['userid'], true, 'id, shortname, fullname, idnumber, visible');
$result = array();
foreach ($courses as $course) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
try {
self::validate_context($context);
} catch (Exception $e) {
// current user can not access this course, sorry we can not disclose who is enrolled in this course!
continue;
}
if ($userid != $USER->id and !has_capability('moodle/course:viewparticipants', $context)) {
// we need capability to view participants
continue;
}
$result[] = array('id' => $course->id, 'shortname' => $course->shortname, 'fullname' => $course->fullname, 'idnumber' => $course->idnumber, 'visible' => $course->visible);
}
return $result;
}
function att_get_user_courses_attendances($userid)
{
global $DB;
$usercourses = enrol_get_users_courses($userid);
list($usql, $uparams) = $DB->get_in_or_equal(array_keys($usercourses), SQL_PARAMS_NAMED, 'cid0');
$sql = "SELECT att.id as attid, att.course as courseid, course.fullname as coursefullname,\n course.startdate as coursestartdate, att.name as attname, att.grade as attgrade\n FROM {attendance} att\n JOIN {course} course\n ON att.course = course.id\n WHERE att.course {$usql}\n ORDER BY coursefullname ASC, attname ASC";
$params = array_merge($uparams, array('uid' => $userid));
return $DB->get_records_sql($sql, $params);
}
/**
* Tries to obtain user details, either recurring directly to the user's system profile
* or through one of the user's course enrollments (course profile).
*
* @param object $user The user.
* @return array if unsuccessful or the allowed user details.
*/
function user_get_user_details_courses($user)
{
global $USER;
$userdetails = null;
// Get the courses that the user is enrolled in (only active).
$courses = enrol_get_users_courses($user->id, true);
$systemprofile = false;
if (can_view_user_details_cap($user) || $user->id == $USER->id || has_coursecontact_role($user->id)) {
$systemprofile = true;
}
// Try using system profile.
if ($systemprofile) {
$userdetails = user_get_user_details($user, null);
} else {
// Try through course profile.
foreach ($courses as $course) {
if (can_view_user_details_cap($user, $course) || $user->id == $USER->id || has_coursecontact_role($user->id)) {
$userdetails = user_get_user_details($user, $course);
}
}
}
return $userdetails;
}
请发表评论