ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilWebResourceImporter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
27 
28  protected ilLogger $logger;
29 
30  public function __construct()
31  {
32  global $DIC;
33 
35  $this->logger = $DIC->logger()->webr();
36  }
37 
41  public function importXmlRepresentation(
42  string $a_entity,
43  string $a_id,
44  string $a_xml,
45  ilImportMapping $a_mapping
46  ): void {
47  if ($new_id = $a_mapping->getMapping(
48  'components/ILIAS/Container',
49  'objs',
50  $a_id
51  )) {
52  $this->link = ilObjectFactory::getInstanceByObjId((int) $new_id, false);
53  if (!$this->link instanceof ilObjLinkResource) {
54  throw new ilObjectNotFoundException(
55  'Invalid id given ' . $a_id
56  );
57  }
58  } else {
59  $this->link = new ilObjLinkResource();
60  $this->link->setType('webr');
61  $this->link->create();
62  }
63 
64  try {
65  $parser = new ilWebLinkXmlParser($this->link, $a_xml);
66  $parser->setMode(ilWebLinkXmlParser::MODE_CREATE);
67  $parser->start();
68  $a_mapping->addMapping(
69  'components/ILIAS/WebResource',
70  'webr',
71  $a_id,
72  (string) $this->link->getId()
73  );
74 
75  $a_mapping->addMapping(
76  'components/ILIAS/MetaData',
77  'md',
78  $a_id . ':0:webr',
79  $this->link->getId() . ':0:webr'
80  );
81  } catch (ilSaxParserException $e) {
82  $this->logger->error(
83  ': Parsing failed with message, "' . $e->getMessage() . '".'
84  );
85  } catch (ilWebLinkXMLParserException $e) {
86  $this->logger->error(
87  ': Parsing failed with message, "' . $e->getMessage() . '".'
88  );
89  }
90  }
91 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getMapping(string $a_comp, string $a_entity, string $a_old_id)
global $DIC
Definition: shib_login.php:26
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
__construct(Container $dic, ilPlugin $plugin)
link(string $caption, string $href, bool $new_viewport=false)
Xml importer class.