ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilRepositorySelectorInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
25 include_once("./Services/Form/classes/class.ilFormPropertyGUI.php");
26 
39 {
43  protected $tpl;
44 
48  protected $tree;
49 
53  protected $user;
54 
58  protected $obj_data_cache;
59 
60  protected $options;
61  protected $value;
62  protected $container_types = array("root", "cat", "grp", "fold", "crs");
63 
70  public function __construct($a_title = "", $a_postvar = "")
71  {
72  global $DIC;
73 
74  $this->lng = $DIC->language();
75  $this->tpl = $DIC["tpl"];
76  $this->ctrl = $DIC->ctrl();
77  $this->tree = $DIC->repositoryTree();
78  $this->user = $DIC->user();
79  $this->obj_data_cache = $DIC["ilObjDataCache"];
80  $lng = $DIC->language();
81 
82  parent::__construct($a_title, $a_postvar);
83  $this->setClickableTypes($this->container_types);
84  $this->setHeaderMessage($lng->txt('search_area_info'));
85  $this->setType("rep_select");
86  $this->setSelectText($lng->txt("select"));
87  }
88 
94  public function setValue($a_value)
95  {
96  $this->value = $a_value;
97  }
98 
104  public function getValue()
105  {
106  return $this->value;
107  }
108 
114  public function setValueByArray($a_values)
115  {
116  $this->setValue($a_values[$this->getPostVar()]);
117  }
118 
124  public function setSelectText($a_val)
125  {
126  $this->select_text = $a_val;
127  }
128 
134  public function getSelectText()
135  {
136  return $this->select_text;
137  }
138 
144  public function setHeaderMessage($a_val)
145  {
146  $this->hm = $a_val;
147  }
148 
154  public function getHeaderMessage()
155  {
156  return $this->hm;
157  }
158 
164  public function setClickableTypes($a_types)
165  {
166  $this->clickable_types = $a_types;
167  }
168 
174  public function getClickableTypes()
175  {
176  return $this->clickable_types;
177  }
178 
184  public function checkInput()
185  {
186  $lng = $this->lng;
187 
188  $_POST[$this->getPostVar()] =
190 
191  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") {
192  $this->setAlert($lng->txt("msg_input_is_required"));
193 
194  return false;
195  }
196  return true;
197  }
198 
202  public function showRepositorySelection()
203  {
204  $tpl = $this->tpl;
205  $lng = $this->lng;
207  $tree = $this->tree;
209 
210  include_once 'Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php';
211  $ilCtrl->setParameter($this, "postvar", $this->getPostVar());
212 
214 
216  $this,
217  "showRepositorySelection",
218  $this,
219  "selectRepositoryItem",
220  "root_id"
221  );
222  $exp->setTypeWhiteList($this->getVisibleTypes());
223  $exp->setClickableTypes($this->getClickableTypes());
224 
225  if ($this->getValue()) {
226  $exp->setPathOpen($this->getValue());
227  $exp->setHighlightedNode($this->getHighlightedNode());
228  }
229 
230  if ($exp->handleCommand()) {
231  return;
232  }
233  // build html-output
234  $tpl->setContent($exp->getHTML());
235  }
236 
240  public function selectRepositoryItem()
241  {
244 
245  $anchor = $ilUser->prefs["screen_reader_optimization"]
246  ? $this->getFieldId() . "_anchor"
247  : "";
248 
249  $this->setValue($_GET["root_id"]);
250  $this->writeToSession();
251 
252  $ilCtrl->returnToParent($this, $anchor);
253  }
254 
258  public function reset()
259  {
262 
263  $anchor = $ilUser->prefs["screen_reader_optimization"]
264  ? $this->getFieldId() . "_anchor"
265  : "";
266 
267  $this->setValue("");
268  $this->writeToSession();
269 
270  $ilCtrl->returnToParent($this, $anchor);
271  }
272 
276  public function render($a_mode = "property_form")
277  {
278  $lng = $this->lng;
280  $ilObjDataCache = $this->obj_data_cache;
281  $tree = $this->tree;
282 
283  $tpl = new ilTemplate("tpl.prop_rep_select.html", true, true, "Services/Form");
284 
285  $tpl->setVariable("POST_VAR", $this->getPostVar());
286  $tpl->setVariable("ID", $this->getFieldId());
287  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
288  $tpl->setVariable("TXT_SELECT", $this->getSelectText());
289  $tpl->setVariable("TXT_RESET", $lng->txt("reset"));
290  switch ($a_mode) {
291  case "property_form":
292  $parent_gui = "ilpropertyformgui";
293  break;
294 
295  case "table_filter":
296  $parent_gui = get_class($this->getParent());
297  break;
298  }
299 
300  $ilCtrl->setParameterByClass(
301  "ilrepositoryselectorinputgui",
302  "postvar",
303  $this->getPostVar()
304  );
305  $tpl->setVariable(
306  "HREF_SELECT",
307  $ilCtrl->getLinkTargetByClass(
308  array($parent_gui, "ilformpropertydispatchgui", "ilrepositoryselectorinputgui"),
309  "showRepositorySelection"
310  )
311  );
312  $tpl->setVariable(
313  "HREF_RESET",
314  $ilCtrl->getLinkTargetByClass(
315  array($parent_gui, "ilformpropertydispatchgui", "ilrepositoryselectorinputgui"),
316  "reset"
317  )
318  );
319 
320  if ($this->getValue() > 0 && $this->getValue() != ROOT_FOLDER_ID) {
321  $tpl->setVariable(
322  "TXT_ITEM",
323  $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($this->getValue()))
324  );
325  } else {
326  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
327  $title = $nd["title"];
328  if ($title == "ILIAS") {
329  $title = $lng->txt("repository");
330  }
331  if (in_array($nd["type"], $this->getClickableTypes())) {
332  $tpl->setVariable("TXT_ITEM", $title);
333  }
334  }
335  return $tpl->get();
336  }
337 
343  public function insert($a_tpl)
344  {
345  $a_tpl->setCurrentBlock("prop_generic");
346  $a_tpl->setVariable("PROP_GENERIC", $this->render());
347  $a_tpl->parseCurrentBlock();
348  }
349 
353  public function getTableFilterHTML()
354  {
355  $html = $this->render("table_filter");
356  return $html;
357  }
358 
364  protected function getHighlightedNode()
365  {
366  $tree = $this->tree;
367 
368  if (!in_array(ilObject::_lookupType($this->getValue(), true), $this->getVisibleTypes())) {
369  return $tree->getParentId($this->getValue());
370  }
371 
372  return $this->getValue();
373  }
374 
380  protected function getVisibleTypes()
381  {
382  return array_merge((array) $this->container_types, (array) $this->getClickableTypes());
383  }
384 }
getHighlightedNode()
Returns the highlighted object.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
Interface for property form input GUI classes that can be used in table filters.
getVisibleTypes()
returns all visible types like container and clickable types
Explorer for selecting repository items.
render($a_mode="property_form")
Render item.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
getPostVar()
Get Post Variable.
__construct($a_title="", $a_postvar="")
Constructor.
checkInput()
Check input, strip slashes etc.
user()
Definition: user.php:4
setAlert($a_alert)
Set Alert Text.
global $ilCtrl
Definition: ilias.php:18
setType($a_type)
Set Type.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
setValueByArray($a_values)
Set value by array.
$nd
Definition: error.php:10
This class represents a repository selector in a property form.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
setClickableTypes($a_types)
Set clickable types.
$ilUser
Definition: imgupload.php:18
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
getParent()
Get Parent GUI object.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property in a property form.
writeToSession()
Write to session.
$_POST["username"]
$html
Definition: example_001.php:87