ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.SkillResourcesManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Skill\Resource;
22 
24 
37 {
39  protected \ilSkillLevelRepository $level_repo;
40 
41  public function __construct(
42  ?SkillResourceDBRepository $skill_res_repo = null,
43  ?\ilSkillLevelRepository $level_repo = null
44  ) {
45  global $DIC;
46 
47  $this->skill_res_repo = ($skill_res_repo)
48  ?: $DIC->skills()->internal()->repo()->getResourceRepo();
49  $this->level_repo = ($level_repo)
50  ?: $DIC->skills()->internal()->repo()->getLevelRepo();
51  }
52 
56  public function getResources(int $skill_id, int $tref_id): array
57  {
58  return $this->skill_res_repo->getAll($skill_id, $tref_id);
59  }
60 
64  public function getResourcesOfLevel(int $skill_id, int $tref_id, int $level_id): array
65  {
66  $all_resources = $this->skill_res_repo->getAll($skill_id, $tref_id);
67  $resources_of_level = [];
68  foreach ($all_resources as $lid => $level) {
69  foreach ($level as $resource) {
70  if ($lid == $level_id) {
71  $resources_of_level[] = $resource;
72  }
73  }
74  }
75 
76  return $resources_of_level;
77  }
78 
79  public function setResource(
80  int $skill_id,
81  int $tref_id,
82  int $level_id,
83  int $rep_ref_id,
84  bool $imparting,
85  bool $trigger
86  ): void {
87  $this->skill_res_repo->addOrUpdate($skill_id, $tref_id, $level_id, $rep_ref_id, $imparting, $trigger);
88  }
89 
90  public function setResourceAsSuggested(
91  int $skill_id,
92  int $tref_id,
93  int $level_id,
94  int $rep_ref_id
95  ): void {
96  $this->skill_res_repo->updateImparting($skill_id, $tref_id, $level_id, $rep_ref_id, true);
97  }
98 
99  public function setResourceAsNotSuggested(
100  int $skill_id,
101  int $tref_id,
102  int $level_id,
103  int $rep_ref_id
104  ): void {
105  $this->skill_res_repo->updateImparting($skill_id, $tref_id, $level_id, $rep_ref_id, false);
106  }
107 
108  public function setResourceAsTrigger(
109  int $skill_id,
110  int $tref_id,
111  int $level_id,
112  int $rep_ref_id
113  ): void {
114  $obj_id = \ilObject::_lookupObjId($rep_ref_id);
115  $obj_type = \ilObject::_lookupType($obj_id);
116  if (!\ilObjectLP::isSupportedObjectType($obj_type)) {
117  return;
118  }
119  $this->skill_res_repo->updateTrigger($skill_id, $tref_id, $level_id, $rep_ref_id, true);
120  }
121 
122  public function setResourceAsNoTrigger(
123  int $skill_id,
124  int $tref_id,
125  int $level_id,
126  int $rep_ref_id
127  ): void {
128  $this->skill_res_repo->updateTrigger($skill_id, $tref_id, $level_id, $rep_ref_id, false);
129  }
130 
131  public function removeResource(
132  int $skill_id,
133  int $tref_id,
134  int $level_id,
135  int $rep_ref_id
136  ): void {
137  $this->skill_res_repo->remove($skill_id, $tref_id, $level_id, $rep_ref_id);
138  }
139 
140  public function removeResourcesForSkill(int $skill_node_id, bool $is_reference = false): void
141  {
142  $this->skill_res_repo->removeForSkill($skill_node_id, $is_reference);
143  }
144 
145  public function isLevelTooLow(int $tref_id, array $skill_levels, array $profile_levels, array $actual_levels): bool
146  {
147  $too_low = true;
148 
149  foreach ($skill_levels as $v) {
150  $v["id"] = (int) $v["id"];
151  $v["skill_id"] = (int) $v["skill_id"];
152  foreach ($profile_levels as $pl) {
153  if ($pl->getLevelId() === $v["id"] &&
154  $pl->getBaseSkillId() === $v["skill_id"]) {
155  $too_low = true;
156  }
157  }
158 
159  if ($actual_levels[$v["skill_id"]][$tref_id] == $v["id"]) {
160  $too_low = false;
161  }
162  }
163  return $too_low;
164  }
165 
169  public function determineCurrentTargetLevel(array $skill_levels, array $profile_levels): int
170  {
171  $target_level = 0;
172  foreach ($skill_levels as $l) {
173  $l["id"] = (int) $l["id"];
174  $l["skill_id"] = (int) $l["skill_id"];
175  foreach ($profile_levels as $pl) {
176  if ($pl->getLevelId() === $l["id"] &&
177  $pl->getBaseSkillId() === $l["skill_id"]) {
178  $target_level = $l["id"];
179  }
180  }
181  }
182 
183  return $target_level;
184  }
185 
190  public function getSuggestedResources(int $skill_id, int $tref_id, array $skill_levels, array $profile_levels): array
191  {
192  $target_level = $this->determineCurrentTargetLevel($skill_levels, $profile_levels);
193  $target_level_order_nr = $this->level_repo->lookupLevelNumber($target_level);
194  $resources = $this->getResources($skill_id, $tref_id);
195  $imp_resources = [];
196  foreach ($resources as $level) {
197  foreach ($level as $r) {
198  $res_level_order_nr = $this->level_repo->lookupLevelNumber($r->getLevelId());
199  if ($r->getImparting() &&
200  $target_level_order_nr >= $res_level_order_nr) {
201  $imp_resources[$res_level_order_nr . "_" . $r->getLevelId()][] = $r;
202  }
203  }
204  }
205 
206  ksort($imp_resources);
207  return $imp_resources;
208  }
209 
213  public function getTriggerLevelsForRefId(int $rep_ref_id): array
214  {
215  return $this->skill_res_repo->getTriggerLevelsForRefId($rep_ref_id);
216  }
217 
221  public static function getUsageInfo(array $a_cskill_ids): array
222  {
223  global $DIC;
224 
225  $usage_manager = $DIC->skills()->internal()->manager()->getUsageManager();
226 
227  return $usage_manager->getUsageInfoGeneric(
228  $a_cskill_ids,
230  "skl_skill_resource",
231  "rep_ref_id",
232  "base_skill_id"
233  );
234  }
235 }
determineCurrentTargetLevel(array $skill_levels, array $profile_levels)
$resources
Definition: ltiservices.php:65
__construct(?SkillResourceDBRepository $skill_res_repo=null, ?\ilSkillLevelRepository $level_repo=null)
setResourceAsNoTrigger(int $skill_id, int $tref_id, int $level_id, int $rep_ref_id)
static isSupportedObjectType(string $type)
getSuggestedResources(int $skill_id, int $tref_id, array $skill_levels, array $profile_levels)
setResourceAsNotSuggested(int $skill_id, int $tref_id, int $level_id, int $rep_ref_id)
Interface ilSkillLevelRepository.
removeResourcesForSkill(int $skill_node_id, bool $is_reference=false)
getResourcesOfLevel(int $skill_id, int $tref_id, int $level_id)
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getUsageInfo(array $a_cskill_ids)
Get title of an assigned item.int, tref_id: int}[] $a_cskill_ids array of common skill idsarray<strin...
setResourceAsSuggested(int $skill_id, int $tref_id, int $level_id, int $rep_ref_id)
global $DIC
Definition: shib_login.php:22
isLevelTooLow(int $tref_id, array $skill_levels, array $profile_levels, array $actual_levels)
removeResource(int $skill_id, int $tref_id, int $level_id, int $rep_ref_id)
setResource(int $skill_id, int $tref_id, int $level_id, int $rep_ref_id, bool $imparting, bool $trigger)
static _lookupType(int $id, bool $reference=false)
Get info on usages of skills.
setResourceAsTrigger(int $skill_id, int $tref_id, int $level_id, int $rep_ref_id)
$r