ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilCourseObjectiveMaterials Class Reference

class ilCourseObjectiveMaterials More...

+ Collaboration diagram for ilCourseObjectiveMaterials:

Public Member Functions

 __construct (int $a_objective_id=0)
 
 cloneDependencies (int $a_new_objective, int $a_copy_id)
 
 getMaterials ()
 
 getChapters ()
 
 getLM (int $lm_id)
 
 getObjectiveId ()
 
 setLMRefId (int $a_ref_id)
 
 getLMRefId ()
 
 setLMObjId (int $a_obj_id)
 
 getLMObjId ()
 
 setType (string $a_type)
 
 getType ()
 
 isAssigned (int $a_ref_id, bool $a_get_id=false)
 
 isChapterAssigned (int $a_ref_id, int $a_obj_id)
 
 checkExists ()
 
 add ()
 
 deleteMaterial (int $ref_id, int $obj_id)
 
 isMaterialAssigned (int $ref_id, int $obj_id)
 
 delete (int $lm_id)
 
 deleteAll ()
 
 writePosition (int $a_ass_id, int $a_position)
 
 __read ()
 
 toXml (ilXmlWriter $writer)
 

Static Public Member Functions

static _getAssignedMaterials (int $a_objective_id)
 
static _getAssignableMaterials (int $a_container_id)
 Get an array of course material ids that can be assigned to learning objectives No tst, fold and grp. More...
 
static _getAllAssignedMaterials (int $a_container_id)
 

Protected Attributes

ilLogger $logger
 
ilDBInterface $db
 
ilObjectDataCache $objectDataCache
 
ilTree $tree
 

Private Attributes

int $objective_id = 0
 
array $lms = []
 
int $lm_ref_id = 0
 
int $lm_obj_id = 0
 
string $type = ''
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCourseObjectiveMaterials::__construct ( int  $a_objective_id = 0)

Definition at line 38 of file class.ilCourseObjectiveMaterials.php.

References $DIC, __read(), ILIAS\Repository\logger(), and ILIAS\Repository\objectDataCache().

39  {
40  global $DIC;
41 
42  $this->objectDataCache = $DIC['ilObjDataCache'];
43  $this->tree = $DIC->repositoryTree();
44  $this->db = $DIC->database();
45  $this->objective_id = $a_objective_id;
46  $this->logger = $DIC->logger()->crs();
47  $this->__read();
48  }
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ __read()

ilCourseObjectiveMaterials::__read ( )

Definition at line 346 of file class.ilCourseObjectiveMaterials.php.

References $res, ilLMObject\_exists(), ilObject\_getAllReferences(), ilCourseObjective\_lookupContainerIdByObjectiveId(), ilDBConstants\FETCHMODE_OBJECT, getObjectiveId(), and ILIAS\Repository\int().

Referenced by __construct().

346  : bool
347  {
348  $container_ref_ids = ilObject::_getAllReferences(ilCourseObjective::_lookupContainerIdByObjectiveId($this->objective_id));
349  $container_ref_id = current($container_ref_ids);
350 
351  $this->lms = array();
352  $query = "SELECT position,lm_ass_id,lm.ref_id,lm.obj_id,lm.type FROM crs_objective_lm lm " .
353  "JOIN object_reference obr ON lm.ref_id = obr.ref_id " .
354  "JOIN object_data obd ON obr.obj_id = obd.obj_id " .
355  "LEFT JOIN lm_data lmd ON lmd.obj_id = lm.obj_id " .
356  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
357  "ORDER BY position,obd.title,lmd.title";
358 
359  $res = $this->db->query($query);
360  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
361  if (
362  !$this->tree->isInTree((int) $row->ref_id) ||
363  !$this->tree->isGrandChild($container_ref_id, (int) $row->ref_id)
364  ) {
365  $this->delete((int) $row->lm_ass_id);
366  continue;
367  }
368  if (
369  $row->obj_id > 0 &&
370  ($row->type == 'pg' || $row->type == 'st') &&
371  !ilLMObject::_exists((int) $row->obj_id)
372  ) {
373  continue;
374  }
375  $lm['ref_id'] = (int) $row->ref_id;
376  $lm['obj_id'] = (int) $row->obj_id;
377  $lm['type'] = (string) $row->type;
378  $lm['lm_ass_id'] = (int) $row->lm_ass_id;
379  $lm['position'] = (int) $row->position;
380  $this->lms[(int) $row->lm_ass_id] = $lm;
381  }
382  return true;
383  }
$res
Definition: ltiservices.php:66
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupContainerIdByObjectiveId(int $a_objective_id)
static _exists(int $a_id)
checks wether a lm content object with specified id exists or not
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getAllAssignedMaterials()

static ilCourseObjectiveMaterials::_getAllAssignedMaterials ( int  $a_container_id)
static
Returns
int[]

Definition at line 151 of file class.ilCourseObjectiveMaterials.php.

References $DIC, $ilDB, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

151  : array
152  {
153  global $DIC;
154 
155  $ilDB = $DIC->database();
156  $query = "SELECT DISTINCT(com.ref_id) ref_id FROM crs_objectives co " .
157  "JOIN crs_objective_lm com ON co.objective_id = com.objective_id " .
158  "JOIN object_reference obr ON com.ref_id = obr.ref_id " .
159  "JOIN object_data obd ON obr.obj_id = obd.obj_id " .
160  "WHERE co.crs_id = " . $ilDB->quote($a_container_id, 'integer') . " " .
161  "ORDER BY obd.title ";
162 
163  $res = $ilDB->query($query);
164  $ref_ids = [];
165  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
166  $ref_ids[] = (int) $row->ref_id;
167  }
168  return $ref_ids;
169  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

◆ _getAssignableMaterials()

static ilCourseObjectiveMaterials::_getAssignableMaterials ( int  $a_container_id)
static

Get an array of course material ids that can be assigned to learning objectives No tst, fold and grp.

Definition at line 112 of file class.ilCourseObjectiveMaterials.php.

References $DIC, ilObject\_lookupObjId(), ilLOTestAssignments\getInstance(), ilTree\getNodeData(), ilTree\getSubTree(), ilArrayUtil\sortArray(), and ilLOSettings\TYPE_TEST_UNDEFINED.

Referenced by ilCourseObjectivesGUI\materialAssignment().

112  : array
113  {
114  global $DIC;
115 
116  $tree = $DIC->repositoryTree();
117  $container_obj_id = ilObject::_lookupObjId($a_container_id);
118 
119  $all_materials = $tree->getSubTree($tree->getNodeData($a_container_id), true);
120  $all_materials = ilArrayUtil::sortArray($all_materials, 'title', 'asc');
121 
122  // Filter
123  $assignable = [];
124  foreach ($all_materials as $material) {
125  switch ($material['type']) {
126  case 'tst':
127  $type = ilLOTestAssignments::getInstance($container_obj_id)->getTypeByTest($material['child']);
129  break;
130  }
131 
132  $assignable[] = $material;
133  break;
134 
135  case 'crs':
136  case 'rolf':
137  case 'itgr':
138  break;
139 
140  default:
141  $assignable[] = $material;
142  break;
143  }
144  }
145  return $assignable;
146  }
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
static _lookupObjId(int $ref_id)
global $DIC
Definition: shib_login.php:22
static getInstance(int $a_container_id)
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getAssignedMaterials()

static ilCourseObjectiveMaterials::_getAssignedMaterials ( int  $a_objective_id)
static
Returns
int[]

Definition at line 93 of file class.ilCourseObjectiveMaterials.php.

References $DIC, $ilDB, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

Referenced by ilObjectActivation\getItemsByObjective().

93  : array
94  {
95  global $DIC;
96 
97  $ilDB = $DIC->database();
98  $query = "SELECT DISTINCT(ref_id) ref_id FROM crs_objective_lm " .
99  "WHERE objective_id = " . $ilDB->quote($a_objective_id, 'integer');
100  $res = $ilDB->query($query);
101  $ref_ids = [];
102  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
103  $ref_ids[] = (int) $row->ref_id;
104  }
105  return $ref_ids;
106  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ add()

ilCourseObjectiveMaterials::add ( )

Definition at line 282 of file class.ilCourseObjectiveMaterials.php.

References $res, getLMObjId(), getLMRefId(), getObjectiveId(), and getType().

282  : int
283  {
284  $next_id = $this->db->nextId('crs_objective_lm');
285  $query = "INSERT INTO crs_objective_lm (lm_ass_id,objective_id,ref_id,obj_id,type) " .
286  "VALUES( " .
287  $this->db->quote($next_id, 'integer') . ", " .
288  $this->db->quote($this->getObjectiveId(), 'integer') . ", " .
289  $this->db->quote($this->getLMRefId(), 'integer') . ", " .
290  $this->db->quote($this->getLMObjId(), 'integer') . ", " .
291  $this->db->quote($this->getType(), 'text') .
292  ")";
293  $res = $this->db->manipulate($query);
294  return $next_id;
295  }
$res
Definition: ltiservices.php:66
+ Here is the call graph for this function:

◆ checkExists()

ilCourseObjectiveMaterials::checkExists ( )

Definition at line 265 of file class.ilCourseObjectiveMaterials.php.

References $res, getLMObjId(), getLMRefId(), and getObjectiveId().

265  : bool
266  {
267  if ($this->getLMObjId()) {
268  $query = "SELECT * FROM crs_objective_lm " .
269  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
270  "AND ref_id = " . $this->db->quote($this->getLMRefId(), 'integer') . " " .
271  "AND obj_id = " . $this->db->quote($this->getLMObjId(), 'integer') . " ";
272  } else {
273  $query = "SELECT * FROM crs_objective_lm " .
274  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
275  "AND ref_id = " . $this->db->quote($this->getLMRefId(), 'integer') . " ";
276  }
277 
278  $res = $this->db->query($query);
279  return (bool) $res->numRows();
280  }
$res
Definition: ltiservices.php:66
+ Here is the call graph for this function:

◆ cloneDependencies()

ilCourseObjectiveMaterials::cloneDependencies ( int  $a_new_objective,
int  $a_copy_id 
)

Definition at line 50 of file class.ilCourseObjectiveMaterials.php.

References ilCopyWizardOptions\_getInstance(), getMaterials(), ILIAS\Repository\int(), ILIAS\Repository\logger(), and ILIAS\Repository\objectDataCache().

50  : void
51  {
52  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
53  $mappings = $cwo->getMappings();
54  foreach ($this->getMaterials() as $material) {
55  // Copy action omit ?
56  if (!isset($mappings[$material['ref_id']]) || !$mappings[$material['ref_id']]) {
57  continue;
58  }
59  $material_ref_id = (int) $material['ref_id'];
60  $material_rbac_obj_id = $this->objectDataCache->lookupObjId($material_ref_id);
61  $material_obj_id = $material['obj_id'];
62  $new_ref_id = (int) $mappings[$material_ref_id];
63  $new_rbac_obj_id = $this->objectDataCache->lookupObjId($new_ref_id);
64 
65  if ($new_rbac_obj_id === $material_rbac_obj_id) {
66  $this->logger->debug('Material has been linked. Keeping object id.');
67  $new_obj_id = $material_obj_id;
68  } elseif ($material['type'] == 'st' || $material['type'] == 'pg') {
69  // Chapter assignment
70  $new_material_info = $mappings[$material_ref_id . '_' . $material_obj_id] ?? '';
71  $new_material_arr = explode('_', $new_material_info);
72  if (!isset($new_material_arr[1]) || !$new_material_arr[1]) {
73  $this->logger->debug(': No mapping found for chapter: ' . $material_obj_id);
74  continue;
75  }
76  $new_obj_id = $new_material_arr[1];
77  $this->logger->debug('New material id is: ' . $new_obj_id);
78  } else {
79  $new_obj_id = $this->objectDataCache->lookupObjId((int) $mappings[$material_ref_id]);
80  }
81 
82  $new_material = new ilCourseObjectiveMaterials($a_new_objective);
83  $new_material->setLMRefId($new_ref_id);
84  $new_material->setLMObjId($new_obj_id);
85  $new_material->setType($material['type']);
86  $new_material->add();
87  }
88  }
class ilCourseObjectiveMaterials
static _getInstance(int $a_copy_id)
+ Here is the call graph for this function:

◆ delete()

ilCourseObjectiveMaterials::delete ( int  $lm_id)

Definition at line 317 of file class.ilCourseObjectiveMaterials.php.

References $res.

317  : bool
318  {
319  if (!$lm_id) {
320  return false;
321  }
322 
323  $query = "DELETE FROM crs_objective_lm " .
324  "WHERE lm_ass_id = " . $this->db->quote($lm_id, 'integer') . " ";
325  $res = $this->db->manipulate($query);
326  return true;
327  }
$res
Definition: ltiservices.php:66

◆ deleteAll()

ilCourseObjectiveMaterials::deleteAll ( )

Definition at line 329 of file class.ilCourseObjectiveMaterials.php.

References $res, and getObjectiveId().

329  : bool
330  {
331  $query = "DELETE FROM crs_objective_lm " .
332  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
333  $res = $this->db->manipulate($query);
334  return true;
335  }
$res
Definition: ltiservices.php:66
+ Here is the call graph for this function:

◆ deleteMaterial()

ilCourseObjectiveMaterials::deleteMaterial ( int  $ref_id,
int  $obj_id 
)

Definition at line 297 of file class.ilCourseObjectiveMaterials.php.

References getObjectiveId().

297  : bool
298  {
299  $query = "DELETE FROM crs_objective_lm " .
300  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
301  "AND ref_id = " . $this->db->quote($ref_id, 'integer') . " " .
302  "AND obj_id = " . $this->db->quote($obj_id, 'integer');
303  $this->db->manipulate($query);
304  return true;
305  }
$ref_id
Definition: ltiauth.php:65
+ Here is the call graph for this function:

◆ getChapters()

ilCourseObjectiveMaterials::getChapters ( )

Definition at line 176 of file class.ilCourseObjectiveMaterials.php.

176  : array
177  {
178  $chapters = [];
179  foreach ($this->lms as $lm_data) {
180  if ($lm_data['type'] == 'st') {
181  $chapters[] = $lm_data;
182  }
183  if ($lm_data['type'] == 'pg') {
184  $chapters[] = $lm_data;
185  }
186  }
187  return $chapters;
188  }

◆ getLM()

ilCourseObjectiveMaterials::getLM ( int  $lm_id)

Definition at line 190 of file class.ilCourseObjectiveMaterials.php.

190  : array
191  {
192  if ($this->lms[$lm_id]) {
193  return $this->lms[$lm_id];
194  } else {
195  return [];
196  }
197  }

◆ getLMObjId()

ilCourseObjectiveMaterials::getLMObjId ( )

Definition at line 219 of file class.ilCourseObjectiveMaterials.php.

References $lm_obj_id.

Referenced by add(), and checkExists().

219  : int
220  {
221  return $this->lm_obj_id;
222  }
+ Here is the caller graph for this function:

◆ getLMRefId()

ilCourseObjectiveMaterials::getLMRefId ( )

Definition at line 209 of file class.ilCourseObjectiveMaterials.php.

References $lm_ref_id.

Referenced by add(), and checkExists().

209  : int
210  {
211  return $this->lm_ref_id;
212  }
+ Here is the caller graph for this function:

◆ getMaterials()

ilCourseObjectiveMaterials::getMaterials ( )

Definition at line 171 of file class.ilCourseObjectiveMaterials.php.

References $lms.

Referenced by cloneDependencies(), and toXml().

171  : array
172  {
173  return $this->lms;
174  }
+ Here is the caller graph for this function:

◆ getObjectiveId()

ilCourseObjectiveMaterials::getObjectiveId ( )

Definition at line 199 of file class.ilCourseObjectiveMaterials.php.

References $objective_id.

Referenced by __read(), add(), checkExists(), deleteAll(), deleteMaterial(), isAssigned(), isChapterAssigned(), isMaterialAssigned(), and writePosition().

199  : int
200  {
201  return $this->objective_id;
202  }
+ Here is the caller graph for this function:

◆ getType()

ilCourseObjectiveMaterials::getType ( )

Definition at line 229 of file class.ilCourseObjectiveMaterials.php.

References $type.

Referenced by add().

229  : string
230  {
231  return $this->type;
232  }
+ Here is the caller graph for this function:

◆ isAssigned()

ilCourseObjectiveMaterials::isAssigned ( int  $a_ref_id,
bool  $a_get_id = false 
)
Returns
bool|int

Definition at line 237 of file class.ilCourseObjectiveMaterials.php.

References $res, ilDBConstants\FETCHMODE_OBJECT, and getObjectiveId().

238  {
239  $query = "SELECT * FROM crs_objective_lm " .
240  "WHERE ref_id = " . $this->db->quote($a_ref_id, 'integer') . " " .
241  "AND objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
242  "AND type != 'st' AND type != 'pg' ";
243  $res = $this->db->query($query);
244  if (!$a_get_id) {
245  return (bool) $res->numRows();
246  } else {
247  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
248  return (int) $row->lm_ass_id;
249  }
250  return 0;
251  }
252  }
$res
Definition: ltiservices.php:66
+ Here is the call graph for this function:

◆ isChapterAssigned()

ilCourseObjectiveMaterials::isChapterAssigned ( int  $a_ref_id,
int  $a_obj_id 
)

Definition at line 254 of file class.ilCourseObjectiveMaterials.php.

References $res, and getObjectiveId().

254  : bool
255  {
256  $query = "SELECT * FROM crs_objective_lm " .
257  "WHERE ref_id = " . $this->db->quote($a_ref_id, 'integer') . " " .
258  "AND obj_id = " . $this->db->quote($a_obj_id, 'integer') . " " .
259  "AND objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
260  "AND (type = 'st' OR type = 'pg')";
261  $res = $this->db->query($query);
262  return (bool) $res->numRows();
263  }
$res
Definition: ltiservices.php:66
+ Here is the call graph for this function:

◆ isMaterialAssigned()

ilCourseObjectiveMaterials::isMaterialAssigned ( int  $ref_id,
int  $obj_id 
)

Definition at line 307 of file class.ilCourseObjectiveMaterials.php.

References $res, and getObjectiveId().

307  : bool
308  {
309  $query = "SELECT * FROM crs_objective_lm " .
310  "WHERE ref_id = " . $this->db->quote($ref_id, 'integer') . " " .
311  "AND obj_id = " . $this->db->quote($obj_id, 'integer') . " " .
312  "AND objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
313  $res = $this->db->query($query);
314  return (bool) $res->numRows();
315  }
$res
Definition: ltiservices.php:66
$ref_id
Definition: ltiauth.php:65
+ Here is the call graph for this function:

◆ setLMObjId()

ilCourseObjectiveMaterials::setLMObjId ( int  $a_obj_id)

Definition at line 214 of file class.ilCourseObjectiveMaterials.php.

214  : void
215  {
216  $this->lm_obj_id = $a_obj_id;
217  }

◆ setLMRefId()

ilCourseObjectiveMaterials::setLMRefId ( int  $a_ref_id)

Definition at line 204 of file class.ilCourseObjectiveMaterials.php.

204  : void
205  {
206  $this->lm_ref_id = $a_ref_id;
207  }

◆ setType()

ilCourseObjectiveMaterials::setType ( string  $a_type)

Definition at line 224 of file class.ilCourseObjectiveMaterials.php.

224  : void
225  {
226  $this->type = $a_type;
227  }

◆ toXml()

ilCourseObjectiveMaterials::toXml ( ilXmlWriter  $writer)

Definition at line 385 of file class.ilCourseObjectiveMaterials.php.

References getMaterials(), and ilXmlWriter\xmlElement().

385  : bool
386  {
387  foreach ($this->getMaterials() as $material) {
388  $writer->xmlElement(
389  'Material',
390  array(
391  'refId' => $material['ref_id'],
392  'objId' => $material['obj_id'],
393  'type' => $material['type'],
394  'position' => $material['position']
395  )
396  );
397  }
398  return true;
399  }
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
+ Here is the call graph for this function:

◆ writePosition()

ilCourseObjectiveMaterials::writePosition ( int  $a_ass_id,
int  $a_position 
)

Definition at line 337 of file class.ilCourseObjectiveMaterials.php.

References getObjectiveId().

337  : void
338  {
339  $query = "UPDATE crs_objective_lm " .
340  "SET position = " . $this->db->quote((string) $a_position, 'integer') . " " .
341  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
342  "AND lm_ass_id = " . $this->db->quote($a_ass_id, "integer");
343  $this->db->manipulate($query);
344  }
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilCourseObjectiveMaterials::$db
protected

Definition at line 34 of file class.ilCourseObjectiveMaterials.php.

◆ $lm_obj_id

int ilCourseObjectiveMaterials::$lm_obj_id = 0
private

Definition at line 30 of file class.ilCourseObjectiveMaterials.php.

Referenced by getLMObjId().

◆ $lm_ref_id

int ilCourseObjectiveMaterials::$lm_ref_id = 0
private

Definition at line 29 of file class.ilCourseObjectiveMaterials.php.

Referenced by getLMRefId().

◆ $lms

array ilCourseObjectiveMaterials::$lms = []
private

Definition at line 28 of file class.ilCourseObjectiveMaterials.php.

Referenced by getMaterials().

◆ $logger

ilLogger ilCourseObjectiveMaterials::$logger
protected

Definition at line 33 of file class.ilCourseObjectiveMaterials.php.

◆ $objectDataCache

ilObjectDataCache ilCourseObjectiveMaterials::$objectDataCache
protected

Definition at line 35 of file class.ilCourseObjectiveMaterials.php.

◆ $objective_id

int ilCourseObjectiveMaterials::$objective_id = 0
private

Definition at line 27 of file class.ilCourseObjectiveMaterials.php.

Referenced by getObjectiveId().

◆ $tree

ilTree ilCourseObjectiveMaterials::$tree
protected

Definition at line 36 of file class.ilCourseObjectiveMaterials.php.

◆ $type

string ilCourseObjectiveMaterials::$type = ''
private

Definition at line 31 of file class.ilCourseObjectiveMaterials.php.

Referenced by getType().


The documentation for this class was generated from the following file: