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
 * Block 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 block 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
        // The block has the following CSS class selector style:
35
        // .block-region .block_[name] .
36
        return sprintf('.block-region .block_%s', $this->step->get_targetvalue());
37
    }
38
 
39
    /**
40
     * Convert the step target to a friendly name for use in the UI.
41
     *
42
     * @return string
43
     */
44
    public function get_displayname() {
45
        return get_string('block_named', 'tool_usertours', $this->get_block_name());
46
    }
47
 
48
    /**
49
     * Get the translated name of the block.
50
     *
51
     * @return string
52
     */
53
    protected function get_block_name() {
54
        return get_string('pluginname', self::get_frankenstyle($this->step->get_targetvalue()));
55
    }
56
 
57
    /**
58
     * Get the frankenstyle name of the block.
59
     *
60
     * @param   string  $block  The block name.
61
     * @return                  The frankenstyle block name.
62
     */
63
    protected static function get_frankenstyle($block) {
64
        return sprintf('block_%s', $block);
65
    }
66
 
67
    /**
68
     * Add the target type configuration to the form.
69
     *
70
     * @param   MoodleQuickForm $mform      The form to add configuration to.
71
     * @return  $this
72
     */
73
    public static function add_config_to_form(\MoodleQuickForm $mform) {
74
        global $PAGE;
75
 
76
        $blocks = [];
77
        foreach ($PAGE->blocks->get_installed_blocks() as $block) {
78
            $blocks[$block->name] = get_string('pluginname', 'block_' . $block->name);
79
        }
80
 
81
        \core_collator::asort($blocks);
82
 
83
        $mform->addElement('select', 'targetvalue_block', get_string('block', 'tool_usertours'), $blocks);
84
    }
85
 
86
    /**
87
     * Add the disabledIf values.
88
     *
89
     * @param   MoodleQuickForm $mform      The form to add configuration to.
90
     */
91
    public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) {
92
        $mform->hideIf(
93
            'targetvalue_block',
94
            'targettype',
95
            'noteq',
96
            \tool_usertours\target::get_target_constant_for_class(self::class)
97
        );
98
    }
99
 
100
    /**
101
     * Prepare data to submit to the form.
102
     *
103
     * @param   object          $data       The data being passed to the form
104
     */
105
    public function prepare_data_for_form($data) {
106
        $data->targetvalue_block = $this->step->get_targetvalue();
107
    }
108
 
109
    /**
110
     * Fetch the targetvalue from the form for this target type.
111
     *
112
     * @param   stdClass        $data       The data submitted in the form
113
     * @return  string
114
     */
115
    public function get_value_from_form($data) {
116
        return $data->targetvalue_block;
117
    }
118
}