19 declare(strict_types=0);
    43         $this->tree = $DIC->repositoryTree();
    44         $this->db = $DIC->database();
    45         $this->objective_id = $a_objective_id;
    46         $this->
logger = $DIC->logger()->crs();
    53         $mappings = $cwo->getMappings();
    56             if (!isset($mappings[$material[
'ref_id']]) || !$mappings[$material[
'ref_id']]) {
    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];
    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') {
    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);
    76                 $new_obj_id = $new_material_arr[1];
    77                 $this->
logger->debug(
'New material id is: ' . $new_obj_id);
    79                 $new_obj_id = $this->
objectDataCache->lookupObjId((
int) $mappings[$material_ref_id]);
    83             $new_material->setLMRefId($new_ref_id);
    84             $new_material->setLMObjId($new_obj_id);
    85             $new_material->setType($material[
'type']);
    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');
   103             $ref_ids[] = (
int) $row->ref_id;
   116         $tree = $DIC->repositoryTree();
   124         foreach ($all_materials as $material) {
   125             switch ($material[
'type']) {
   132                     $assignable[] = $material;
   141                     $assignable[] = $material;
   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 ";
   166             $ref_ids[] = (
int) $row->ref_id;
   179         foreach ($this->lms as $lm_data) {
   180             if ($lm_data[
'type'] == 
'st') {
   181                 $chapters[] = $lm_data;
   183             if ($lm_data[
'type'] == 
'pg') {
   184                 $chapters[] = $lm_data;
   190     public function getLM(
int $lm_id): array
   192         if ($this->lms[$lm_id]) {
   193             return $this->lms[$lm_id];
   206         $this->lm_ref_id = $a_ref_id;
   216         $this->lm_obj_id = $a_obj_id;
   226         $this->type = $a_type;
   237     public function isAssigned(
int $a_ref_id, 
bool $a_get_id = 
false)
   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);
   245             return (
bool) 
$res->numRows();
   248                 return (
int) $row->lm_ass_id;
   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();
   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') . 
" ";
   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') . 
" ";
   278         $res = $this->db->query($query);
   279         return (
bool) 
$res->numRows();
   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) " .
   287             $this->db->quote($next_id, 
'integer') . 
", " .
   289             $this->db->quote($this->
getLMRefId(), 
'integer') . 
", " .
   290             $this->db->quote($this->
getLMObjId(), 
'integer') . 
", " .
   291             $this->db->quote($this->
getType(), 
'text') .
   293         $res = $this->db->manipulate($query);
   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);
   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();
   317     public function delete(
int $lm_id): 
bool   323         $query = 
"DELETE FROM crs_objective_lm " .
   324             "WHERE lm_ass_id = " . $this->db->quote($lm_id, 
'integer') . 
" ";
   325         $res = $this->db->manipulate($query);
   331         $query = 
"DELETE FROM crs_objective_lm " .
   332             "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(), 
'integer') . 
" ";
   333         $res = $this->db->manipulate($query);
   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);
   349         $container_ref_id = current($container_ref_ids);
   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";
   359         $res = $this->db->query($query);
   362                 !$this->tree->isInTree((
int) $row->ref_id) ||
   363                 !$this->tree->isGrandChild($container_ref_id, (
int) $row->ref_id)
   365                 $this->
delete((
int) $row->lm_ass_id);
   370                 ($row->type == 
'pg' || $row->type == 
'st') &&
   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;
   391                     'refId' => $material[
'ref_id'],
   392                     'objId' => $material[
'obj_id'],
   393                     'type' => $material[
'type'],
   394                     'position' => $material[
'position']
 
static _getAssignedMaterials(int $a_objective_id)
 
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node. 
 
static _getAllAssignedMaterials(int $a_container_id)
 
deleteMaterial(int $ref_id, int $obj_id)
 
isAssigned(int $a_ref_id, bool $a_get_id=false)
 
static _getAllReferences(int $id)
get all reference ids for object ID 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
static _lookupContainerIdByObjectiveId(int $a_objective_id)
 
setLMRefId(int $a_ref_id)
 
static _lookupObjId(int $ref_id)
 
class ilCourseObjectiveMaterials 
 
setLMObjId(int $a_obj_id)
 
cloneDependencies(int $a_new_objective, int $a_copy_id)
 
writePosition(int $a_ass_id, int $a_position)
 
isChapterAssigned(int $a_ref_id, int $a_obj_id)
 
ilObjectDataCache $objectDataCache
 
__construct(int $a_objective_id=0)
 
static _exists(int $a_id)
checks wether a lm content object with specified id exists or not 
 
static getInstance(int $a_container_id)
 
isMaterialAssigned(int $ref_id, int $obj_id)
 
static _getInstance(int $a_copy_id)
 
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content) 
 
static _getAssignableMaterials(int $a_container_id)
Get an array of course material ids that can be assigned to learning objectives No tst...
 
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node 
 
const TYPE_TEST_UNDEFINED
 
toXml(ilXmlWriter $writer)
 
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)