Merge branch 'wip-MDL-28954-master' of https://github.com/marinaglancy/moodle
This commit is contained in:
+26
-5
@@ -116,15 +116,18 @@ if ($hide && $cohort->id && confirm_sesskey()) {
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
$editoroptions = array('maxfiles'=>0, 'context'=>$context);
|
||||
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES,
|
||||
'maxbytes' => $SITE->maxbytes, 'context' => $context);
|
||||
if ($cohort->id) {
|
||||
// Edit existing.
|
||||
$cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions, $context);
|
||||
$cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions,
|
||||
$context, 'cohort', 'description', $cohort->id);
|
||||
$strheading = get_string('editcohort', 'cohort');
|
||||
|
||||
} else {
|
||||
// Add new.
|
||||
$cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions, $context);
|
||||
$cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions,
|
||||
$context, 'cohort', 'description', null);
|
||||
$strheading = get_string('addcohort', 'cohort');
|
||||
}
|
||||
|
||||
@@ -138,12 +141,30 @@ if ($editform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
|
||||
} else if ($data = $editform->get_data()) {
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $context);
|
||||
$oldcontextid = $context->id;
|
||||
$editoroptions['context'] = $context = context::instance_by_id($data->contextid);
|
||||
|
||||
if ($data->id) {
|
||||
if ($data->contextid != $oldcontextid) {
|
||||
// Cohort was moved to another context.
|
||||
get_file_storage()->move_area_files_to_new_context($oldcontextid, $context->id,
|
||||
'cohort', 'description', $data->id);
|
||||
}
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions,
|
||||
$context, 'cohort', 'description', $data->id);
|
||||
cohort_update_cohort($data);
|
||||
} else {
|
||||
cohort_add_cohort($data);
|
||||
$data->descriptionformat = $data->description_editor['format'];
|
||||
$data->description = $description = $data->description_editor['text'];
|
||||
$data->id = cohort_add_cohort($data);
|
||||
$editoroptions['context'] = $context = context::instance_by_id($data->contextid);
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions,
|
||||
$context, 'cohort', 'description', $data->id);
|
||||
if ($description != $data->description) {
|
||||
$updatedata = (object)array('id' => $data->id,
|
||||
'description' => $data->description, 'contextid' => $context->id);
|
||||
cohort_update_cohort($updatedata);
|
||||
}
|
||||
}
|
||||
|
||||
if ($returnurl->get_param('showall') || $returnurl->get_param('contextid') == $data->contextid) {
|
||||
|
||||
@@ -122,6 +122,8 @@ $editcolumnisempty = true;
|
||||
foreach($cohorts['cohorts'] as $cohort) {
|
||||
$line = array();
|
||||
$cohortcontext = context::instance_by_id($cohort->contextid);
|
||||
$cohort->description = file_rewrite_pluginfile_urls($cohort->description, 'pluginfile.php', $cohortcontext->id,
|
||||
'cohort', 'description', $cohort->id);
|
||||
if ($showall) {
|
||||
if ($cohortcontext->contextlevel == CONTEXT_COURSECAT) {
|
||||
$line[] = html_writer::link(new moodle_url('/cohort/index.php' ,
|
||||
|
||||
@@ -4199,6 +4199,35 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
} else if ($component === 'cohort') {
|
||||
|
||||
$cohortid = (int)array_shift($args);
|
||||
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
|
||||
$cohortcontext = context::instance_by_id($cohort->contextid);
|
||||
|
||||
// The context in the file URL must be either cohort context or context of the course underneath the cohort's context.
|
||||
if ($context->id != $cohort->contextid &&
|
||||
($context->contextlevel != CONTEXT_COURSE || !in_array($cohort->contextid, $context->get_parent_context_ids()))) {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
// User is able to access cohort if they have view cap on cohort level or
|
||||
// the cohort is visible and they have view cap on course level.
|
||||
$canview = has_capability('moodle/cohort:view', $cohortcontext) ||
|
||||
($cohort->visible && has_capability('moodle/cohort:view', $context));
|
||||
|
||||
if ($filearea === 'description' && $canview) {
|
||||
$filename = array_pop($args);
|
||||
$filepath = $args ? '/'.implode('/', $args).'/' : '/';
|
||||
if (($file = $fs->get_file($cohortcontext->id, 'cohort', 'description', $cohort->id, $filepath, $filename))
|
||||
&& !$file->is_directory()) {
|
||||
\core\session\manager::write_close(); // Unlock session during file serving.
|
||||
send_stored_file($file, 60 * 60, 0, $forcedownload, array('preview' => $preview));
|
||||
}
|
||||
}
|
||||
|
||||
send_file_not_found();
|
||||
|
||||
} else if ($component === 'group') {
|
||||
if ($context->contextlevel != CONTEXT_COURSE) {
|
||||
send_file_not_found();
|
||||
|
||||
Reference in New Issue
Block a user