ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLMImportGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
26 {
27  protected ilCtrl $ctrl;
28  protected ilLanguage $lng;
32  public function __construct(ilObjLearningModule $a_lm)
33  {
34  global $DIC;
35 
36  $this->request = $DIC
37  ->learningModule()
38  ->internal()
39  ->gui()
40  ->editing()
41  ->request();
42 
43 
44  $this->ctrl = $DIC->ctrl();
45  $this->lng = $DIC->language();
46  $this->tpl = $DIC["tpl"];
47  $this->lm = $a_lm;
48  }
49 
50  public function executeCommand(): void
51  {
52  $ilCtrl = $this->ctrl;
53 
54  $cmd = $ilCtrl->getCmd("showTranslationImportForm");
55 
56  if (in_array($cmd, array("showTranslationImportForm", "importTranslation"))) {
57  $this->$cmd();
58  }
59  }
60 
61  public function showTranslationImportForm(): void
62  {
63  $lng = $this->lng;
64  $tpl = $this->tpl;
65 
66  $this->tpl->setOnScreenMessage('info', $lng->txt("cont_trans_import_info"));
67  $form = $this->initTranslationImportForm();
68  $tpl->setContent($form->getHTML());
69  }
70 
72  {
73  $lng = $this->lng;
74  $ilCtrl = $this->ctrl;
75 
76  $options = [];
77 
78  $lng->loadLanguageModule("meta");
79 
80  $form = new ilPropertyFormGUI();
81 
82  // import file
83  $fi = new ilFileInputGUI($lng->txt("file"), "importfile");
84  $fi->setSuffixes(array("zip"));
85  $fi->setRequired(true);
86  $fi->setSize(30);
87  $form->addItem($fi);
88 
89  $ot = ilObjectTranslation::getInstance($this->lm->getId());
90  foreach ($ot->getLanguages() as $l) {
91  if ($l->getLanguageCode() !== $ot->getMasterLanguage()) {
92  $options[$l->getLanguageCode()] = $lng->txt("meta_l_" . $l->getLanguageCode());
93  }
94  }
95  $si = new ilSelectInputGUI($lng->txt("cont_import_lang"), "import_lang");
96  $si->setOptions($options);
97  $form->addItem($si);
98 
99  $form->addCommandButton("importTranslation", $lng->txt("import"));
100  $form->setTitle($lng->txt("cont_import_trans"));
101  $form->setFormAction($ilCtrl->getFormAction($this));
102 
103  return $form;
104  }
105 
106  public function importTranslation(): void
107  {
108  $ilCtrl = $this->ctrl;
109  $lng = $this->lng;
110 
111  $imp = new ilImport();
112  $conf = $imp->getConfig("Modules/LearningModule");
113 
114  $target_lang = $this->request->getImportLang();
115  $ot = ilObjectTranslation::getInstance($this->lm->getId());
116  if ($target_lang == $ot->getMasterLanguage() || $target_lang == "") {
117  $this->tpl->setOnScreenMessage('failure', $lng->txt("cont_transl_master_language_not_allowed"), true);
118  $ilCtrl->redirect($this, "showTranslationImportForm");
119  }
120 
121  $conf->setTranslationImportMode($this->lm, $target_lang);
122  $imp->importObject(
123  null,
124  $_FILES["importfile"]["tmp_name"],
125  $_FILES["importfile"]["name"],
126  "lm",
127  "Modules/LearningModule"
128  );
129  //echo "h"; exit;
130  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
131  $ilCtrl->redirect($this, "showTranslationImportForm");
132  }
133 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Import related features for learning modules.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
ilGlobalTemplateInterface $tpl
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
getCmd(string $fallback_command=null)
This class represents a file property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setSuffixes(array $a_suffixes)
loadLanguageModule(string $a_module)
Load language module.
global $DIC
Definition: feed.php:28
setContent(string $a_html)
Sets content for standard template.
ilObjLearningModule $lm
EditingGUIRequest $request
static getInstance(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjLearningModule $a_lm)