Exception - Call to a member function add grade condition() on null

Exception - Call to a member function add grade condition() on null

од Jose Velazquez-Torres -
Број на одговори: 3

Im getting the following exeption:

Exception - Call to a member function add grade condition() on null

Im trying to add a grade condition for complition to a certain activity in a course. Im ussing this command:

$quiz1->add_grade_condition($qidingradeitem,$thresholdgrade,null,true);

the $qidingradeitem stores the id of the activity from the mdl_grade_items table and the $thresholdgrade stores the grade it will be set to minimumgrade in the DB.

Could someone tell me what I'm missing or doing wrong?

Просек на рејтинзи: -
Во одговорот до Jose Velazquez-Torres

Re: Exception - Call to a member function add grade condition() on null

од lior gil -
Слика од Core developers
The problem is described in the exception. You are trying to call a function on a null value, meaning, your $quiz1 variable is undefined.
For example, you'll get the same exception with $foo->bar().
Во одговорот до lior gil

Re: Exception - Call to a member function add grade condition() on null

од Jose Velazquez-Torres -
Thank Lior,

Could you explain me how to correct define the $quiz1 variable? I have been reading a few API and I do not see how to define it.
Во одговорот до Jose Velazquez-Torres

Re: Exception - Call to a member function add grade condition() on null

од lior gil -
Слика од Core developers
I'm afraid I can't. I'm unfamiliar with this function and also don't know what object/class is $quiz1 supposed to be from this single line of code.
Maybe you could try and familiarize yourself with the quiz or just the course module structure, or look for another place the uses this function and see how it's done there.