Conditional activities: ActivityLocking v 2.4 beta

Conditional activities: ActivityLocking v 2.4 beta

by John Gschnaidner -
Number of replies: 32

Hello everybody,

after some time of development I created the next step of the AL 2.X branch:

ActivityLocking V 2.4 (currently beta status)

This version supports Moodle 1.6 and includes:

  • Supports module and section locks
  • Locking and Completing modules and sections parallel
  • CSS style and checkbox for locking and completing
  • Hide when locked
  • Language support and help (english and german)
  • Readme for features and installation (english only)
  • SQL commands for manual DB update
  • Info text on how to update CSS style sheet

Unfortunately the hack is to big to be a ZIP file (more than 100 kB). Therefore it is coded with 7z. You will have to use other tools like TugZIP or so.

I tried to make the code a bit more transparent; all changes against the original Moodle files should be labelled '// ALX'. The readme should also give you some hints; it includes a file list, too.

This will be the last version of ActivityLocking as a hack from my side.
I am planing to make the whole thing installable and what is more important de-installable; but this might take a while.

Anyway, if you like try it, but remeber, this is a beta version. I tested it with Moodle 1.6 (release 27th of June) and XAMPP Lite.
So far I got no more errors in debugging mode.

DO NOT TRY THIS ON A PRODUCTION SERVER!
except you are 100% sure of what you are doing.

If you happen to find any bugs, you can report them here, but I won't be able to check this forum before August 16th!
So please be patient. wink

Thanks for trying out AL V 2.4

Regards
   John

Average of ratings: -
In reply to John Gschnaidner

Re: ActivityLocking v 2.4 beta ThX

by Chris Collman -
Picture of Documentation writers
Thank you John and everyone else for their work on this feature.  Many of us appreciate that you have other jobs but you work makes our own easier.

Chris
In reply to John Gschnaidner

Re: Conditional activities: ActivityLocking v 2.4 beta

by Bernard Boucher -
Hi John,
            I will try it probably next week.

Thanks,

Bernard
In reply to John Gschnaidner

Re: Conditional activities: ActivityLocking v 2.4 beta

by marco farfan -
Hi John, i just like to thank you because I have installed AL successfully on my Moodle 1.6. I did use the version AL 2.4 from http://docs.moodle.org/en/Activity_Locking

Some recommendations for beginners like me: It is very important to read the documentation files to make the installation done BUT I like to add two things to this documentation:  
1. if you get the names of the downloaded file CAPITALIZED, change these names to NOT CAPITALIZED names.
2. if you try to access to an activity without doing the “conditional job” before, you will probably get this warning:

Warning: Invalid argument supplied for foreach() in /blabla/blabla/web/moodle/lib/locklib.php on line 106

To help this i replaced these codes (on line 106 of the locklib.php file):

foreach ($locks as $lock => $value){
if ($lock and $value) {
$instance = get_record($mods[$lock]->modname, "id", $mods[$lock]->instance);
$locklist .= "$instance->name<br />";       
}                 
}

WHIT THESE:

if (is_array($locks)){ //-->added
foreach ($locks as $lock => $value){
if ($lock and $value) {
$instance = get_record($mods[$lock]->modname, "id", $mods[$lock]->instance);
$locklist .= "$instance->name<br />";       
}                 
}
} //----> added

good luck

Marco
In reply to marco farfan

Re: Conditional activities: ActivityLocking v 2.4 beta

by John Gschnaidner -

Hallo Marco,

thank you for trying 2.4 and for feeding back that bug. I was looking for a solution on this, but this did not pop to my mind.

The uppercase file names where produced by TugZIP somehow; I realized just a couple of days ago, when I picked up the code for further development.

Currently I am working on the code, to make this thing work as a block again (the former versions did have this to install the DBs).
I am planning for some big changes (if I get this working):
This version will have a sequence to backup the original files and to restore them on de-installation. Storing logs of accessing resources in a separate DB is already fixed (Nikki will like this, I hope ).
And I will rename the whole thing (to prevent further version branch confusion), and place it in sourceforge for public development.
Maybe you want to look for ScoreLock in the near future (depends on how much time I can spend on programming and testing.

I will place a link to it in the MoodleDocs and a new forum branch.

Thanks again.

 John

In reply to marco farfan

Re: Conditional activities: ActivityLocking v 2.4 beta

by John Gschnaidner -

Hello Marc,

I included your code and fixed the files. So I hope everything is OK now.

Regards John

In reply to John Gschnaidner

Re: Conditional activities: ActivityLocking v 2.4 beta

by John Gschnaidner -

I found one more bug in /moodle/course/locking.php:

The function for getting all mods in the section for completed score has a bit to much checking (// A module can't be a lock for itself) in line159 and 180. Line 159 is to be deleted (including the braces in 177) and line 180
if (!($locktype == 'section' && $mod->id == $target->id)) {
has to be changed into
if (!($locktype == 'section')) {

Or simply replace the file with this fixed one.

John

In reply to John Gschnaidner

Ang: Re: ActivityLocking v 2.4 beta

by Jens Gammelgaard -
Picture of Translators

Hi John,

I get this error when I access with studentview or as a student:

Fatal error: Call to undefined function: _() in /moodle/course/lib.php on line 856

Line 856 is in this section in the lib.php file:

// ALX_S

// get lock data for module locks

$locks = get_module_locks($mod, 'module');

$activitycomplete = activity_complete($mod);

if ($isteacher or _ // is teacher?

Line 856: ($mod->visible and _ //is it visible?

($mod->lockedvisible and $thissection->lockedvisible) or _ // is it locked visible (module and section)?

(!array_sum($locks) and !array_sum($sectionlocks)))) { // is it unlocked for this user?

The test above is with Moodle version 1.61+ (2006050513)

 

In reply to Jens Gammelgaard

Re: Ang: Re: ActivityLocking v 2.4 beta

by John Gschnaidner -

I think the moodle version is not the problem; looks more like the PHP version to me.
I tested the thing with XAMPP Lite, which has a PHP version 5 +.
Yours seems to be a different one.

To overcome the problem simply remove the underscore (_) and the comments (// blabla) at the end of the three lines (the first is if ($isteacher or) and put the line together from if to {, so it will look like this:
if ($isteacher or ($mod->visible and ($mod->lockedvisible and $thissection->lockedvisible) or (!array_sum($locks) and !array_sum($sectionlocks)))) {
That should fix it. Let me know, if it does.

I used this writing, because it makes the code more easy to read. I think it is only this one time, that I did split up the code.

Regards
  John

In reply to John Gschnaidner

Re: Ang: Re: ActivityLocking v 2.4 beta

by Nicola Bennett -

Hi,

I've added activity locking (version 2 not beta) to my site and it all works fine until I add a resource on the homepage. This is the error I get:

Fatal error: Call to undefined function: _() in /moodle/course/lib.php on line 829

This is the code on this line:

if (($mod->visible and (isunlocked($mod) or $mod->visiblewhenlocked)) or $isteacher)

Do I need to edit this?

This is a serious bug in the lib.php file.

Does anyone have a definate fix?

Thanks
Nicola

In reply to Nicola Bennett

Re: Ang: Re: ActivityLocking v 2.4 beta

by John Gschnaidner -

Hi Nicola,

yes, you need this!

The only problem is, that some browser/server seem to have a problem with deviding a long line using an underscore. To solve this simply add this fragments (the first line starting with if ( and the following with an underscore _) into a whole line (until you reach the curly brace {) and remove the underscores. This should solve the problem.

Regards
  John

PS:
Optional to ALv2.4 you could use Score Lock, which is built on ALv2.4, but has more functionality and an install / deinstall function.

In reply to John Gschnaidner

Re: Ang: Re: ActivityLocking v 2.4 beta

by Nicola Bennett -

Hi John,

Thanks for your reply but I don't understand how I need to edit this. Is there any chance you could type this out for me exactly as it should be.

Thanks in advance.

Nicola.

In reply to Nicola Bennett

Re: Ang: Re: ActivityLocking v 2.4 beta

by John Gschnaidner -

Ooops, sorry.blush

That is what is comming from not reading the mail exactly.

Nicola, you are using a different version than v2.4beta. I am not the author of that.
See, the trouble with AL is, that there are many differnt versions, which originated from the same source, but developed in different directions. I have developed the ALv2.4 branch and Score Lock. I do not know the work of the others in detail. You need to get in touch with Stuart Mayor, if I am not mistaken. Please check in the moodle Docs for your version.

Regards
  John

In reply to Nicola Bennett

ActivityLocking v 2.4 beta

by Bernard Boucher -
Hi Nicola,
can you precise from that table wich version of activity locking and Moodle you are testing?

Unfortunately there are many versions around in different state of developpement ( mostly hacks ) and only few combinaison of Moodle and actvity locking are working well together.

For example we are in the forum of "ActivityLocking v 2.4 beta" but your post mention "activity locking (version 2 not beta)" without indicating the Moodle version you are using.

I hope it may help,

Bernard


In reply to John Gschnaidner

Re: Conditional activities: ActivityLocking v 2.4 beta

by Shawn Cannon -
I have installed this version on my Moodle 1.6.x version and everything seemed to work OK. What I have discovered with the modified files in place is that anyone with the role of Student cannot view the courses that are already setup. If the role of teacher or admin logs in they can see the course no problem. If I restore the original Moodle files the Student role can view the course again. Any idea what couldbe causing this?
In reply to John Gschnaidner

ActivityLocking v 2.4 moves on to Score Lock

by John Gschnaidner -

As announced, this is a ongoing development for Activity Locking v2.4, with a couple of new features.
For further information please refer to

moodle Docs: Score Lock

Score Lock is scheduled for beta release until middle of September 2006.

In reply to John Gschnaidner

Re: ActivityLocking v 2.4 moves on to Score Lock

by Nikki Macfarlane -
John,

I had a go at installing v 2.4 today but ran into some problems.

I uploaded it all no problem. But when I log in to Moodle and click on Admin, there is no advice that the tables or anything else is being set up. When I go into a course I can set up activity locking just fine and it alllooks good with boxes and ticks in the right places etc. However, it is not actually locking anything - all locked activities are still accessible by students. I suspect this is because it did not actually install properly as I would have expected to see the tables being set up when I clicked on admin.

Any ideas where I might have gone wrong? I cannot see the block and get no messages to set anything up.

Can you tell me is v 2.4 the same as score lock? Is this the version I should be using if I want to have the locking now using a separate database rather than the logs to store locked info? (thanks Stuart and others who worked ojn this change, so happy to see this change going through!)

Nikki Macfarlane
In reply to Nikki Macfarlane

Re: ActivityLocking v 2.4 moves on to Score Lock

by John Gschnaidner -

Hi Nikki,

easy explanation:
Score Lock would have been v2.5 . V2.4 is the same old hack as the other, only, that is has the capability of section locking, tab based integrated in editing the section description (and I fixed the bugs Marco reported in this branch).
That means no install (you still need to modify the tables manually), no turning back (de-install) and no extra database for the logs.

Score Lock will be on beta release within the next two weeks. I mostly have everything working, except some extras for the block, were the teacher can reset all students logs (that is working) and specific students (that I am currently working on) plus some utf8 support problem for the block. I will release it once I got no more debugging message on testing.

Short preview:
The block is installed as usual, as you tried with 2.4, by accessing the admin page. The Score Lock block has a global setting, where you can install (de-install) the hack of the course and lib files and the database extension of course_modules and course_sections. When you load the block (after set global setting install) all files will be installed (there is even an error handling, in case anything should go wrong with installation resp. de-installation). Score Lock is tab based, so you can do the settings (same as in 2.4) by accessing the 'edit' icon of the activities/resources as well as that of the section/week description.

Score Lock is (or will be shortly) some of the activity locking code (or a collection of different versions) labeled as a new block/hack, to avoid further version mix-up, with source code available from source forge for anybody to work on.

As I said, all in a week or two.

Regards
John

In reply to John Gschnaidner

Re: ActivityLocking v 2.4 moves on to Score Lock

by Sam Wynens -

Hi John,

First of all, great hack!!!

Now on to the question...

I have already hacked my backuplib.php and restorelib.php to include some custom user fields that I made a requirement for user setup. Got all of that working properly so that the new information is backed up and restored properly.

If wanted to backup and restore the activity locks, would all I have to do is add the fields from the db into the respective php files so that it would know what is locked and what isn't according to the user?

Sam

In reply to Sam Wynens

Re: ActivityLocking v 2.4 moves on to Score Lock

by John Gschnaidner -

Hello Sam,

Thanks for the praise. shy
To be honest, I have not been looking into the backup matter up to now.blush Also Score Lock (which will be beta released this weekend) does not include backup functionality. I just tested it and there is no information of Score Lock stored (except some of the block). mixed

But this is definitely something I will have to include (since a good part of my motivation of reworking Activity Locking into Score Lock was, that I need it).

Now back to your question: All data is stored in the database:
I believe in AL 2.4 it is
- Locks: contains all information of what is locking down a certain module/section, plus the IDs
- course_sections: style elements for this section lock (is visible, CSS, checkbox) and the completed score (= the minimum score necessary for each module of this section to mark it completed by style and/or checkbox)
- course_modules: the same stuff as in sections with the difference, that the completed score is only for this module, and the addition of the field lockedbysection indicating, that it is part of a locked section.

I noticed, that moodle 1.6 is no longer dumping the sql into a filesurprise, but is creating a xml containing all data. What would have to be done is, to include this additional fields of the course_sections / _modules tables and the locks table into the backup. For Score Locks there is an additional table, where I backup the log files, indicating that the student has been accessing this or that resource; in AL that information is still with the log entries. thoughtful

I am not sure right now, but from what I have seen, there is no backup functionality, that could have been worked into a block or module. That will leave us back with a hack.
Well, since AL has always been a hack and Score Lock is still a bit of a hack, I believe, we have to live with this. Still, SL offers the possibility to restore the system to the original state on deinstallation; that could be easily accomplished for backup functionality.

I hope this answer will help you a bit. If you could post this changes of yours, I will have a look into, how to fix that one. Any contributions on the brainwork are always welcome. big grin

Regards
John

In reply to John Gschnaidner

Re: Backup - Restore

by John Gschnaidner -

On correction: I just noticed, that also earlier versions of moodle are using XML for backup.blush

I really need to sort things out.

In reply to John Gschnaidner

Ang: ActivityLocking v 2.4 beta

by Jens Gammelgaard -
Picture of Translators
I have now tested the AL. 2.4 with Chardelles Certificate 3.1 - and they all seem to work together.

Has any of you experienced that AL 2.4 should work with Moodles with existing courses or should it only work with Moodle that you setup from new?
In reply to Jens Gammelgaard

Ang: ActivityLocking v 2.4 beta

by Jens Gammelgaard -
Picture of Translators
With Chardelles certificate, you though have to set it to invicible in the activity locking.
In reply to Jens Gammelgaard

Ang: ActivityLocking v 2.4 beta

by Jens Gammelgaard -
Picture of Translators
Hi John,

Can you add the Certificate Mod to be included in the AL, so that the students can see the Cert. as locked?
In reply to Jens Gammelgaard

Re: Ang: ActivityLocking v 2.4 beta

by John Gschnaidner -

Hi Jens,

I just tried Chardelle Bush Certificate 3.1 beta with my test version of Score Lock and had no problems to put a lock on the certificate and (as a real student - be careful with the student view for the teacher/developer) had it unlocked, after I fulfilled the requirements.

Remember: The lock setting tabs will not be shown on the initial setup of a module (meaning, if you 'Add an activity ... / resource ...'). This tabs will show when you access the module through the edit icon.

Score Lock is based on Activity Lock v2.4. I did not much touch the lock/unlock functions, but I remember, that I did spot and fixed a bug there.
If that is really the problem I will need some time for checking and fixing on AL v2.4 (about two weeks, since I am out of the country next week).
An alternative would be, that you catch up on Score Lock, where I will release the beta today or tomorrow. The bonus is, that you can much more easy update it, since it has a install and de-install function. Simply check on Saturday in the moodle Docs for Score Lock; there will be a download link.

Regards
  John

In reply to John Gschnaidner

Ang: Re: Ang: ActivityLocking v 2.4 beta

by Jens Gammelgaard -
Picture of Translators
Hi John,

That sounds truely great. I will try the Scorelock out this weekend and be back with feedback a.s.a.p.

BR
Jens
In reply to John Gschnaidner

Re: Conditional activities: ActivityLocking v 2.4 beta

by Asier Suarez -
Hello everyone!!! I am getting some problems to try to decide for a module like this... which is the best one? Because there are many... I need something like what ActivityLocking does... but I still have Moodle 1.5.3+, can I use it?
In reply to Asier Suarez

Re: Conditional activities: ActivityLocking v 2.4 beta

by John Gschnaidner -

Hi,

ALv2.4 works with moodle 1.6 only. I have not tried it with 1.5.3 and I think there might be some problems to do so.
AL is a hack (in any version), meaning some system files are replaced with the code of AL.
If you check the moodle Docs: Activity Locking you will see, that there are only two versions supporting 1.5: AL 3.0 and CA 1.0

I have somewhere an old version, that works with 1.5.3, but with less functionality. If you can wait a few days I will try to find it.

Regards
  John

In reply to Asier Suarez

Re: Conditional activities: ActivityLocking v 2.4 beta

by Bernard Boucher -

Hi Asier,

            as you noticed you have to choose the appropriate matching versions of Moodle and activity locking to get good results. That table show many good combinasions but for Moodle 1.5.3  there is no specific version,  only 2 versions for 1.5.2 that may work but I did'nt test these with 1.5.3sad.

If you are really interested ( or forced ) by 1.5.3  then I have one version here not packaged that I used last semester. Let me know, I will package it and post it if you want it.

But you should test it before on a test server, not on your production server because it is a hack that replace some Moodle files.

I hope it may help,

Bernard

In reply to John Gschnaidner

Re: Conditional activities: ActivityLocking v 2.4 beta

by Blake Arnold -
Hi John,

Thank you very much for your hard work on this module. I hope you and the rest of the community will forgive a novice moodle user (myself) for a basic question.

I've successfully installed the module on my test bed but am having a hard time understanding the basic interface. My objective is to have a series of quizzes (multiple choice) unlock in succession upon receipt of a passing score.

For example, if a student passes Quiz 1, then (and only then) may they proceed to Quiz 2. Once they pass Quiz 2, they may proceed to Quiz 3. The intent is to apply this not in an assessment capacity as much as a basic review. Unfortunately, I am a bit confused by the Activity Locking versus Settings tab. I notice that I can only "lock" Quizzes outside of the one I am currently editing. Is there a simple way to structure them in the succession I am aiming for?

Thanks,
Blake
In reply to Blake Arnold

Re: ActivityLocking v 2.4 beta - How to use tab settings

by John Gschnaidner -

Hi Blake,

in short, if you edit any module (resource or activity), you will see three tabs:

  • normal edit function of the module
  • Activity Locks
    Actually the name is a bit misleading; here you do not set which modules to lock, but which module needs to be completed with what score to unlock the current module.
  • Settings
    Upper part is for setting the completed condition of this module and its visual options. This is more or less just a display and does not really lock anything.
    In the lower part you find the visual settings of the lock (conditions on the tab before): Check-box, style when locked (requires a change in your CSS) and hide when locked (the module won't be visible to the student until the lock conditions are fulfilled).

Actually, what you want to do is quite easy:

Lets say you have created test AB and C; important is, you won't see locking tabs during creation of a module (resource & activity).
A needs no lock; you will have to start somewhere.
Click the edit icon for B and select the middle tab (where it says 'Activity Locks'. You need to set the score of test A, which is the predecessor, to unlock the test B; save it and go to the last tab. Adjust the options Check-box, style or hidden when locked to your liking.
Do the same with C using only the B score as lock condition.

So what the student gets is, that he can only access test A. Only after completing test A with the score (you defined as lock condition for B) he will be able to access B. And only after completing B he will be able to access C.

Quite easy, I think.

Regards
  John