/** * Creates necessary fields in the messaging config form. * * @param array $preferences An array of user preferences */ public function config_form($preferences) { global $CFG, $OUTPUT, $USER, $PAGE; $systemcontext = context_system::instance(); if (!has_capability('message/airnotifier:managedevice', $systemcontext)) { return get_string('nopermissiontomanagedevices', 'message_airnotifier'); } if (!$this->is_system_configured()) { return get_string('notconfigured', 'message_airnotifier'); } else { $airnotifiermanager = new message_airnotifier_manager(); $devicetokens = $airnotifiermanager->get_user_devices($CFG->airnotifiermobileappname, $USER->id); if (!empty($devicetokens)) { $output = ''; foreach ($devicetokens as $devicetoken) { if ($devicetoken->enable) { $hideshowiconname = 't/hide'; $dimmed = ''; } else { $hideshowiconname = 't/show'; $dimmed = 'dimmed_text'; } $hideshowicon = $OUTPUT->pix_icon($hideshowiconname, get_string('showhide', 'message_airnotifier')); $name = "{$devicetoken->name} {$devicetoken->model} {$devicetoken->platform} {$devicetoken->version}"; $output .= html_writer::start_tag('li', array('id' => $devicetoken->id, 'class' => 'airnotifierdevice ' . $dimmed)) . "\n"; $output .= html_writer::label($name, 'deviceid-' . $devicetoken->id, array('class' => 'devicelabel ')) . ' ' . html_writer::link('#', $hideshowicon, array('class' => 'hidedevice', 'alt' => 'show/hide')) . "\n"; $output .= html_writer::end_tag('li') . "\n"; } // Include the AJAX script to automatically trigger the action. $airnotifiermanager->include_device_ajax(); $output = html_writer::tag('ul', $output, array('class' => 'list-unstyled unstyled', 'id' => 'airnotifierdevices')); } else { $output = get_string('nodevices', 'message_airnotifier'); } return $output; } }