Quiz access rule - checkbox status

Quiz access rule - checkbox status

von Jose Velazquez-Torres -
Anzahl Antworten: 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? 

Mittelwert:  -
Als Antwort auf Jose Velazquez-Torres

Re: Quiz access rule - checkbox status

von Tim Hunt -
Nutzerbild von Core developers Nutzerbild von Documentation writers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Peer reviewers Nutzerbild von 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.
Als Antwort auf Tim Hunt

Re: Quiz access rule - checkbox status

von Jose Velazquez-Torres -
Tim for confirmation, does get_settings_sql() is the function that manage the status of the honestycheckrequired checkbox?
Als Antwort auf Jose Velazquez-Torres

Re: Quiz access rule - checkbox status

von Tim Hunt -
Nutzerbild von Core developers Nutzerbild von Documentation writers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Peer reviewers Nutzerbild von 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.
Als Antwort auf Tim Hunt

Re: Quiz access rule - checkbox status

von 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?
Als Antwort auf Jose Velazquez-Torres

Re: Quiz access rule - checkbox status

von Tim Hunt -
Nutzerbild von Core developers Nutzerbild von Documentation writers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Peer reviewers Nutzerbild von 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
Als Antwort auf Tim Hunt

Re: Quiz access rule - checkbox status

von 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?