In working on something related to enrolments, Antoni Mas suggested a modification to gdlib.php which allows one of the functions to take a URL argument, not just a file-path argument.
I'd like to ask if this change could feasibly be committed to the main code tree. I haven't done any other work with gdlib so there may be issues I'm unaware of. However, I'd like the IMS enrolment module to be available for use in "vanilla" installations in future, without users having to modify any Moodle system files.
The modified gdlib can be downloaded from here:
http://moodle.org/mod/forum/discuss.php?d=34351&parent=166292
Here is the diff against the current HEAD code:
85c85
< function save_profile_image($id, $uploadmanager, $dir='users') {
---
> function save_profile_image($id, $uploadmanager, $dir='users', $url=false) {
112,115d111
< $destination = $CFG->dataroot .'/'. $dir .'/'. $id;
< if (!$uploadmanager->save_files($destination)) {
< return false;
< }
117c113,122
< $originalfile = $uploadmanager->get_new_filepath();
---
> if (!$url) {
> $destination = $CFG->dataroot .'/'. $dir .'/'. $id;
> if (!$uploadmanager->save_files($destination)) {
> return false;
> }
>
> $originalfile = $uploadmanager->get_new_filepath();
> }else{
> $originalfile = $uploadmanager;
> }
163c168,170
< unlink($originalfile);
---
> if (!$url) {
> unlink($originalfile);
> }
Hi Anthony,
I don't know if you are still interested in batch importing user pics, but I've recently made a patch (against 1.8.2+) that allows exactly that, but using the username instead of the userid. The change to use the later is trivial though.
There is a new admin page, 'Upload user pictures', where you upload a zip file that contains the user pictures. The users pictures are named username1.jpg, username2.jpg and so on. They don't have to be JPEG images. Any Moodle supported format will do it.
The patch if fully integrated and translatable. In case you are insterested, I'm attaching the patch here.
The attached file has two patches that have to be applied in order (self evident from the names ).
The first one splits the file upload process apart from the picture assigning process, so any authentication plugin can set the user picture (as requested in MDL-4520, which is what sent me to this thread in the first place ).
The second one creates the new admin menu entry to upload the zip file with the pictures.
Beware this second patch doesn't work with the new 1.8.3 and 1.9beta2 versions, as the user data directory structure has recently changed and the patch predates those changes. I plan to update the patch to cover 1.8.3 and 1.9 in the following days though.
Saludos. Iñaki.
Anthony,
here are the patches for the lastes 1.8.3+ and 1.9beta2 (current as of today).
Instead of using $CFG->whatever to configure this, I think it's better to add a field to the upload form so the user can choose what user attribute wants to use to assign the pictures (this is not part of the current patch, but will add it in a day or two)..
With respect to the location of the upload image file, my patch uses an upload form, so you just upload a zip file containing the pictures, and the rest is automatic.
Saludos. Iñaki.
And here is the patch for 1.9beta2 (pity you can only attach one file to forum posts).
Saludos. Iñaki.
Ok, so here is the patch that adds a drop down list to specify which user attribute (username, id, id number) you want to use to match users and picture files.
This is the patch against 1.8.3+ current as of today. I'll attach the one against 1.9beta2 in another message.
Saludos. Iñaki.
Here's the one for 1.9beta2.
Saludos. Iñaki.
I have attached updated patches to the bug tracker in MDL-11752
Saludos. Iñaki.
Could you possibly send me this patch for 1.8+ (current 1.8 release)?
Thanks in advance!
Brian Pool
Anthony,
there have been a couple of enhancements in the 1.9 code that are not present in the patch for 1.8 available as part of MDL-11752. I'm not sure if I still have the patches for 1.8 around, but if I don't I'll create a new one with all the bells and whistles and upload it to MDL-11752.
[Edit: I still have the git branch here; I'll rebase the patch on top of current 1.8 and add the missing bits]
Saludos. Iñaki.
Done!
Saludos. Iñaki.
I did go in and hardcode it to use idnumber instead of username and it works great. I only wanted you to know about it if you do a revision. Otherwise it is a great addition and I really appreciated it!
Brian
You'll be pleased to hear that the upload user pictures feature is now included in Moodle 1.9 - a big THANK YOU to Iñaki! Please see the upload user pictures documentation for more information.