1: <?php
2:
3: namespace Budabot\Core;
4:
5: class SettingHandler {
6:
7: public $text;
8:
9: protected $row;
10:
11: public function __construct(DBRow $row) {
12: $this->row = $row;
13: }
14:
15: 16: 17:
18: public function displayValue() {
19: if ($this->row->intoptions != "") {
20: $options = explode(";", $this->row->options);
21: $intoptions = explode(";", $this->row->intoptions);
22: $intoptions2 = array_flip($intoptions);
23: $key = $intoptions2[$this->row->value];
24: return "<highlight>{$options[$key]}<end>";
25: } else {
26: return "<highlight>" . htmlspecialchars($this->row->value) . "<end>";
27: }
28: }
29:
30: 31: 32:
33: public function getOptions() {
34: if ($this->row->options != '') {
35: $options = explode(";", $this->row->options);
36: }
37: if ($this->row->intoptions != '') {
38: $intoptions = explode(";", $this->row->intoptions);
39: $options_map = array_combine($intoptions, $options);
40: }
41: if ($options) {
42: $msg = "Predefined Options:\n";
43: if ($intoptions) {
44: forEach ($options_map as $key => $label) {
45: $save_link = $this->text->makeChatcmd('Select', "/tell <myname> settings save {$this->row->name} {$key}");
46: $msg .= "<tab> <highlight>{$label}<end> ({$save_link})\n";
47: }
48: } else {
49: forEach ($options as $char) {
50: $save_link = $this->text->makeChatcmd('Select', "/tell <myname> settings save {$this->row->name} {$char}");
51: $msg .= "<tab> <highlight>{$char}<end> ({$save_link})\n";
52: }
53: }
54: }
55: return $msg;
56: }
57:
58: 59: 60:
61: public function save($newValue) {
62: return $newValue;
63: }
64: }