ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.CharacteristicCopyPasteSessionRepo.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Style\Content;
22
23use ilSession;
24use stdClass;
25
30{
31 protected const SESSION_KEY = "sty_copy";
32
33 protected Session $session;
34
35 public function __construct(?Session $session = null)
36 {
37 $this->session = ($session)
38 ?: new class () implements Session {
39 public function set(string $key, string $value): void
40 {
41 ilSession::set($key, $value);
42 }
43
44 public function get(string $key): string
45 {
46 return (string) ilSession::get($key);
47 }
48
49 public function clear(string $key): void
50 {
51 ilSession::clear($key);
52 }
53 };
54 }
55
59 public function set(int $style_id, string $style_type, array $characteristics): void
60 {
61 $style_cp = implode("::", $characteristics);
62 $style_cp = $style_id . ":::" . $style_type . ":::" . $style_cp;
63 $this->session->set(self::SESSION_KEY, $style_cp);
64 }
65
66 public function getData(): stdClass
67 {
68 $st_c = explode(":::", $this->getValue());
69 $data = new stdClass();
70 $data->style_id = $st_c[0] ?? 0;
71 $data->style_type = $st_c[1] ?? "";
72 $data->characteristics = explode("::", $st_c[2] ?? "");
73 return $data;
74 }
75
76 protected function getValue(): string
77 {
78 return $this->session->get(self::SESSION_KEY);
79 }
80
81 public function hasEntries(string $style_type): bool
82 {
83 $val = $this->getValue();
84 if ($val != "") {
85 $style_cp = explode(":::", $val);
86 if ($style_cp[1] == $style_type) {
87 return true;
88 }
89 }
90 return false;
91 }
92
93 public function clear(): void
94 {
95 $this->session->clear(self::SESSION_KEY);
96 }
97}
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
Wrapper interface for session.