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
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
Thanks for sharing your code. I think this will go nicely with the new Progress Bar block.
Just a few questions:
- Is it for 1.9.5?
- Which course formats have you tested it with?
- What conditions change x to a tick?
Cheers,
Barry
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
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
//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
> 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
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
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' /> ";
} else {
echo "<img src='".$CFG->wwwroot."/pix/i/cross_red_big.gif' /> ";
}
}
Cheers,
Barry
Thank you for your fast reply. I will try it out soon.
With kind regards,
Hartmut
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
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
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!!
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.
--sam
Thank you very much. This is a very useful. Will the lib.php work in conjunction with Activity Locking?
Tieku
Will it work with it?
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
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
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
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