Show Completion

Show Completion

by David Peachey -
Number of replies: 35
I was wondering if anyone has ever seen something that can mark assignments quizzes etc completed on the main screen?

Thanks
Average of ratings: -
In reply to David Peachey

Re: Show Completion

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I have. It already exists in Moodle 2.0, which is currently in development.
In reply to Tim Hunt

Re: Show Completion

by David Peachey -
Do you think there's an easy way of getting that and implementing it into the current version of Moodle?
In reply to Tim Hunt

Re: Show Completion

by David Peachey -
I figured out a way

completion.png
In reply to David Peachey

Re: Show Completion

by Paul Vaughan -
Yes, would love to know how you're achieving this.
In reply to Paul Vaughan

Re: Show Completion

by David Peachey -
It's not quite finished yet. The forum part is not completely working yet. When I'm all finished I can show you guys.
In reply to David Peachey

Re: Show Completion

by Zachary Johnson -
That is fantastic news. Not to put undue pressure on you but any idea when you might be able to share?
In reply to Zachary Johnson

Re: Show Completion

by Geoff Lubich -

Hi Zachary

The program is undergoing some beta 1 testing before we install full functionality, and then we will look at ways to enable sharing.

We are a little cautous because of the commercial applications in real time performance support, dont want to give away too much yet.

But we will keep people informed of the progress through these pages

In reply to David Peachey

Re: Show Completion

by David Peachey -
I am now finished it. The code isn't the greatest but it works. Feel free to do whatever you want with it. As you can see from the image, I changed the icons to the images from the quiz module. I've also changed the code so it should work with any database prefix.

completion.png


To install this file, unzip and upload lib.php to the course folder. Make sure you make a copy of the original file before you upload this one, just to be safe.

Download Here
Average of ratings: Useful (1)
In reply to David Peachey

Re: Show Completion

by Barry Oosthuizen -
Hi David,

Thanks for sharing your code. I think this will go nicely with the new Progress Bar block.

Just a few questions:
  1. Is it for 1.9.5?
  2. Which course formats have you tested it with?
  3. What conditions change x to a tick?

Cheers,

Barry
In reply to Barry Oosthuizen

Re: Show Completion

by David Peachey -
Good questions, I should have mentioned these.

1. Yes
2. Topics and Weekly

Assignments - Submitted
Resource - Viewed
Lesson - Completely finished
HotPot - Submitted
Quiz - Submitted
Questionnaire - Submitted
Forum - 1 post - You can change this to as many posts as needed by changing the value of $postNum

Also, this is not compatible with the QuizPort mod
In reply to David Peachey

Re: Show Completion

by Barry Oosthuizen -
Thanks David,

it seems to be working ok with the contributed 'Collapsed Topics' format as well.

Looking at your code it would seem that this would only work with MySQL databases.

You could replace the mysql_query() and mysql_fetch_array() queries with Moodle's own functions.

E.g get_records_select() or get_records_sql() will make it work across most other databases.

Cheers,

Barry
In reply to Barry Oosthuizen

Re: Show Completion

by David Peachey -
That would be great, I was wondering if there was anything like that in moodle.
In reply to David Peachey

Re: Show Completion

by Barry Oosthuizen -
Here's how to replace the code for checking forum posts (not tested):

//Detect Completion
$forumSQL2 = ("SELECT COUNT(p.id) AS postcount, MAX(p.modified) AS lastpost
FROM {$CFG->prefix}forum f
JOIN {$CFG->prefix}forum_discussions d ON d.forum = f.id
JOIN {$CFG->prefix}forum_posts p ON p.discussion = d.id
JOIN {$CFG->prefix}user u ON u.id = p.userid
WHERE f.id = $forumid
AND p.userid = $userid
$timedsql");

$forumIDRow = get_records_sql($forumSQL2);

and here how to replace the code for the other modules (e.g. assignments):

$completedRow = get_records_select('assignment_submissions',"assignment = '$instance' AND userid ='$USER->id'");

Cheers,

Barry
Average of ratings: Useful (1)
In reply to Barry Oosthuizen

Re: Show Completion

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

> Also, this is not compatible with the QuizPort mod

Here's some untested SQL to detect whether the current user has completed a QuizPort or not: 

$quizportSQL2 = ""
    ."SELECT id FROM {$CFG->prefix}quizport_unit_grades "
    ."WHERE parentid=$instance AND parenttype=0" // 0=QUIZPORT_PARENTTYPE_ACTIVITY
    ." AND userid=$USER->id AND status=4" // 4=QUIZPORT_STATUS_COMPLETED
;

or using the Moodle API for database access:

$select = "parentid=$instance AND parenttype=0 AND userid=$USER->id AND status=4";
$completedRow = get_records_select('quizport_unit_grades', $select);

And actually, since you only want to test whether these records exist or not you can use a Moodle function which has been set up just for that purpose:

$select = "parentid=$instance AND parenttype=0 AND userid=$USER->id AND status=4";
if (record_exists_select('quizport_unit_grades', $select)) {
    // activity has been completed
} else {
    // activity has not been completed yet
}

Have a look at "lib/dmllib.php" for details of the other functions in the Moodle database API.

keep up the great work!
Gordon

Average of ratings: Useful (1)
In reply to David Peachey

Re: Show Completion

by Hartmut Scherer -
Hi Barry,

Thank you for all your work. This will help students to track their assignments and activities. If I change $postNum, it will change the required numbers of posts for all classes. Is it possible to increase the number of posts for only two classes and keep the default number of posts = 1?

Is there a chance to include the database activity?

With kind regards,

Hartmut
In reply to Hartmut Scherer

Re: Show Completion

by Barry Oosthuizen -
Hi Hartmut,

I can't take any credit for this work: David Peachey posted the code for this functionality.

Anyway, here is my 5min attempt for the database activity.

Insert this block of code rigth before any line that says
" // Determine what type of course this is" (somewhere after line 1551)

//Determine what type of activity module this is
if ($mod->modname == "data") {
$instance = $mod->instance;
$select = "dataid = '$instance' AND userid ='$USER->id'";
if (record_exists_select('data_records', $select)) {
echo "<img src='".$CFG->wwwroot."/pix/i/tick_green_big.gif' />&nbsp;&nbsp;";
} else {
echo "<img src='".$CFG->wwwroot."/pix/i/cross_red_big.gif' />&nbsp;&nbsp;";
}
}

Cheers,

Barry
In reply to Barry Oosthuizen

Re: Show Completion

by Hartmut Scherer -
Hi Barry,

Thank you for your fast reply. I will try it out soon.

With kind regards,

Hartmut
In reply to Hartmut Scherer

Re: Show Completion

by Barry Oosthuizen -
You can find a reworked copy of the code that works on other databases and caters for database & feedback module here
In reply to David Peachey

Re: Show Completion

by Hartmut Scherer -
Hi David,

I really appreciate your work. Thank's a lot for your contribution. Can "Show Completion" be set to only a few courses and others will not have it?

With kind regards,

Hartmut
In reply to Hartmut Scherer

Re: Show Completion

by David Shaw -
Help I am new to all this - how do I do a similar thing for SCORM modules - again I only really want a tick if they have viewed the scorm course.  (My SCORM course is only a basic packaged Flash file).  Thanks
In reply to David Peachey

Re: Show Completion

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Cool - but I glanced at the code, so just adding a few warning notes:

1. This code is not suitable for use on any large site or site with high usage, because it does queries on mdl_log when viewing the page.

2. It is mysql-specific rather than using moodle database access, so it won't work for anyone using a real nother database.

I'm sure this is fine for your situation, just in case other people might need to know.

The completion system I built for Moodle 2 doesn't have these problems, however it is a good deal more complicated [some of which is for good reason, some may be a bad idea] and required wide changes to the system, so unfortunately it's difficult to port it to 1.9.

(We actually run a version of this code on 1.9 but it is rather OU-specific and it isn't useful for me to release this - the only route that could work is to backport based on the current Moodle 2 code or the patch in the bug. Anyone who wants to backport it is on their own, I'm afraid, it'll be difficult.)

--sam
Average of ratings: Useful (1)
In reply to sam marshall

Re: Show Completion

by David Wallace -
Hi all,

Thanks very much for your efforts so far, and thanks Sam for this reality check when intending to use Progress Block on large sites - invaluable warning.

If I may ask, do you have a figure-based gauge at all on the performance issue mentioned? I understand if it's just a case of 'large performance issues', but if there's some figures out there somewhere to determine the 'safety level' of user numbers, then I'd really appreciate a heads up!

cheers again everyone!!
In reply to David Wallace

Re: Show Completion

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
No exact figures, but:

a) course view page is one of the most frequently-shown pages. adding queries of any type to this page is a potential issue where performance is a concern.

b) log table can get very very big (ours is 81,774,983 rows and a total of 20GB at the moment) and performance can get poor. Even though it might be using a user index so it can find the necessary rows quickly, going to get that data can involve skipping through hundreds of individual blocks all over the disk. If the database's planner doesn't manage to use indexes and it has to do a sequential scan... well, that takes 70 seconds on our system at the moment [probably because it wasn't all in RAM].

To be fair, with the user index, it is normally quite quick to access the log table (getting all my entries takes about 60ms at the moment, for instance - not exactly great to add to every course page, but possibly not unacceptable). But if anything goes wrong, it's this type of table (massive and with lots of churn) which will perform poorly.

compare that to say the course_modules table, which is not really a 'small' table exactly - but that has only 169,117 rows on our system, and you can do a sequential scan in 30ms [presumably because it's cached in RAM].

basically for large sites, any query that access the log table is a potential issue, especially if it isn't time-bound. (Also, log table is archived after a configurable time, typically a few months, did your system take that into account ie might it show up like somebody hasn't done something when actually they have? I forget.) Consequently I think it's safer to either:

a) store information (if required) somewhere more specific in addition to log table, at the time something happens.

or

b) process mdl_log table a day at a time in overnight cron to extract necessary information and store in another more specific table

both these things are likely to add a lot more work so if you have a small system and no problem with performance and you can leave the archiving off or for a long enough time period, please do continue to go crazy with mdl_log. smile

--sam


In reply to David Peachey

Re: Show Completion

by Tieku Bortei-Doku -
Does the download link still work? Where can I get the file?
In reply to Tieku Bortei-Doku

Re: Show Completion

by Barry Oosthuizen -
Hi Tieku,

A reworked copy including completion status for Database & Feedback modules that should work on all supported databases is available at MDL-20212

I guess it should really be moved to Contrib.

Cheers,

Barry
In reply to Barry Oosthuizen

Re: Show Completion

by Tieku Bortei-Doku -
Barry,

Thank you very much. This is a very useful. Will the lib.php work in conjunction with Activity Locking?

Tieku
In reply to Tieku Bortei-Doku

Re: Show Completion

by Barry Oosthuizen -
If your activity locking solution (I think there are a few) applies a patch to lib.php then no it won't work. But it shouldn't be difficult to make it work by manually editing the files.
In reply to Barry Oosthuizen

Re: Show Completion

by Tieku Bortei-Doku -
I am referring to the Activity Locking Course Format for Moodle 1.9. See the thread here. http://moodle.org/mod/forum/discuss.php?d=128318#p562002

Will it work with it?

In reply to Tieku Bortei-Doku

Re: Show Completion

by Barry Oosthuizen -
Hi Tieku,

I just had a look at the AL Course format and it doesn't touch the course/lib.php. Whether it will work, I don't know, why not try it and see?. At least there shouldn't be any conflict codewise.

I will post a patch in CONTRIB soon so you might find that useful.

Cheers,

Barry


In reply to Barry Oosthuizen

Re: Show Completion

by Tieku Bortei-Doku -
Barry,

I tried it. When I switch to the AL course format, the completion icons disappear but when I switch back to Topics format they reappear. Would anyone know why, even though AL does not touch the lib.php?

Tieku
In reply to Tieku Bortei-Doku

Re: Show Completion

by Barry Oosthuizen -
I've uploaded a patch file to CONTRIB-1787 which contains some minor changes and a small fix. It should help you to see how it works in the first place. From there maybe you or someone else (or me if I find the time) can figure out how to make it work for the Activity Lock solution.
In reply to Barry Oosthuizen

Re: Show Completion

by Tieku Bortei-Doku -
Hello Barry,

I tried your new code and it works OK. Unfortunately since i am not a programmer i cannot see what's happening.

My question is if the AL course format does not make any changes to the lib.php, why do they not work together? I change back to Topics format and the images re-appear???

Any help is very much appreciated.

Tieku
In reply to Barry Oosthuizen

Re: Show Completion

by Tieku Bortei-Doku -

Hello Barry, after one year i would like to ask my question again:

I tried your new code and it works OK. Unfortunately since i am not a programmer i cannot see what's happening.

My question is if the AL course format does not make any changes to the lib.php, why do they not work together? I change back to Topics format and the images re-appear???

Any help is very much appreciated.

Tieku