Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea -...
17
namespace core\output;
-
 
18
 
-
 
19
use renderable;
-
 
20
use renderer_base;
-
 
21
use core\output\named_templatable;
17
namespace core\output;
22
 
18
 
23
/**
19
/**
24
 * A generic user choice output class.
20
 * A generic user choice output class.
25
 *
21
 *
26
 * This class can be used as a generic user choice data structure for any dropdown,  modal, or any
22
 * This class can be used as a generic user choice data structure for any dropdown,  modal, or any
27
 * other component that offers choices to the user.
23
 * other component that offers choices to the user.
28
 *
24
 *
29
 * @package    core
25
 * @package    core
30
 * @copyright  2023 Ferran Recio <ferran@moodle.com>
26
 * @copyright  2023 Ferran Recio <ferran@moodle.com>
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
-
 
33
class choicelist implements renderable, named_templatable {
28
 */
34
 
29
class choicelist implements named_templatable, renderable {
Línea 35... Línea 30...
35
    /** @var object[] The user choices. */
30
    /** @var object[] The user choices. */
36
    protected $options = [];
31
    protected $options = [];
Línea 100... Línea 95...
100
     * This method returns an array of options that are selectable, excluding the selected option and any disabled options.
95
     * This method returns an array of options that are selectable, excluding the selected option and any disabled options.
101
     *
96
     *
102
     * @return \stdClass[]
97
     * @return \stdClass[]
103
     */
98
     */
104
    public function get_selectable_options(): array {
99
    public function get_selectable_options(): array {
105
        $selectableOptions = [];
100
        $selectableoptions = [];
106
        foreach ($this->options as $option) {
101
        foreach ($this->options as $option) {
107
            if ($option['value'] !== $this->selected && !$option['disabled']) {
102
            if ($option['value'] !== $this->selected && !$option['disabled']) {
108
                $selectableOptions[] = (object) $option;
103
                $selectableoptions[] = (object) $option;
109
            }
104
            }
110
        }
105
        }
111
        return $selectableOptions;
106
        return $selectableoptions;
112
    }
107
    }
Línea 113... Línea 108...
113
 
108
 
114
    /**
109
    /**
115
     * Set the selected option.
110
     * Set the selected option.
Línea 124... Línea 119...
124
     * Get the selected option.
119
     * Get the selected option.
125
     *
120
     *
126
     * @return string|null The value of the selected option.
121
     * @return string|null The value of the selected option.
127
     */
122
     */
128
    public function get_selected_value(): ?string {
123
    public function get_selected_value(): ?string {
129
        if (empty($this->selected) && !$this->allowempty && !empty($this->options)) {
124
        if (is_null($this->selected) && !$this->allowempty && !empty($this->options)) {
130
            return array_key_first($this->options);
125
            return array_key_first($this->options);
131
        }
126
        }
132
        return $this->selected;
127
        return $this->selected;
133
    }
128
    }
Línea 247... Línea 242...
247
     *
242
     *
248
     * @param renderer_base $output The renderer.
243
     * @param renderer_base $output The renderer.
249
     * @return string
244
     * @return string
250
     */
245
     */
251
    public function get_selected_content(renderer_base $output): string {
246
    public function get_selected_content(renderer_base $output): string {
252
        if (empty($this->selected)) {
247
        if (is_null($this->selected)) {
253
            return '';
248
            return '';
254
        }
249
        }
255
        $option = $this->options[$this->selected];
250
        $option = $this->options[$this->selected];
256
        $icon = '';
251
        $icon = '';
257
        if (!empty($option['icon'])) {
252
        if (!empty($option['icon'])) {