mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
Merge branch 'MDL-54965-master' of git://github.com/tobiasreischmann/moodle
This commit is contained in:
commit
64ea4b5edd
2 changed files with 29 additions and 63 deletions
|
@ -26,13 +26,8 @@ class data_field_file extends data_field_base {
|
||||||
var $type = 'file';
|
var $type = 'file';
|
||||||
|
|
||||||
function display_add_field($recordid = 0, $formdata = null) {
|
function display_add_field($recordid = 0, $formdata = null) {
|
||||||
global $CFG, $DB, $OUTPUT, $PAGE, $USER;
|
global $DB, $OUTPUT, $PAGE;
|
||||||
|
|
||||||
$file = false;
|
|
||||||
$content = false;
|
|
||||||
$displayname = '';
|
|
||||||
$fs = get_file_storage();
|
|
||||||
$context = $PAGE->context;
|
|
||||||
$itemid = null;
|
$itemid = null;
|
||||||
|
|
||||||
// editing an existing database entry
|
// editing an existing database entry
|
||||||
|
@ -40,27 +35,16 @@ class data_field_file extends data_field_base {
|
||||||
$fieldname = 'field_' . $this->field->id . '_file';
|
$fieldname = 'field_' . $this->field->id . '_file';
|
||||||
$itemid = clean_param($formdata->$fieldname, PARAM_INT);
|
$itemid = clean_param($formdata->$fieldname, PARAM_INT);
|
||||||
} else if ($recordid) {
|
} else if ($recordid) {
|
||||||
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
|
if (!$content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
|
||||||
|
// Quickly make one now!
|
||||||
file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id);
|
$content = new stdClass();
|
||||||
|
$content->fieldid = $this->field->id;
|
||||||
if (!empty($content->content)) {
|
$content->recordid = $recordid;
|
||||||
if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
|
$id = $DB->insert_record('data_content', $content);
|
||||||
$usercontext = context_user::instance($USER->id);
|
$content = $DB->get_record('data_content', array('id' => $id));
|
||||||
if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (empty($content->content1)) {
|
|
||||||
// Print icon if file already exists
|
|
||||||
$src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename());
|
|
||||||
$displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')). '<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$displayname = 'no file added';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$itemid = file_get_unused_draft_itemid();
|
$itemid = file_get_unused_draft_itemid();
|
||||||
}
|
}
|
||||||
|
@ -170,15 +154,8 @@ class data_field_file extends data_field_base {
|
||||||
global $CFG, $DB, $USER;
|
global $CFG, $DB, $USER;
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
|
|
||||||
if (!$content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
|
// Should always be available since it is set by display_add_field before initializing the draft area.
|
||||||
|
$content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid));
|
||||||
// Quickly make one now!
|
|
||||||
$content = new stdClass();
|
|
||||||
$content->fieldid = $this->field->id;
|
|
||||||
$content->recordid = $recordid;
|
|
||||||
$id = $DB->insert_record('data_content', $content);
|
|
||||||
$content = $DB->get_record('data_content', array('id'=>$id));
|
|
||||||
}
|
|
||||||
|
|
||||||
file_save_draft_area_files($value, $this->context->id, 'mod_data', 'content', $content->id);
|
file_save_draft_area_files($value, $this->context->id, 'mod_data', 'content', $content->id);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ class data_field_picture extends data_field_base {
|
||||||
|
|
||||||
$file = false;
|
$file = false;
|
||||||
$content = false;
|
$content = false;
|
||||||
$displayname = '';
|
|
||||||
$alttext = '';
|
$alttext = '';
|
||||||
$itemid = null;
|
$itemid = null;
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
|
@ -45,29 +44,25 @@ class data_field_picture extends data_field_base {
|
||||||
$alttext = $formdata->$fieldname;
|
$alttext = $formdata->$fieldname;
|
||||||
}
|
}
|
||||||
} else if ($recordid) {
|
} else if ($recordid) {
|
||||||
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
|
if (!$content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
|
||||||
file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id);
|
// Quickly make one now!
|
||||||
if (!empty($content->content)) {
|
$content = new stdClass();
|
||||||
if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
|
$content->fieldid = $this->field->id;
|
||||||
$usercontext = context_user::instance($USER->id);
|
$content->recordid = $recordid;
|
||||||
if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false)) {
|
$id = $DB->insert_record('data_content', $content);
|
||||||
return false;
|
$content = $DB->get_record('data_content', array('id' => $id));
|
||||||
}
|
}
|
||||||
if ($thumbfile = $fs->get_file($usercontext->id, 'user', 'draft', $itemid, '/', 'thumb_'.$content->content)) {
|
file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id);
|
||||||
$thumbfile->delete();
|
if (!empty($content->content)) {
|
||||||
}
|
if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
|
||||||
if (empty($content->content1)) {
|
$usercontext = context_user::instance($USER->id);
|
||||||
// Print icon if file already exists
|
|
||||||
$src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename());
|
|
||||||
$displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')). '<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
|
|
||||||
|
|
||||||
} else {
|
if ($thumbfile = $fs->get_file($usercontext->id, 'user', 'draft', $itemid, '/', 'thumb_'.$content->content)) {
|
||||||
$displayname = get_string('nofilesattached', 'repository');
|
$thumbfile->delete();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$alttext = $content->content1;
|
|
||||||
}
|
}
|
||||||
|
$alttext = $content->content1;
|
||||||
} else {
|
} else {
|
||||||
$itemid = file_get_unused_draft_itemid();
|
$itemid = file_get_unused_draft_itemid();
|
||||||
}
|
}
|
||||||
|
@ -228,14 +223,8 @@ class data_field_picture extends data_field_base {
|
||||||
function update_content($recordid, $value, $name='') {
|
function update_content($recordid, $value, $name='') {
|
||||||
global $CFG, $DB, $USER;
|
global $CFG, $DB, $USER;
|
||||||
|
|
||||||
if (!$content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
|
// Should always be available since it is set by display_add_field before initializing the draft area.
|
||||||
// Quickly make one now!
|
$content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid));
|
||||||
$content = new stdClass();
|
|
||||||
$content->fieldid = $this->field->id;
|
|
||||||
$content->recordid = $recordid;
|
|
||||||
$id = $DB->insert_record('data_content', $content);
|
|
||||||
$content = $DB->get_record('data_content', array('id'=>$id));
|
|
||||||
}
|
|
||||||
|
|
||||||
$names = explode('_', $name);
|
$names = explode('_', $name);
|
||||||
switch ($names[2]) {
|
switch ($names[2]) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue