Skip to content

Commit b7011d4

Browse files
committed
content style: preview table
1 parent 756e0a8 commit b7011d4

8 files changed

Lines changed: 257 additions & 137 deletions

File tree

components/ILIAS/Style/Content/Service/class.InternalDomainService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use ILIAS\Style\Content\Style\StyleManager;
3131
use ILIAS\Style\Content\Images\ImageRetrieval;
3232
use ILIAS\Style\Content\Color\ColorRetrieval;
33+
use ILIAS\Style\Content\Template\TemplateRetrieval;
3334

3435
/**
3536
* @author Alexander Killing <killing@leifos.de>
@@ -114,6 +115,13 @@ public function colorRetrieval(\ilObjStyleSheet $style_obj): ColorRetrieval
114115
return new ColorRetrieval($style_obj);
115116
}
116117

118+
public function templateRetrieval(
119+
\ilObjStyleSheet $style_obj,
120+
string $temp_type
121+
): TemplateRetrieval {
122+
return new TemplateRetrieval($style_obj, $temp_type);
123+
}
124+
117125
public function repositoryContainer(int $ref_id): ContainerManager
118126
{
119127
return new ContainerManager(

components/ILIAS/Style/Content/Service/class.InternalGUIService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class InternalGUIService
3838
protected CharacteristicUIFactory $characteristic;
3939
protected ImageUIFactory $image;
4040
protected ColorUIFactory $color;
41+
protected TemplateUIFactory $template;
4142

4243
public function __construct(
4344
Container $DIC,
@@ -56,6 +57,7 @@ public function __construct(
5657
$this
5758
);
5859
$this->color = new ColorUIFactory($this->domain_service);
60+
$this->template = new TemplateUIFactory($this->domain_service);
5961
}
6062

6163
public function characteristic(
@@ -73,6 +75,11 @@ public function color(
7375
return $this->color;
7476
}
7577

78+
public function template(
79+
): TemplateUIFactory {
80+
return $this->template;
81+
}
82+
7683
public function standardRequest(
7784
?array $passed_query_params = null,
7885
?array $passed_post_data = null
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with
10+
* the source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS\Style\Content\Template;
22+
23+
use ILIAS\Data\Order;
24+
use ILIAS\Data\Range;
25+
use ILIAS\Repository\RetrievalBase;
26+
use ILIAS\Repository\RetrievalInterface;
27+
28+
class TemplateRetrieval implements RetrievalInterface
29+
{
30+
use RetrievalBase;
31+
32+
public function __construct(
33+
protected \ilObjStyleSheet $style_obj,
34+
protected string $temp_type
35+
) {
36+
}
37+
38+
public function getData(
39+
array $visible_column_ids,
40+
?Range $range = null,
41+
?Order $order = null,
42+
array $filter_data = [],
43+
array $additional_parameters = []
44+
): \Generator {
45+
$data = [];
46+
foreach ($this->style_obj->getTemplates($this->temp_type) as $template) {
47+
$data[] = [
48+
"id" => (int) $template["id"],
49+
"name" => (string) $template["name"],
50+
"preview" => (string) ($template["preview"] ?? "")
51+
];
52+
}
53+
54+
$data = $this->applyOrder($data, $order);
55+
yield from $this->applyRange($data, $range);
56+
}
57+
58+
public function count(
59+
array $filter_data = [],
60+
array $additional_parameters = []
61+
): int {
62+
return count($this->style_obj->getTemplates($this->temp_type));
63+
}
64+
65+
public function isFieldNumeric(string $field): bool
66+
{
67+
return $field === "id";
68+
}
69+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with
10+
* the source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS\Style\Content\Template;
22+
23+
use ILIAS\Repository\RetrievalInterface;
24+
use ILIAS\Repository\Table\CommonTableBuilder;
25+
use ILIAS\Repository\Table\TableAdapterGUI;
26+
use ILIAS\Style\Content\Access\StyleAccessManager;
27+
use ILIAS\Style\Content\InternalDomainService;
28+
29+
class TemplateTableBuilder extends CommonTableBuilder
30+
{
31+
public function __construct(
32+
protected InternalDomainService $domain,
33+
protected \ilObjStyleSheet $style_obj,
34+
protected string $temp_type,
35+
protected StyleAccessManager $access_manager,
36+
object $parent_gui,
37+
string $parent_cmd
38+
) {
39+
parent::__construct($parent_gui, $parent_cmd);
40+
}
41+
42+
protected function getId(): string
43+
{
44+
return "style_templates";
45+
}
46+
47+
protected function getTitle(): string
48+
{
49+
return $this->domain->lng()->txt("sty_templates");
50+
}
51+
52+
protected function getRetrieval(): RetrievalInterface
53+
{
54+
return $this->domain->templateRetrieval($this->style_obj, $this->temp_type);
55+
}
56+
57+
protected function transformRow(array $data_row): array
58+
{
59+
$preview = (string) $data_row["preview"];
60+
if ($preview === "") {
61+
$preview = \ilObjStyleSheetGUI::_getTemplatePreview(
62+
$this->style_obj,
63+
$this->temp_type,
64+
(int) $data_row["id"],
65+
true
66+
);
67+
}
68+
69+
return [
70+
"id" => (int) $data_row["id"],
71+
"name" => (string) $data_row["name"],
72+
"preview" => $preview
73+
];
74+
}
75+
76+
protected function build(TableAdapterGUI $table): TableAdapterGUI
77+
{
78+
$lng = $this->domain->lng();
79+
80+
$table = $table
81+
->textColumn("name", $lng->txt("sty_template_name"), true)
82+
->textColumn("preview", $lng->txt("sty_preview"));
83+
84+
if ($this->access_manager->checkWrite()) {
85+
$table = $table
86+
->singleRedirectAction(
87+
"editTemplate",
88+
$lng->txt("edit"),
89+
[get_class($this->parent_gui)],
90+
"editTemplate",
91+
"t_id"
92+
)
93+
->multiAction(
94+
"deleteTemplateConfirmation",
95+
$lng->txt("delete"),
96+
true
97+
);
98+
}
99+
100+
return $table;
101+
}
102+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with
10+
* the source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS\Style\Content;
22+
23+
use ILIAS\Style\Content\Access\StyleAccessManager;
24+
use ILIAS\Style\Content\Template\TemplateTableBuilder;
25+
26+
class TemplateUIFactory
27+
{
28+
public function __construct(
29+
protected InternalDomainService $domain_service
30+
) {
31+
}
32+
33+
public function templateTableBuilder(
34+
\ilObjStyleSheet $style_obj,
35+
string $temp_type,
36+
StyleAccessManager $access_manager,
37+
object $parent_gui,
38+
string $parent_cmd
39+
): TemplateTableBuilder {
40+
return new TemplateTableBuilder(
41+
$this->domain_service,
42+
$style_obj,
43+
$temp_type,
44+
$access_manager,
45+
$parent_gui,
46+
$parent_cmd
47+
);
48+
}
49+
}

components/ILIAS/Style/Content/classes/class.ilObjStyleSheetGUI.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ public function listTemplatesObject(): void
12171217
$this->setTemplatesSubTabs();
12181218
$ilCtrl->setParameter($this, "temp_type", $ctype);
12191219
$ilTabs->setSubTabActive("sty_" . $ctype . "_templates");
1220+
ilAccordionGUI::addCss();
12201221

12211222
// action commands
12221223
if ($this->access_manager->checkWrite()) {
@@ -1235,14 +1236,23 @@ public function listTemplatesObject(): void
12351236

12361237

12371238
$this->includeCSS();
1238-
$table_gui = new ilTableTemplatesTableGUI(
1239-
$ctype,
1240-
$this,
1241-
"listTemplates",
1239+
$table = $this->getTemplateTable($ctype);
1240+
if ($table->handleCommand()) {
1241+
return;
1242+
}
1243+
$tpl->setContent($table->render());
1244+
}
1245+
1246+
protected function getTemplateTable(
1247+
string $temp_type
1248+
): \ILIAS\Repository\Table\TableAdapterGUI {
1249+
return $this->gui_service->template()->templateTableBuilder(
12421250
$this->getStyleSheet(),
1243-
$this->access_manager
1244-
);
1245-
$tpl->setContent($table_gui->getHTML());
1251+
$temp_type,
1252+
$this->access_manager,
1253+
$this,
1254+
"listTemplates"
1255+
)->getTable();
12461256
}
12471257

12481258
public function addTemplateObject(): void
@@ -1583,12 +1593,16 @@ public function getTemplateFormValues(): void
15831593
* Delete table template confirmation
15841594
*/
15851595
public function deleteTemplateConfirmationObject(): void
1596+
{
1597+
$this->deleteTemplateConfirmation($this->style_request->getTemplateIds());
1598+
}
1599+
1600+
public function deleteTemplateConfirmation(array $tids): void
15861601
{
15871602
$ilCtrl = $this->ctrl;
15881603
$tpl = $this->gui_service->ui()->mainTemplate();
15891604
$lng = $this->lng;
15901605

1591-
$tids = $this->style_request->getTemplateIds();
15921606
if (count($tids) == 0) {
15931607
$this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
15941608
$ilCtrl->redirect($this, "listTemplates");

0 commit comments

Comments
 (0)