Skip to content

Commit 3a7383d

Browse files
committed
content style: color table
1 parent 8044002 commit 3a7383d

8 files changed

Lines changed: 272 additions & 146 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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\Color;
22+
23+
use ILIAS\Data\Order;
24+
use ILIAS\Data\Range;
25+
use ILIAS\Repository\RetrievalBase;
26+
use ILIAS\Repository\RetrievalInterface;
27+
28+
class ColorRetrieval implements RetrievalInterface
29+
{
30+
use RetrievalBase;
31+
32+
public function __construct(
33+
protected \ilObjStyleSheet $style_obj
34+
) {
35+
}
36+
37+
public function getData(
38+
array $visible_column_ids,
39+
?Range $range = null,
40+
?Order $order = null,
41+
array $filter_data = [],
42+
array $additional_parameters = []
43+
): \Generator {
44+
$data = [];
45+
foreach ($this->style_obj->getColors() as $color) {
46+
$data[] = [
47+
"id" => $color["name"],
48+
"name" => $color["name"],
49+
"code" => $color["code"]
50+
];
51+
}
52+
53+
$data = $this->applyOrder($data, $order);
54+
yield from $this->applyRange($data, $range);
55+
}
56+
57+
public function count(
58+
array $filter_data = [],
59+
array $additional_parameters = []
60+
): int {
61+
return count($this->style_obj->getColors());
62+
}
63+
64+
public function isFieldNumeric(string $field): bool
65+
{
66+
return false;
67+
}
68+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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\Color;
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 ColorTableBuilder extends CommonTableBuilder
30+
{
31+
public function __construct(
32+
protected InternalDomainService $domain,
33+
protected \ilObjStyleSheet $style_obj,
34+
protected StyleAccessManager $access_manager,
35+
object $parent_gui,
36+
string $parent_cmd
37+
) {
38+
parent::__construct($parent_gui, $parent_cmd, false);
39+
}
40+
41+
protected function getId(): string
42+
{
43+
return "style_colors";
44+
}
45+
46+
protected function getTitle(): string
47+
{
48+
return $this->domain->lng()->txt("sty_colors");
49+
}
50+
51+
protected function getRetrieval(): RetrievalInterface
52+
{
53+
return $this->domain->colorRetrieval($this->style_obj);
54+
}
55+
56+
protected function transformRow(array $data_row): array
57+
{
58+
$code = (string) $data_row["code"];
59+
if (!preg_match("/^[a-fA-F0-9]{6}$/D", $code)) {
60+
$code = "000000";
61+
}
62+
63+
$name = htmlspecialchars(
64+
(string) $data_row["name"],
65+
ENT_QUOTES | ENT_SUBSTITUTE,
66+
"UTF-8"
67+
);
68+
$color = "<div style=\"width:30px; height:30px; background-color:#$code;\">&nbsp;</div>";
69+
$flavors = [];
70+
for ($i = -80; $i <= 80; $i += 20) {
71+
$flavor_code = \ilObjStyleSheet::_getColorFlavor($code, $i);
72+
$flavors[] = "<td width=\"11%\">" .
73+
"<div style=\"width:20px; height:20px; background-color:#$flavor_code;\">&nbsp;</div>" .
74+
"<div class=\"small\">($i)</div>" .
75+
"</td>";
76+
}
77+
78+
return [
79+
"id" => $data_row["id"],
80+
"name" => $name,
81+
"code" => "#$code",
82+
"color" => $color,
83+
"flavors" => "<table width=\"100%\"><tr>" . implode("", $flavors) . "</tr></table>"
84+
];
85+
}
86+
87+
protected function build(TableAdapterGUI $table): TableAdapterGUI
88+
{
89+
$lng = $this->domain->lng();
90+
91+
$table = $table
92+
->textColumn("name", $lng->txt("sty_color_name"), true)
93+
->textColumn("code", $lng->txt("sty_color_code"))
94+
->textColumn("color", $lng->txt("sty_color"))
95+
->textColumn("flavors", $lng->txt("sty_color_flavors"));
96+
97+
if ($this->access_manager->checkWrite()) {
98+
$table = $table
99+
->singleRedirectAction(
100+
"editColor",
101+
$lng->txt("edit"),
102+
[get_class($this->parent_gui)],
103+
"editColor",
104+
"c_name"
105+
)
106+
->multiAction("confirmDeleteColors", $lng->txt("delete"), true);
107+
}
108+
109+
return $table;
110+
}
111+
}

components/ILIAS/Style/Content/Color/class.ilStyleColorTableGUI.php

Lines changed: 0 additions & 110 deletions
This file was deleted.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use ILIAS\Style\Content\Style\CSSBuilder;
3030
use ILIAS\Style\Content\Style\StyleManager;
3131
use ILIAS\Style\Content\Images\ImageRetrieval;
32+
use ILIAS\Style\Content\Color\ColorRetrieval;
3233

3334
/**
3435
* @author Alexander Killing <killing@leifos.de>
@@ -108,6 +109,11 @@ public function imageRetrieval(ImageManager $image_manager): ImageRetrieval
108109
return new ImageRetrieval($image_manager);
109110
}
110111

112+
public function colorRetrieval(\ilObjStyleSheet $style_obj): ColorRetrieval
113+
{
114+
return new ColorRetrieval($style_obj);
115+
}
116+
111117
public function repositoryContainer(int $ref_id): ContainerManager
112118
{
113119
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
@@ -37,6 +37,7 @@ class InternalGUIService
3737

3838
protected CharacteristicUIFactory $characteristic;
3939
protected ImageUIFactory $image;
40+
protected ColorUIFactory $color;
4041

4142
public function __construct(
4243
Container $DIC,
@@ -54,6 +55,7 @@ public function __construct(
5455
$this->domain_service,
5556
$this
5657
);
58+
$this->color = new ColorUIFactory($this->domain_service);
5759
}
5860

5961
public function characteristic(
@@ -66,6 +68,11 @@ public function image(
6668
return $this->image;
6769
}
6870

71+
public function color(
72+
): ColorUIFactory {
73+
return $this->color;
74+
}
75+
6976
public function standardRequest(
7077
?array $passed_query_params = null,
7178
?array $passed_post_data = null
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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\Color\ColorTableBuilder;
25+
26+
class ColorUIFactory
27+
{
28+
public function __construct(
29+
protected InternalDomainService $domain_service
30+
) {
31+
}
32+
33+
public function colorTableBuilder(
34+
\ilObjStyleSheet $style_obj,
35+
StyleAccessManager $access_manager,
36+
object $parent_gui,
37+
string $parent_cmd
38+
): ColorTableBuilder {
39+
return new ColorTableBuilder(
40+
$this->domain_service,
41+
$style_obj,
42+
$access_manager,
43+
$parent_gui,
44+
$parent_cmd
45+
);
46+
}
47+
}

0 commit comments

Comments
 (0)