Skip to content

Commit

Permalink
Merge pull request #6140 from chlulei/mt_29772_release_8
Browse files Browse the repository at this point in the history
Mantis Ticket 29772, release 8
  • Loading branch information
smeyer-ilias committed Jul 12, 2023
1 parent a7eadb4 commit c5fe95c
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

declare(strict_types=0);
/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -17,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=0);

/**
* TableGUI for material assignments of course objectives
* @author Stefan Meyer <[email protected]>
Expand All @@ -36,6 +37,7 @@ public function __construct(object $a_parent_obj, ilObject $a_course_obj, int $a
$this->objectDefinition = $DIC['objDefinition'];
$this->objective_id = $a_objective_id;

$this->setId('tbl_crs_obj_mat_assignment');
parent::__construct($a_parent_obj, 'materialAssignment');
$this->lng->loadLanguageModule('crs');

Expand All @@ -46,7 +48,7 @@ public function __construct(object $a_parent_obj, ilObject $a_course_obj, int $a
$this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
$this->setRowTemplate("tpl.crs_objective_list_materials_row.html", "Modules/Course");
$this->setDefaultOrderField('title');
$this->setLimit(200);
$this->setShowRowsSelector(true);
$this->setNoEntriesText($this->lng->txt('crs_no_objective_lms_found'));
$this->addCommandButton('updateMaterialAssignment', $this->lng->txt('crs_wiz_next'));
$this->initObjectiveAssignments();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=0);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=0);

/**
* class ilCourseObjectiveMaterials
* @author Stefan Meyer <[email protected]>
Expand Down Expand Up @@ -293,6 +293,26 @@ public function add(): int
return $next_id;
}

public function deleteMaterial(int $ref_id, int $obj_id): bool
{
$query = "DELETE FROM crs_objective_lm " .
"WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
"AND ref_id = " . $this->db->quote($ref_id, 'integer') . " " .
"AND obj_id = " . $this->db->quote($obj_id, 'integer');
$this->db->manipulate($query);
return true;
}

public function isMaterialAssigned(int $ref_id, int $obj_id): bool
{
$query = "SELECT * FROM crs_objective_lm " .
"WHERE ref_id = " . $this->db->quote($ref_id, 'integer') . " " .
"AND obj_id = " . $this->db->quote($obj_id, 'integer') . " " .
"AND objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
$res = $this->db->query($query);
return (bool) $res->numRows();
}

public function delete(int $lm_id): bool
{
if (!$lm_id) {
Expand Down
84 changes: 57 additions & 27 deletions Modules/Course/classes/Objectives/class.ilCourseObjectivesGUI.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=0);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=0);

use ILIAS\UI\Component\Listing\Workflow\Step;
use ILIAS\UI\Component\Listing\Workflow\Factory as Workflow;
use ILIAS\UI\Renderer as UIRenderer;
Expand Down Expand Up @@ -399,6 +399,38 @@ protected function materialAssignment(): void
$this->tpl->setContent($table->getHTML());
}

/**
* @return int[]
*/
private function getIntArrayFromPost(string $key): array
{
if ($this->http->wrapper()->post()->has($key)) {
return $this->http->wrapper()->post()->retrieve(
$key,
$this->refinery->kindlyTo()->listOf(
$this->refinery->kindlyTo()->int()
)
);
}
return [];
}

/**
* @return string[]
*/
private function getStringArrayFromPost(string $key): array
{
if ($this->http->wrapper()->post()->has($key)) {
return $this->http->wrapper()->post()->retrieve(
$key,
$this->refinery->kindlyTo()->listOf(
$this->refinery->kindlyTo()->string()
)
);
}
return [];
}

protected function updateMaterialAssignment(): void
{
if (!$this->access->checkAccess('write', '', $this->course_obj->getRefId())) {
Expand All @@ -410,38 +442,36 @@ protected function updateMaterialAssignment(): void
}

$this->__initLMObject($this->initObjectiveIdFromQuery());
$this->objectives_lm_obj->deleteAll();

$materials = [];
if ($this->http->wrapper()->post()->has('materials')) {
$materials = $this->http->wrapper()->post()->retrieve(
'materials',
$this->refinery->kindlyTo()->listOf(
$this->refinery->kindlyTo()->int()
)
);
}
foreach ($materials as $node_id) {
$obj_id = $this->objectDataCache->lookupObjId((int) $node_id);
$type = $this->objectDataCache->lookupType($obj_id);
$visibleMaterials = $this->getIntArrayFromPost('visible_materials');
$visibleChapters = $this->getStringArrayFromPost('visible_chapters');
$materials = $this->getIntArrayFromPost('materials');
$chapters = $this->getStringArrayFromPost('chapters');

foreach ($visibleMaterials as $node_id) {
$obj_id = $this->objectDataCache->lookupObjId((int) $node_id);
if (!in_array($node_id, $materials)) {
$this->objectives_lm_obj->deleteMaterial($node_id, $obj_id);
continue;
}
if ($this->objectives_lm_obj->isMaterialAssigned($node_id, $obj_id)) {
continue;
}
$this->objectives_lm_obj->setLMRefId($node_id);
$this->objectives_lm_obj->setLMObjId($obj_id);
$this->objectives_lm_obj->setType($type);
$this->objectives_lm_obj->setType($this->objectDataCache->lookupType($obj_id));
$this->objectives_lm_obj->add();
}
$chapters = [];
if ($this->http->wrapper()->post()->has('chapters')) {
$chapters = $this->http->wrapper()->post()->retrieve(
'chapters',
$this->refinery->kindlyTo()->listOf(
$this->refinery->kindlyTo()->string()
)
);
}
foreach ($chapters as $chapter) {
list($ref_id, $chapter_id) = explode('_', $chapter);

foreach ($visibleChapters as $chapter) {
list($ref_id, $chapter_id) = explode('_', $chapter);
if (!in_array($chapter, $chapters)) {
$this->objectives_lm_obj->deleteMaterial($ref_id, $chapter_id);
continue;
}
if ($this->objectives_lm_obj->isMaterialAssigned($ref_id, $chapter_id)) {
continue;
}
$this->objectives_lm_obj->setLMRefId($ref_id);
$this->objectives_lm_obj->setLMObjId($chapter_id);
$this->objectives_lm_obj->setType(ilLMObject::_lookupType($chapter_id));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<tr class="{CSS_ROW}">
<td class="std">
<input type="checkbox" name="materials[]" value="{VAL_ID}" id="{VAL_ID}" {VAL_CHECKED} />
</td>
<input type="hidden" name="visible_materials[]" value="{VAL_ID}" />
</td>
<td class="std ilCenter">
<label for="{VAL_ID}">
<img class="ilIcon" src="{ROW_TYPE_IMG}" alt="{ROW_TYPE_ALT}" title="{ROW_TYPE_ALT}" />
Expand All @@ -20,7 +21,8 @@
<!-- BEGIN begin_depth --><div class="listIndent"><!-- END begin_depth -->
<li>
<input type="checkbox" name="chapters[]" value="{CHAP_ID}" id="{CHAP_ID}" {CHAP_CHECKED} />
<label for="{CHAP_ID}">
<input type="hidden" name="visible_chapters[]" value="{CHAP_ID}" />
<label for="{CHAP_ID}">
<img src="{CHAP_TYPE_IMG}" class="ilIcon" alt="{CHAP_TYPE_ALT}" title="{CHAP_TYPE_ALT}" />
{CHAPTER_TITLE}
</label>
Expand Down

0 comments on commit c5fe95c

Please sign in to comment.