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
/**
20
 * Selector target.
21
 *
22
 * @package    tool_usertours
23
 * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
class selector extends base {
27
    /**
28
     * Convert the target value to a valid CSS selector for use in the
29
     * output configuration.
30
     *
31
     * @return string
32
     */
33
    public function convert_to_css() {
34
        return $this->step->get_targetvalue();
35
    }
36
 
37
    /**
38
     * Convert the step target to a friendly name for use in the UI.
39
     *
40
     * @return string
41
     */
42
    public function get_displayname() {
43
        return get_string('selectordisplayname', 'tool_usertours', $this->step->get_targetvalue());
44
    }
45
 
46
    /**
47
     * Get the default title.
48
     *
49
     * @return string
50
     */
51
    public function get_default_title() {
52
        return get_string('selector_defaulttitle', 'tool_usertours');
53
    }
54
 
55
    /**
56
     * Get the default content.
57
     *
58
     * @return string
59
     */
60
    public function get_default_content() {
61
        return get_string('selector_defaultcontent', 'tool_usertours');
62
    }
63
 
64
    /**
65
     * Add the target type configuration to the form.
66
     *
67
     * @param   MoodleQuickForm $mform      The form to add configuration to.
68
     * @return  $this
69
     */
70
    public static function add_config_to_form(\MoodleQuickForm $mform) {
71
        $mform->addElement('text', 'targetvalue_selector', get_string('cssselector', 'tool_usertours'));
72
        $mform->setType('targetvalue_selector', PARAM_RAW);
73
        $mform->addHelpButton('targetvalue_selector', 'target_selector_targetvalue', 'tool_usertours');
74
    }
75
 
76
    /**
77
     * Add the disabledIf values.
78
     *
79
     * @param   MoodleQuickForm $mform      The form to add configuration to.
80
     */
81
    public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) {
82
        $mform->hideIf(
83
            'targetvalue_selector',
84
            'targettype',
85
            'noteq',
86
            \tool_usertours\target::get_target_constant_for_class(self::class)
87
        );
88
    }
89
 
90
    /**
91
     * Prepare data to submit to the form.
92
     *
93
     * @param   object          $data       The data being passed to the form
94
     */
95
    public function prepare_data_for_form($data) {
96
        $data->targetvalue_selector = $this->step->get_targetvalue();
97
    }
98
 
99
    /**
100
     * Fetch the targetvalue from the form for this target type.
101
     *
102
     * @param   stdClass        $data       The data submitted in the form
103
     * @return  string
104
     */
105
    public function get_value_from_form($data) {
106
        return $data->targetvalue_selector;
107
    }
108
}