ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExcCriteriaText.php
Go to the documentation of this file.
1<?php
2
26{
27 public function getType(): string
28 {
29 return "text";
30 }
31
32 public function setMinChars(int $a_value): void
33 {
34 $this->setDefinition(array("chars" => $a_value));
35 }
36
37 public function getMinChars(): int
38 {
39 $def = $this->getDefinition();
40 if (is_array($def)) {
41 return (int) $def["chars"];
42 }
43
44 return 0;
45 }
46
47 //
48 // ASSIGNMENT EDITOR
49 //
50
51 public function initCustomForm(ilPropertyFormGUI $a_form): void
52 {
54
55 $peer_char_tgl = new ilCheckboxInputGUI($lng->txt("exc_peer_review_min_chars_tgl"), "peer_char_tgl");
56 $a_form->addItem($peer_char_tgl);
57
58 $peer_char = new ilNumberInputGUI($lng->txt("exc_peer_review_min_chars"), "peer_char");
59 $peer_char->setInfo($lng->txt("exc_peer_review_min_chars_info"));
60 $peer_char->setRequired(true);
61 $peer_char->setSize(3);
62 $peer_char_tgl->addSubItem($peer_char);
63 }
64
65 public function exportCustomForm(ilPropertyFormGUI $a_form): void
66 {
67 $min = $this->getMinChars();
68 if ($min) {
69 $a_form->getItemByPostVar("peer_char_tgl")->setChecked(true);
70 $a_form->getItemByPostVar("peer_char")->setValue($min);
71 }
72 }
73
74 public function importCustomForm(ilPropertyFormGUI $a_form): void
75 {
76 $this->setDefinition(null);
77
78 if ($a_form->getInput("peer_char_tgl")) {
79 $this->setMinChars($a_form->getInput("peer_char"));
80 }
81 }
82
83
84 // PEER REVIEW
85
86 public function addToPeerReviewForm($a_value = null): void
87 {
89
90 $info = array();
91 if ($this->getDescription()) {
92 $info[] = $this->getDescription();
93 }
94 if ($this->getMinChars()) {
95 $info[] = $lng->txt("exc_peer_review_min_chars") . ": " . $this->getMinChars();
96 }
97 $info = implode("<br />", $info);
98
99 $input = new ilTextAreaInputGUI($this->getTitle(), "prccc_text_" . $this->getId());
100 $input->setRows(10);
101 $input->setInfo($info);
102 $input->setRequired($this->isRequired());
103 $input->setValue((string) $a_value);
104
105 $this->form->addItem($input);
106 }
107
108 public function importFromPeerReviewForm(): string
109 {
110 return trim($this->form->getInput("prccc_text_" . $this->getId()));
111 }
112
113 public function validate($a_value): bool
114 {
116
117 if (!$this->hasValue($a_value) &&
118 !$this->isRequired()) {
119 return true;
120 }
121
122 $min = $this->getMinChars();
123 if ($min) {
124 if (ilStr::strLen((string) $a_value) < $min) {
125 if ($this->form) {
126 $mess = sprintf($lng->txt("exc_peer_review_chars_invalid"), $min);
127 $this->form->getItemByPostVar("prccc_text_" . $this->getId())->setAlert($mess);
128 }
129 return false;
130 }
131 }
132 return true;
133 }
134
135 public function hasValue($a_value): bool
136 {
137 return (bool) strlen((string) $a_value);
138 }
139
140 public function getHTML($a_value): string
141 {
142 return nl2br($this->gui->html()->escapeCurly((string) $a_value));
143 }
144}
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addToPeerReviewForm($a_value=null)
initCustomForm(ilPropertyFormGUI $a_form)
importCustomForm(ilPropertyFormGUI $a_form)
exportCustomForm(ilPropertyFormGUI $a_form)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setDefinition(?array $a_value=null)
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 number property in a property form.
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
static strLen(string $a_string)
Definition: class.ilStr.php:60
This class represents a text area property in a property form.
$info
Definition: entry_point.php:21
form( $class_path, string $cmd, string $submit_caption="")