ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExportOptions.php
Go to the documentation of this file.
1<?php
25{
26 private static ?ilExportOptions $instance = null;
27
28 public const EXPORT_EXISTING = 1;
29 public const EXPORT_BUILD = 2;
30 public const EXPORT_OMIT = 3;
31
32 public const KEY_INIT = 1;
33 public const KEY_ITEM_MODE = 2;
34 public const KEY_ROOT = 3;
35
36 private int $export_id = 0;
37 private array $ref_options = array();
38 private array $obj_options = array();
39 private array $options = array();
40
41 protected ilDBInterface $db;
42
43 private function __construct(int $a_export_id)
44 {
45 global $DIC;
46
47 $this->db = $DIC->database();
48 $this->export_id = $a_export_id;
49 if ($this->export_id) {
50 $this->read();
51 }
52 }
53
54 public static function getInstance(): ?ilExportOptions
55 {
56 if (self::$instance) {
57 return self::$instance;
58 }
59 return null;
60 }
61
62 public static function newInstance(int $a_export_id): ilExportOptions
63 {
64 return self::$instance = new ilExportOptions($a_export_id);
65 }
66
67 public static function allocateExportId(): int
68 {
69 global $DIC;
70
71 $ilDB = $DIC->database();
72
73 // get last export id
74 $query = 'SELECT MAX(export_id) exp FROM export_options ' .
75 'GROUP BY export_id ';
76 $res = $ilDB->query($query);
77 $exp_id = 1;
78 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
79 $exp_id = $row->exp + 1;
80 }
81 $query = 'INSERT INTO export_options (export_id,keyword,ref_id,obj_id,value) ' .
82 'VALUES( ' .
83 $ilDB->quote($exp_id, 'integer') . ', ' .
84 $ilDB->quote(self::KEY_INIT, 'integer') . ', ' .
85 $ilDB->quote(0, 'integer') . ', ' .
86 $ilDB->quote(0, 'integer') . ', ' .
87 $ilDB->quote(0, 'integer') . ' ' .
88 ')';
89 $ilDB->manipulate($query);
90 return (int) $exp_id;
91 }
92
96 public function getSubitemsForCreation(int $a_source_id): array
97 {
98 $refs = array();
99 foreach ((array) $this->ref_options[self::KEY_ITEM_MODE] as $ref_id => $mode) {
100 if ($mode == self::EXPORT_BUILD) {
101 $refs[] = $ref_id;
102 }
103 }
104 return $refs;
105 }
106
111 public function getSubitemsForExport()
112 {
113 $refs = array();
114 foreach ((array) $this->ref_options[self::KEY_ITEM_MODE] as $ref_id => $mode) {
115 if ($mode != self::EXPORT_OMIT) {
116 $refs[] = (int) $ref_id;
117 }
118 }
119 return $refs;
120 }
121
122 public function getExportId(): int
123 {
124 return $this->export_id;
125 }
126
133 public function addOption(int $a_keyword, int $a_ref_id, int $a_obj_id, $a_value): void
134 {
135 $query = "SELECT MAX(pos) position FROM export_options";
136 $res = $this->db->query($query);
137
138 $pos = 0;
139 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
140 $pos = (int) $row->position;
141 }
142 $pos++;
143
144 $query = 'INSERT INTO export_options (export_id,keyword,ref_id,obj_id,value,pos) ' .
145 'VALUES( ' .
146 $this->db->quote($this->getExportId(), ilDBConstants::T_INTEGER) . ', ' .
147 $this->db->quote($a_keyword, ilDBConstants::T_INTEGER) . ', ' .
148 $this->db->quote($a_ref_id, ilDBConstants::T_INTEGER) . ', ' .
149 $this->db->quote($a_obj_id, ilDBConstants::T_INTEGER) . ', ' .
150 $this->db->quote($a_value, ilDBConstants::T_INTEGER) . ', ' .
151 $this->db->quote($pos, ilDBConstants::T_INTEGER) . ' ' .
152 ')';
153 $this->db->manipulate($query);
154 }
155
156 public function addOptions(
157 int $parent_ref_id,
158 ilObjectDefinition $object_definition,
159 ilAccessHandler $il_access,
160 array $child_nodes,
161 array $cp_options
162 ): bool {
163 global $DIC;
164 $items_selected = false;
165 foreach ($child_nodes as $node) {
166 if ($node['type'] === 'rolf') {
167 continue;
168 }
169 if ((int) $node['ref_id'] === $parent_ref_id) {
170 $this->addOption(
172 (int) $node['ref_id'],
173 (int) $node['obj_id'],
175 );
176 continue;
177 }
178 // no export available or no access
179 if (!$object_definition->allowExport($node['type']) || !$il_access->checkAccess(
180 'write',
181 '',
182 (int) $node['ref_id']
183 )) {
184 $this->addOption(
186 (int) $node['ref_id'],
187 (int) $node['obj_id'],
189 );
190 continue;
191 }
192
193 $mode = $cp_options[$node['ref_id']]['type'] ?? ilExportOptions::EXPORT_OMIT;
194 $this->addOption(
196 (int) $node['ref_id'],
197 (int) $node['obj_id'],
198 $mode
199 );
200 if ($mode != ilExportOptions::EXPORT_OMIT) {
201 $items_selected = true;
202 }
203 }
204 return $items_selected;
205 }
206
211 public function getOption(int $a_keyword)
212 {
213 return $this->options[$a_keyword] ?? null;
214 }
215
222 public function getOptionByObjId(int $a_obj_id, int $a_keyword)
223 {
224 return $this->obj_options[$a_keyword][$a_obj_id] ?? null;
225 }
226
233 public function getOptionByRefId(int $a_ref_id, int $a_keyword)
234 {
235 return $this->ref_options[$a_keyword][$a_ref_id] ?? null;
236 }
237
238 public function delete(): void
239 {
240 $query = "DELETE FROM export_options " .
241 "WHERE export_id = " . $this->db->quote($this->getExportId(), ilDBConstants::T_INTEGER);
242 $this->db->manipulate($query);
243 }
244
245 public function read(): void
246 {
247 $this->options = array();
248 $this->obj_options = array();
249 $this->ref_options = array();
250
251 $query = "SELECT * FROM export_options " .
252 "WHERE export_id = " . $this->db->quote($this->getExportId(), ilDBConstants::T_INTEGER) . ' ' .
253 "ORDER BY pos";
254 $res = $this->db->query($query);
255 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
256 if ($row->ref_id) {
257 $this->ref_options[(int) $row->keyword][(int) $row->ref_id] = $row->value;
258 }
259 if ($row->obj_id) {
260 $this->obj_options[(int) $row->keyword][(int) $row->obj_id] = $row->value;
261 }
262 if (!$row->ref_id and !$row->obj_id) {
263 $this->options[(int) $row->keyword] = $row->value;
264 }
265 }
266 }
267}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getOptionByRefId(int $a_ref_id, int $a_keyword)
Get option by.
getSubitemsForCreation(int $a_source_id)
Get all subitems with mode ilExportOptions::EXPORT_BUILD
addOptions(int $parent_ref_id, ilObjectDefinition $object_definition, ilAccessHandler $il_access, array $child_nodes, array $cp_options)
__construct(int $a_export_id)
static newInstance(int $a_export_id)
getSubitemsForExport()
Get all subitems with mode != self::EXPORT_OMIT.
getOption(int $a_keyword)
getOptionByObjId(int $a_obj_id, int $a_keyword)
Get option by.
static ilExportOptions $instance
addOption(int $a_keyword, int $a_ref_id, int $a_obj_id, $a_value)
parses the objects.xml it handles the xml-description of all ilias objects
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
Interface ilDBInterface.
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance)
$ref_id
Definition: ltiauth.php:66
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26