Creating a new activity module with completion tracking - missing grade item error

Creating a new activity module with completion tracking - missing grade item error

by Joe Cape -
Number of replies: 5
Picture of Plugin developers

I am creating a new activity module. I don't want it to track grades (which are not applicable to it) but I do want it to track activity completion.


I have implemented the method mymodule_get_completion_state() method in lib.php.


The problem I am having is that when the update_state() method is called (from a completion_info object), I get the following error:


 Cannot find grade item for 'mymodule'

cm '116' matching number '0' 


----


Does there need to be a record in the grade item table corresponding to the new module for completion tracking to work? If so, how do I set up the new module to ensure this gets added?


Thanks.

Average of ratings: -
In reply to Joe Cape

Re: Creating a new activity module with completion tracking - missing grade item error

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

Do you have your module's code available in a public repository such as github? What does it declare in its lib.php foobar_supports() (where foobar is your plugin), particularly for the FEATURE_GRADE_HAS_GRADE.

Also, please make sure you have full developer debug mode enabled while developing plugins for Moodle. There should be more detailed callstack to trace where the error comes from.

In reply to David Mudrák

Re: Creating a new activity module with completion tracking - missing grade item error

by Joe Cape -
Picture of Plugin developers

Hi David,

Thanks for the response. I can see the full stack trace-

Stack trace:
  • line 1688 of \lib\completionlib.php: moodle_exception thrown
  • line 761 of \lib\completionlib.php: call to completion_info->internal_systemerror()
  • line 673 of \lib\completionlib.php: call to completion_info->internal_get_state()
  • line 818 of \lib\completionlib.php: call to completion_info->update_state()
  • line 76 of \mod\mymodule\view.php: call to completion_info->set_module_viewed()

I can see that completion_info->internal_systemerror() gets triggered because there is no record in the grade_items table. 

I made sure that:

case FEATURE_GRADE_HAS_GRADE:         return true;
- even though I don't need to use grades (just completion tracking) due to the fact that it looks for a matching record in the grade items table.

Here is the switch statement in the supports() method:

switch($feature) {
case FEATURE_IDNUMBER: return true;
case FEATURE_GROUPS: return false;
case FEATURE_GROUPINGS: return false;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_OTHER;
case FEATURE_BACKUP_MOODLE2: return true;
case FEATURE_NO_VIEW_LINK: return false;
case FEATURE_COMPLETION_HAS_RULES: return true;

default: return null;
}

In reply to Joe Cape

Re: Creating a new activity module with completion tracking - missing grade item error

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

I made sure that FEATURE_GRADE_HAS_GRADE returns true

That's the point. Your module should return false if it does not maintain its own grade item in the gradebook. You may want to check how other modules that do not have their grades (such as url, page or feedback) implement the completion API.

In reply to David Mudrák

Re: Creating a new activity module with completion tracking - missing grade item error

by Joe Cape -
Picture of Plugin developers

The problem is that I'm getting the same error whether or not FEATURE_GRADE_HAS_GRADE is set to true.

I'll try creating a new instance of the mod when set to false to see if that works.

In reply to Joe Cape

Re: Creating a new activity module with completion tracking - missing grade item error

by Joe Cape -
Picture of Plugin developers

Right - it is working now.

I had turned  FEATURE_GRADE_HAS_GRADE on because it was the only way I could see to get more completion options.

This must be turned off. Then add a method 

add_completion_rules()

to mod_form.php and implement in a similar way to other modules. You also need the 

completion_rule_enabled()
method (in mod_form.php as well).



Average of ratings: Useful (1)