ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.SkillProfileLevelsDBRepository.php
Go to the documentation of this file.
1 <?php
2 
20 namespace ILIAS\Skill\Profile;
21 
23 {
24  protected \ilDBInterface $db;
25 
26  public function __construct(\ilDBInterface $db = null)
27  {
28  global $DIC;
29 
30  $this->db = ($db) ?: $DIC->database();
31  }
32 
33  public function getProfileLevels(int $profile_id): array
34  {
35  $ilDB = $this->db;
36 
37  $set = $ilDB->query(
38  "SELECT * FROM skl_profile_level " .
39  " WHERE profile_id = " . $ilDB->quote($profile_id, "integer")
40  );
41 
42  $levels = [];
43  while ($rec = $ilDB->fetchAssoc($set)) {
44  $levels[] = [
45  "base_skill_id" => (int) $rec["base_skill_id"],
46  "tref_id" => (int) $rec["tref_id"],
47  "level_id" => (int) $rec["level_id"],
48  "order_nr" => (int) $rec["order_nr"]
49  ];
50  }
51 
52  return $levels;
53  }
54 
55  public function createProfileLevels(int $profile_id, array $levels): void
56  {
57  $ilDB = $this->db;
58 
59  foreach ($levels as $level) {
60  $ilDB->replace(
61  "skl_profile_level",
62  array("profile_id" => array("integer", $profile_id),
63  "tref_id" => array("integer", (int) $level["tref_id"]),
64  "base_skill_id" => array("integer", (int) $level["base_skill_id"])
65  ),
66  array("order_nr" => array("integer", (int) $level["order_nr"]),
67  "level_id" => array("integer", (int) $level["level_id"])
68  )
69  );
70  }
71  }
72 
73  public function updateProfileLevels(int $profile_id, array $levels): void
74  {
75  $ilDB = $this->db;
76 
77  $ilDB->manipulate(
78  "DELETE FROM skl_profile_level WHERE " .
79  " profile_id = " . $ilDB->quote($profile_id, "integer")
80  );
81  foreach ($levels as $level) {
82  $ilDB->replace(
83  "skl_profile_level",
84  array("profile_id" => array("integer", $profile_id),
85  "tref_id" => array("integer", (int) $level["tref_id"]),
86  "base_skill_id" => array("integer", (int) $level["base_skill_id"])
87  ),
88  array("order_nr" => array("integer", (int) $level["order_nr"]),
89  "level_id" => array("integer", (int) $level["level_id"])
90  )
91  );
92  }
93  }
94 
95  public function deleteProfileLevels(int $profile_id): void
96  {
97  $ilDB = $this->db;
98 
99  $ilDB->manipulate(
100  "DELETE FROM skl_profile_level WHERE " .
101  " profile_id = " . $ilDB->quote($profile_id, "integer")
102  );
103  }
104 
105  public function updateSkillOrder(int $profile_id, array $order): void
106  {
107  $ilDB = $this->db;
108 
109  $cnt = 1;
110  foreach ($order as $id => $o) {
111  $id_arr = explode("_", $id);
112  $ilDB->manipulate(
113  "UPDATE skl_profile_level SET " .
114  " order_nr = " . $ilDB->quote(($cnt * 10), "integer") .
115  " WHERE base_skill_id = " . $ilDB->quote($id_arr[0], "integer") .
116  " AND tref_id = " . $ilDB->quote($id_arr[1], "integer") .
117  " AND profile_id = " . $ilDB->quote($profile_id, "integer")
118  );
119  $cnt++;
120  }
121  }
122 
123  public function fixSkillOrderNumbering(int $profile_id): void
124  {
125  $ilDB = $this->db;
126 
127  $set = $ilDB->query(
128  "SELECT profile_id, base_skill_id, tref_id, order_nr FROM skl_profile_level WHERE " .
129  " profile_id = " . $ilDB->quote($profile_id, "integer") .
130  " ORDER BY order_nr ASC"
131  );
132  $cnt = 1;
133  while ($rec = $ilDB->fetchAssoc($set)) {
134  $ilDB->manipulate(
135  "UPDATE skl_profile_level SET " .
136  " order_nr = " . $ilDB->quote(($cnt * 10), "integer") .
137  " WHERE profile_id = " . $ilDB->quote($rec["profile_id"], "integer") .
138  " AND base_skill_id = " . $ilDB->quote($rec["base_skill_id"], "integer") .
139  " AND tref_id = " . $ilDB->quote($rec["tref_id"], "integer")
140  );
141  $cnt++;
142  }
143  }
144 
145  public function getMaxLevelOrderNr(int $profile_id): int
146  {
147  $ilDB = $this->db;
148 
149  $set = $ilDB->query(
150  "SELECT MAX(order_nr) mnr FROM skl_profile_level WHERE " .
151  " profile_id = " . $ilDB->quote($profile_id, "integer")
152  );
153  $rec = $ilDB->fetchAssoc($set);
154  return (int) $rec["mnr"];
155  }
156 }
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23