ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSkillUsage.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Skill/interfaces/interface.ilSkillUsageInfo.php");
6 
27 {
28  const TYPE_GENERAL = "gen";
29  const USER_ASSIGNED = "user";
30  const PERSONAL_SKILL = "pers";
31  const USER_MATERIAL = "mat";
32  const SELF_EVAL = "seval";
33  const PROFILE = "prof";
34  const RESOURCE = "res";
35 
36  // these classes implement the ilSkillUsageInfo interface
37  // currently this array is ok, we do not need any subscription model here
38  /*protected $classes = array("ilBasicSkill", "ilPersonalSkill",
39  "ilSkillSelfEvaluation", "ilSkillProfile", "ilSkillResources", "ilSkillUsage");*/
40  protected $classes = array("ilBasicSkill", "ilPersonalSkill", "ilSkillProfile", "ilSkillResources", "ilSkillUsage");
41 
50  static function setUsage($a_obj_id, $a_skill_id, $a_tref_id, $a_use = true)
51  {
52  global $ilDB;
53 
54  if ($a_use)
55  {
56  $ilDB->replace("skl_usage",
57  array(
58  "obj_id" => array("integer", $a_obj_id),
59  "skill_id" => array("integer", $a_skill_id),
60  "tref_id" => array("integer", $a_tref_id)
61  ),
62  array()
63  );
64  }
65  else
66  {
67  $ilDB->manipulate($q = "DELETE FROM skl_usage WHERE ".
68  " obj_id = ".$ilDB->quote($a_obj_id, "integer").
69  " AND skill_id = ".$ilDB->quote($a_skill_id, "integer").
70  " AND tref_id = ".$ilDB->quote($a_tref_id, "integer")
71  );
72 //echo $q; exit;
73  }
74  }
75 
83  static function getUsages($a_skill_id, $a_tref_id)
84  {
85  global $ilDB;
86 
87  $set = $ilDB->query("SELECT obj_id FROM skl_usage ".
88  " WHERE skill_id = ".$ilDB->quote($a_skill_id, "integer").
89  " AND tref_id = ".$ilDB->quote($a_tref_id, "integer")
90  );
91  $obj_ids = array();
92  while ($rec = $ilDB->fetchAssoc($set))
93  {
94  $obj_ids[] = $rec["obj_id"];
95  }
96 
97  return $obj_ids;
98  }
99 
106  static public function getUsageInfo($a_cskill_ids, &$a_usages)
107  {
108  global $ilDB;
109 
110  self::getUsageInfoGeneric($a_cskill_ids, $a_usages, ilSkillUsage::TYPE_GENERAL,
111  "skl_usage", "obj_id");
112  }
113 
120  static function getUsageInfoGeneric($a_cskill_ids, &$a_usages, $a_usage_type, $a_table, $a_key_field,
121  $a_skill_field = "skill_id", $a_tref_field = "tref_id")
122  {
123  global $ilDB;
124 
125  if (count($a_cskill_ids) == 0)
126  {
127  return;
128  }
129 
130  $w = "WHERE";
131  $q = "SELECT ".$a_key_field.", ".$a_skill_field.", ".$a_tref_field." FROM ".$a_table." ";
132  foreach ($a_cskill_ids as $sk)
133  {
134  $q.= $w." (".$a_skill_field." = ".$ilDB->quote($sk["skill_id"], "integer").
135  " AND ".$a_tref_field." = ".$ilDB->quote($sk["tref_id"], "integer").") ";
136  $w = "OR";
137  }
138  $q.= " GROUP BY ".$a_key_field.", ".$a_skill_field.", ".$a_tref_field;
139 
140  $set = $ilDB->query($q);
141  while ($rec = $ilDB->fetchAssoc($set))
142  {
143  $a_usages[$rec[$a_skill_field].":".$rec[$a_tref_field]][$a_usage_type][] =
144  array("key" => $rec[$a_key_field]);
145  }
146  }
147 
148 
155  function getAllUsagesInfo($a_cskill_ids)
156  {
158 
159  $usages = array();
160  foreach ($classes as $class)
161  {
162  // make static call
163  include_once("./Services/Skill/classes/class.".$class.".php");
164  //call_user_func($class.'::getUsageInfo', $a_cskill_ids, $usages);
165  $class::getUsageInfo($a_cskill_ids, $usages);
166  }
167  return $usages;
168  }
169 
177  function getAllUsagesInfoOfSubtree($a_skill_id, $a_tref_id = 0)
178  {
179  // get nodes
180  include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
181  $vtree = new ilVirtualSkillTree();
182  $nodes = $vtree->getSubTreeForCSkillId($a_skill_id.":".$a_tref_id);
183 
184  return $this->getAllUsagesInfo($nodes);
185  }
186 
193  function getAllUsagesInfoOfSubtrees($a_cskill_ids)
194  {
195  // get nodes
196  include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
197  $vtree = new ilVirtualSkillTree();
198  $allnodes = array();
199  foreach ($a_cskill_ids as $s)
200  {
201  $nodes = $vtree->getSubTreeForCSkillId($s["skill_id"].":".$s["tref_id"]);
202  foreach ($nodes as $n)
203  {
204  $allnodes[] = $n;
205  }
206  }
207 
208  return $this->getAllUsagesInfo($allnodes);
209  }
210 
217  function getAllUsagesOfTemplate($a_tempate_id)
218  {
219  $skill_logger = ilLoggerFactory::getLogger('skll');
220  $skill_logger->debug("ilSkillUsage: getAllUsagesOfTemplate(".$a_tempate_id.")");
221 
222  // get all trefs for template id
223  include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
225 
226  // get all usages of subtrees of template_id:tref
227  $cskill_ids = array();
228  foreach ($trefs as $tref)
229  {
230  $cskill_ids[] = array("skill_id" => $a_tempate_id, "tref_id" => $tref);
231  $skill_logger->debug("ilSkillUsage: ... skill_id: ".$a_tempate_id.", tref_id: ".$tref.".");
232  }
233 
234  $skill_logger->debug("ilSkillUsage: ... count cskill_ids: ".count($cskill_ids).".");
235 
236  return $this->getAllUsagesInfoOfSubtrees($cskill_ids);
237  }
238 
245  static function getTypeInfoString($a_type)
246  {
247  global $lng;
248 
249  return $lng->txt("skmg_usage_type_info_".$a_type);
250  }
251 
258  static function getObjTypeString($a_type)
259  {
260  global $lng;
261 
262  switch ($a_type)
263  {
264  case self::TYPE_GENERAL:
265  case self::RESOURCE:
266  return $lng->txt("skmg_usage_obj_objects");
267  break;
268 
269  case self::USER_ASSIGNED:
270  case self::PERSONAL_SKILL:
271  case self::USER_MATERIAL:
272  case self::SELF_EVAL:
273  return $lng->txt("skmg_usage_obj_users");
274  break;
275 
276  case self::PROFILE:
277  return $lng->txt("skmg_usage_obj_profiles");
278  break;
279  }
280 
281  return $lng->txt("skmg_usage_type_info_".$a_type);
282  }
283 
284 }
285 
286 ?>
Get info on usages of skills.
getAllUsagesInfoOfSubtrees($a_cskill_ids)
Get all usages info of subtree.
getAllUsagesInfoOfSubtree($a_skill_id, $a_tref_id=0)
Get all usages info of subtree.
static _lookupTrefIdsForTemplateId($a_tid)
Get all tref ids for a template id.
getAllUsagesInfo($a_cskill_ids)
Get all usages info.
static getObjTypeString($a_type)
Get type info string.
getAllUsagesOfTemplate($a_tempate_id)
Get all usages of template.
static setUsage($a_obj_id, $a_skill_id, $a_tref_id, $a_use=true)
Set usage.
$w
$a_type
Definition: workflow.php:93
static getUsageInfo($a_cskill_ids, &$a_usages)
Get usage info.
static getTypeInfoString($a_type)
Get type info string.
$n
Definition: RandomTest.php:80
Create styles array
The data for the language used.
static getUsageInfoGeneric($a_cskill_ids, &$a_usages, $a_usage_type, $a_table, $a_key_field, $a_skill_field="skill_id", $a_tref_field="tref_id")
Get standard usage query.
global $lng
Definition: privfeed.php:17
global $ilDB
static getLogger($a_component_id)
Get component logger.
static getUsages($a_skill_id, $a_tref_id)
Get usages.
Skill usage.