ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ModuleDBRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
25  protected \ilDBInterface $db;
26 
27  public function __construct(
28  \ilDBInterface $db
29  ) {
30  $this->db = $db;
31  }
32 
33  public function create(): int
34  {
35  $id = $this->db->nextId("help_module");
36 
37  $this->db->manipulate("INSERT INTO help_module " .
38  "(id) VALUES (" .
39  $this->db->quote($id, "integer") .
40  ")");
41 
42  return $id;
43  }
44 
45  public function writeHelpModuleLmId(
46  int $a_id,
47  int $a_lm_id
48  ): void {
49  $this->db->manipulate(
50  "UPDATE help_module SET " .
51  " lm_id = " . $this->db->quote($a_lm_id, "integer") .
52  " WHERE id = " . $this->db->quote($a_id, "integer")
53  );
54  }
55 
56  public function saveOrder(array $order): void
57  {
58  foreach ($order as $id => $order_nr) {
59  $this->db->update(
60  "help_module",
61  [
62  "order_nr" => ["integer", (int) $order_nr]
63  ],
64  [ // where
65  "id" => ["integer", (int) $id]
66  ]
67  );
68  }
69  }
70 
71  public function getHelpModules(): array
72  {
73  $set = $this->db->query("SELECT * FROM help_module ORDER BY order_nr ASC");
74 
75  $mods = array();
76  while ($rec = $this->db->fetchAssoc($set)) {
77  if (\ilObject::_lookupType((int) $rec["lm_id"]) === "lm") {
78  $rec["title"] = \ilObject::_lookupTitle((int) $rec["lm_id"]);
79  $rec["create_date"] = \ilObject::_lookupCreationDate((int) $rec["lm_id"]);
80  }
81 
82  $mods[] = $rec;
83  }
84 
85  return $mods;
86  }
87 
88  public function lookupModuleTitle(
89  int $a_id
90  ): string {
91 
92  $set = $this->db->query(
93  "SELECT * FROM help_module " .
94  " WHERE id = " . $this->db->quote($a_id, "integer")
95  );
96  $rec = $this->db->fetchAssoc($set);
97  if (\ilObject::_lookupType((int) $rec["lm_id"]) === "lm") {
98  return \ilObject::_lookupTitle((int) $rec["lm_id"]);
99  }
100  return "";
101  }
102 
103  public function lookupModuleLmId(
104  int $a_id
105  ): int {
106  $set = $this->db->query(
107  "SELECT lm_id FROM help_module " .
108  " WHERE id = " . $this->db->quote($a_id, "integer")
109  );
110  $rec = $this->db->fetchAssoc($set);
111  return (int) $rec["lm_id"];
112  }
113 
114  public function deleteModule(
115  int $id
116  ): void {
117  $this->db->manipulate("DELETE FROM help_module WHERE " .
118  " id = " . $this->db->quote($id, "integer"));
119  }
120 
124  public function isHelpLM(
125  int $a_lm_id
126  ): bool {
127  $set = $this->db->query(
128  "SELECT id FROM help_module " .
129  " WHERE lm_id = " . $this->db->quote($a_lm_id, "integer")
130  );
131  if ($rec = $this->db->fetchAssoc($set)) {
132  return true;
133  }
134  return false;
135  }
136 
137  public function writeActive(int $module_id, bool $active): void
138  {
139  $this->db->update(
140  "help_module",
141  [
142  "active" => ["integer", (int) $active]
143  ],
144  [ // where
145  "id" => ["integer", $module_id]
146  ]
147  );
148 
149  }
150 }
writeHelpModuleLmId(int $a_id, int $a_lm_id)
static _lookupTitle(int $obj_id)
writeActive(int $module_id, bool $active)
isHelpLM(int $a_lm_id)
Check if LM is a help LM.
static _lookupCreationDate(int $obj_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupType(int $id, bool $reference=false)