ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilMediaPoolImportGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
27 {
28  protected \ILIAS\MediaPool\StandardGUIRequest $request;
29  protected ilObjMediaPool $mep;
30  protected ilCtrl $ctrl;
31  protected ilLanguage $lng;
33  protected Translations $ot;
34 
35  public function __construct(ilObjMediaPool $a_mep)
36  {
37  global $DIC;
38 
39  $this->ctrl = $DIC->ctrl();
40  $this->lng = $DIC->language();
41  $this->tpl = $DIC->ui()->mainTemplate();
42  $this->mep = $a_mep;
43  $this->request = $DIC->mediaPool()
44  ->internal()
45  ->gui()
46  ->standardRequest();
47  $this->ot = $a_mep->getObjectProperties()->getPropertyTranslations();
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("mep_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  $lng->loadLanguageModule("meta");
77 
78  $form = new ilPropertyFormGUI();
79 
80  // import file
81  $fi = new ilFileInputGUI($lng->txt("file"), "importfile");
82  $fi->setSuffixes(array("zip"));
83  $fi->setRequired(true);
84  $fi->setSize(30);
85  $form->addItem($fi);
86 
87  $ot = $this->ot;
88  $options = [];
89  foreach ($ot->getLanguages() as $l) {
90  if ($l->getLanguageCode() != $ot->getBaseLanguage()) {
91  $options[$l->getLanguageCode()] = $lng->txt("meta_l_" . $l->getLanguageCode());
92  }
93  }
94  $si = new ilSelectInputGUI($lng->txt("mep_import_lang"), "import_lang");
95  $si->setOptions($options);
96  $form->addItem($si);
97 
98  $form->addCommandButton("importTranslation", $lng->txt("import"));
99  $form->setTitle($lng->txt("mep_import_trans"));
100  $form->setFormAction($ilCtrl->getFormAction($this));
101 
102  return $form;
103  }
104 
105  public function importTranslation(): void
106  {
107  $ilCtrl = $this->ctrl;
108  $lng = $this->lng;
109 
110  $imp = new ilImport();
111 
113  $conf = $imp->getConfig("components/ILIAS/MediaPool");
114 
115  $target_lang = $this->request->getImportLang();
116  $ot = $this->ot;
117  if ($target_lang === $ot->getBaseLanguage()) {
118  $this->tpl->setOnScreenMessage('failure', $lng->txt("mep_transl_master_language_not_allowed"), true);
119  $ilCtrl->redirect($this, "showTranslationImportForm");
120  }
121 
122  $conf->setTranslationImportMode($this->mep, $target_lang);
123  $imp->importObject(
124  null,
125  $_FILES["importfile"]["tmp_name"],
126  $_FILES["importfile"]["name"],
127  "mep",
128  "components/ILIAS/MediaPool"
129  );
130  //echo "h"; exit;
131  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
132  $ilCtrl->redirect($this, "showTranslationImportForm");
133  }
134 }
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
This class represents a selection list property in a property form.
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...
This class represents a file property in a property form.
Class handles translation mode for an object.
getCmd(?string $fallback_command=null)
Import class.
setContent(string $a_html)
Sets content for standard template.
setSuffixes(array $a_suffixes)
loadLanguageModule(string $a_module)
Load language module.
setOptions(array $a_options)
__construct(ilObjMediaPool $a_mep)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
Import related features for media pools (currently used for translation imports)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS MediaPool StandardGUIRequest $request
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...