ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMediaPoolImportGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected \ILIAS\MediaPool\StandardGUIRequest $request;
27  protected ilObjMediaPool $mep;
28  protected ilCtrl $ctrl;
29  protected ilLanguage $lng;
31 
32  public function __construct(ilObjMediaPool $a_mep)
33  {
34  global $DIC;
35 
36  $this->ctrl = $DIC->ctrl();
37  $this->lng = $DIC->language();
38  $this->tpl = $DIC->ui()->mainTemplate();
39  $this->mep = $a_mep;
40  $this->request = $DIC->mediaPool()
41  ->internal()
42  ->gui()
43  ->standardRequest();
44  }
45 
46  public function executeCommand(): void
47  {
48  $ilCtrl = $this->ctrl;
49 
50  $cmd = $ilCtrl->getCmd("showTranslationImportForm");
51 
52  if (in_array($cmd, array("showTranslationImportForm", "importTranslation"))) {
53  $this->$cmd();
54  }
55  }
56 
57  public function showTranslationImportForm(): void
58  {
59  $lng = $this->lng;
60  $tpl = $this->tpl;
61 
62  $this->tpl->setOnScreenMessage('info', $lng->txt("mep_trans_import_info"));
63  $form = $this->initTranslationImportForm();
64  $tpl->setContent($form->getHTML());
65  }
66 
68  {
69  $lng = $this->lng;
70  $ilCtrl = $this->ctrl;
71 
72  $lng->loadLanguageModule("meta");
73 
74  $form = new ilPropertyFormGUI();
75 
76  // import file
77  $fi = new ilFileInputGUI($lng->txt("file"), "importfile");
78  $fi->setSuffixes(array("zip"));
79  $fi->setRequired(true);
80  $fi->setSize(30);
81  $form->addItem($fi);
82 
83  $ot = ilObjectTranslation::getInstance($this->mep->getId());
84  $options = [];
85  foreach ($ot->getLanguages() as $l) {
86  if ($l->getLanguageCode() != $ot->getMasterLanguage()) {
87  $options[$l->getLanguageCode()] = $lng->txt("meta_l_" . $l->getLanguageCode());
88  }
89  }
90  $si = new ilSelectInputGUI($lng->txt("mep_import_lang"), "import_lang");
91  $si->setOptions($options);
92  $form->addItem($si);
93 
94  $form->addCommandButton("importTranslation", $lng->txt("import"));
95  $form->setTitle($lng->txt("mep_import_trans"));
96  $form->setFormAction($ilCtrl->getFormAction($this));
97 
98  return $form;
99  }
100 
101  public function importTranslation(): void
102  {
103  $ilCtrl = $this->ctrl;
104  $lng = $this->lng;
105 
106  $imp = new ilImport();
107 
109  $conf = $imp->getConfig("Modules/MediaPool");
110 
111  $target_lang = $this->request->getImportLang();
112  $ot = ilObjectTranslation::getInstance($this->mep->getId());
113  if ($target_lang === $ot->getMasterLanguage()) {
114  $this->tpl->setOnScreenMessage('failure', $lng->txt("mep_transl_master_language_not_allowed"), true);
115  $ilCtrl->redirect($this, "showTranslationImportForm");
116  }
117 
118  $conf->setTranslationImportMode($this->mep, $target_lang);
119  $imp->importObject(
120  null,
121  $_FILES["importfile"]["tmp_name"],
122  $_FILES["importfile"]["name"],
123  "mep",
124  "Modules/MediaPool"
125  );
126  //echo "h"; exit;
127  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
128  $ilCtrl->redirect($this, "showTranslationImportForm");
129  }
130 }
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...
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.
__construct(ilObjMediaPool $a_mep)
global $DIC
Definition: feed.php:28
setContent(string $a_html)
Sets content for standard template.
static getInstance(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS MediaPool StandardGUIRequest $request
ilGlobalTemplateInterface $tpl