ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SkillUsageDBRepository.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(
28 ?\ilDBInterface $db = null
29 ) {
30 global $DIC;
31
32 $this->db = ($db) ?: $DIC->database();
33 }
34
35 public function add(int $obj_id, int $skill_id, int $tref_id): void
36 {
37 $this->db->replace(
38 "skl_usage",
39 [
40 "obj_id" => ["integer", $obj_id],
41 "skill_id" => ["integer", $skill_id],
42 "tref_id" => ["integer", $tref_id]
43 ],
44 []
45 );
46 }
47
48 public function remove(int $obj_id, int $skill_id, int $tref_id): void
49 {
50 $this->db->manipulate(
51 "DELETE FROM skl_usage WHERE " .
52 " obj_id = " . $this->db->quote($obj_id, "integer") .
53 " AND skill_id = " . $this->db->quote($skill_id, "integer") .
54 " AND tref_id = " . $this->db->quote($tref_id, "integer")
55 );
56 }
57
58 public function removeFromObject(int $obj_id): void
59 {
60 $this->db->manipulate(
61 "DELETE FROM skl_usage WHERE " .
62 " obj_id = " . $this->db->quote($obj_id, "integer")
63 );
64 }
65
66 public function removeForSkill(int $node_id, bool $is_referenece = false): void
67 {
68 if (!$is_referenece) {
69 $this->db->manipulate(
70 "DELETE FROM skl_usage WHERE " .
71 " skill_id = " . $this->db->quote($node_id, "integer")
72 );
73 } else {
74 $this->db->manipulate(
75 "DELETE FROM skl_usage WHERE " .
76 " tref_id = " . $this->db->quote($node_id, "integer")
77 );
78 }
79 }
80
84 public function getUsages(int $skill_id, int $tref_id): array
85 {
86 $set = $this->db->query(
87 "SELECT obj_id FROM skl_usage " .
88 " WHERE skill_id = " . $this->db->quote($skill_id, "integer") .
89 " AND tref_id = " . $this->db->quote($tref_id, "integer")
90 );
91 $obj_ids = [];
92 while ($rec = $this->db->fetchAssoc($set)) {
93 $obj_ids[] = (int) $rec["obj_id"];
94 }
95
96 return $obj_ids;
97 }
98
105 public function getUsageInfoGeneric(
106 array $cskill_ids,
107 string $usage_type,
108 string $table,
109 string $key_field,
110 string $skill_field = "skill_id",
111 string $tref_field = "tref_id"
112 ): array {
113 $usages = [];
114
115 $w = "WHERE";
116 $q = "SELECT " . $key_field . ", " . $skill_field . ", " . $tref_field . " FROM " . $table . " ";
117 foreach ($cskill_ids as $sk) {
118 $q .= $w . " (" . $skill_field . " = " . $this->db->quote($sk["skill_id"], "integer") .
119 " AND " . $tref_field . " = " . $this->db->quote($sk["tref_id"], "integer") . ") ";
120 $w = "OR";
121 }
122 $q .= " GROUP BY " . $key_field . ", " . $skill_field . ", " . $tref_field;
123
124 $set = $this->db->query($q);
125 while ($rec = $this->db->fetchAssoc($set)) {
126 $usages[$rec[$skill_field] . ":" . $rec[$tref_field]][$usage_type][] =
127 array("key" => $rec[$key_field]);
128 }
129
130 return $usages;
131 }
132}
add(int $obj_id, int $skill_id, int $tref_id)
getUsageInfoGeneric(array $cskill_ids, string $usage_type, string $table, string $key_field, string $skill_field="skill_id", string $tref_field="tref_id")
Get standard usage query.
removeForSkill(int $node_id, bool $is_referenece=false)
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23