ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 include_once "Modules/Exercise/classes/class.ilExcCriteria.php";
6 
14 {
18  protected $lng;
19 
20 
24  public function __construct()
25  {
26  global $DIC;
27  parent::__construct();
28 
29  $this->lng = $DIC->language();
30  }
31 
32  public function getType()
33  {
34  return "text";
35  }
36 
37  public function setMinChars($a_value)
38  {
39  $this->setDefinition(array("chars" => (int) $a_value));
40  }
41 
42  public function getMinChars()
43  {
44  $def = $this->getDefinition();
45  if (is_array($def)) {
46  return $def["chars"];
47  }
48  }
49 
50  //
51  // ASSIGNMENT EDITOR
52  //
53 
54  public function initCustomForm(ilPropertyFormGUI $a_form)
55  {
56  $lng = $this->lng;
57 
58  $peer_char_tgl = new ilCheckboxInputGUI($lng->txt("exc_peer_review_min_chars_tgl"), "peer_char_tgl");
59  $a_form->addItem($peer_char_tgl);
60 
61  $peer_char = new ilNumberInputGUI($lng->txt("exc_peer_review_min_chars"), "peer_char");
62  $peer_char->setInfo($lng->txt("exc_peer_review_min_chars_info"));
63  $peer_char->setRequired(true);
64  $peer_char->setSize(3);
65  $peer_char_tgl->addSubItem($peer_char);
66  }
67 
68  public function exportCustomForm(ilPropertyFormGUI $a_form)
69  {
70  $min = $this->getMinChars();
71  if ($min) {
72  $a_form->getItemByPostVar("peer_char_tgl")->setChecked(true);
73  $a_form->getItemByPostVar("peer_char")->setValue($min);
74  }
75  }
76 
77  public function importCustomForm(ilPropertyFormGUI $a_form)
78  {
79  $this->setDefinition(null);
80 
81  if ($a_form->getInput("peer_char_tgl")) {
82  $this->setMinChars($a_form->getInput("peer_char"));
83  }
84  }
85 
86 
87  // PEER REVIEW
88 
89  public function addToPeerReviewForm($a_value = null)
90  {
91  $lng = $this->lng;
92 
93  $info = array();
94  if ($this->getDescription()) {
95  $info[] = $this->getDescription();
96  }
97  if ($this->getMinChars()) {
98  $info[] = $lng->txt("exc_peer_review_min_chars") . ": " . $this->getMinChars();
99  }
100  $info = implode("<br />", $info);
101 
102  $input = new ilTextAreaInputGUI($this->getTitle(), "prccc_text_" . $this->getId());
103  $input->setRows(10);
104  $input->setInfo($info);
105  $input->setRequired($this->isRequired());
106  $input->setValue($a_value);
107 
108  $this->form->addItem($input);
109  }
110 
111  public function importFromPeerReviewForm()
112  {
113  return trim($this->form->getInput("prccc_text_" . $this->getId()));
114  }
115 
116  public function validate($a_value)
117  {
118  $lng = $this->lng;
119 
120  if (!$this->hasValue($a_value) &&
121  !$this->isRequired()) {
122  return true;
123  }
124 
125  $min = $this->getMinChars();
126  if ($min) {
127  include_once "Services/Utilities/classes/class.ilStr.php";
128  if (ilStr::strLen($a_value) < $min) {
129  if ($this->form) {
130  $mess = sprintf($lng->txt("exc_peer_review_chars_invalid"), $min);
131  $this->form->getItemByPostVar("prccc_text_" . $this->getId())->setAlert($mess);
132  }
133  return false;
134  }
135  }
136  return true;
137  }
138 
139  public function hasValue($a_value)
140  {
141  return (bool) strlen($a_value);
142  }
143 
144  public function getHTML($a_value)
145  {
146  return nl2br($a_value);
147  }
148 }
Class ilExcCriteria.
static strLen($a_string)
Definition: class.ilStr.php:78
addToPeerReviewForm($a_value=null)
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
importCustomForm(ilPropertyFormGUI $a_form)
Class ilExcCriteriaText.
This class represents a checkbox property in a property form.
setDefinition(array $a_value=null)
addItem($a_item)
Add Item (Property, SectionHeader).
exportCustomForm(ilPropertyFormGUI $a_form)
setInfo($a_info)
Set Information Text.
This class represents a number property in a property form.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
initCustomForm(ilPropertyFormGUI $a_form)
This class represents a text area property in a property form.
$info
Definition: index.php:5