ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilPCSourceCodeGUI Class Reference

Class ilPCSourcecodeGUI. More...

+ Inheritance diagram for ilPCSourceCodeGUI:
+ Collaboration diagram for ilPCSourceCodeGUI:

Public Member Functions

 __construct (ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
 
 executeCommand ()
 
 edit ()
 
 insert ()
 
 update ()
 
 cancelUpdate ()
 
 create ()
 
 cancelCreate ()
 
 upload_source ()
 
 getProgLangOptions ()
 Get selectable programming languages. More...
 
 initPropertyForm (string $a_title, string $a_cmd, string $a_cmd_cancel)
 
 getImportFormAdapter ()
 
 getManualFormAdapter (?string $download_title=null, ?string $subchar=null, ?bool $line_numbers=null)
 
 getEditingFormAdapter ()
 
 handleUploadResult (FileUpload $upload, UploadResult $result)
 
- Public Member Functions inherited from ilPageContentGUI
 __construct (ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id="", string $a_pc_id="0")
 
 setContentObject (ilPageContent $a_val)
 
 getContentObject ()
 
 setPage (ilPageObject $a_val)
 
 getPage ()
 
 setPageConfig (ilPageConfig $a_val)
 
 getPageConfig ()
 
 setStyleId (int $a_styleid)
 
 getStyleId ()
 
 getStyle ()
 
 getCharacteristicsOfCurrentStyle (array $a_type)
 Get characteristics of current style and call setCharacteristics, if style is given. More...
 
 setCharacteristics (array $a_chars)
 
 getCharacteristics ()
 
 getHierId ()
 
 setHierId (string $a_hier_id)
 set hierarchical id in dom object More...
 
 delete ()
 
 displayValidationError ()
 
 cancelCreate ()
 cancel creating page content More...
 
 cancelUpdate ()
 cancel update More...
 
 cancel ()
 Cancel. More...
 
 deactivate ()
 gui function set enabled if is not enabled and vice versa More...
 
 cut ()
 Cut single element. More...
 
 copy ()
 Copy single element. More...
 
 getTemplateOptions (string $a_type="")
 Get table templates. More...
 

Protected Attributes

ilTabsGUI $tabs
 
string $requested_par_downloadtitle
 
string $requested_par_content
 
ilObjUser $user
 
- Protected Attributes inherited from ilPageContentGUI
ILIAS COPage Editor GUIService $editor_gui
 
ILIAS COPage InternalGUIService $gui
 
EditSessionRepository $edit_repo
 
string $pc_id = ""
 
array $chars
 
ilObjStyleSheet $style = null
 
ilLogger $log
 
int $styleid = 0
 
EditGUIRequest $request
 
string $sub_command = ""
 
int $requested_ref_id = 0
 
ILIAS GlobalScreen ScreenContext ContextServices $tool_context
 
Style Content CharacteristicManager $char_manager
 

Additional Inherited Members

- Static Public Member Functions inherited from ilPageContentGUI
static _getCommonBBButtons ()
 
- Data Fields inherited from ilPageContentGUI
ilPageContent $content_obj
 
ilGlobalTemplateInterface $tpl
 
ilLanguage $lng
 
ilCtrl $ctrl
 
ilPageObject $pg_obj
 
string $hier_id = ""
 
DOMDocument $dom
 
 $updated
 
string $target_script = ""
 
string $return_location = ""
 
ilPageConfig $page_config = null
 
- Static Public Attributes inherited from ilPageContentGUI
static string $style_selector_reset = "margin-top:2px; margin-bottom:2px; text-indent:0px; position:static; float:none; width: auto;"
 
- Protected Member Functions inherited from ilPageContentGUI
 redirectToParent (string $hier_id="")
 
 getParentReturn (string $hier_id="")
 
 updateAndReturn ()
 
 setCurrentTextLang (string $lang_key)
 
 getCurrentTextLang ()
 
 setEditorToolContext ()
 
 initEditor ()
 
 getEditorScriptTag (string $form_pc_id="", string $form_cname="")
 
- Static Protected Attributes inherited from ilPageContentGUI
static array $common_bb_buttons
 

Detailed Description

Class ilPCSourcecodeGUI.

User Interface for Paragraph Editing ilPCSourceCodeGUI: ilRepoStandardUploadHandlerGUI

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 32 of file class.ilPCSourceCodeGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilPCSourceCodeGUI::__construct ( ilPageObject  $a_pg_obj,
?ilPageContent  $a_content_obj,
string  $a_hier_id,
string  $a_pc_id = "" 
)

Definition at line 42 of file class.ilPCSourceCodeGUI.php.

References $DIC, ILIAS\MetaData\Repository\Validation\Data\__construct(), ILIAS\Repository\tabs(), and ILIAS\Repository\user().

47  {
48  global $DIC;
49 
50  $this->user = $DIC->user();
51  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
52  $this->tabs = $DIC->tabs();
53  }
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
+ Here is the call graph for this function:

Member Function Documentation

◆ cancelCreate()

ilPCSourceCodeGUI::cancelCreate ( )

Definition at line 257 of file class.ilPCSourceCodeGUI.php.

References ILIAS\Repository\ctrl().

257  : void
258  {
259  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
260  }
+ Here is the call graph for this function:

◆ cancelUpdate()

ilPCSourceCodeGUI::cancelUpdate ( )

Definition at line 204 of file class.ilPCSourceCodeGUI.php.

References ILIAS\Repository\ctrl().

204  : void
205  {
206  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
207  }
+ Here is the call graph for this function:

◆ create()

ilPCSourceCodeGUI::create ( )

Definition at line 209 of file class.ilPCSourceCodeGUI.php.

References ILIAS\Repository\ctrl(), ilPageContentGUI\getPage(), insert(), ilPageContentGUI\setCurrentTextLang(), and upload_source().

209  : void
210  {
211  $this->content_obj = new ilPCSourceCode($this->getPage());
212  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
213  $this->content_obj->setLanguage($this->request->getString("par_language"));
214 
215  $this->setCurrentTextLang($this->request->getString("par_language"));
216 
217  $this->requested_par_content = $this->request->getRaw("par_content");
218  $this->requested_par_downloadtitle = str_replace('"', '', $this->request->getString("par_downloadtitle"));
219 
220  $uploaded = $this->upload_source();
221 
222  $this->content_obj->setCharacteristic(
223  $this->request->getString("par_characteristic")
224  );
225  $this->content_obj->setSubCharacteristic(
226  $this->request->getString("par_subcharacteristic")
227  );
228  $this->content_obj->setDownloadTitle(str_replace('"', '', $this->requested_par_downloadtitle));
229  $this->content_obj->setShowLineNumbers(
230  $this->request->getString("par_showlinenumbers") ? 'y' : 'n'
231  );
232  $this->content_obj->setCharacteristic('Code');
233 
234  if ($uploaded) {
235  $this->insert();
236  return;
237  }
238 
239  $this->updated = $this->content_obj->setText(
240  $this->content_obj->input2xml($this->requested_par_content, 0, false)
241  );
242 
243  if ($this->updated !== true) {
244  $this->insert();
245  return;
246  }
247 
248  $this->updated = $this->pg_obj->update();
249 
250  if ($this->updated === true) {
251  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
252  } else {
253  $this->insert();
254  }
255  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setCurrentTextLang(string $lang_key)
+ Here is the call graph for this function:

◆ edit()

ilPCSourceCodeGUI::edit ( )

Definition at line 77 of file class.ilPCSourceCodeGUI.php.

References Vendor\Package\$f, ILIAS\Repository\ctrl(), ilPageContentGUI\displayValidationError(), ilPageContentGUI\getEditorScriptTag(), ilPageContentGUI\initEditor(), initPropertyForm(), ILIAS\Repository\lng(), ILIAS\Repository\tabs(), and ILIAS\UI\Implementation\Component\Input\withValue().

Referenced by update().

77  : void
78  {
79  $form = $this->initPropertyForm($this->lng->txt("cont_edit_src"), "update", "cancelCreate");
80 
81  $this->displayValidationError();
82 
83  $this->initEditor();
84  $this->tabs->setBackTarget("", "");
85 
86  $cmd = $this->ctrl->getCmd();
87  if ($cmd == "update") {
88  $form->setValuesByPost();
89  } else {
90  /*
91  $form->getItemByPostVar("par_language")->setValue($this->content_obj->getLanguage());
92  $form->getItemByPostVar("par_subcharacteristic")->setValue($this->content_obj->getSubCharacteristic());
93  $form->getItemByPostVar("par_downloadtitle")->setValue($this->content_obj->getDownloadTitle());
94  $form->getItemByPostVar("par_showlinenumbers")->setChecked(
95  $this->content_obj->getShowLineNumbers() == "y"
96  );
97  // $form->getItemByPostVar("par_autoindent")->setChecked(
98  // $this->content_obj->getAutoIndent()=="y"?true:false);
99  */
100  $par_content = $this->content_obj->xml2output($this->content_obj->getText());
101 
102  $par_content = str_replace("{", "[curlybegin ", $par_content);
103  $par_content = str_replace("}", " curlyend]", $par_content);
104 
105  $form->getItemByPostVar("par_content")->setValue($par_content);
106  }
107 
108  $f = $this->gui
109  ->ui()
110  ->factory()->input()->field()
111  ->textarea(
112  $this->lng->txt("cont_pc_code")
113  )->withValue($par_content);
114  $t = $this->gui->ui()->renderer()->render($f);
115  $t = str_replace("<textarea", "<textarea name='code' rows='20' form='copg-src-form' ", $t);
116  $t = str_replace("[curlybegin ", "&#123;", $t);
117  $t = str_replace(" curlyend]", "&#125;", $t);
118  $this->tpl->setContent($t . $this->getEditorScriptTag($this->pc_id, "SourceCode"));
119  }
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
getEditorScriptTag(string $form_pc_id="", string $form_cname="")
initPropertyForm(string $a_title, string $a_cmd, string $a_cmd_cancel)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilPCSourceCodeGUI::executeCommand ( )

Definition at line 55 of file class.ilPCSourceCodeGUI.php.

References ilPageContentGUI\$gui, ILIAS\Repository\ctrl(), and getImportFormAdapter().

55  : void
56  {
57  // get next class that processes or forwards current command
58  $next_class = $this->ctrl->getNextClass($this);
59 
60  // get current command
61  $cmd = $this->ctrl->getCmd();
62 
63  switch ($next_class) {
64 
65  case strtolower(ilRepoStandardUploadHandlerGUI::class):
66  $form = $this->getImportFormAdapter();
67  $gui = $form->getRepoStandardUploadHandlerGUI("input_file");
68  $this->ctrl->forwardCommand($gui);
69  break;
70 
71  default:
72  $this->$cmd();
73  break;
74  }
75  }
ILIAS COPage InternalGUIService $gui
+ Here is the call graph for this function:

◆ getEditingFormAdapter()

ilPCSourceCodeGUI::getEditingFormAdapter ( )

Definition at line 406 of file class.ilPCSourceCodeGUI.php.

References getManualFormAdapter().

Referenced by ilPCSourceCodeEditorGUI\getEditorElements().

407  {
408  return $this->getManualFormAdapter(
409  $this->content_obj->getDownloadTitle(),
410  $this->content_obj->getSubCharacteristic(),
411  ($this->content_obj->getShowLineNumbers() == "y")
412  );
413  }
getManualFormAdapter(?string $download_title=null, ?string $subchar=null, ?bool $line_numbers=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImportFormAdapter()

ilPCSourceCodeGUI::getImportFormAdapter ( )

Definition at line 342 of file class.ilPCSourceCodeGUI.php.

References ILIAS\Repository\ctrl(), getProgLangOptions(), and ILIAS\Repository\lng().

Referenced by executeCommand(), and ilPCSourceCodeEditorGUI\getRenderedImportForm().

343  {
344  $this->ctrl->setParameter($this, "cname", "SourceCode");
345  $form = $this->gui->form([self::class], "#")
346  ->async()
347  ->hidden("mode", "import")
348  ->file(
349  "input_file",
350  $this->lng->txt("import_file"),
351  \Closure::fromCallable([$this, 'handleUploadResult']),
352  "filename",
353  "",
354  1,
355  [],
356  [self::class],
357  "copg"
358  )
359  ->text(
360  "title",
361  $this->lng->txt("cont_download_title")
362  )
363  ->select(
364  "subchar",
365  $this->lng->txt("cont_src"),
366  $this->getProgLangOptions()
367  )
368  ->checkbox(
369  "linenumbers",
370  $this->lng->txt("cont_show_line_numbers")
371  );
372  return $form;
373  }
getProgLangOptions()
Get selectable programming languages.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getManualFormAdapter()

ilPCSourceCodeGUI::getManualFormAdapter ( ?string  $download_title = null,
?string  $subchar = null,
?bool  $line_numbers = null 
)

Definition at line 375 of file class.ilPCSourceCodeGUI.php.

References ILIAS\Repository\ctrl(), getProgLangOptions(), and ILIAS\Repository\lng().

Referenced by getEditingFormAdapter(), and ilPCSourceCodeEditorGUI\getRenderedManualForm().

380  $this->ctrl->setParameter($this, "cname", "SourceCode");
381  $form = $this->gui->form([self::class], "#")
382  ->async()
383  ->hidden("mode", "manual")
384  ->text(
385  "title",
386  $this->lng->txt("cont_download_title"),
387  "",
388  $download_title
389  )
390  ->select(
391  "subchar",
392  $this->lng->txt("cont_src"),
393  $this->getProgLangOptions(),
394  "",
395  $subchar
396  )
397  ->checkbox(
398  "linenumbers",
399  $this->lng->txt("cont_show_line_numbers"),
400  "",
401  $line_numbers
402  );
403  return $form;
404  }
getProgLangOptions()
Get selectable programming languages.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getProgLangOptions()

ilPCSourceCodeGUI::getProgLangOptions ( )

Get selectable programming languages.

Returns
string[]

Definition at line 293 of file class.ilPCSourceCodeGUI.php.

References ilSyntaxHighlighter\getSupportedLanguagesV51().

Referenced by getImportFormAdapter(), and getManualFormAdapter().

293  : array
294  {
295  $prog_langs = array(
296  "" => "other");
297  foreach (ilSyntaxHighlighter::getSupportedLanguagesV51() as $k => $v) {
298  $prog_langs[$k] = $v;
299  }
300  return $prog_langs;
301  }
static getSupportedLanguagesV51()
Get supported languages (keys are ILIAS <= 5.1 internal values, values are for representation) ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleUploadResult()

ilPCSourceCodeGUI::handleUploadResult ( FileUpload  $upload,
UploadResult  $result 
)

Definition at line 415 of file class.ilPCSourceCodeGUI.php.

References ILIAS\FileUpload\FileUpload\moveOneFileTo().

419  $fac = new ILIAS\Data\UUID\Factory();
420  $uuid = $fac->uuid4AsString();
421  $name = $uuid . ".txt";
422  $upload->moveOneFileTo(
423  $result,
424  "",
425  Location::TEMPORARY,
426  $name,
427  true
428  );
429 
430  return new BasicHandlerResult(
431  "filename",
432  HandlerResult::STATUS_OK,
433  $name,
434  ''
435  );
436  }
moveOneFileTo(UploadResult $uploadResult, string $destination, int $location=Location::STORAGE, string $file_name='', bool $override_existing=false)
Moves a single File (the attributes, metadata and upload-status of which are contained in UploadResul...
+ Here is the call graph for this function:

◆ initPropertyForm()

ilPCSourceCodeGUI::initPropertyForm ( string  $a_title,
string  $a_cmd,
string  $a_cmd_cancel 
)

Definition at line 303 of file class.ilPCSourceCodeGUI.php.

References ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

Referenced by edit(), and insert().

308  $form = new ilPropertyFormGUI();
309  $form->setTitle($a_title);
310  $form->setFormAction($this->ctrl->getFormAction($this, $a_cmd));
311  $form->addCommandButton($a_cmd, $this->lng->txt("save"));
312  $form->addCommandButton($a_cmd_cancel, $this->lng->txt("cancel"));
313 
314  /*
315  $lang_var = ilMDLanguageItem::_getLanguages();
316  $lang = new ilSelectInputGUI($this->lng->txt("language"), "par_language");
317  $lang->setOptions($lang_var);
318  $form->addItem($lang);
319 
320  $prog_langs = $this->getProgLangOptions();
321  $code_style = new ilSelectInputGUI($this->lng->txt("cont_src"), "par_subcharacteristic");
322  $code_style->setOptions($prog_langs);
323  $form->addItem($code_style);
324  $line_number = new ilCheckboxInputGUI($this->lng->txt("cont_show_line_numbers"), "par_showlinenumbers");
325  $form->addItem($line_number);
326 */
327  $code = new ilTextAreaInputGUI("", "par_content");
328  $code->setRows(12);
329  $form->addItem($code);
330 
331  /*
332  $downlaod_title = new ilTextInputGUI($this->lng->txt("cont_download_title"), "par_downloadtitle");
333  $downlaod_title->setSize(40);
334  $form->addItem($downlaod_title);
335 
336  $file = new ilFileInputGUI($this->lng->txt("import_file"), "userfile");
337  $form->addItem($file);*/
338 
339  return $form;
340  }
This class represents a text area property in a property form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insert()

ilPCSourceCodeGUI::insert ( )

Definition at line 121 of file class.ilPCSourceCodeGUI.php.

References $user, ILIAS\Repository\ctrl(), ilPageContentGUI\displayValidationError(), ilPageContentGUI\getCurrentTextLang(), initPropertyForm(), and ILIAS\Repository\lng().

Referenced by create().

121  : void
122  {
123  $ilUser = $this->user;
124 
125  $form = $this->initPropertyForm($this->lng->txt("cont_insert_src"), "create_src", "cancelCreate");
126 
127  if ($this->pg_obj->getParentType() == "lm") {
128  $this->tpl->setVariable(
129  "LINK_ILINK",
130  $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp")
131  );
132  $this->tpl->setVariable("TXT_ILINK", "[" . $this->lng->txt("cont_internal_link") . "]");
133  }
134 
135  $this->displayValidationError();
136 
137  $cmd = $this->ctrl->getCmd();
138  if ($cmd == "create_src") {
139  $form->setValuesByPost();
140  } else {
141  if ($this->getCurrentTextLang() != "") {
142  $form->getItemByPostVar("par_language")->setValue($this->getCurrentTextLang());
143  } else {
144  $form->getItemByPostVar("par_language")->setValue($ilUser->getLanguage());
145  }
146 
147  $form->getItemByPostVar("par_showlinenumbers")->setChecked(true);
148  // $form->getItemByPostVar("par_autoindent")->setChecked(true);
149  $form->getItemByPostVar("par_subcharacteristic")->setValue("");
150  $form->getItemByPostVar("par_content")->setValue("");
151  }
152 
153  $this->tpl->setContent($form->getHTML());
154  }
initPropertyForm(string $a_title, string $a_cmd, string $a_cmd_cancel)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

ilPCSourceCodeGUI::update ( )

Definition at line 156 of file class.ilPCSourceCodeGUI.php.

References ILIAS\Repository\ctrl(), and edit().

156  : void
157  {
158  $this->requested_par_content = $this->request->getRaw("par_content");
159  $this->requested_par_downloadtitle = str_replace('"', '', $this->request->getString("par_downloadtitle"));
160 
161  // $this->upload_source();
162 
163  // set language and characteristic
164 
165  /*
166  $this->content_obj->setLanguage(
167  $this->request->getString("par_language")
168  );
169  $this->content_obj->setCharacteristic($this->request->getString("par_characteristic"));*/
170 
171  // set language and characteristic
172  /*$this->content_obj->setLanguage($this->request->getString("par_language"));
173  $this->content_obj->setSubCharacteristic($this->request->getString("par_subcharacteristic"));
174  $this->content_obj->setDownloadTitle(
175  str_replace('"', '', $this->requested_par_downloadtitle)
176  );
177  $this->content_obj->setShowLineNumbers(
178  $this->request->getString("par_showlinenumbers") ? "y" : "n"
179  );
180  $this->content_obj->setSubCharacteristic($this->request->getString("par_subcharacteristic"));
181  $this->content_obj->setCharacteristic("Code");
182 
183  */
184 
185  $this->updated = $this->content_obj->setText(
186  $this->content_obj->input2xml($this->requested_par_content, 0, false)
187  );
188 
189  if ($this->updated !== true) {
190  //echo "Did not update!";
191  $this->edit();
192  return;
193  }
194 
195  $this->updated = $this->pg_obj->update();
196 
197  if ($this->updated === true && $this->ctrl->getCmd() != "upload") {
198  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
199  } else {
200  $this->edit();
201  }
202  }
+ Here is the call graph for this function:

◆ upload_source()

ilPCSourceCodeGUI::upload_source ( )

Definition at line 262 of file class.ilPCSourceCodeGUI.php.

Referenced by create().

262  : bool
263  {
264  if (isset($_FILES['userfile']['name'])) {
265  $userfile = $_FILES['userfile']['tmp_name'];
266 
267  if ($userfile == "" || !is_uploaded_file($userfile)) {
268  $error_str = "<strong>Error(s):</strong><br>Upload error: file name must not be empty!";
269  $this->tpl->setVariable("MESSAGE", $error_str);
270  $this->content_obj->setText(
271  $this->content_obj->input2xml(
272  $this->request->getRaw("par_content"),
273  0,
274  false
275  )
276  );
277  return false;
278  }
279 
280  $this->requested_par_content = file_get_contents($userfile);
281  $this->requested_par_downloadtitle = $_FILES['userfile']['name'];
282  return true;
283  }
284 
285  return false;
286  }
+ Here is the caller graph for this function:

Field Documentation

◆ $requested_par_content

string ilPCSourceCodeGUI::$requested_par_content
protected

Definition at line 39 of file class.ilPCSourceCodeGUI.php.

◆ $requested_par_downloadtitle

string ilPCSourceCodeGUI::$requested_par_downloadtitle
protected

Definition at line 38 of file class.ilPCSourceCodeGUI.php.

◆ $tabs

ilTabsGUI ilPCSourceCodeGUI::$tabs
protected

Definition at line 34 of file class.ilPCSourceCodeGUI.php.

◆ $user

ilObjUser ilPCSourceCodeGUI::$user
protected

Definition at line 40 of file class.ilPCSourceCodeGUI.php.

Referenced by insert().


The documentation for this class was generated from the following file: