ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TooltipsDBRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 protected \ilDBInterface $db;
26
27 public function __construct(
29 ) {
30 $this->db = $db;
31 }
32
34 string $a_tt_id,
35 array $module_ids
36 ): string {
37 $set = $this->db->query(
38 $q =
39 "SELECT tt.tt_text FROM help_tooltip tt LEFT JOIN help_module hmod " .
40 " ON (tt.module_id = hmod.id) " .
41 " WHERE tt.tt_id = " . $this->db->quote($a_tt_id, "text") .
42 " AND " . $this->db->in("tt.module_id", $module_ids, false, "integer") .
43 " ORDER BY hmod.order_nr "
44 );
45 $rec = $this->db->fetchAssoc($set);
46 if (is_array($rec) && $rec["tt_text"] != "") {
47 $t = $rec["tt_text"];
48 if (count($module_ids) === 1 && current($module_ids) === 0) {
49 $t .= "<br/><i>(" . $a_tt_id . ")</i>";
50 }
51 return $t;
52 } else { // try to get general version
53 $fu = (int) strpos($a_tt_id, "_");
54 $gen_tt_id = "*" . substr($a_tt_id, $fu);
55 $set = $this->db->query(
56 "SELECT tt.tt_text FROM help_tooltip tt LEFT JOIN help_module hmod " .
57 " ON (tt.module_id = hmod.id) " .
58 " WHERE tt.tt_id = " . $this->db->quote($gen_tt_id, "text") .
59 " AND " . $this->db->in("tt.module_id", $module_ids, false, "integer") .
60 " ORDER BY hmod.order_nr "
61 );
62 $rec = $this->db->fetchAssoc($set);
63 if (is_array($rec) && $rec["tt_text"] != "") {
64 $t = $rec["tt_text"];
65 if (count($module_ids) === 1 && current($module_ids) === 0) {
66 $t .= "<br/><i>(" . $a_tt_id . ")</i>";
67 }
68 return $t;
69 }
70 }
71 if (count($module_ids) === 1 && current($module_ids) === 0) {
72 return "<i>" . $a_tt_id . "</i>";
73 }
74 return "";
75 }
76
77 public function getAllTooltips(
78 string $a_comp = "",
79 int $a_module_id = 0
80 ): array {
81 $q = "SELECT * FROM help_tooltip";
82 $q .= " WHERE module_id = " . $this->db->quote($a_module_id, "integer");
83 if ($a_comp !== "") {
84 $q .= " AND comp = " . $this->db->quote($a_comp, "text");
85 }
86 $set = $this->db->query($q);
87 $tts = array();
88 while ($rec = $this->db->fetchAssoc($set)) {
89 $tts[$rec["id"]] = array("id" => $rec["id"], "text" => $rec["tt_text"],
90 "tt_id" => $rec["tt_id"]);
91 }
92 return $tts;
93 }
94
95 public function addTooltip(
96 string $a_tt_id,
97 string $a_text,
98 int $a_module_id = 0
99 ): void {
100 $fu = strpos($a_tt_id, "_");
101 $comp = substr($a_tt_id, 0, $fu);
102
103 $nid = $this->db->nextId("help_tooltip");
104 $this->db->manipulate("INSERT INTO help_tooltip " .
105 "(id, tt_text, tt_id, comp,module_id) VALUES (" .
106 $this->db->quote($nid, "integer") . "," .
107 $this->db->quote($a_text, "text") . "," .
108 $this->db->quote($a_tt_id, "text") . "," .
109 $this->db->quote($comp, "text") . "," .
110 $this->db->quote($a_module_id, "integer") .
111 ")");
112 }
113
114 public function updateTooltip(
115 int $a_id,
116 string $a_text,
117 string $a_tt_id
118 ): void {
119 $fu = strpos($a_tt_id, "_");
120 $comp = substr($a_tt_id, 0, $fu);
121
122 $this->db->manipulate(
123 "UPDATE help_tooltip SET " .
124 " tt_text = " . $this->db->quote($a_text, "text") . ", " .
125 " tt_id = " . $this->db->quote($a_tt_id, "text") . ", " .
126 " comp = " . $this->db->quote($comp, "text") .
127 " WHERE id = " . $this->db->quote($a_id, "integer")
128 );
129 }
130
131
135 public function getTooltipComponents(
136 int $a_module_id = 0
137 ): array {
138 $set = $this->db->query("SELECT DISTINCT comp FROM help_tooltip " .
139 " WHERE module_id = " . $this->db->quote($a_module_id, "integer") .
140 " ORDER BY comp ");
141 $comps = [];
142 while ($rec = $this->db->fetchAssoc($set)) {
143 $comps[] = $rec["comp"];
144 }
145 return $comps;
146 }
147
148 public function deleteTooltip(
149 int $a_id
150 ): void {
151 $this->db->manipulate(
152 "DELETE FROM help_tooltip WHERE " .
153 " id = " . $this->db->quote($a_id, "integer")
154 );
155 }
156
157 public function deleteTooltipsOfModule(
158 int $a_id
159 ): void {
160 $this->db->manipulate(
161 "DELETE FROM help_tooltip WHERE " .
162 " module_id = " . $this->db->quote($a_id, "integer")
163 );
164 }
165
166}
updateTooltip(int $a_id, string $a_text, string $a_tt_id)
addTooltip(string $a_tt_id, string $a_text, int $a_module_id=0)
getAllTooltips(string $a_comp="", int $a_module_id=0)
getTooltipComponents(int $a_module_id=0)
Get all tooltip components.
getTooltipPresentationText(string $a_tt_id, array $module_ids)
Interface ilDBInterface.
$q
Definition: shib_logout.php:23