Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions components/ILIAS/Container/Content/class.ilContainerContentGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,34 +809,24 @@ public function renderItemGroup(array $a_itgr): void
$a_itgr["title"],
$a_itgr["description"]
);
$commands_html = $item_list_gui->getCommandsHTML($a_itgr["title"], false);

// determine behaviour
$item_group = new ilObjItemGroup($a_itgr["ref_id"]);
$beh = $item_group->getBehaviour();
$stored_val = $this->block_repo->getProperty(
"itgr_" . $a_itgr["ref_id"],
$ilUser->getId(),
"opened"
);
if ($stored_val !== "" && $beh !== ilItemGroupBehaviour::ALWAYS_OPEN) {
$beh = ($stored_val === "1")
? ilItemGroupBehaviour::EXPANDABLE_OPEN
: ilItemGroupBehaviour::EXPANDABLE_CLOSED;
}
$item_group = new ilObjItemGroup($a_itgr['ref_id']);
$opened = $this->block_repo->getProperty("itgr_{$a_itgr['ref_id']}", $ilUser->getId(), 'opened');

$data = [
"behaviour" => $beh,
"store-url" => "./ilias.php?baseClass=ilcontainerblockpropertiesstoragegui&cmd=store" .
"&cont_block_id=itgr_" . $a_itgr['ref_id']
];
if (ilObjItemGroup::lookupHideTitle($a_itgr["obj_id"]) &&
!$this->getContainerGUI()->isActiveAdministrationPanel()) {
$this->renderer->addCustomBlock($a_itgr["ref_id"], "", $commands_html, $data);
} else {
$this->renderer->addCustomBlock($a_itgr["ref_id"], $a_itgr["title"], $commands_html, $data);
}
$this->ctrl->setParameterByClass(ilContainerBlockPropertiesStorageGUI::class, 'cont_block_id', "itgr_{$a_itgr['ref_id']}");
$store_url = $this->ctrl->getLinkTargetByClass(ilContainerBlockPropertiesStorageGUI::class, 'store');
$this->ctrl->clearParameterByClass(ilContainerBlockPropertiesStorageGUI::class, 'cont_block_id');

$this->renderer->addCustomBlock(
$a_itgr["ref_id"],
$item_group->getShowTitle() || $this->container_gui->isActiveAdministrationPanel() ? $a_itgr['title'] : '',
$item_list_gui->getCommandsHTML($a_itgr['title'], false),
[
'behaviour' => $item_group->getBehaviour(in_array($opened, ['0', '1'], true) ? (bool) $opened : null),
'store-url' => "./{$store_url}"
]
);

// render item group sub items

Expand Down
39 changes: 15 additions & 24 deletions components/ILIAS/Container/Content/class.ilContainerRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,33 +1184,24 @@ protected function addItemGroupBlock(string $block_id, int $block_pos = 0): void
$item_data["title"],
$item_data["description"]
);
$commands_html = $item_list_gui->getCommandsHTML();

// determine behaviour
$item_group = new ilObjItemGroup($item_data["ref_id"]);
$beh = $item_group->getBehaviour();
$stored_val = $this->block_repo->getProperty(
"itgr_" . $item_data["ref_id"],
$this->user->getId(),
"opened"
$item_group = new ilObjItemGroup($item_data['ref_id']);
$opened = $this->block_repo->getProperty("itgr_{$item_data['ref_id']}", $this->user->getId(), 'opened');

$this->ctrl->setParameterByClass(ilContainerBlockPropertiesStorageGUI::class, 'cont_block_id', "itgr_{$item_data['ref_id']}");
$store_url = $this->ctrl->getLinkTargetByClass(ilContainerBlockPropertiesStorageGUI::class, 'store');
$this->ctrl->clearParameterByClass(ilContainerBlockPropertiesStorageGUI::class, 'cont_block_id');

$this->addCustomBlock(
$block_id,
$item_group->getShowTitle() || $this->container_gui->isActiveAdministrationPanel() ? $item_data['title'] : '',
$item_list_gui->getCommandsHTML(),
[
'behaviour' => $item_group->getBehaviour(in_array($opened, ['0', '1'], true) ? (bool) $opened : null),
'store-url' => "./{$store_url}"
]
);
if ($stored_val !== "" && $beh !== ilItemGroupBehaviour::ALWAYS_OPEN) {
$beh = ($stored_val === "1")
? ilItemGroupBehaviour::EXPANDABLE_OPEN
: ilItemGroupBehaviour::EXPANDABLE_CLOSED;
}

$data = [
"behaviour" => $beh,
"store-url" => "./ilias.php?baseClass=ilcontainerblockpropertiesstoragegui&cmd=store" .
"&cont_block_id=itgr_" . $item_data['ref_id']
];
if (ilObjItemGroup::lookupHideTitle($item_data["obj_id"]) &&
!$this->container_gui->isActiveAdministrationPanel()) {
$this->addCustomBlock($block_id, "", $commands_html, $data);
} else {
$this->addCustomBlock($block_id, $item_data["title"], $commands_html, $data);
}
}

protected function getBlockPrefix($block_id): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

namespace ILIAS\ItemGroup\Setup;

use ilDBConstants;
use ilItemGroupAR;

/**
* @author Alexander Killing <killing@leifos.de>
*/
Expand Down Expand Up @@ -51,4 +54,25 @@ public function step_2()
));
}
}

public function step_3(): void
{
if (!$this->db->tableColumnExists('itgr_data', 'display')) {
$this->db->addTableColumn('itgr_data', 'display', [
'type' => ilDBConstants::T_TEXT,
'notnull' => true,
'default' => ilItemGroupAR::DISPLAY_WITH_TITLE,
'length' => 255
]);
}

if (!$this->db->tableColumnExists('itgr_data', 'toggleable_initially')) {
$this->db->addTableColumn('itgr_data', 'toggleable_initially', [
'type' => ilDBConstants::T_TEXT,
'notnull' => true,
'default' => ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_OPEN,
'length' => 255
]);
}
}
}
42 changes: 25 additions & 17 deletions components/ILIAS/ItemGroup/classes/class.ilItemGroupAR.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
*/
class ilItemGroupAR extends ActiveRecord
{
public const DISPLAY = 'display';
public const DISPLAY_WITHOUT_TITLE = 'without_title';
public const DISPLAY_WITH_TITLE = 'with_title';
public const DISPLAY_WITH_TITLE_AND_TOGGLEABLE = 'with_title_and_toggleable';
public const DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY = self::DISPLAY_WITH_TITLE_AND_TOGGLEABLE . '_initially';
public const DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_CLOSED = self::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY . '_closed';
public const DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_OPEN = self::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY . '_open';

public static function returnDbTableName(): string
{
return 'itgr_data';
Expand All @@ -45,21 +53,21 @@ public static function returnDbTableName(): string
* @var string
*
* @con_has_field true
* @con_fieldtype integer
* @con_length 1
* @con_is_notnull false
* @con_fieldtype text
* @con_length 255
* @con_is_notnull yes
*/
protected ?string $hide_title = '';
protected string $display = self::DISPLAY_WITH_TITLE;

/**
* @var int
* @var string
*
* @con_has_field true
* @con_fieldtype integer
* @con_length 1
* @con_is_notnull false
* @con_fieldtype text
* @con_length 255
* @con_is_notnull yes
*/
protected ?int $behaviour = 0;
protected string $toggleable_initially = self::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_OPEN;

/**
* @var string
Expand Down Expand Up @@ -91,24 +99,24 @@ public function setId(int $id): void
$this->id = $id;
}

public function setHideTitle(bool $a_hide_title): void
public function getDisplay(): string
{
$this->hide_title = $a_hide_title;
return $this->display;
}

public function getHideTitle(): bool
public function setDisplay(string $a_val): void
{
return $this->hide_title;
$this->display = $a_val;
}

public function setBehaviour(int $a_val): void
public function getDisplayWithTitleAndToggleableInitially(): string
{
$this->behaviour = $a_val;
return $this->toggleable_initially;
}

public function getBehaviour(): int
public function setDisplayWithTitleAndToggleableInitially(string $a_val): void
{
return $this->behaviour;
$this->toggleable_initially = $a_val;
}

public function getListPresentation(): string
Expand Down
12 changes: 10 additions & 2 deletions components/ILIAS/ItemGroup/classes/class.ilItemGroupDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,16 @@ public function importRecord(

$newObj->setTitle($a_rec["Title"]);
$newObj->setDescription($a_rec["Description"]);
$newObj->setBehaviour($a_rec["Behaviour"]);
$newObj->setHideTitle($a_rec["HideTitle"]);
$newObj->setDisplay(
$a_rec["HideTitle"] === "1"
? ilItemGroupAR::DISPLAY_WITHOUT_TITLE
: ilItemGroupAR::DISPLAY_WITH_TITLE
);
$newObj->setDisplayWithTitleAndToggleableInitially(
$a_rec["Behaviour"] === "1"
? ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_OPEN
: ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_CLOSED
);
$newObj->update();
$this->current_obj = $newObj;
$a_mapping->addMapping("components/ILIAS/ItemGroup", "itgr", $a_rec["Id"], $newObj->getId());
Expand Down
71 changes: 34 additions & 37 deletions components/ILIAS/ItemGroup/classes/class.ilObjItemGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,24 @@ public function initType(): void
$this->type = "itgr";
}

public function setHideTitle(bool $a_val): void
public function getDisplay(): string
{
$this->item_data_ar->setHideTitle($a_val);
return $this->item_data_ar->getDisplay();
}

public function getHideTitle(): bool
public function setDisplay(string $a_val): void
{
return $this->item_data_ar->getHideTitle();
$this->item_data_ar->setDisplay($a_val);
}

/**
* Set behaviour (see ilItemGroupBehaviour)
*/
public function setBehaviour(int $a_val): void
public function getDisplayWithTitleAndToggleableInitially(): string
{
$this->item_data_ar->setBehaviour($a_val);
return $this->item_data_ar->getDisplayWithTitleAndToggleableInitially();
}

public function setDisplayWithTitleAndToggleableInitially(string $a_val): void
{
$this->item_data_ar->setDisplayWithTitleAndToggleableInitially($a_val);
}

public function getListPresentation(): string
Expand All @@ -98,16 +100,35 @@ public function setTileSize(int $a_val): void
$this->item_data_ar->setTileSize($a_val);
}

public function getBehaviour(): int
public function getBehaviour(?bool $stored_value = null): int
{
return $this->item_data_ar->getBehaviour();
if ($this->getDisplay() !== ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE) {
return ilItemGroupBehaviour::ALWAYS_OPEN;
}

if (is_bool($stored_value)) {
return $stored_value ? ilItemGroupBehaviour::EXPANDABLE_OPEN : ilItemGroupBehaviour::EXPANDABLE_CLOSED;
}

return $this->getDisplayWithTitleAndToggleableInitially() === ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_OPEN
? ilItemGroupBehaviour::EXPANDABLE_OPEN
: ilItemGroupBehaviour::EXPANDABLE_CLOSED;
}

protected function doRead(): void
{
$this->item_data_ar = new ilItemGroupAR($this->getId());
}

public function getShowTitle(): bool
{
return in_array(
$this->getDisplay(),
[ilItemGroupAR::DISPLAY_WITH_TITLE, ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE],
true
);
}

protected function doCreate(bool $clone_mode = false): void
{
global $DIC;
Expand Down Expand Up @@ -154,8 +175,8 @@ protected function doDelete(): void
protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
{
assert($new_obj instanceof ilObjItemGroup);
$new_obj->setHideTitle($this->getHideTitle());
$new_obj->setBehaviour($this->getBehaviour());
$new_obj->setDisplay($this->getDisplay());
$new_obj->setDisplayWithTitleAndToggleableInitially($this->getDisplayWithTitleAndToggleableInitially());
$new_obj->setListPresentation($this->getListPresentation());
$new_obj->setTileSize($this->getTileSize());

Expand Down Expand Up @@ -212,28 +233,4 @@ public static function fixContainerItemGroupRefsAfterCloning(
}
$ilLog->write(__METHOD__ . ': 5');
}

public static function lookupHideTitle(int $a_id): bool
{
return (bool) self::lookup($a_id, "hide_title");
}

public static function lookupBehaviour(int $a_id): int
{
return (int) self::lookup($a_id, "behaviour");
}

protected static function lookup(int $a_id, string $a_key): string
{
global $DIC;

$ilDB = $DIC->database();

$set = $ilDB->query(
"SELECT " . $a_key . " FROM itgr_data " .
" WHERE id = " . $ilDB->quote($a_id, "integer")
);
$rec = $ilDB->fetchAssoc($set);
return $rec[$a_key];
}
}
Loading
Loading