Quiz access rule - checkbox status

Quiz access rule - checkbox status

by Jose Velazquez-Torres -
Number of replies: 6

I added a checkbox in the add_settings_form_fields(). I want that checkbox to appear selected when I visit the from again, if it was selected previously. Currently I have this code: 


Do someone know what Im doing wrong or a way I could achieve the same? 

Average of ratings: -
In reply to Jose Velazquez-Torres

Re: Quiz access rule - checkbox status

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Look at some other access rules that work. https://github.com/moodleou/moodle-quizaccess_honestycheck/ is an access rull with an on/off setting.
In reply to Tim Hunt

Re: Quiz access rule - checkbox status

by Jose Velazquez-Torres -
Tim for confirmation, does get_settings_sql() is the function that manage the status of the honestycheckrequired checkbox?
In reply to Jose Velazquez-Torres

Re: Quiz access rule - checkbox status

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well, it is the function for loading the previously stored data.

If you load the data into the quiz object with the right name, Moodle's forms library will deal with populating the current value of the checkbox when the quiz is re-edited.
In reply to Tim Hunt

Re: Quiz access rule - checkbox status

by Jose Velazquez-Torres -
Tim seeing your class for honesty check in the get_settings_sql() you have this:

public static function get_settings_sql($quizid) {
return array(
'honestycheckrequired',
'LEFT JOIN {quizaccess_honestycheck} honestycheck ON honestycheck.quizid = quiz.id',
array());
}

I don't understand what the parameters honestycheck ON honestycheck.quizid stands for. Could you explain this to me please?
In reply to Jose Velazquez-Torres

Re: Quiz access rule - checkbox status

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
What is your level of knowledge of SQL?

For efficency, Moodle tries to load the settings for all the installed access rules at the same time as loading the quiz settings. This is some fragments of SQL which get added to the main query to include these settings.

The best documentation for this is the PHPdoc on the base class https://github.com/moodle/moodle/blob/338b60f43b25c84e684dc075ff59132a24461d32/mod/quiz/accessrule/accessrulebase.php#L302
In reply to Tim Hunt

Re: Quiz access rule - checkbox status

by Jose Velazquez-Torres -
My level of SQL is really basic. I have never use Left join before. I found that before but Im still don't get how to use the function. The checkbox Im trying to load it status I created with this code:
$mform->addElement('advcheckbox', 'notwoquizrequire', 'Do you want this quiz not to open if the student has another open quiz in this class?: ',
'by selecting this check box it will set that restiction. ', array(0, 1));
on add_settings_form_fields. Then on get_settings_sql I have the following code: public static function get_settings_sql($quizid) {



return array(
'notwoquizrequired',
"LEFT JOIN {quizaccess_notwoatsametime} notwoquizrequire ON quizid = quiz.id",
array());
}
and is not loading the status of the checkbox. Also when I write after the ON notwoquizatthetime.quizid I get an error saying that the column can't be find. Any idea of what Im doing wrong?