19 declare(strict_types=1);
48 $this->
logger = $DIC->logger()->otpl();
49 $this->type = $a_type;
50 $this->objDefinition = $DIC[
'objDefinition'];
56 $this->xmlfile = $a_file;
75 $use_internal_errors = libxml_use_internal_errors(
true);
77 case self::IMPORT_FILE:
78 $root = simplexml_load_string(file_get_contents($this->
getInputFile()));
81 libxml_use_internal_errors($use_internal_errors);
82 if (!$root instanceof SimpleXMLElement) {
88 $this->
parseActions($settings, $root->didacticTemplate->actions);
94 $status =
new ilImportStatusFactory();
96 return $status->collection()->withAddedStatus($status->handler()
98 ->withContent($status->content()->builder()->string()
99 ->withString(
"Invalid import status, import status 'IMPORT_FILE' expected.")));
102 $import =
new ilImportHandlerFactory();
104 $xsd_spl_info = $schema->getLatest(self::SCHEMA_TYPE);
105 $xml_file_handler = $import->file()->xml()->withFileInfo($xml_spl_info);
106 $xsd_file_handler = $import->file()->xsd()->withFileInfo($xsd_spl_info);
107 return $import->file()->validation()->handler()->validateXMLFile($xml_file_handler, $xsd_file_handler);
117 foreach ($root->didacticTemplate as $tpl) {
118 switch ((
string) $tpl->attributes()->type) {
124 $setting->setTitle(trim((
string) $tpl->title));
125 $setting->setDescription(trim((
string) $tpl->description));
127 $icon = (string) $tpl->icon;
130 foreach ((array) $tpl->info->p as $paragraph) {
134 $info .= trim((
string) $paragraph);
136 $setting->setInfo($info);
138 if (isset($tpl->effectiveFrom) && (
string) $tpl->effectiveFrom[
"nic_id"] == $this->settings->get(
'inst_id')) {
140 foreach ($tpl->effectiveFrom->node as $element) {
141 $node[] = (
int) $element;
144 $setting->setEffectiveFrom($node);
147 if (isset($tpl->exclusive)) {
148 $setting->setExclusive(
true);
151 foreach ($tpl->assignments->assignment as $element) {
152 $setting->addAssignment(trim((
string) $element));
157 if ($icon !==
'' && $this->
canUseIcons($setting)) {
158 $setting->getIconHandler()->writeSvg($icon);
161 if (isset($root->didacticTemplate->translations)) {
162 $trans->fromXML($root->didacticTemplate->translations);
172 if (!$this->objDefinition->isContainer($assignment)) {
182 SimpleXMLElement $local_role_action
185 $act->setTemplateId($didactic_template_setting->
getId());
187 foreach ($local_role_action->roleTemplate as $tpl) {
189 foreach ($tpl->role as $roleDef) {
191 $role_id = $rimporter->importSimpleXml($roleDef);
192 $act->setRoleTemplateId($role_id);
200 SimpleXMLElement $block_role_action
203 $act->setTemplateId($didactic_template_setting->
getId());
205 foreach ($block_role_action->roleFilter as $rfi) {
206 switch ((
string) $rfi->attributes()->source) {
218 foreach ($rfi->includePattern as $pat) {
222 $pattern->setPattern((
string) $pat->attributes()->preg);
223 $act->addFilterPattern($pattern);
225 foreach ($rfi->excludePattern as $pat) {
229 $pattern->setPattern((
string) $pat->attributes()->preg);
230 $act->addFilterPattern($pattern);
238 SimpleXMLElement $local_policy_action
241 $act->setTemplateId($didactic_template_setting->
getId());
243 foreach ($local_policy_action->roleFilter as $rfi) {
246 'Current filter source: ' . $rfi->attributes()->source
248 switch ((
string) $rfi->attributes()->source) {
262 foreach ($rfi->includePattern as $pat) {
266 $pattern->setPattern((
string) $pat->attributes()->preg);
267 $act->addFilterPattern($pattern);
269 foreach ($rfi->excludePattern as $pat) {
273 $pattern->setPattern((
string) $pat->attributes()->preg);
274 $act->addFilterPattern($pattern);
278 foreach ($local_policy_action->localPolicyTemplate as $lpo) {
279 switch ((
string) $lpo->attributes()->type) {
291 foreach ($lpo->role as $roleDef) {
294 $role_id = $rimporter->importSimpleXml($roleDef);
295 $act->setRoleTemplateId($role_id);
298 $didactic_template_setting->
delete();
312 if ($actions === null) {
315 foreach ($actions->children() as $action) {
316 if ($action->getName() === self::XML_ELEMENT_NAME_LOCAL_ROLE_ACTION) {
320 if ($action->getName() === self::XML_ELEMENT_NAME_BLOCK_ROLE_ACIONE) {
324 if ($action->getName() === self::XML_ELEMENT_NAME_LOCAL_POLICY_ACTION) {
337 foreach (libxml_get_errors() as $err) {
338 $errors .= $err->code .
'<br/>';
const FILTER_PARENT_ROLES
const XML_ELEMENT_NAME_BLOCK_ROLE_ACIONE
static getInstance(int $a_obj_id, string $a_type)
Description of ilDidacticTemplateBlockRoleAction.
const TPL_ACTION_INTERSECT
const TPL_ACTION_OVERWRITE
const XML_ELEMENT_NAME_LOCAL_ROLE_ACTION
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parseXmlErrors()
Parse xml errors from libxml_get_errors.
setInputFile(string $a_file)
parseBlockRoleAction(ilDidacticTemplateSetting $didactic_template_setting, SimpleXMLElement $block_role_action)
parses the objects.xml it handles the xml-description of all ilias objects
parseSettings(SimpleXMLElement $root)
Parse settings.
parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions=null)
Parse template action from xml.
const FILTER_SOURCE_OBJ_ID
Implementation of an include filter pattern for didactic template actions.
Description of ilDidacticTemplateImportException.
Description of ilDidacticTemplateImport.
parseLocalRoleAction(ilDidacticTemplateSetting $didactic_template_setting, SimpleXMLElement $local_role_action)
ilObjectDefinition $objDefinition
const XML_ELEMENT_NAME_LOCAL_POLICY_ACTION
represents a creation of local roles action
const PATTERN_SUBTYPE_REGEX
parseLocalPolicyAction(ilDidacticTemplateSetting $didactic_template_setting, SimpleXMLElement $local_policy_action)
const FILTER_SOURCE_TITLE
canUseIcons(ilDidacticTemplateSetting $setting)
Implementation of an include filter pattern for didactic template actions.