MDL-20808 "Create AMF test client" Some updates to client
[moodle.git] / filter / local_settings_form.php
blob17aedba47fad03821fdec163d0e78b15e0e8da3e
1 <?php
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
9 // //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
11 // //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
16 // //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
21 // //
22 // http://www.gnu.org/copyleft/gpl.html //
23 // //
24 ///////////////////////////////////////////////////////////////////////////
26 /**
27 * A Moodle form base class for editing local filter settings.
29 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
30 * @package moodlecore
31 *//** */
32 if (!defined('MOODLE_INTERNAL')) {
33 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
36 require_once($CFG->libdir . '/formslib.php');
38 abstract class filter_local_settings_form extends moodleform {
39 protected $filter;
40 protected $context;
42 public function __construct($submiturl, $filter, $context) {
43 $this->filter = $filter;
44 $this->context = $context;
45 parent::moodleform($submiturl);
48 /**
49 * Build the form definition. Rather than overriding this method, you
50 * should probably override definition_inner instead.
52 * This method adds the necessary hidden fields and submit buttons,
53 * and calls definition_inner to insert the custom controls in the appropriate place.
55 public function definition() {
56 $mform =& $this->_form;
58 $this->definition_inner($mform);
60 $mform->addElement('hidden', 'contextid');
61 $mform->setType('contextid', PARAM_INT);
62 $mform->setDefault('contextid', $this->context->id);
64 $mform->addElement('hidden', 'filter');
65 $mform->setType('filter', PARAM_ALPHAEXT);
66 $mform->setDefault('filter', $this->filter);
68 $this->add_action_buttons();
71 /**
72 * Override this method to add your form controls.
73 * @param $mform the form we are building. $this->_form, but passed in for convinience.
75 abstract protected function definition_inner($mform);
77 /**
78 * Override this method to save the settings to the database. The default
79 * implementation will probalby be sufficient for most simple cases.
80 * @param object $data the form data that was submitted.
82 public function save_changes($data) {
83 $data = (array) $data;
84 unset($data['filter']);
85 unset($data['contextid']);
86 foreach ($data as $name => $value) {
87 if ($value !== '') {
88 filter_set_local_config($this->filter, $this->context->id, $name, $value);
89 } else {
90 filter_unset_local_config($this->filter, $this->context->id, $name);