ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilAlphabetInputGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  private string $value = "";
30  protected array $letters = [];
31  protected object $parent_object;
32  protected string $parent_cmd = "";
33  protected bool $highlight = false;
34  protected string $highlight_letter = "";
35  protected bool $fix_db_umlauts = false;
37  protected ilDBInterface $db;
38 
39  public function __construct(
40  string $a_title = "",
41  string $a_postvar = ""
42  ) {
43  global $DIC;
44 
45  $this->lng = $DIC->language();
46  $this->ctrl = $DIC->ctrl();
47  $this->db = $DIC->database();
48  parent::__construct($a_title, $a_postvar);
49  }
50 
55  private function dbSupportsDisctinctUmlauts(): ?bool
56  {
57  if (!isset($this->db_supports_distinct_umlauts)) {
58  $set = $this->db->query(
59  "SELECT (" . $this->db->quote("A", "text") . " = " . $this->db->quote("Ä", "text") . ") t FROM DUAL "
60  );
61  $rec = $this->db->fetchAssoc($set);
62  $this->db_supports_distinct_umlauts = !(bool) $rec["t"];
63  }
64 
66  }
67 
68  public function setValue(string $a_value): void
69  {
70  $this->value = $a_value;
71  }
72 
73  public function getValue(): string
74  {
75  return $this->value;
76  }
77 
78  public function setValueByArray(array $a_values): void
79  {
80  $this->setValue($a_values[$this->getPostVar()]);
81  }
82 
83  public function setLetters(array $a_val): void
84  {
85  $this->letters = $a_val;
86  }
87 
88  public function getLetters(): array
89  {
90  return $this->letters;
91  }
92 
93  public function checkInput(): bool
94  {
95  $lng = $this->lng;
96 
97  if ($this->getRequired() && trim($this->str($this->getPostVar())) == "") {
98  $this->setAlert($lng->txt("msg_input_is_required"));
99  return false;
100  }
101 
102  return true;
103  }
104 
105  public function getInput(): string
106  {
107  return $this->str($this->getPostVar());
108  }
109 
110  public function setFixDBUmlauts(bool $a_val): void
111  {
112  $this->fix_db_umlauts = $a_val;
113  }
114 
115  public function getFixDBUmlauts(): bool
116  {
117  return $this->fix_db_umlauts;
118  }
119 
120  public function fixDBUmlauts(string $l): string
121  {
122  if ($this->fix_db_umlauts && !$this->dbSupportsDisctinctUmlauts()) {
123  $l = str_replace(array("Ä", "Ö", "Ü", "ä", "ö", "ü"), array("A", "O", "U", "a", "o", "u"), $l);
124  }
125  return $l;
126  }
127 
128 
129  protected function render(string $a_mode = ""): string
130  {
131  return "";
132  }
133 
134  public function setParentCommand(
135  object $a_obj,
136  string $a_cmd
137  ): void {
138  $this->parent_object = $a_obj;
139  $this->parent_cmd = $a_cmd;
140  }
141 
142  public function setHighlighted(
143  string $a_high_letter
144  ): void {
145  $this->highlight = ($a_high_letter != "");
146  $this->highlight_letter = $a_high_letter;
147  }
148 
149  public function getToolbarHTML(): string
150  {
151  $ilCtrl = $this->ctrl;
152  $lng = $this->lng;
153 
154  $lng->loadLanguageModule("form");
155 
156  $tpl = new ilTemplate("tpl.prop_alphabet.html", true, true, "components/ILIAS/Form");
157  foreach ($this->getLetters() as $l) {
158  if (is_null($l)) {
159  continue;
160  }
161  $l = $this->fixDBUmlauts($l);
162  $tpl->setCurrentBlock("letter");
163  $tpl->setVariable("TXT_LET", $l);
164  $ilCtrl->setParameter($this->parent_object, "letter", rawurlencode($l));
165  $tpl->setVariable("TXT_LET", $l);
166  $tpl->setVariable("HREF_LET", $ilCtrl->getLinkTarget($this->parent_object, $this->parent_cmd));
167  if ($this->highlight && $this->highlight_letter !== null && $this->highlight_letter == $l) {
168  $tpl->setVariable("CLASS", ' class="ilHighlighted" ');
169  }
170  $tpl->parseCurrentBlock();
171  }
172  $ilCtrl->setParameter($this->parent_object, "letter", "");
173  $tpl->setVariable("TXT_ALL", $lng->txt("form_alphabet_all"));
174  $tpl->setVariable("HREF_ALL", $ilCtrl->getLinkTarget($this->parent_object, $this->parent_cmd));
175  if ($this->highlight && $this->highlight_letter === null) {
176  $tpl->setVariable("CLASSA", ' class="ilHighlighted" ');
177  }
178  return $tpl->get();
179  }
180 }
setParentCommand(object $a_obj, string $a_cmd)
dbSupportsDisctinctUmlauts()
Only temp fix for #8603, should go to db classes.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setHighlighted(string $a_high_letter)
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
loadLanguageModule(string $a_module)
Load language module.
setValueByArray(array $a_values)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
__construct(Container $dic, ilPlugin $plugin)
getToolbarHTML()
Get input item HTML to be inserted into ilToolbarGUI.
__construct(string $a_title="", string $a_postvar="")