ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilImportExportFactory.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12  const PLUGINS_DIR = "Plugins";
13 
14  public static function getExporterClass($a_type)
15  {
19  global $objDefinition;
20 
21  if ($objDefinition->isPlugin($a_type)) {
22  $classname = 'il' . $objDefinition->getClassName($a_type) . 'Exporter';
23  $location = $objDefinition->getLocation($a_type);
24  if (include_once $location . '/class.' . $classname . '.php') {
25  return $classname;
26  }
27  } else {
28  $comp = $objDefinition->getComponentForType($a_type);
29  $class = array_pop(explode("/", $comp));
30  $class = "il" . $class . "Exporter";
31 
32  // page component plugin exporter classes are already included
33  // the component is not registered by ilObjDefinition
34  if (class_exists($class)) {
35  return $class;
36  }
37 
38  // the next line had a "@" in front of the include_once
39  // I removed this because it tages ages to track down errors
40  // if the include class contains parse errors.
41  // Alex, 20 Jul 2012
42  if (include_once "./" . $comp . "/classes/class." . $class . ".php") {
43  return $class;
44  }
45  }
46 
47  throw new InvalidArgumentException('Invalid exporter type given');
48  }
49 
50  public static function getComponentForExport($a_type)
51  {
55  global $objDefinition;
56 
57  if ($objDefinition->isPlugin($a_type)) {
58  return self::PLUGINS_DIR . "/" . $a_type;
59  } else {
60  return $objDefinition->getComponentForType($a_type);
61  }
62  }
63 
71  public static function getImporterClass($a_component)
72  {
76  global $objDefinition;
77 
78  $parts = explode('/', $a_component);
79  $component_type = $parts[0];
80  $component = $parts[1];
81 
82  if ($component_type == self::PLUGINS_DIR &&
83  $objDefinition->isPlugin($component)) {
84  $classname = 'il' . $objDefinition->getClassName($component) . 'Importer';
85  $location = $objDefinition->getLocation($component);
86  if (include_once $location . '/class.' . $classname . '.php') {
87  return $classname;
88  }
89  } else {
90  $class = "il" . $component . "Importer";
91 
92  // treat special case of page component plugins
93  // they are imported with component type PLUGINS_DIR
94  // but are not yet recognized by ilObjDefinition::isPlugin()
95  //
96  // if they are active, then their importer class is already included by ilCOPageImporter::init()
97  if (class_exists($class)) {
98  return $class;
99  }
100  // the page component plugin is not installed or not active
101  // return an empty class name instead of throwing an exception
102  // in this case the import should be continued without treating the page component
103  elseif ($component_type == self::PLUGINS_DIR) {
104  return "";
105  }
106  $a_component = str_replace("..", "", $a_component);
107  if (is_file("./" . $a_component . "/classes/class." . $class . ".php")) {
108  if (include_once "./" . $a_component . "/classes/class." . $class . ".php") {
109  return $class;
110  }
111  }
112  }
113 
114  throw new InvalidArgumentException('Invalid importer type given: ' . "./" . $a_component . "/classes/class." . $class . ".php");
115  }
116 }
Factory for importer/exporter implementers.
$location
Definition: buildRTE.php:44
$a_type
Definition: workflow.php:92