ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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
 
array bool null $updated = null
 
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 235 of file class.ilPCSourceCodeGUI.php.

235 : void
236 {
237 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
238 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ cancelUpdate()

ilPCSourceCodeGUI::cancelUpdate ( )

cancel update

Reimplemented from ilPageContentGUI.

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

182 : void
183 {
184 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
185 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ create()

ilPCSourceCodeGUI::create ( )

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

187 : void
188 {
189 $this->content_obj = new ilPCSourceCode($this->getPage());
190 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
191 $this->content_obj->setLanguage($this->request->getString("par_language"));
192
193 $this->setCurrentTextLang($this->request->getString("par_language"));
194
195 $this->requested_par_content = $this->request->getRaw("par_content");
196 $this->requested_par_downloadtitle = str_replace('"', '', $this->request->getString("par_downloadtitle"));
197
198 $uploaded = $this->upload_source();
199
200 $this->content_obj->setCharacteristic(
201 $this->request->getString("par_characteristic")
202 );
203 $this->content_obj->setSubCharacteristic(
204 $this->request->getString("par_subcharacteristic")
205 );
206 $this->content_obj->setDownloadTitle(str_replace('"', '', $this->requested_par_downloadtitle));
207 $this->content_obj->setShowLineNumbers(
208 $this->request->getString("par_showlinenumbers") ? 'y' : 'n'
209 );
210 $this->content_obj->setCharacteristic('Code');
211
212 if ($uploaded) {
213 $this->insert();
214 return;
215 }
216
217 $this->updated = $this->content_obj->setText(
218 $this->content_obj->input2xml($this->requested_par_content, 0, false)
219 );
220
221 if ($this->updated !== true) {
222 $this->insert();
223 return;
224 }
225
226 $this->updated = $this->pg_obj->update();
227
228 if ($this->updated === true) {
229 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
230 } else {
231 $this->insert();
232 }
233 }
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 363 of file class.ilPCSourceCodeGUI.php.

364 {
365 return $this->getManualFormAdapter(
366 $this->content_obj->getDownloadTitle(),
367 $this->content_obj->getSubCharacteristic(),
368 ($this->content_obj->getShowLineNumbers() == "y")
369 );
370 }
getManualFormAdapter(?string $download_title=null, ?string $subchar=null, ?bool $line_numbers=null)

◆ getImportFormAdapter()

ilPCSourceCodeGUI::getImportFormAdapter ( )

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

300 {
301 $this->ctrl->setParameter($this, "cname", "SourceCode");
302 $form = $this->gui->form([self::class], "#")
303 ->async()
304 ->hidden("mode", "import")
305 ->file(
306 "input_file",
307 $this->lng->txt("import_file"),
308 \Closure::fromCallable([$this, 'handleUploadResult']),
309 "filename",
310 "",
311 1,
312 [],
313 [self::class],
314 "copg"
315 )
316 ->text(
317 "title",
318 $this->lng->txt("cont_download_title")
319 )
320 ->select(
321 "subchar",
322 $this->lng->txt("cont_src"),
323 $this->getProgLangOptions()
324 )
325 ->checkbox(
326 "linenumbers",
327 $this->lng->txt("cont_show_line_numbers")
328 );
329 return $form;
330 }

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

337 $this->ctrl->setParameter($this, "cname", "SourceCode");
338 $form = $this->gui->form([self::class], "#")
339 ->async()
340 ->hidden("mode", "manual")
341 ->text(
342 "title",
343 $this->lng->txt("cont_download_title"),
344 "",
345 $download_title
346 )
347 ->select(
348 "subchar",
349 $this->lng->txt("cont_src"),
350 $this->getProgLangOptions(),
351 "",
352 $subchar
353 )
354 ->checkbox(
355 "linenumbers",
356 $this->lng->txt("cont_show_line_numbers"),
357 "",
358 $line_numbers
359 );
360 return $form;
361 }

◆ getProgLangOptions()

ilPCSourceCodeGUI::getProgLangOptions ( )

Get selectable programming languages.

Returns
string[]

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

271 : array
272 {
273 $prog_langs = array(
274 "" => "other");
275 foreach (ilPCSourceCode::getSupportedLanguages() as $k => $v) {
276 $prog_langs[$k] = $v;
277 }
278 return $prog_langs;
279 }
static getSupportedLanguages()

References ilPCSourceCode\getSupportedLanguages().

+ Here is the call graph for this function:

◆ handleUploadResult()

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

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

376 $fac = new ILIAS\Data\UUID\Factory();
377 $uuid = $fac->uuid4AsString();
378 $name = $uuid . ".txt";
379 $upload->moveOneFileTo(
380 $result,
381 "",
382 Location::TEMPORARY,
383 $name,
384 true
385 );
386
387 return new BasicHandlerResult(
388 "filename",
389 HandlerResult::STATUS_OK,
390 $name,
391 ''
392 );
393 }
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 281 of file class.ilPCSourceCodeGUI.php.

286 $form = new ilPropertyFormGUI();
287 $form->setTitle($a_title);
288 $form->setFormAction($this->ctrl->getFormAction($this, $a_cmd));
289 $form->addCommandButton($a_cmd, $this->lng->txt("save"));
290 $form->addCommandButton($a_cmd_cancel, $this->lng->txt("cancel"));
291
292 $code = new ilTextAreaInputGUI("", "par_content");
293 $code->setRows(12);
294 $form->addItem($code);
295
296 return $form;
297 }
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->updated = $this->content_obj->setText(
164 $this->content_obj->input2xml($this->requested_par_content, 0, false)
165 );
166
167 if ($this->updated !== true) {
168 //echo "Did not update!";
169 $this->edit();
170 return;
171 }
172
173 $this->updated = $this->pg_obj->update();
174
175 if ($this->updated === true && $this->ctrl->getCmd() != "upload") {
176 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
177 } else {
178 $this->edit();
179 }
180 }

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

+ Here is the call graph for this function:

◆ upload_source()

ilPCSourceCodeGUI::upload_source ( )

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

240 : bool
241 {
242 if (isset($_FILES['userfile']['name'])) {
243 $userfile = $_FILES['userfile']['tmp_name'];
244
245 if ($userfile == "" || !is_uploaded_file($userfile)) {
246 $error_str = "<strong>Error(s):</strong><br>Upload error: file name must not be empty!";
247 $this->tpl->setVariable("MESSAGE", $error_str);
248 $this->content_obj->setText(
249 $this->content_obj->input2xml(
250 $this->request->getRaw("par_content"),
251 0,
252 false
253 )
254 );
255 return false;
256 }
257
258 $this->requested_par_content = file_get_contents($userfile);
259 $this->requested_par_downloadtitle = $_FILES['userfile']['name'];
260 return true;
261 }
262
263 return false;
264 }

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: