管理员的 Moodle advcheckbox

Moodle advcheckbox for Administrator

我在面对面 mod_form.php 中添加了一个 advcheckbox 表单,我作为管理员可以在其中选中该框,从而允许学生在注册页面中看到一些租车选项,如果管理员未标记该复选框,则隐藏该复选框。 这是我在 mod_form.php

中的代码
$mform->addElement('advcheckbox', 'allowcarhire',    get_string('facetoface_allowcarhire', 'facetoface'));
    $mform->setDefault('allowcarhire', 0);
    $mform->setType('allowcarhire', PARAM_BOOL);

这是我在用户注册表单 (signup_form.php) 中的代码,它为我们提供了租车选项:

$mform->addElement('advcheckbox', 'carrequired', get_string('facetoface_carrequired', 'facetoface'));
    $mform->setDefault('carrequired', 0);
    $mform->setType('carrequired', PARAM_BOOL);

    $mform->addElement('date_selector', 'checkin', get_string('facetoface_checkin', 'facetoface'));
    $mform->setType('checkin', PARAM_INT);
    $mform->disabledIf('checkin', 'carrequired', 'notchecked');

    $mform->addElement('date_selector', 'checkout', get_string('facetoface_checkout', 'facetoface'));
    $mform->setType('checkout', PARAM_INT);
    $mform->disabledIf('checkout', 'carrequired', 'notchecked');

    $mform->addElement('advcheckbox', 'minivan', get_string('facetoface_minivan', 'facetoface'));
    $mform->setDefault('minivan', 0);
    $mform->setType('minivan', PARAM_BOOL);

如何连接它们,如果未选中 mod_form.php 中的第一个复选框,则用户无法在他的注册表单中看到租车选项?只能用 php 制作还是我们还需要 javascript? Moodle 中的其他所有内容均未修改并且是全新安装。

首先,我假设您已经将设置从 mod_form 保存到数据库中(我假设您已经将一个名为 'allowcarhire' 的新字段添加到 table mdl_facetoface 保留此设置)。

现在您需要通过 'customdata' 表单值将此值传递到表单中(查找 $params = compact('s', ...) 行,就在 $mform = mod_facetoface_signup_form(null, $params) 在 mod/facetoface/signup.php).

进入表单后,假设您在将设置添加到自定义数据时保留了名称 'allowcarhire',那么您应该能够编写:

if ($this->_customdata['allowcarhire']) {
    $mform->addElement('advcheckbox', 'carrequired', ...
}