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