uploaduser.php enhanced to upload also courses

uploaduser.php enhanced to upload also courses

by Rosario Carcò -
Number of replies: 53
Dear all,

I took the existing code of /admin/uploaduser.php and uploaduser_form.php and enahnced it to create also new courses.

The code is called when you click on the link in Admin->Users->Accounts->Upload users. After Installation of my code you will find a new entry there with a link to uploadusersandcourses.php

  • In the first pass the uploaded file is parsed for new courses to upload/create.
  • In the second pass, the original code gets executed as it was to create new users and/or enrol existing ones.
Could you please test it on your test-servers and let me know what you think of it?

Could an experienced moodle programmer have a look at it also to judge whether this code could be used to replace the existing uploaduser.php?

You will find a readme file in the zip file with installation instructions.

I included also a revised help file and needed language files.

In debug modus I found a minor php-notice if course1, course2, etc. are present in the first line of the csv file, but without valid data. So I corrected this issue.

NOTE: I have planned also to engineer this code down to make script out of it which could be run as an unattended cron-job, i.e. without going through the mentioned Admin->GUI

Rosario

Average of ratings: Useful (2)
In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -
There is a second version with courseTemplates working fine, i.e. you can put a path to an existing backup-file you want to use as template to restore into the newly created course. Example of path: 20/courseTemplate.zip, i.e. the directory where it is stored. See the README file for more informations.

Again, feel free to test and report back.

Rosario
Average of ratings: Useful (1)
In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Martin Vögeli -
Will this (or something similar) be in the core one day? Would be great! Best wishes, Martin smile PS: 5 years Moodle @ ZHAW anniversary!
In reply to Martin Vögeli

Re: uploaduser.php enhanced to upload also courses

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
No reason why it shouldn't be, if it is generally useful and good enough.

The procedure is Development:Overview#Minor_Development. (That is, get a nicely polished patch attached to a tracer issue.)
In reply to Tim Hunt

Re: uploaduser.php enhanced to upload also courses

by Mark Stevens -
Would MDL-13114 qualify? This is really needed, given all of the forum discussions, and code written to try to get this going (CONTRIB-605).
In reply to Mark Stevens

Re: uploaduser.php enhanced to upload also courses

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes. Those would be the ones.

And with that many votes, someone will deal with it eventually. However, lots of other things in things on the Moodle 2.0 roadmap, so don't hold your breath.
In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -
Here is version 03 with the promised code you can run as an unattended batch/cron job.

Please read the readme file and my comments in the code regarding execution security and privileges.

To debug and test the script you are able to call it by web, e.g.

https://yourMoodle.com/admin/uploadusersandcourses_silently.php

or by wget as a cron job, e.g.

wget -q -O /var/log/uploadusersandcourses_silently.log https://yourMoodle.com/admin/uploadusersandcourses_silently.php

or even by the php interpreter on a command line. I could not test the latter, as on my server php execution on the command line is disabled. But it should work, as I copied the necessary code from admin/cron.php which is designed to do so.

Regarding the mentioned Threads/Contribs I have contacted Anthony Borrow to see what could be my humble contribution. I fear that there is so much code already I didn't even know of and - even worse - I did not find, when I looked for it. If I would have found it, probably I would not have started to code my own solution.

Any feedback is greately appreciated, Rosario
In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -
Using a backup of a course as template works fine. There is only one strange thing: the Enrolment Key is not restored from the backup, i.e. the setting is empty after the restore.

Does anybody know why?

Depending on the aswer I will have to code this option myself or check and modify the script import_backup_file_silently to restore also the Enrolment Key.

Rosario
In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Rosario - Is this code related to a particular tracker issue? If so, would you mind uploading it to the appropriate issue. Peace - Anthony
In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Michel Sandri -
Hi. I don't know with u are developing this tools. I'm testing it to use on my institution and i have a dout about the category creation. Your tool don't create the category, just use one still created right?! have any update?!
Thanks.
In reply to Michel Sandri

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -
Yes, my code does create ONLY COURSES in EXISTING categories. As I mentioned in one of my posts, there are many many bulk operation scripts around in the contrib moodules & plugins section.

I could also introduce category creation but I have no time for the moment.

I was also asked to split up the code so that we could:

- upload categories

- upload users

- upload courses

individually and integrate the code into the accourding Admin-Block -> users and Admin-Block -> courses menus.

But you are right, as my script is also intedend for silent upload as cron/batch script, it should also be able to create categories if they do not exist yet.

As I am working on two Blocks (myCourses and siteNavigation), I will resume this around Christmas I hope.

Rosario
In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -
Here is version 04. I have only a few minor edits/enhancements or bug fixes.

Rosario
In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

I will start working on Version 05 in the next days. Here are the features requested by our Moodle-Admins:

- option to rename a course

- option to copy a course

- option to archive a course

- option to delete a course

So I will add another column in the Excel/CSV File: COURSEACTION, which can be:

- new (if empty or new, a new course will be created, as before, using a given path to an existing backup-zip-file as course-template)

- rename (based on course-idnumber, which should be unique) to given short and fullname

- copy (create a new course using the own backup-zip-file as course-template. I am not sure on how to achieve this, but I could use course-idnumber again to find the path to the own backup-zip-file. The new course would then receive the given short and fullname and course-idnumber should always be identical to shortname). Pay attention, this could be a very bad idea because duplicating whole courses in unattended mode could fill your data-disk.

- archive (not clear, has to be defined yet. But this should maintain the course's actual link while creating the copy as a new course or simply copying the backup-zip-file of the course into a course or category defined to receive all archived courses.)

I will report back during my work and when I am finished, I could add also the requested option to create categories if they do not exist yet.

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Marin Sok -

Hello Everyone,

I want to create an import courses in PHP script for  Moodle 2.0

Does everyone has sample code?

I couldn't figure out to use create_course function.

I'm new to PHP.

Any sample code of call create_course function, will be appreciate.

 

Thanks,

 

 

In reply to Marin Sok

Re: uploaduser.php enhanced to upload also courses

by Johnny America -

Yes, anyone has an example of how to use create_course function?

In reply to Johnny America

Re: uploaduser.php enhanced to upload also courses

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There's a tool for uploading courses using a CSV flatfile which I recently updated for 2.x: http://moodle.org/mod/forum/discuss.php?d=173705

In reply to Mark Johnson

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Thanks for this it will help me to convert my own uploadusersandcourses.php script to Moodle 2. I feel it very strange that such an important function was not incorporated into core. Even Tim Hunt speaks for it in his post here.

P.S. for "new to php", then you have no chance unless you invest a lot of time. It is better to use scripts others have developed to a ready to use level. My own script is not at this stage yet. Depending on your needs you have to tune the code yourself, which can only be done, if you understand what my code does. I am used to comment every line to help you reed my code. So it is up to you and I can only answer the questions you may have.

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Konrad Lorinczi -

Did you finished the Version 05 of your script?

I need this feature:
- option to copy a course

 

I need to make course duplication (course copy) to be done automatically.

Thanks in advance,

Konrad

In reply to Konrad Lorinczi

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

I can upload the BETA stage for you, but already in production use since mid December.

- I finished programming only the copy and new features because this required only little modifications to the existing code

All the other features like rename, archive, delete, create categories that do not exist, still needs to be done.

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Konrad Lorinczi -

No problem, if beta.

I only need the copy feature, to make copy of a course.


Thanks in advance for your upload.


Konrad

In reply to Konrad Lorinczi

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Here you are. You are free to put these two files in your moodleDir/admin

And do not forget to switch on/off my category translation table or to adapt it for your needs.

I join also the new template to upload users AND courses in excel-format. You would then have to fill it up and save it as csv file IN utf8-format! If Excel is not capable of utf8 simply open the generated csv file with a texteditor capable of storing in utf8-character-format.

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Javier González Díaz -

Good morning Rosario

In first time all congratulations for your great work and share with us.

I have found that version 2.2 does not work properly and I would like to know if you plan to get an updated version.

Thanks and best regards.

Javier Gonzalez.

In reply to Javier González Díaz

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

YES, YES, my chiefs decided to migrate to Moodle 2.3 so I am working on it. Watch out here.

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Alan Zaitchik -

Rosario,

Do you have a version of the uploadusersandcoruses.php that works for Moodle 2.x ?

Actually what I really want to do is programmatically restore from a single template course into a set of newly created course shells so that they all end up with a uniform set of blocks and activities and other settings. If I an do this in PHP I will add the code to the enrollment plugin where it creates the new empty courses. If I cannot then perhaps I can schedule it to run in a cron job with a list of courses as input. I was hoping that you have a versnio 2.x of your plugin that I could read and learn from, but perhaps you have some other suggestions?

I searched in my 2.3 Moodle system and could not find the method import_backup_file_silently anywhere, or I would have tried using that.  Is there something else that could be used instead, which you could recommend? This seems like such a common need that I assume I am missing the obvious, and that there is code somewhere in Moodle which supports automated restore operations from a template course into a (set of) empty course(s).

All suggestions are welcome!

Thanks,

Alan

In reply to Alan Zaitchik

Re: uploaduser.php enhanced to upload also courses

by Thorsten Bieser -

Hello Rosario, I am also very interrested in your script working with actual versions of moodle. Any solutions yet?

When using your version 05beta  I get the following error:

 

Fatal error: Call to undefined function get_records() in /srv/www/virtual/99999/wwwtest10.belwue.de/vhostdata/htdoc/moodle/admin/uploadusersandcourses.php on line 329

thanks

Thorsten

 

In reply to Thorsten Bieser

Re: uploaduser.php enhanced to upload also courses

by Alan Zaitchik -

Thorsten,

Did you make any progress with this? Rosario didn't respond to our posts, but perhaps you have figured out how to get this functionality in Moodle 2?

Alan

In reply to Alan Zaitchik

Re: uploaduser.php enhanced to upload also courses

by Thorsten Bieser -

Hello Alan,

 

I've testet the script with all Moodle 2.X Versions without success. : (

There is an alternative Script package  I am acutally testing. Unfortunatitly I am workin with Solaris an the script ist a cli Script based  on linux servers. Today I will test it in a XAMPP environment. Hope it works.

 Here is the link :https://moodle.org/mod/forum/discuss.php?d=196596

DO you know the scripts from piers Harding? He wrote "uploadcourse tool" a browser-based ( and in the new version also batch-based) Course Upload via csv.

I tried to implement the user restore in his scripts without success:

Here is the link to Piers Scripts:h ttps://github.com/piersharding/moodle-tool_uploadcourse

 And here my not working code manipulation in locallib.php. I altered the part where the backupfile is restored in a new created course.

---schnipp----
        // after creation/update, do we need to import a Moodle backup?
        if (!empty($backupfile)) {
                    $backupdefaults = array(
            'activities' => 1,
            'blocks' => 1,
            'filters' => 1,
            'users'  => 1,
            'role_assignments'=> 1
        );

        $backupsettings = array();

        // Check for backup and restore options.
       // if (!empty($params['options'])) {
            foreach ($params['options'] as $option) {

                // Strict check for a correct value (allways 1 or 0, true or false).
                $value = clean_param($option['value'], PARAM_INT);

                if ($value !== 0 and $value !== 1) {
                    throw new moodle_exception('invalidextparam', 'webservice', '', $option['name']);
                }

                if (!isset($backupdefaults[$option['name']])) {
                    throw new moodle_exception('invalidextparam', 'webservice', '', $option['name']);
                }

                $backupsettings[$option['name']] = $value;
            }
        //}




            // check if tmp dir exists
            $tmpdir = $CFG->tempdir . '/backup';
            if (!check_dir_exists($tmpdir, true, true)) {
                throw new restore_controller_exception('cannot_create_backup_temp_dir');
            }
            $filename = restore_controller::get_tempdir_name($course->id, $USER->id);
            $pathname = $tmpdir . '/' . $filename;
            $packer = get_file_packer('application/zip');
            $packer->extract_to_pathname($backupfile, $pathname);

            // restore the backup immediately
            $rc = new restore_controller($filename, $course->id,
                            backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id, backup::TARGET_CURRENT_ADDING);


                    foreach ($backupsettings as $name => $value) {
                                    $rc->get_plan()->get_setting($name)->set_status(base_setting::NOT_LOCKED);
                                    $rc->get_plan()->get_setting($name)->set_value($value);
                                            }

                                          // I do not really know what I am making there...

                                          // But If I don't set this to unlocked  I got a permission denied error
                                          // wich one is the right one  or is there a general setting to unlock the whole array for writing

                                          //  $rc->get_plan()->get_setting('users')->set_status(base_setting::NOT_LOCKED);
                                            $rc->get_plan()->get_setting('users')->set_status(backup_setting::NOT_LOCKED);
                                            $rc->get_plan()->get_setting('users')->set_value(1);
                                            $rc->get_plan()->get_setting('role_assignments')->set_status(base_setting::NOT_LOCKED);
                                            $rc->get_plan()->get_setting('role_assignments')->set_status(backup_setting::NOT_LOCKED);
                                            $rc->get_plan()->get_setting('role_assignments')->set_value(1);
            // check if the format conversion must happen first

----schnapp----

 

Hope this helps a bit

 

Thorsten

In reply to Thorsten Bieser

Re: uploaduser.php enhanced to upload also courses

by Alan Zaitchik -

Thorsten,

Thanks. I will take a look at what you sent and see if I can figure anything out. If I make any progress I will let you know!  I have to say that I am really puzzled why no one other than you and I seem to feel the lack of this capability in Moodle 2. Is it hiding somewhere under another name??

Alan

In reply to Alan Zaitchik

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Alan, Thorsten, I am very sorry for the delay, but I hope you saw that  my version for Moodle 2.3 was uploaded in JULY 2012 at the end of the thread, and that since then similar code is being integrated in core.

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Please follow progress also in this tracker issue:

http://tracker.moodle.org/browse/MDL-13114

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by ursula macfarlane -

Hi,

I'm gatecrashing here - sorry - but as our organisations IT trainer I really want an automatic process that will upload new users without having to go into Moodle myself and upload the .csv file.

Our network login process creates the users in email and on the network. This is added into a spreadsheet. We would like to run an overnight process that picks up this spreadsheet and creates the Moddle accounts.

IT guys I am talking to here prefers that I get into the discussion forums to find the answer! So I'm playing middleman......

Another organisation  is hosting our part of the moodle server so I guess we can't actually do anything, but they do have an LDAP over a VPN.

For  our technical infrastructure Andy says this;

"Can we configure a persistent VPN to you guys, then call an LDAP script from our clinical account creation script, that could create the Moodle account in your LDAP server?"

I think they are stumped at the other end......

cheers,

Ursula.

In reply to ursula macfarlane

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

LDAP can be scripted, indeed. But LDAP scripts can only be executed on LDAP Servers. So if you use LDAP authentication like I did for years, before switching to Shibboleth authentication, you would set up the new users on your LDAP Server first. Then, if I am not mistaken, the Moodle LDAP-Module does not offer any "overnight" synchronisation of the Moodle users with your LDAP Database, but you could export your LDAP Database to something you can process with Moodle's EXTERNAL DATABASE Authentication Plugin. See users->authentication->external database where you can choose a lot of different "databases" even plain csv files.

But pay attention to what "synchronisation" means in this auth-plugin, so as not to loose Moodle users accidentally deleted in your LDAP database, unless this is what you want to do.

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

LDAP can be scripted, indeed. But LDAP scripts can only be executed on LDAP Servers.

As long as you can connect to the LDAP server (more precisely, to the LDAP service ports), you can run the scripts from anywhere you want smile (I've done it many times in the past )

Then, if I am not mistaken, the Moodle LDAP-Module does not offer any "overnight" synchronisation of the Moodle users with your LDAP Database

It sure does smile It's under auth/ldap/auth_ldap_sync_users.php in Moodle 1.x and auth/ldap/cli/sync.php in Moodle 2.x

Saludos. Iñaki.

Average of ratings: Useful (2)
In reply to Iñaki Arenaza

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Iñaki, thanks for the details. You are rigth (as ever). I had some confused remembrance of the auth_ldap_synch_users.php but did not find it in the GUI auth-ldap-settings. But you are right, it exists nevertheless, and I am remembering now that I did study that code before coding my uploadusersandcourses.php - my brains are getting older...

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Dear all, I am working on a version for Moodle 2.3 now. If the Moodle API calls didn't change too much, I should be able to post the first beta in the next 7 days. The only headache will be to use the new Backup-Zip-files to copy/duplicate an existing course as the file names and directories are no more in plain text inside the course directory. May be I will need your help to program this.

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Just finished the first mockup. I will upload my first beta here soon. Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Dear all, here is the first beta. To install proceed as follows and described also in the readme file:

  • unzip everything onto a local drive
  • copy the whole uploadusersandcourses folder/directory to you moodleDir/local/ directory
  • in the Moodle GUI visit the NOTIFICATIONS link to load that new local plugin

You will then find automatically a new Menu-Option Upload users and courses in your siteAdministration->Users->Accounts Menu.

For the moment, to make our first tests, only the interactive code is there. Next week, if your echo is positive, I will copy the new code into the uploadusersandcourses_silently.php script, test again and release it here.

The version numbers have changed a little bit: the first two digits are meaning the Moodle version my code was tested on and works fine on. So 23.01 has been tested on Moodle 2.3

Rosario

 

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

And here is the complete BETA, with _silently.php version.

a) use it on a TEST-SERVER until we are through with testing

b) REMEMBER the code can now be neatly integrated into Moodle as external plugin but this does not mean you can simply install and use it!

NO, No, no...

Before using it, you must have a look at my readme file. You must have a look at the code because it reflects mainly the needs of my University.

BUT with little effort you can modify the code to reflect your own workflow and adapt it for your needs. There is no magic in it. And if you need my help to tailor the code to fit your own needs, just let me know.


In the silently-version I left things so that you can use/run it by a web-call, so as to see immediate output in your browser. To make it run in cli on the command shell, remove // from the line where

define('CLI_SCRIPT', true);

is defined. Toggle also the flag $checkadminuser to FALSE, as when runnig from command line you suppose that no other user is able to run it.

Calling by web means https://yourMoodle.com/local/uploadusersandcourses/uploadusersandcourses_silently.php

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Nigel Cunningham -

Thanks for this Rosario.

I'll certainly be looking at it and giving it a try because I've gone from manually creating users and enrolments to a process of using a CSV export from our Student Database, combined with running three scripts and two visits to the Upload users page. If I can use your solution, I might be able to make the whole process fully automatic, which would be great!

In reply to Nigel Cunningham

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

You are welcome. As I said the 1.9 version was in production since december 2011 in silent, full automated version. And I used it in the GUI-Version ever since I developed and published it here. Now the 2.3.1 Version is in production since september 14th, even if I say it is a BETA version here...

I will enhance it and clean up the code a little bit, but I want the code to be clear and understandable also for newbies, so that everyone can tailor to fit heir own needs. I think I will add some admin-config-options to facilitate using the GUI-version without having to set the variables in the code itself, to make it more ready-and-out-of-the-box.

But those who want to automate, must have a look into the code to avoid surprises.

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Mark Jones -

Rosario,

Where do i get a copy of the production version? also it only works with Moodle 2.3.1 and above...correct? mark

In reply to Mark Jones

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Mark, for the moment the above BETA Version is what is in production for us... it works fine for us.

I will upload the next version as soon as I have time to make little changes to make the GUI-version working out-of-the-box.

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by Daniel Phillips -

Hi Rosaio,

Your mod looks promising.

I am wondering if I could use it to semi-automate backing up and restoring of courses.

At my place we use an integration to create the courses from our SMS, but then have to manually backup/restore or import the course content.  The usual process is to restore content (or import) from the most recent iteration of the same course that has run previously e.g. We will restore the Semester One course for the Semester Two course.

Can this mod achieve this by adding the appropriate info into the spreadsheet?  Would be great if it could - save me a ton of time smile

I appreciate your help.

Cheers
Dan

In reply to Daniel Phillips

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

YES, you will find all the code you need to do so.

The actual logic is this way:

  • read in csv file
  • in first pass create courses that do not exist already
  • if a course-template file is given in the file or a course to copy from, the same procedure is started for "new" and "copy" courseaction. The existing course is backed up on the fly and restored to get a copy of it which becomes the new course
  • in the second pass users in the csv file are enrolled in those courses or in any other existing course
  • to create the courses in certain categories you can either use a category-translation-table or deactivate the table and use course-category-IDs directly in the csv file

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by R.T. Brown -

Hi Rosario,

My apologies if the answer to my question has been posted elsewhere. Does the script only enroll students whose accounts are created at the time of upload, or does it accommodate enrollment of students who already exist in the system?

Many thanks --

rtb

In reply to R.T. Brown

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

I am very sorry for the delay. As I wrote at the beginning, the uploaduser-part does exectly what it ever did, as it is simply a copy of this code. So it enrolls BOTH users already existing or newly created on the fly. And it does not matter whether you use uploadusersandcourses to either create only courses and/or create new users and/or enrol them in existing or newly created courses.

In reply to Daniel Phillips

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Daniel, I am not sure whether I caught your idea/workflow:

>>The usual process is to restore content (or import) from the most recent iteration of the same course that has run previously

If your courses exist already, it would be enough to DEACTIVATE/HIDE and ACTIVATE/SHOW them to the Students. I think my code to read in your csv file with the simple course-short-names and one api-call to set the visible-flag to true/false would do the trick.

Another possibility would be to re-set the start-dates and/or enrolment-dates and/or enrolment-duration of the existing courses, so that access for the students would be automatically controlled by the dates you set. And with my script you would simply re-set those dates for the next term.

Finally, if you want to unenroll the previous students automatically and enroll the new ones still using my script, the best way to go is really using a backup/restore of the existing course without user data. But if you copy existing courses to new ones, of course, one day you will have to delete the old/original courses. So you have two new options here: either I finish implementing the deletion of existing courses in my script, as I had already scheduled to do, or I/you modify the script to fit your needs to unenroll previous students and enroll new ones. Even the latter should not be too difficult to implement.

Rosario

In reply to Rosario Carcò

Re: uploaduser.php enhanced to upload also courses

by marco cassisa -

Hi all!

I enjoyed Rosario Carcò's script and tried to enhance it a little more.

Yes I know, there is Piers Harding's work that allows to upload users in bulk, but it seems that uploadusersandcourses fits almost exactly to the needs of my school, at least to an extent that I couldn't resist temptation to take a little further its functionalities.

I rewrote a part of the script so that it takes a category-tree and recreates it if not exists (with this syntax:   MAINCATEGORY@@SubCategory@@SubSubCategory and without limits to the number of subcategories (except moodle'ones of course).

The category-tree delimiter can be easily changed in the script. The code is still quite dirty and can be surely optimize (idcategory isn't necessary anymore, but it is set internally, which can be avoided now), but, hey, WorksForMe! 

I sent the script to Rosario asking for a review, but he has a lot to do, as it seems.

The power of open source and free software is that everyone can contribute. My contribution is attached (just uploadusersandcourses.php file I modified - not the entire plugin! - and a sample-csv): enjoy and improve it further!

marco

In reply to marco cassisa

Re: uploaduser.php enhanced to upload also courses

by Rosario Carcò -

Yes, I was busy, but the script for Moodle 2.3 has been working and continues to work fine on our production server since one year now.

In the meantime big efforts have been made to integrate this code into core. Have a look here to follow development:

https://tracker.moodle.org/browse/MDL-13114

I still have no time to look at that code either. But I feel that my code can continue to help those who want to tailor it to fit exactly their own needs and special workflows.

As I explained Marco, the category structure at our University of Applied Sciences is something that does not change a lot. So our need is only to create courses in those given categories. If we have changes in our category-structure I simple rename the categories or create new ones in the GUI and then I have to modify my course-category-table in the code to match the new names or new categories.

But as Marco says, you are all free to use the code as is, or modify it to fit your exact neeeds.

Rosario

In reply to marco cassisa

Re: uploaduser.php enhanced to upload also courses

by marco cassisa -


To use rosario's script in moodle 2.7 it is enough to add 

$systemcontext = context_system::instance();


to settings.php @line 27 (before any other interpreted code)


Bye all, thanks rosario!

In reply to marco cassisa

Re: uploaduser.php enhanced to upload also courses

by sas ss -

Hello, thanks for the amazing work! is there any solution for 2.9? I tried $systemcontext = context_system::instance(); it removed a syntax error but the page keeps giving me blank

In reply to sas ss

Re: uploaduser.php enhanced to upload also courses

by sas ss -

Hello, I made the upload user work for 2.9, but still the create course is not it is giving me Courseaction missing or unknown, I will attach the zipped code to where I reached, I do not know if its still a deprecated code or is it something to do with $filepath = '/mnt/evento/'
 
$statusfile = $filepath . 'moodleCoursesNewStatus.csv' maybe is it comparing to it; any suggestions?