ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 ()
 cancel update More...
 
 create ()
 
 cancelCreate ()
 cancel creating page content More...
 
 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
 
LOMServices $lom_services
 
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 @ilCtrl_Calls 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 = "" 
)

Reimplemented from ilPageContentGUI.

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

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 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), ILIAS\Repository\tabs(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ cancelCreate()

ilPCSourceCodeGUI::cancelCreate ( )

cancel creating page content

Reimplemented from ilPageContentGUI.

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

259 : void
260 {
261 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
262 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ cancelUpdate()

ilPCSourceCodeGUI::cancelUpdate ( )

cancel update

Reimplemented from ilPageContentGUI.

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

206 : void
207 {
208 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
209 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ create()

ilPCSourceCodeGUI::create ( )

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

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

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

+ Here is the call graph for this function:

◆ edit()

ilPCSourceCodeGUI::edit ( )

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

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

References Vendor\Package\$f, ILIAS\Repository\ctrl(), ilPageContentGUI\displayValidationError(), ilObjStyleSheet\getBaseContentStylePath(), ilPageContentGUI\getEditorScriptTag(), ilPageContentGUI\initEditor(), initPropertyForm(), ILIAS\Repository\lng(), and ILIAS\Repository\tabs().

Referenced by update().

+ 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.

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

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

+ Here is the call graph for this function:

◆ getEditingFormAdapter()

ilPCSourceCodeGUI::getEditingFormAdapter ( )

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

409 {
410 return $this->getManualFormAdapter(
411 $this->content_obj->getDownloadTitle(),
412 $this->content_obj->getSubCharacteristic(),
413 ($this->content_obj->getShowLineNumbers() == "y")
414 );
415 }
getManualFormAdapter(?string $download_title=null, ?string $subchar=null, ?bool $line_numbers=null)

◆ getImportFormAdapter()

ilPCSourceCodeGUI::getImportFormAdapter ( )

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

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

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

Referenced by executeCommand().

+ 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 377 of file class.ilPCSourceCodeGUI.php.

382 $this->ctrl->setParameter($this, "cname", "SourceCode");
383 $form = $this->gui->form([self::class], "#")
384 ->async()
385 ->hidden("mode", "manual")
386 ->text(
387 "title",
388 $this->lng->txt("cont_download_title"),
389 "",
390 $download_title
391 )
392 ->select(
393 "subchar",
394 $this->lng->txt("cont_src"),
395 $this->getProgLangOptions(),
396 "",
397 $subchar
398 )
399 ->checkbox(
400 "linenumbers",
401 $this->lng->txt("cont_show_line_numbers"),
402 "",
403 $line_numbers
404 );
405 return $form;
406 }

◆ getProgLangOptions()

ilPCSourceCodeGUI::getProgLangOptions ( )

Get selectable programming languages.

Returns
string[]

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

295 : array
296 {
297 $prog_langs = array(
298 "" => "other");
299 foreach (ilSyntaxHighlighter::getSupportedLanguagesV51() as $k => $v) {
300 $prog_langs[$k] = $v;
301 }
302 return $prog_langs;
303 }
static getSupportedLanguagesV51()
Get supported languages (keys are ILIAS <= 5.1 internal values, values are for representation)

References ilSyntaxHighlighter\getSupportedLanguagesV51().

+ Here is the call graph for this function:

◆ handleUploadResult()

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

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

421 $fac = new ILIAS\Data\UUID\Factory();
422 $uuid = $fac->uuid4AsString();
423 $name = $uuid . ".txt";
424 $upload->moveOneFileTo(
425 $result,
426 "",
427 Location::TEMPORARY,
428 $name,
429 true
430 );
431
432 return new BasicHandlerResult(
433 "filename",
434 HandlerResult::STATUS_OK,
435 $name,
436 ''
437 );
438 }
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...

◆ initPropertyForm()

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

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

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

Referenced by edit(), and insert().

+ Here is the caller graph for this function:

◆ insert()

ilPCSourceCodeGUI::insert ( )

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

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

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

Referenced by create().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

ilPCSourceCodeGUI::update ( )

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

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

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

+ Here is the call graph for this function:

◆ upload_source()

ilPCSourceCodeGUI::upload_source ( )

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

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

Referenced by create().

+ 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: