ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSkillManagement.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObject.php";
6 
16 {
17 
24  function ilObjSkillManagement($a_id = 0,$a_call_by_reference = true)
25  {
26  $this->type = "skmg";
27  $this->ilObject($a_id,$a_call_by_reference);
28  }
29 
36  function update()
37  {
38  global $ilDB;
39 
40  if (!parent::update())
41  {
42  return false;
43  }
44 
45  return true;
46  }
47 
51  function read()
52  {
53  global $ilDB;
54 
55  parent::read();
56 
57  }
58 
65  function delete()
66  {
67  // always call parent delete function first!!
68  if (!parent::delete())
69  {
70  return false;
71  }
72 
73  //put here your module specific stuff
74 
75  return true;
76  }
77 
87  function initDefaultRoles()
88  {
89  global $rbacadmin;
90 
91  // create a local role folder
92  //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
93 
94  // create moderator role and assign role to rolefolder...
95  //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
96  //$roles[] = $roleObj->getId();
97 
98  //unset($rfoldObj);
99  //unset($roleObj);
100 
101  return $roles ? $roles : array();
102  }
103 
117  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
118  {
119  global $tree;
120 
121  switch ($a_event)
122  {
123  case "link":
124 
125  //var_dump("<pre>",$a_params,"</pre>");
126  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
127  //exit;
128  break;
129 
130  case "cut":
131 
132  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
133  //exit;
134  break;
135 
136  case "copy":
137 
138  //var_dump("<pre>",$a_params,"</pre>");
139  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
140  //exit;
141  break;
142 
143  case "paste":
144 
145  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
146  //exit;
147  break;
148 
149  case "new":
150 
151  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
152  //exit;
153  break;
154  }
155 
156  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
157  if ($a_node_id==$_GET["ref_id"])
158  {
159  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
160  $parent_type = $parent_obj->getType();
161  if($parent_type == $this->getType())
162  {
163  $a_node_id = (int) $tree->getParentId($a_node_id);
164  }
165  }
166 
167  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
168  }
169 
178  function executeDragDrop($source_id, $target_id, $first_child, $as_subitem = false, $movecopy = "move")
179  {
180  include_once("./Services/Skill/classes/class.ilSkillTree.php");
181  $tree = new ilSkillTree();
182 
183  include_once("./Services/Skill/classes/class.ilSkillTreeNodeFactory.php");
184 
185  $source_obj = ilSkillTreeNodeFactory::getInstance($source_id);
186 
187  if (!$first_child)
188  {
190  $target_parent = $tree->getParentId($target_id);
191  }
192  // handle skills
193  if ($source_obj->getType() == "skll")
194  {
195  if ($tree->isInTree($source_obj->getId()))
196  {
197  $node_data = $tree->getNodeData($source_obj->getId());
198 
199  // cut on move
200  if ($movecopy == "move")
201  {
202  $parent_id = $tree->getParentId($source_obj->getId());
203  $tree->deleteTree($node_data);
204 
205  }
206 
207  // paste page
208  if(!$tree->isInTree($source_obj->getId()))
209  {
210  if ($first_child) // as first child
211  {
212  $target_pos = IL_FIRST_NODE;
213  $parent = $target_id;
214  }
215  else if ($as_subitem) // as last child
216  {
217  $parent = $target_id;
218  $target_pos = IL_FIRST_NODE;
219  $childs = $tree->getChildsByType($parent, array("skll", "scat"));
220  if (count($childs) != 0)
221  {
222  $target_pos = $childs[count($childs) - 1]["obj_id"];
223  }
224  }
225  else // at position
226  {
227  $target_pos = $target_id;
228  $parent = $target_parent;
229  }
230  // insert skill into tree
231  $tree->insertNode($source_obj->getId(),
232  $parent, $target_pos);
233  }
234  }
235  }
236 
237  // handle skil categories
238  if ($source_obj->getType() == "scat")
239  {
240  $source_node = $tree->getNodeData($source_id);
241  $subnodes = $tree->getSubtree($source_node);
242 
243  // check, if target is within subtree
244  foreach ($subnodes as $subnode)
245  {
246  if($subnode["obj_id"] == $target_id)
247  {
248  return;
249  }
250  }
251 
252  $target_pos = $target_id;
253 
254  if ($first_child) // as first node
255  {
256  $target_pos = IL_FIRST_NODE;
257  $target_parent = $target_id;
258  }
259  else if ($as_subitem) // as last node
260  {
261  $target_parent = $target_id;
262  $target_pos = IL_FIRST_NODE;
263  $childs = $tree->getChilds($target_parent);
264  if (count($childs) != 0)
265  {
266  $target_pos = $childs[count($childs) - 1]["obj_id"];
267  }
268  }
269 
270  // delete source tree
271  if ($movecopy == "move")
272  {
273  $tree->deleteTree($source_node);
274  }
275 
276  if (!$tree->isInTree($source_id))
277  {
278  $tree->insertNode($source_id, $target_parent, $target_pos);
279 
280  // insert moved tree
281  if ($movecopy == "move")
282  {
283  foreach ($subnodes as $node)
284  {
285  if($node["obj_id"] != $source_id)
286  {
287  $tree->insertNode($node["obj_id"], $node["parent"]);
288  }
289  }
290  }
291  }
292  }
293 
294  }
295 }
296 ?>