ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.PersonalSkillDBRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Skill\Personal;
22 
25 
30 {
31  protected \ilSkillTreeRepository $tree_repo;
32  protected \ilDBInterface $db;
34 
35  public function __construct(
36  \ilSkillTreeRepository $tree_repo,
37  ?\ilDBInterface $db = null,
38  ?Service\SkillInternalFactoryService $factory_service = null
39  ) {
40  global $DIC;
41 
42  $this->tree_repo = $tree_repo;
43  $this->db = ($db) ?: $DIC->database();
44  $this->factory_service = ($factory_service) ?: $DIC->skills()->internal()->factory();
45  }
46 
50  public function get(int $user_id): array
51  {
52  $ilDB = $this->db;
53 
54  $set = $ilDB->query(
55  "SELECT * FROM skl_personal_skill " .
56  " WHERE user_id = " . $ilDB->quote($user_id, "integer")
57  );
58  $pskills = [];
59  while ($rec = $ilDB->fetchAssoc($set)) {
60  $skill_node_id = (int) $rec["skill_node_id"];
61  if ($this->tree_repo->isInAnyTree($skill_node_id)) {
62  $pskills[$skill_node_id] = $this->getFromRecord($rec);
63  }
64  }
65  return $pskills;
66  }
67 
68  protected function getFromRecord(array $rec): SelectedUserSkill
69  {
70  $skill_node_id = (int) $rec["skill_node_id"];
71 
72  return $this->factory_service->personal()->selectedUserSkill(
73  $skill_node_id,
74  \ilSkillTreeNode::_lookupTitle($skill_node_id)
75  );
76  }
77 
78  public function add(int $user_id, int $skill_node_id): void
79  {
80  $ilDB = $this->db;
81 
82  $set = $ilDB->query(
83  "SELECT * FROM skl_personal_skill " .
84  " WHERE user_id = " . $ilDB->quote($user_id, "integer") .
85  " AND skill_node_id = " . $ilDB->quote($skill_node_id, "integer")
86  );
87  if (!$ilDB->fetchAssoc($set)) {
88  $ilDB->manipulate("INSERT INTO skl_personal_skill " .
89  "(user_id, skill_node_id) VALUES (" .
90  $ilDB->quote($user_id, "integer") . "," .
91  $ilDB->quote($skill_node_id, "integer") .
92  ")");
93  }
94  }
95 
96  public function remove(int $user_id, int $skill_node_id): void
97  {
98  $ilDB = $this->db;
99 
100  $ilDB->manipulate(
101  "DELETE FROM skl_personal_skill WHERE " .
102  " user_id = " . $ilDB->quote($user_id, "integer") .
103  " AND skill_node_id = " . $ilDB->quote($skill_node_id, "integer")
104  );
105  }
106 
107  public function removeAllForUser(int $user_id): void
108  {
109  $ilDB = $this->db;
110 
111  $ilDB->manipulate(
112  "DELETE FROM skl_personal_skill WHERE " .
113  " user_id = " . $ilDB->quote($user_id, "integer")
114  );
115  }
116 
117  public function removeAllForSkill(int $skill_node_id): void
118  {
119  $ilDB = $this->db;
120 
121  $ilDB->manipulate(
122  "DELETE FROM skl_personal_skill WHERE " .
123  " skill_node_id = " . $ilDB->quote($skill_node_id, "integer")
124  );
125  }
126 
134  public function getUsages(array $usages, array $pskill_ids, array $tref_ids): array
135  {
136  $ilDB = $this->db;
137 
138  $set = $ilDB->query(
139  "SELECT skill_node_id, user_id FROM skl_personal_skill " .
140  " WHERE " . $ilDB->in("skill_node_id", $pskill_ids, false, "integer") .
141  " GROUP BY skill_node_id, user_id"
142  );
143  while ($rec = $ilDB->fetchAssoc($set)) {
144  if (isset($tref_ids[(int) $rec["skill_node_id"]])) {
145  $usages[$tref_ids[$rec["skill_node_id"]] . ":" . $rec["skill_node_id"]][SkillUsageManager::PERSONAL_SKILL][] =
146  array("key" => $rec["user_id"]);
147  } else {
148  $usages[$rec["skill_node_id"] . ":0"][SkillUsageManager::PERSONAL_SKILL][] =
149  array("key" => $rec["user_id"]);
150  }
151  }
152 
153  return $usages;
154  }
155 }
__construct(\ilSkillTreeRepository $tree_repo, ?\ilDBInterface $db=null, ?Service\SkillInternalFactoryService $factory_service=null)
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
getUsages(array $usages, array $pskill_ids, array $tref_ids)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22