ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilExcCriteriaText.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
16 protected $lng;
17
18
22 public function __construct()
23 {
24 global $DIC;
26
27 $this->lng = $DIC->language();
28 }
29
30 public function getType()
31 {
32 return "text";
33 }
34
35 public function setMinChars($a_value)
36 {
37 $this->setDefinition(array("chars" => (int) $a_value));
38 }
39
40 public function getMinChars()
41 {
42 $def = $this->getDefinition();
43 if (is_array($def)) {
44 return $def["chars"];
45 }
46 }
47
48 //
49 // ASSIGNMENT EDITOR
50 //
51
52 public function initCustomForm(ilPropertyFormGUI $a_form)
53 {
55
56 $peer_char_tgl = new ilCheckboxInputGUI($lng->txt("exc_peer_review_min_chars_tgl"), "peer_char_tgl");
57 $a_form->addItem($peer_char_tgl);
58
59 $peer_char = new ilNumberInputGUI($lng->txt("exc_peer_review_min_chars"), "peer_char");
60 $peer_char->setInfo($lng->txt("exc_peer_review_min_chars_info"));
61 $peer_char->setRequired(true);
62 $peer_char->setSize(3);
63 $peer_char_tgl->addSubItem($peer_char);
64 }
65
66 public function exportCustomForm(ilPropertyFormGUI $a_form)
67 {
68 $min = $this->getMinChars();
69 if ($min) {
70 $a_form->getItemByPostVar("peer_char_tgl")->setChecked(true);
71 $a_form->getItemByPostVar("peer_char")->setValue($min);
72 }
73 }
74
75 public function importCustomForm(ilPropertyFormGUI $a_form)
76 {
77 $this->setDefinition(null);
78
79 if ($a_form->getInput("peer_char_tgl")) {
80 $this->setMinChars($a_form->getInput("peer_char"));
81 }
82 }
83
84
85 // PEER REVIEW
86
87 public function addToPeerReviewForm($a_value = null)
88 {
90
91 $info = array();
92 if ($this->getDescription()) {
93 $info[] = $this->getDescription();
94 }
95 if ($this->getMinChars()) {
96 $info[] = $lng->txt("exc_peer_review_min_chars") . ": " . $this->getMinChars();
97 }
98 $info = implode("<br />", $info);
99
100 $input = new ilTextAreaInputGUI($this->getTitle(), "prccc_text_" . $this->getId());
101 $input->setRows(10);
102 $input->setInfo($info);
103 $input->setRequired($this->isRequired());
104 $input->setValue($a_value);
105
106 $this->form->addItem($input);
107 }
108
109 public function importFromPeerReviewForm()
110 {
111 return trim($this->form->getInput("prccc_text_" . $this->getId()));
112 }
113
114 public function validate($a_value)
115 {
117
118 if (!$this->hasValue($a_value) &&
119 !$this->isRequired()) {
120 return true;
121 }
122
123 $min = $this->getMinChars();
124 if ($min) {
125 if (ilStr::strLen($a_value) < $min) {
126 if ($this->form) {
127 $mess = sprintf($lng->txt("exc_peer_review_chars_invalid"), $min);
128 $this->form->getItemByPostVar("prccc_text_" . $this->getId())->setAlert($mess);
129 }
130 return false;
131 }
132 }
133 return true;
134 }
135
136 public function hasValue($a_value)
137 {
138 return (bool) strlen($a_value);
139 }
140
141 public function getHTML($a_value)
142 {
143 return nl2br($a_value);
144 }
145}
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
Class ilExcCriteriaText.
addToPeerReviewForm($a_value=null)
initCustomForm(ilPropertyFormGUI $a_form)
importCustomForm(ilPropertyFormGUI $a_form)
exportCustomForm(ilPropertyFormGUI $a_form)
Class ilExcCriteria.
setDefinition(array $a_value=null)
This class represents a number property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
getItemByPostVar($a_post_var)
Get Item by POST variable.
static strLen($a_string)
Definition: class.ilStr.php:78
This class represents a text area property in a property form.
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc