Conditional activities: Activity Locking for Moodle 1.5.1

Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
Number of replies: 52
Behold the latest incarnation.

This is mainly a bugfix release. It's been a while since the last release, and I'm not sure if there are any new features.

As always, any and all coments are welcome and remember - USE AT YOUR OWN RISK

By the way, this is now also available via CVS in the contrib folder.

Ah. I appear to have exceeded the 100kb limit for the zip file. I'll post it in two posts here, but in the future this may have to go CVS only mixed
Average of ratings: -
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by David T. Cannon -

Hmm, I didn't see it in CVS. named activity.... right?
Dave.

In reply to David T. Cannon

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
I don't see it in CVS either if I browse the repository on the Sourceforge site. I assume it takes a while to update or something.

If however, you use a CVS client and try to check out contrib/activity_locking it works fine.
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by David T. Cannon -

Well, I tried both a client and through the web. I'll just wait until later in the day and see if it shows up.
Dave.

In reply to David T. Cannon

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
On the other hand...

It might be my first journey into CVS use hasn't been altogether successful.
We'll see.
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
It has now appeared on the Sourceforge CVS browser.
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Bernard Boucher -
Hi Stuart and David,
                             first thanks.

The pcakage should be updated and zipped automatically every 24 hours to ( will start tomorrow only ) :

http://download.moodle.org/download.php/modules/activity_locking.zip

Bye,

Bernard

In reply to Bernard Boucher

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Nikki Macfarlane -
Bernard,

The activity locking is working great for me. One question.

I use evaluation forms (using the new feedback module by Andreas). The student has to submit these evaluations before they can complete their course. When I look at the feedback forms though in activity locking, it just says the student has to access the feedback. However, I would like them to have to submit it rather than just open the page.

There are two tables - feedback and feedback_completed. How can I make the activity locking look in feedback_completed rather than just feedback?

Nikki
In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
Nikki,

I'll have a look at the feedback module and see if I can "fix" it for you...
In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
Hi Nikki.

I think I have figured out how to do what you want with the feedback module. Unfortunately, I can't check if it works as I can't get the feedback module to work at all on my system.

Getting it to do what you want involves 2 steps:
  1. Firstly, you need to add a field to the feedback_completed table.
    ALTER TABLE `mdl_feedback_completed` ADD `completed` TINYINT UNSIGNED DEFAULT '1' NOT NULL AFTER `userid` ;
    Basically, all you need to add is a fielde called "completed" which has a default value of 1
  2. Next you need to edit the file mod/feedback/lib.php
    Go down to line 121. You should be at a function called "feedback_grades". You need to edit that function so that it is as follows
    function feedback_grades($feedbackid) {
    /// Must return an array of grades for a given instance of this module,
    /// indexed by user.  It also returns a maximum allowed grade.
    ///
    ///    $return->grades = array of grades;
    ///    $return->maxgrade = maximum allowed grade;
    ///
    ///    return $return;

       $feedback = get_record("feedback", "id", $feedbackid);
        if (empty($feedback)) {
            return NULL;
        }
     
        $return->grades = get_records_menu("feedback_completed", "feedback", $feedbackid, "", "userid,completed");
        $return->maxgrade = 1;
        return $return;
    }
Now, when you lock modules there should be an entry for the feedback item and it should have the option of 1 or 0. Setting it to 1 means that a student must send off the feedback form for the activity to be complete.
Let me know if it works...
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Nikki Macfarlane -
Thanks Stuart for such an amazingly quick response!

OK, so part worked and part did not.

I created the extra field in the database - worked fine.

I changed the function in the lib.php file - worked fine.

I went into the course and opened the locked activity - and sure enough, there was a drop down list now showing the option of flag 0 or 1, for viewed or submitted - worked fine

I went on to a dummy student account and submitted the feedback form. Checked the database (feedback_completed) and the flag had been set to 1 correctly - worked fine.

However, the student still could not access the locked activity that was dependant on this feedback form being submitted. The form is definitely there - i can see it on the feedback pages under analysis. But from the students view, they still cannot access the activity that was conditional on the submission.

If it is easier to test and see what i mean I have set up a dummy teacher and student account for you to take a look at. I will send a message directly to you with the access details. The url is:

www.childbirthinternational.com/study

The course is Testing (under Administration). There are two feedback forms - one that should be submitted and one that does not have to be. And one conditional activity - a request for certification to be processed form that is reliant on the first feedback form being submitted.

Thanks so much for all your help with this.

Nikki
In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
I think I might have figured out why it's not working.
(although I may well be wrong)

I think it is because you have renamed the module to "evaluation" instead of "feedback". It all depends where you changed the name of the module.
Did you change the record for feedback in the "modules" table? If so, change it back and see if it then works.
If you'd like to change the name of a module that appears to a user, then you only need to edit it in the language files (assuming it is written according to Moodle's rules)
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Nikki Macfarlane -
No such luck Stuart! I wish it had been that easy. The name in the tabel itself was still Feedback. I changed it in the language file where there are only two entries for feedback but it still was the same.

I can see the feedback has been updated with the grade of 1 in the feedback_completed table. It appears in the gradebook with the correct score of 1. Just is not unlocking once it has been submitted. Confused???

Nikki
In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
Yes. Very confused.
What makes it all the more difficult is that I can't get the feedback module to work at all here on any of my systems.

I think the next step is to start putting some debug code in the locking code.
Is there any chance you could download this version of locklib.php and put it in your lib folder of your moodle installation. It will hopefully show what is going wrong...

Bear in mind that this will print ugly debugging code above any locked activity.
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Nikki Macfarlane -
Thanks Stuart. No problem about the ugly code - my site is not live yet.

OK, I have attached one file - at the beginning is what i see in the debugging on the course topics page, and second is what I see in the locked activity itself.

Good luck!

Nikki
In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
Aha.
I've figured out why it's not working.

Basically, the piece of code that checks if a module is (un)locked works as follows:
  1. It looks at each module that is locking that module
  2. For each module, it forst looks in the logs for an entry. If there isn't one it assumes the module hasn't been accessed and stops.
  3. Only if there is an entry in the logs does it continue to see if a user has the necessary grade
The problem we have with the feedback module is that if anonymous posting is on, then nothing (useful) is written to the logs.

With that in mind, try the attached locklib.php file.
Hopefully it should work for you. There may be more issues, though, with this anonymous thing.
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Nikki Macfarlane -
Stuart,

You are a star!! This worked perfectly. I created a feedback form that was nonanonymous and it was perfect. I have no need for anonymous forms but would you like me to test to see if it works ok?

Nikki
In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -

If you wouldn't mind.

As I said, I've got no way of checking it as feedback doesn't seem to work on my system. It'd be nice to know it works.

It should...

In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Nikki Macfarlane -
Anonymous does NOT work Stuart. I tried to set it up with thre different feedbacks using the three different options of anonymous, non anonymous and self defined. Non anonymous works but when it is set to anonymous it does not. Sorry! This won't be a problem for me since I always want students to identify themselves but can see it would nice if it worked for others.

Nikki
In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -

...but can see it would nice if it worked for others...

It would. But then thinking about it, adding an entry to the log when a user submits an "anonymous" feedback kind of makes a mockery of the anonimity.

In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Bernard Boucher -
Hi Nikki,
              sorry to not be as fastwink as Stuart  who his the activity locking creator!

It is a good idea to try to adapt Andreas nice feedback module with activity locking.

You are on a right way with Stuart suggestions.

Bye,

Bernard

In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by David T. Cannon -

Bit of a pain that CVS is, wouldn't let me grab an export copy(without all the cvs dirs).

OK. I have a clean install of moodle 1.5.1, new db, and latest al_0.41.

Label problem doesn't appear. Cool.

  1. When the locked message comes up "This activity is currently locked. You must complete the following prerequisites first "Time Delay" . I think the amount of time remaining should be displayed.
  2. By clicking the topic lock, you can select pre-requisites for that topic, I assumed. So I selected all the activities in the previous topic as pre-requisites. Now, the lock only seems to appear on the first activity of the topic I locked. Seems it ought to lock the whole topic.

Topic 1
  activity 1
  activity 2

Topic 2
  activity 3
  activity 4

IE. By clicking on the topic 2 lock, and setting activity 1 and 2 as pre-requisites, locks should be placed on activity 3 and 4. Sound right? It is only placing a lock on activity 3 currently.

     3. The lock page (http://192.168.1.100/moodle/course/lock.php?)  is not completing its output. Please add:

print_footer($course);

just before closing php tag:

?>

Dave.

In reply to David T. Cannon

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
When the locked message comes up "This activity is currently locked. You must complete the following prerequisites first "Time Delay" . I think the amount of time remaining should be displayed.

It is for students (or at least it should be).

By clicking the topic lock, you can select pre-requisites for that topic, I assumed. So I selected all the activities in the previous topic as pre-requisites. Now, the lock only seems to appear on the first activity of the topic I locked. Seems it ought to lock the whole topic.

You assumed correctly. I think I must have made a mistake in the coding. I did a couple of 11th-hour changes and may have broken something.

In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
It seems to work fine on my system. I suspect this could be another php4/5 problem. It may well be another "foreach" thing. Have a look on line 54 of course/sectionlock.php
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Nikki Macfarlane -
Stuart,

Think I have found a minor bug - at least I think it is minor!

It seems I cannot have activity locking together with copy resources. I had copy resources a few days ago. Then I copied in activity locking and copy resources disappeared - did not connect the two at the time.

I just now copied in copy resources again and activity locking was lost straight away.

Would be nice to have both features. Do I post this here or somewhere else since it crosses over two different features?

Nikki

In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Luke Diah -

I recently upgraded from 1.4.5 to 1.5.+, and now to 1.5.2 the certificate locks where running perfectly but after the upgrade I get this error:

"Call to undefined function: islocked() in /home/minnay/public_html/CEU/course/lib.php on line 1062", students can print a certificate without going through a course lesson. I have been carefully following the discussions and silently using the hacks but now I am kind like stuck.

Any idea on how to fix would greatly be appreciated.

Thanks

Luke

In reply to Luke Diah

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
Luke.

The first thing I would suggest you try is go to

http://download.moodle.org/download.php/modules/activity_locking.zip

to get the latest version of activity locking.
Unzip it to the relevent folders and it should fix your problem.


In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Luke Diah -

Thanks Stuart

I have just downloaded and added the newer files but it has not fix the problem, the error line now moved to /course/lib.php line 1061 with the same message. Fatal error: Call to undefined function: islocked() in /home/minnay/public_html/CEU/course/lib.php on line 1061

Any further suggestions

Luke

In reply to Luke Diah

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -

If you have overrwitten your existing files with the ones in the zip then I can't see what has happened.

One thing you could check for me. Can you have a look near the top of the course\lib.php and see whether it has a "require_once" line for lib\locklib.php

Anyone got any other suggestions? I'm stumped.

In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Nikki Macfarlane -
There are two require_oce lines Stuart, although none near the top of the file.

Line 1163:
        require_once("$CFG->dirroot/mod/resource/lib.php");

Line 1424:
        require_once("$CFG->dirroot/enrol/$CFG->enrol/enrol.php");

This is all that is in there that says require_once.

In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Luke Diah -

That's correct; the two require_once lines are found at 1163 and 1464

Luke

In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Luke Diah -

Here is what I found

if (file_exists($libfile)) { //4  require_once($libfile); line 33

if (file_exists($libfile)) { require_once($libfile); line 67


global $USER, $CFG, $course;  //It there an alternative to global $course?

  require_once($CFG->dirroot.'/course/lib.php');
  get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
  $locklist = ""; line 102

Thanks

Luke

In reply to Luke Diah

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
How about at the top of your course\view.php?
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Luke Diah -

This is what is found


    require_once('../config.php');
    require_once('lib.php');
    require_once($CFG->libdir.'/blocklib.php');
    require_once($CFG->libdir.'/locklib.php');
on line 5

and

 require_once($CFG->dirroot.'/calendar/lib.php') line 46

Luke

In reply to Luke Diah

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Luke Diah -

Any suggestions on what I should try to crank?

Luke

In reply to Luke Diah

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by S. Perito -
Hi all

I too am getting Fatal error: Call to undefined function: islocked() with Moodle 1.5.2 and the latest version of activity_locking.

Has anyone found the solution?

Thanks
In reply to S. Perito

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by S. Perito -
Adding require_once($CFG->libdir.'/locklib.php'); to course/lib.php seems to fix things...
In reply to S. Perito

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Luke Diah -

Thanks Perito

Where exactly do you insert require_once($CFG->libdir.'/locklib.php');? I have tried different places but it still gives me the same fatal error.

Luke

In reply to S. Perito

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Jens Gammelgaard -
Picture of Translators
I have added S. Pirotos code here in the course/lib.php file, which makes it work on my installation:

///Activity Locking ///
}
require_once($CFG->libdir.'/locklib.php');
if (($locks = islocked($mod)) and (array_search("closed", $locks) or isteacher($course->id))) {
$linkcss = " class=\"dimmed\" ";
echo "<img src=\"$icon\"".
" height=16 width=16 alt=\"$mod->modfullname\">".
" <font size=2><a title=\"$mod->modfullname\" $linkcss $extra".
" href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename (".get_string("locked", "lock").")</a></font>";

} else { // Normal activity
$linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
echo '<img src="'.$icon.'"'.
' class="activityicon" alt="'.$mod->modfullname.'" />'.
' <a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.
$instancename.'</a>';
}

if ($locks) {
if (isset($course->showactivitytracking) and $course->showactivitytracking == 1) {
foreach ($locks as $lock => $state) {
if ($state == "open") {
echo "&nbsp;<img src=\"$CFG->pixpath/t/open.gif\" height=\"11\" width=\"11\"".
" title=\"".get_string("predecessorcomplete", "lock").": ".urldecode($modinfo[$lock]->name)."\"".
" alt=\"".get_string("predecessorcomplete", "lock").": ".urldecode($modinfo[$lock]->name)."\">";
} else {
echo "&nbsp;<img src=\"$CFG->pixpath/t/closed.gif\" height=\"11\" width=\"11\"".
" title=\"".get_string("predecessornotcomplete", "lock").": ".urldecode($modinfo[$lock]->name)."\"".
" alt=\"".get_string("predecessornotcomplete", "lock").": ".urldecode($modinfo[$lock]->name)."\">";
}
}
}
}
///End Activity Locking ///
In reply to Jens Gammelgaard

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Chardelle Busch -
Picture of Core developers
Jens,

I'm soooooo sorry, I sent you my copy from contrib and didn't realize that Stuart hadn't added that lineblush

I'm glad you've gotten it all figured out!!!
In reply to Chardelle Busch

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Jens Gammelgaard -
Picture of Translators

Oh,- Chardelle...

I thought you've given me this as a task in your Lifeworkout programme. smile

Maybe Stuart needs a hand to keep the CVS up to date?

So Stuart if you are back from vacation, then you can let us know, if you need help.

In reply to Jens Gammelgaard

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by James Robertson -

I have been using activity locking on my localhost without problem.  I have added the line shown.  Do I need to do anything else?

In reply to Luke Diah

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Jens Gammelgaard -
Picture of Translators

Hi Stuart and others!

I have identified this error too, with the latest Moodle 1.52+ version of today.

The error is 'only' seen on the frontpage,

Look forward to see what we can do about it.

In reply to Jens Gammelgaard

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Jens Gammelgaard -
Picture of Translators

Hi Moodlers,

Regarding the fatal error with the locklib issue, then it seems you only can reproduce it IF you have a subject in the middle of your front page.

If I set the site settings to only show the courses, then I don't see the fatal error, but it is still there of course.

I use it with Moodle 1.5.2 + (2005060222) version.

And when I try to lock an activity it says: Warning: Variable passed to each() is not an array or object in C:\minixampp\htdocs\moodle\lib\locklib.php on line 145

Chardelle thank you for the files you send me, I am sorry it did not help, so for now we can maybe conclude that this works with up til  Moodle version 1.5.2 (2005060220) - the version that Chardelle has success with?

So fellow Moodlers don't get to tempted to update your Moodle with this great mod yet.

KR
Jens

In reply to Nikki Macfarlane

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -
Yes Nikki. Activity Locking uses a custom course/lib.php file. I would imagine copy resources does too.

It would require manually editing that (and possibly other) file to include both pieces of custom code.

As both hack are under development, it would be difficult to keep it all up to date.
In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by David T. Cannon -

Very strange behaviour. I looked at PHP and zend bugs, and nothing.

It appears that you need to place in lib/locklib.php:

reset($passmarks);

right before the

while(list($predecessor, $passmark) = each($passmarks)){

call. Otherwise this statement fails after first call. IE, if you need to lock 3 activities in a section, only first 1 will lock.

Dave.

In reply to David T. Cannon

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -

I think I know why.

As you know, $passmarks is an array. The elements delayday, delayhour, delaymin are the last 3 entries in the array.

The lines above the one you have referenced above work with those last 3 elements, e.g $delay = $passmarks->delayday or something.

After that has been done this must leave (on some versions of php) the array's internal pointer pointing to one of those elements, which is at the end of the array.

When the foreach function is called, it works its way through the array from the pointer to the end of the array. In this case, the pointer is at, or almost at, the end of the array so nothing is done.

That's why the reset() function works nicely.

That's my guess anyway.

In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by David T. Cannon -

Stuart,

Any bugs still outstanding? I am having some trouble getting locking to work based on a grade. I can still click on a link, thats greyed, and says locked. And enter that activity. Is that suppose to happen?

Where is the code that checks that a grade has been met, which file, and function?

Dave.

In reply to David T. Cannon

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Stuart Mayor -

Off the top of my head, it's the lib/locklib.php file.

I believe the function is called islocked().

The checking of user grades happens, I think, somewhere around the deepest part of the nesting within that function.

In reply to Stuart Mayor

Re: Conditional activities: Activity Locking for Moodle 1.5.1

by Ralph Blakeslee -

Hi Stuart,

I was just wondering what the status was of this/

Thanks!

Ralph