ILIAS  release_8 Revision v8.23
class.ilLPCollectionOfSCOs.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
4 
5 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
6 
13 {
14  protected static array $possible_items = array();
15 
16  public function getPossibleItems(): array
17  {
18  if (!isset(self::$possible_items[$this->obj_id])) {
19  $items = array();
20 
21  switch (ilObjSAHSLearningModule::_lookupSubType($this->obj_id)) {
22  case 'hacp':
23  case 'aicc':
24  foreach (ilObjAICCLearningModule::_getTrackingItems(
25  $this->obj_id
26  ) as $item) {
27  $items[$item['obj_id']]['title'] = $item['title'];
28  }
29  break;
30 
31  case 'scorm':
33  $this->obj_id
34  ) as $item) {
35  $items[$item->getId()]['title'] = $item->getTitle();
36  }
37  break;
38 
39  case 'scorm2004':
41  $this->obj_id
42  ) as $item) {
43  $items[$item['id']]['title'] = $item['title'];
44  }
45  break;
46  }
47 
48  self::$possible_items[$this->obj_id] = $items;
49  }
50 
51  return self::$possible_items[$this->obj_id];
52  }
53 
54  public function getTableGUIData(int $a_parent_ref_id): array
55  {
56  $data = array();
57 
58  foreach ($this->getPossibleItems() as $sco_id => $item) {
59  $tmp = array();
60  $tmp['id'] = $sco_id;
61  $tmp['ref_id'] = 0;
62  $tmp['type'] = 'sco';
63  $tmp['title'] = $item['title'];
64  $tmp["status"] = $this->isAssignedEntry($sco_id);
65 
66  $data[] = $tmp;
67  }
68 
69  return $data;
70  }
71 
72 
73  //
74  // HELPER
75  //
76 
77  // see ilSCORMCertificateAdapter
79  int $item_id,
80  int $user_id
81  ): array {
82  switch (ilObjSAHSLearningModule::_lookupSubType($this->obj_id)) {
83  case 'hacp':
84  case 'aicc':
85  return ilObjAICCLearningModule::_getScoresForUser(
86  $item_id,
87  $user_id
88  );
89 
90  case 'scorm':
92  $item_id,
93  $user_id
94  );
95 
96  case 'scorm2004':
98  $item_id,
99  $user_id
100  );
101  }
102 
103  return array("raw" => null, "max" => null, "scaled" => null);
104  }
105 
112  public function cloneCollection(int $a_target_id, int $a_copy_id): void
113  {
114  $target_obj_id = ilObject::_lookupObjId($a_target_id);
115  $new_collection = new static($target_obj_id, $this->mode);
116  $possible_items = $new_collection->getPossibleItems();
117  foreach ($this->items as $item_id) {
118  foreach ($possible_items as $pos_item_id => $pos_item) {
119  if ($this->itemsAreEqual($item_id, $pos_item_id)) {
120  $new_collection->addEntry($pos_item_id);
121  }
122  }
123  }
124  }
125 
126  protected function itemsAreEqual(int $item_a_id, int $item_b_id): bool
127  {
128  global $DIC;
129  switch (ilObjSAHSLearningModule::_lookupSubType($this->obj_id)) {
130  case 'scorm':
131  $res_a = $DIC->database()->query(
132  'SELECT import_id, identifierref FROM sc_item WHERE obj_id = ' . $DIC->database(
133  )->quote(
134  $item_a_id,
135  'integer'
136  )
137  )->fetchAssoc();
138  $res_b = $DIC->database()->query(
139  'SELECT import_id, identifierref FROM sc_item WHERE obj_id = ' . $DIC->database(
140  )->quote(
141  $item_b_id,
142  'integer'
143  )
144  )->fetchAssoc();
145  return (
146  $res_a
147  && $res_b
148  && ($res_a['import_id'] == $res_b['import_id'])
149  && ($res_a['identifierref'] == $res_b['identifierref'])
150  );
151  case 'scorm2004':
152  $res_a = $DIC->database()->query(
153  'SELECT id, resourceid FROM cp_item WHERE cp_node_id = ' . $DIC->database(
154  )->quote(
155  $item_a_id,
156  'integer'
157  )
158  )->fetchAssoc();
159  $res_b = $DIC->database()->query(
160  'SELECT id, resourceid FROM cp_item WHERE cp_node_id = ' . $DIC->database(
161  )->quote(
162  $item_b_id,
163  'integer'
164  )
165  )->fetchAssoc();
166  return (
167  $res_a
168  && $res_b
169  && ($res_a['id'] == $res_b['id'])
170  && ($res_a['resourceid'] == $res_b['resourceid'])
171  );
172  default:
173  return false;
174  }
175  }
176 }
isAssignedEntry(int $a_item_id)
itemsAreEqual(int $item_a_id, int $item_b_id)
cloneCollection(int $a_target_id, int $a_copy_id)
Scorm items are not copied, they are newly created by reading the manifest.
static _getTrackingItems(int $a_obj_id)
get all tracking items of scorm object
static _lookupSubType(int $a_obj_id)
lookup subtype id (scorm, )
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
static _getScoresForUser(int $a_item_id, int $a_user_id)
getTableGUIData(int $a_parent_ref_id)
static _getScores2004ForUser(int $a_cp_node_id, int $a_user)
getScoresForUserAndCP_Node_Id(int $item_id, int $user_id)
LP collection base class.
static _getTrackingItems(int $a_obj_id)
get all tracking items of scorm object currently a for learning progress only