MDL-33425 user: Replaced filepicker with filemanager on edit profile page
This commit is contained in:
+32
-12
@@ -42,7 +42,7 @@ function useredit_update_user_preference($usernew) {
|
||||
* @param moodleform $userform The form that was submitted to edit the form
|
||||
* @return bool True if the user was updated, false if it stayed the same.
|
||||
*/
|
||||
function useredit_update_picture(stdClass $usernew, moodleform $userform) {
|
||||
function useredit_update_picture(stdClass $usernew, moodleform $userform, $filemanageroptions = array()) {
|
||||
global $CFG, $DB;
|
||||
require_once("$CFG->libdir/gdlib.php");
|
||||
|
||||
@@ -50,20 +50,40 @@ function useredit_update_picture(stdClass $usernew, moodleform $userform) {
|
||||
$user = $DB->get_record('user', array('id'=>$usernew->id), 'id, picture', MUST_EXIST);
|
||||
|
||||
$newpicture = $user->picture;
|
||||
|
||||
// Get file_storage to process files.
|
||||
$fs = get_file_storage();
|
||||
if (!empty($usernew->deletepicture)) {
|
||||
// The user has chosen to delete the selected users picture
|
||||
$fs = get_file_storage();
|
||||
$fs->delete_area_files($context->id, 'user', 'icon'); // drop all images in area
|
||||
$newpicture = 0;
|
||||
|
||||
} else if ($iconfile = $userform->save_temp_file('imagefile')) {
|
||||
// There is a new image that has been uploaded
|
||||
// Process the new image and set the user to make use of it.
|
||||
// NOTE: Uploaded images always take over Gravatar
|
||||
$newpicture = (int)process_new_icon($context, 'user', 'icon', 0, $iconfile);
|
||||
// Delete the file that has now been processed
|
||||
@unlink($iconfile);
|
||||
} else {
|
||||
// Save newly uploaded file, this will avoid context mismatch for newly created users.
|
||||
file_save_draft_area_files($usernew->imagefile, $context->id, 'user', 'newicon', 0, $filemanageroptions);
|
||||
if (($iconfiles = $fs->get_area_files($context->id, 'user', 'newicon')) && count($iconfiles) == 2) {
|
||||
// Get file which was uploaded in draft area
|
||||
foreach ($iconfiles as $file) {
|
||||
if (!$file->is_directory()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Copy file to temporary location and the send it for processing icon
|
||||
if ($iconfile = $file->copy_content_to_temp()) {
|
||||
// There is a new image that has been uploaded
|
||||
// Process the new image and set the user to make use of it.
|
||||
// NOTE: Uploaded images always take over Gravatar
|
||||
$newpicture = (int)process_new_icon($context, 'user', 'icon', 0, $iconfile);
|
||||
// Delete temporary file
|
||||
@unlink($iconfile);
|
||||
// Remove uploaded file.
|
||||
$fs->delete_area_files($context->id, 'user', 'newicon');
|
||||
} else {
|
||||
// Something went wrong while creating temp file.
|
||||
// Remove uploaded file.
|
||||
$fs->delete_area_files($context->id, 'user', 'newicon');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($newpicture != $user->picture) {
|
||||
@@ -101,7 +121,7 @@ function useredit_update_interests($user, $interests) {
|
||||
tag_set('user', $user->id, $interests);
|
||||
}
|
||||
|
||||
function useredit_shared_definition(&$mform, $editoroptions = null) {
|
||||
function useredit_shared_definition(&$mform, $editoroptions = null, $filemanageroptions = null) {
|
||||
global $CFG, $USER, $DB;
|
||||
|
||||
$user = $DB->get_record('user', array('id' => $USER->id));
|
||||
@@ -268,7 +288,7 @@ function useredit_shared_definition(&$mform, $editoroptions = null) {
|
||||
$mform->addElement('checkbox', 'deletepicture', get_string('delete'));
|
||||
$mform->setDefault('deletepicture', 0);
|
||||
|
||||
$mform->addElement('filepicker', 'imagefile', get_string('newpicture'), '', array('maxbytes'=>get_max_upload_file_size($CFG->maxbytes)));
|
||||
$mform->addElement('filemanager', 'imagefile', get_string('newpicture'), '', $filemanageroptions);
|
||||
$mform->addHelpButton('imagefile', 'newpicture');
|
||||
|
||||
$mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
|
||||
|
||||
Reference in New Issue
Block a user