ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilGroupExporter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  private ilLogger $logger;
27 
28  public function __construct()
29  {
30  global $DIC;
31 
32  $this->logger = $DIC->logger()->grp();
33  }
34 
38  public function init(): void
39  {
40  }
41 
45  public function getXmlExportHeadDependencies(string $a_entity, string $a_target_release, array $a_ids): array
46  {
47  // always trigger container because of co-page(s)
48  return array(
49  array(
50  'component' => 'components/ILIAS/Container',
51  'entity' => 'struct',
52  'ids' => $a_ids
53  )
54  );
55  }
56 
57  public function getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids): array
58  {
59  $deps = [];
60  $advmd_ids = [];
61  foreach ($a_ids as $id) {
62  $rec_ids = $this->getActiveAdvMDRecords($id);
63  foreach ($rec_ids as $rec_id) {
64  $advmd_ids[] = $id . ":" . $rec_id;
65  }
66  }
67 
68  if ($advmd_ids !== []) {
69  $deps[] = [
70  "component" => "components/ILIAS/AdvancedMetaData",
71  "entity" => "advmd",
72  "ids" => $advmd_ids
73  ];
74  }
75 
76  $md_ids = [];
77  foreach ($a_ids as $grp_id) {
78  $md_ids[] = $grp_id . ":0:grp";
79  }
80  if ($md_ids !== []) {
81  $deps[] =
82  array(
83  "component" => "components/ILIAS/MetaData",
84  "entity" => "md",
85  "ids" => $md_ids
86  );
87  }
88  return $deps;
89  }
90 
94  public function getXmlRepresentation(string $a_entity, string $a_schema_version, string $a_id): string
95  {
96  $refs = ilObject::_getAllReferences((int) $a_id);
97  $group_ref_id = end($refs);
98  $group = ilObjectFactory::getInstanceByRefId($group_ref_id, false);
99 
100  if (!$group instanceof ilObjGroup) {
101  $this->logger->warning($a_id . ' is not instance of type group');
102  return '';
103  }
104 
105  $writer = new ilGroupXMLWriter($group);
106  $writer->setMode(ilGroupXMLWriter::MODE_EXPORT);
107  $writer->start();
108  return $writer->getXML();
109  }
110 
111  protected function getActiveAdvMDRecords(int $a_id): array
112  {
113  $active = [];
114 
115  foreach (ilAdvancedMDRecord::_getActivatedRecordsByObjectType('grp') as $record_obj) {
116  foreach ($record_obj->getAssignedObjectTypes() as $obj_info) {
117  if ($obj_info['obj_type'] == 'grp' && $obj_info['optional'] == 0) {
118  $active[] = $record_obj->getRecordId();
119  }
120  // local activation
121  if (
122  $obj_info['obj_type'] == 'grp' &&
123  $obj_info['optional'] == 1 &&
124  $a_id == $record_obj->getParentObject()
125  ) {
126  $active[] = $record_obj->getRecordId();
127  }
128  }
129  }
130  return $active;
131  }
132 
133  public function getValidSchemaVersions(string $a_entity): array
134  {
135  return [
136  "11.0" => [
137  "namespace" => 'http://www.ilias.de/Modules/Group/grp/11',
138  "xsd_file" => 'ilias_grp_11_0.xsd',
139  "uses_dataset" => false,
140  "min" => "11.0",
141  "max" => ""
142  ],
143  "9.0" => [
144  "namespace" => 'http://www.ilias.de/Modules/Group/grp/9',
145  "xsd_file" => 'ilias_grp_9_0.xsd',
146  "uses_dataset" => false,
147  "min" => "9.0",
148  "max" => "10.99"
149  ],
150  "4.1.0" => [
151  "namespace" => "http://www.ilias.de/Modules/Group/grp/4_1",
152  "xsd_file" => "ilias_grp_4_1.xsd",
153  "uses_dataset" => false,
154  "min" => "4.1.0",
155  "max" => "4.4.999"
156  ],
157  "5.0.0" => [
158  "namespace" => "http://www.ilias.de/Modules/Group/grp/5_0",
159  "xsd_file" => "ilias_grp_5_0.xsd",
160  "uses_dataset" => false,
161  "min" => "5.0.0",
162  "max" => "5.9.999"
163  ]
164  ];
165  }
166 }
getActiveAdvMDRecords(int $a_id)
getXmlRepresentation(string $a_entity, string $a_schema_version, string $a_id)
static _getActivatedRecordsByObjectType(string $a_obj_type, string $a_sub_type="", bool $a_only_optional=false)
Get activated records by object type.
static _getAllReferences(int $id)
get all reference ids for object ID
getXmlExportHeadDependencies(string $a_entity, string $a_target_release, array $a_ids)
getValidSchemaVersions(string $a_entity)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
global $DIC
Definition: shib_login.php:26
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids)
Class ilObjGroup.