Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace tool_usertours\local\target;
18
 
19
use tool_usertours\step;
20
 
21
/**
22
 * Target base.
23
 *
24
 * @package    tool_usertours
25
 * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
abstract class base {
29
    /**
30
     * @var     step        $step           The step being targetted.
31
     */
32
    protected $step;
33
 
34
    /**
35
     * @var     array       $forcedsettings The settings forced by this type.
36
     */
37
    protected static $forcedsettings = [];
38
 
39
    /**
40
     * Create the target type.
41
     *
42
     * @param   step        $step       The step being targetted.
43
     */
44
    public function __construct(step $step) {
45
        $this->step = $step;
46
    }
47
 
48
    /**
49
     * Convert the target value to a valid CSS selector for use in the
50
     * output configuration.
51
     *
52
     * @return string
53
     */
54
    abstract public function convert_to_css();
55
 
56
    /**
57
     * Convert the step target to a friendly name for use in the UI.
58
     *
59
     * @return string
60
     */
61
    abstract public function get_displayname();
62
 
63
    /**
64
     * Add the target type configuration to the form.
65
     *
66
     * @param   MoodleQuickForm $mform      The form to add configuration to.
67
     */
68
    public static function add_config_to_form(\MoodleQuickForm $mform) {
69
    }
70
 
71
    /**
72
     * Add the disabledIf values.
73
     *
74
     * @param   MoodleQuickForm $mform      The form to add configuration to.
75
     */
76
    public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) {
77
    }
78
 
79
    /**
80
     * Prepare data to submit to the form.
81
     *
82
     * @param   object          $data       The data being passed to the form
83
     */
84
    abstract public function prepare_data_for_form($data);
85
 
86
    /**
87
     * Whether the specified step setting is forced by this target type.
88
     *
89
     * @param   string          $key        The name of the key to check.
90
     * @return  boolean
91
     */
92
    public function is_setting_forced($key) {
93
        return isset(static::$forcedsettings[$key]);
94
    }
95
 
96
    /**
97
     * The value of the forced setting.
98
     *
99
     * @param   string          $key        The name of the key to check.
100
     * @return  mixed
101
     */
102
    public function get_forced_setting_value($key) {
103
        if ($this->is_setting_forced($key)) {
104
            return static::$forcedsettings[$key];
105
        }
106
 
107
        return null;
108
    }
109
 
110
    /**
111
     * Fetch the targetvalue from the form for this target type.
112
     *
113
     * @param   stdClass        $data       The data submitted in the form
114
     * @return  string
115
     */
116
    abstract public function get_value_from_form($data);
117
}