/**
* get all resources!
*
*/
function block_resources_get_all_resources()
{
global $DB;
// get courses list in wich logged user was enrolled
$courses = enrol_get_my_courses();
if (empty($courses)) {
return false;
}
$ids = implode(',', array_keys($courses));
// --------- cycle by courses
foreach ($courses as $key => $course) {
if (!isset($courses[$key]->resources)) {
$courses[$key]->resources = array();
}
// get videoresources list from courses and then render it
// * link to videoresource = link to course modules
$courses[$key]->videoresources = get_coursemodules_in_course('videoresource', $course->id);
}
// get resources list from all courses with AVG rating
$resources = $DB->get_records_sql('
SELECT DISTINCT rl.course * 10000 + si.id as id, si.id as section_id, rl.course, r.id as resource_id, r.url, r.title, r.internal_title, r.description, r.author, r.source
, (SELECT AVG(t.rating) FROM mdl_rating t
LEFT JOIN mdl_resource_section_items si ON si.id = t.itemid WHERE si.resource_item_id = r.id) as avgrate
FROM mdl_resourcelib rl
RIGHT JOIN mdl_resourcelib_content rc ON rl.id = rc.resourcelib_id
RIGHT JOIN mdl_resource_lists l ON rc.instance_id = l.id
RIGHT JOIN mdl_resource_list_sections ls ON l.id = ls.resource_list_id
RIGHT JOIN mdl_resource_section_items si ON ls.resource_section_id = si.resource_section_id
RIGHT JOIN mdl_resource_items r ON r.id = si.resource_item_id
WHERE rl.course IN (' . $ids . ')
ORDER BY ls.sort_order, si.sort_order');
foreach ($resources as $key => $resource) {
if (!isset($courses[$resource->course]->resources[$resource->resource_id])) {
$courses[$resource->course]->resources[$resource->resource_id] = $resource;
}
}
return $courses;
}
/**
* Returns an array of courses the user is enrolled, and for each course all of the assignments that the user can
* view within that course.
*
* @param array $courseids An optional array of course ids. If provided only assignments within the given course
* will be returned. If the user is not enrolled in or can't view a given course a warning will be generated and returned.
* @param array $capabilities An array of additional capability checks you wish to be made on the course context.
* @param bool $includenotenrolledcourses Wheter to return courses that the user can see even if is not enroled in.
* This requires the parameter $courseids to not be empty.
* @return An array of courses and warnings.
* @since Moodle 2.4
*/
public static function get_assignments($courseids = array(), $capabilities = array(), $includenotenrolledcourses = false)
{
global $USER, $DB, $CFG;
$params = self::validate_parameters(self::get_assignments_parameters(), array('courseids' => $courseids, 'capabilities' => $capabilities, 'includenotenrolledcourses' => $includenotenrolledcourses));
$warnings = array();
$courses = array();
$fields = 'sortorder,shortname,fullname,timemodified';
// If the courseids list is empty, we return only the courses where the user is enrolled in.
if (empty($params['courseids'])) {
$courses = enrol_get_users_courses($USER->id, true, $fields);
$courseids = array_keys($courses);
} else {
if ($includenotenrolledcourses) {
// In this case, we don't have to check here for enrolmnents. Maybe the user can see the course even if is not enrolled.
$courseids = $params['courseids'];
} else {
// We need to check for enrolments.
$mycourses = enrol_get_users_courses($USER->id, true, $fields);
$mycourseids = array_keys($mycourses);
foreach ($params['courseids'] as $courseid) {
if (!in_array($courseid, $mycourseids)) {
unset($courses[$courseid]);
$warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => '2', 'message' => 'User is not enrolled or does not have requested capability');
} else {
$courses[$courseid] = $mycourses[$courseid];
}
}
$courseids = array_keys($courses);
}
}
foreach ($courseids as $cid) {
try {
$context = context_course::instance($cid);
self::validate_context($context);
// Check if this course was already loaded (by enrol_get_users_courses).
if (!isset($courses[$cid])) {
$courses[$cid] = get_course($cid);
}
$courses[$cid]->contextid = $context->id;
} catch (Exception $e) {
unset($courses[$cid]);
$warnings[] = array('item' => 'course', 'itemid' => $cid, 'warningcode' => '1', 'message' => 'No access rights in course context ' . $e->getMessage());
continue;
}
if (count($params['capabilities']) > 0 && !has_all_capabilities($params['capabilities'], $context)) {
unset($courses[$cid]);
}
}
$extrafields = 'm.id as assignmentid, ' . 'm.course, ' . 'm.nosubmissions, ' . 'm.submissiondrafts, ' . 'm.sendnotifications, ' . 'm.sendlatenotifications, ' . 'm.sendstudentnotifications, ' . 'm.duedate, ' . 'm.allowsubmissionsfromdate, ' . 'm.grade, ' . 'm.timemodified, ' . 'm.completionsubmit, ' . 'm.cutoffdate, ' . 'm.teamsubmission, ' . 'm.requireallteammemberssubmit, ' . 'm.teamsubmissiongroupingid, ' . 'm.blindmarking, ' . 'm.revealidentities, ' . 'm.attemptreopenmethod, ' . 'm.maxattempts, ' . 'm.markingworkflow, ' . 'm.markingallocation, ' . 'm.requiresubmissionstatement, ' . 'm.preventsubmissionnotingroup, ' . 'm.intro, ' . 'm.introformat';
$coursearray = array();
foreach ($courses as $id => $course) {
$assignmentarray = array();
// Get a list of assignments for the course.
if ($modules = get_coursemodules_in_course('assign', $courses[$id]->id, $extrafields)) {
foreach ($modules as $module) {
$context = context_module::instance($module->id);
try {
self::validate_context($context);
require_capability('mod/assign:view', $context);
} catch (Exception $e) {
$warnings[] = array('item' => 'module', 'itemid' => $module->id, 'warningcode' => '1', 'message' => 'No access rights in module context');
continue;
}
$assign = new assign($context, null, null);
// Get configurations for only enabled plugins.
$plugins = $assign->get_submission_plugins();
$plugins = array_merge($plugins, $assign->get_feedback_plugins());
$configarray = array();
foreach ($plugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible()) {
$configrecords = $plugin->get_config_for_external();
foreach ($configrecords as $name => $value) {
$configarray[] = array('plugin' => $plugin->get_type(), 'subtype' => $plugin->get_subtype(), 'name' => $name, 'value' => $value);
}
}
}
$assignment = array('id' => $module->assignmentid, 'cmid' => $module->id, 'course' => $module->course, 'name' => $module->name, 'nosubmissions' => $module->nosubmissions, 'submissiondrafts' => $module->submissiondrafts, 'sendnotifications' => $module->sendnotifications, 'sendlatenotifications' => $module->sendlatenotifications, 'sendstudentnotifications' => $module->sendstudentnotifications, 'duedate' => $module->duedate, 'allowsubmissionsfromdate' => $module->allowsubmissionsfromdate, 'grade' => $module->grade, 'timemodified' => $module->timemodified, 'completionsubmit' => $module->completionsubmit, 'cutoffdate' => $module->cutoffdate, 'teamsubmission' => $module->teamsubmission, 'requireallteammemberssubmit' => $module->requireallteammemberssubmit, 'teamsubmissiongroupingid' => $module->teamsubmissiongroupingid, 'blindmarking' => $module->blindmarking, 'revealidentities' => $module->revealidentities, 'attemptreopenmethod' => $module->attemptreopenmethod, 'maxattempts' => $module->maxattempts, 'markingworkflow' => $module->markingworkflow, 'markingallocation' => $module->markingallocation, 'requiresubmissionstatement' => $module->requiresubmissionstatement, 'preventsubmissionnotingroup' => $module->preventsubmissionnotingroup, 'configs' => $configarray);
// Return or not intro and file attachments depending on the plugin settings.
if ($assign->show_intro()) {
list($assignment['intro'], $assignment['introformat']) = external_format_text($module->intro, $module->introformat, $context->id, 'mod_assign', 'intro', null);
$assignment['introfiles'] = external_util::get_area_files($context->id, 'mod_assign', 'intro', false, false);
$assignment['introattachments'] = external_util::get_area_files($context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0);
}
if ($module->requiresubmissionstatement) {
// Submission statement is required, return the submission statement value.
$adminconfig = get_config('assign');
list($assignment['submissionstatement'], $assignment['submissionstatementformat']) = external_format_text($adminconfig->submissionstatement, FORMAT_MOODLE, $context->id, 'mod_assign', '', 0);
}
//.........这里部分代码省略.........
/**
* This function is used by the reset_course_userdata function in moodlelib.
* This function will remove all posts from the specified vpl instance
* and clean up any related data.
* @param $data the data submitted from the reset course.
* @return array status array
*/
function vpl_reset_userdata($data)
{
global $CFG, $DB;
$status = array();
if ($data->reset_vpl_submissions) {
$componentstr = get_string('modulenameplural', VPL);
if ($cms = get_coursemodules_in_course(VPL, $data->courseid)) {
foreach ($cms as $cmid => $cm) {
//For each vpl instance in course
$vpl = new mod_vpl($cmid);
$instance = $vpl->get_instance();
//Delete submissions records
$DB->delete_records(VPL_SUBMISSIONS, array('vpl' => $instance->id));
//Delete variations assigned
$DB->delete_records(VPL_ASSIGNED_VARIATIONS, array('vpl' => $instance->id));
//Delete submission files
fulldelete($CFG->dataroot . '/vpl_data/' . $data->courseid . '/' . $instance->id . '/usersdata');
$status[] = array('component' => $componentstr, 'item' => get_string('resetvpl', VPL, $instance->name), 'error' => false);
}
}
}
return $status;
}
/**
* Returns a recordset of emarking objects which are in courses parallel
* to a course parameter
*
* @param unknown $course
* @param unknown $includeown
* @return multitype:
*/
function emarking_get_parallel_emarkings($course, $includeown)
{
global $DB;
$parallelcourses = emarking_get_parallel_courses($course, $includeown);
if (!$parallelcourses) {
return false;
}
$parallelsids = array();
foreach ($parallelcourses as $parallelcourse) {
if ($parallelcourse->id == $course->id) {
continue;
}
foreach (get_coursemodules_in_course('emarking', $parallelcourse->id) as $cmdst) {
$parallelsids[] = $cmdst->instance;
}
}
$parallelsids = implode(",", $parallelsids);
$parallelemarkings = $DB->get_records_sql("\n SELECT e.*, c.id as courseid, c.shortname, c.fullname\n FROM {emarking} AS e\n INNER JOIN {course} AS c ON (e.course = c.id AND c.id <> ?)\n WHERE e.id IN ({$parallelsids})\n ORDER BY c.fullname, e.name", array($course->id));
return $parallelemarkings;
}
请发表评论