function definition() { $mform =& $this->_form; $mnet_peer =& $this->_customdata['peer']; $myservices =& mnet_get_service_info($mnet_peer); $mform->addElement('hidden', 'hostid', $mnet_peer->id); $count = 0; foreach ($myservices as $name => $versions) { $version = current($versions); $langmodule = ($version['plugintype'] == 'mod' ? '' : $version['plugintype'] . '_') . $version['pluginname']; // TODO there should be a moodle-wide way to do this if ($count > 0) { $mform->addElement('html', '<hr />'); } $mform->addElement('html', '<h3>' . get_string($name . '_name', $langmodule, $mnet_peer->name) . '</h3>' . get_string($name . '_description', $langmodule, $mnet_peer->name)); $mform->addElement('hidden', 'exists[' . $version['serviceid'] . ']', 1); $pubstr = get_string('publish', 'mnet'); if (!empty($version['hostsubscribes'])) { $pubstr .= ' <a class="notifysuccess" title="' . s(get_string('issubscribed', 'mnet', $mnet_peer->name)) . '">√</a> '; } $mform->addElement('advcheckbox', 'publish[' . $version['serviceid'] . ']', $pubstr); $substr = get_string('subscribe', 'mnet'); if (!empty($version['hostpublishes'])) { $substr .= ' <a class="notifysuccess" title="' . s(get_string('ispublished', 'mnet', $mnet_peer->name)) . '">√</a> '; } $mform->addElement('advcheckbox', 'subscribe[' . $version['serviceid'] . ']', $substr); $count++; } $this->add_action_buttons(); }
// We don't have or need a record - do nothing! } else { // We don't need the record - delete it $DB->delete_records('mnet_host2service', array('hostid' => $hostid, 'serviceid' => $key)); } } elseif (false == $host2service && ($publish == 1 || $subscribe == 1)) { $host2service = new stdClass(); $host2service->hostid = $hostid; $host2service->serviceid = $key; $host2service->publish = $publish; $host2service->subscribe = $subscribe; $host2service->id = $DB->insert_record('mnet_host2service', $host2service); } elseif ($host2service->publish != $publish || $host2service->subscribe != $subscribe) { $host2service->publish = $publish; $host2service->subscribe = $subscribe; $DB->update_record('mnet_host2service', $host2service); } } $redirecturl = new moodle_url('/admin/mnet/services.php?hostid=' . $hostid); redirect($redirecturl, get_string('changessaved')); } echo $OUTPUT->header(); $currenttab = 'mnetservices'; require_once $CFG->dirroot . '/admin/mnet/tabs.php'; echo $OUTPUT->box_start(); $s = mnet_get_service_info($mnet_peer, false); // basic data only $mform->set_data($s); $mform->display(); echo $OUTPUT->box_end(); echo $OUTPUT->footer();
/** * Describes the form, with the triplet (service_name, publish, subscribe). */ public function definition() { global $CFG, $SESSION, $DB; // Settings variables. $mform =& $this->_form; // Master services. $defaultservices = $DB->get_records('mnet_service', array('offer' => 1), 'name'); // get version info to get real names $self_mnet_peer = new mnet_peer(); $self_mnet_peer->set_id($CFG->mnet_localhost_id); $myservices = mnet_get_service_info($self_mnet_peer); if (!empty($defaultservices)) { // Services fieldset. $mform->addElement('header', 'servicesform', get_string('servicesformselection', 'local_vmoodle')); $grid =& $mform->addElement('elementgrid', 'grid', get_string('mainservicesformselection', 'local_vmoodle')); $row = array(); $row[] = get_string('publish', 'local_vmoodle'); $row[] = get_string('subscribe', 'local_vmoodle'); $row[] = ''; $row[] = ''; $grid->setColumnNames($row); foreach ($defaultservices as $defaultservice) { $row = array(); $row[] = $mform->createElement('advcheckbox', 'main_' . $defaultservice->name . '_publish'); $row[] = $mform->createElement('advcheckbox', 'main_' . $defaultservice->name . '_subscribe'); $row[] = $mform->createElement('static', 'main_' . $defaultservice->name . '_description'); $row[] = $mform->createElement('hidden', 'main_' . $defaultservice->name . '_id'); $description = $defaultservice->description; if (empty($description)) { $version = current($myservices[$defaultservice->name]); $langmodule = ($version['plugintype'] == 'mod' ? '' : $version['plugintype'] . '_') . $version['pluginname']; // TODO there should be a moodle-wide way to do this $description = get_string($defaultservice->name . '_name', $langmodule); } $mform->setDefault('main_' . $defaultservice->name . '_description', $description); $mform->setDefault('main_' . $defaultservice->name . '_id', $defaultservice->id); $mform->setType('main_' . $defaultservice->name . '_id', PARAM_INT); $grid->addRow($row); } // Services fieldset. $grid =& $mform->addElement('elementgrid', 'grid', get_string('peerservicesformselection', 'local_vmoodle')); $row = array(); $row[] = get_string('publish', 'local_vmoodle'); $row[] = get_string('subscribe', 'local_vmoodle'); $row[] = ''; $row[] = ''; $grid->setColumnNames($row); foreach ($defaultservices as $defaultservice) { $row = array(); $row[] = $mform->createElement('advcheckbox', 'peer_' . $defaultservice->name . '_publish'); $row[] = $mform->createElement('advcheckbox', 'peer_' . $defaultservice->name . '_subscribe'); $row[] = $mform->createElement('static', 'peer_' . $defaultservice->name . '_description'); $row[] = $mform->createElement('hidden', 'peer_' . $defaultservice->name . '_id'); $description = $defaultservice->description; if (empty($description)) { $version = current($myservices[$defaultservice->name]); $langmodule = ($version['plugintype'] == 'mod' ? '' : $version['plugintype'] . '_') . $version['pluginname']; // TODO there should be a moodle-wide way to do this $description = get_string($defaultservice->name . '_name', $langmodule); } $mform->setDefault('peer_' . $defaultservice->name . '_description', $description); $mform->setDefault('peer_' . $defaultservice->name . '_id', $defaultservice->id); $mform->setType('peer_' . $defaultservice->name . '_id', PARAM_INT); $grid->addRow($row); } // Submit button. $mform->addElement('submit', 'submitbutton', get_string('edit')); } else { // Confirmation message. $message_object = new stdclass(); $message_object->message = get_string('badservicesnumber', 'local_vmoodle'); $message_object->style = 'notifyproblem'; // Save confirm message before redirection. $SESSION->vmoodle_ma['confirm_message'] = $message_object; new moodle_url('/local/vmoodle/view.php', array('view' => 'management')); } }