1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8namespace Tracker\Filter\Control;
9
10class TextField implements Control
11{
12	private $fieldName;
13	private $value = '';
14
15	function __construct($name)
16	{
17		$this->fieldName = $name;
18	}
19
20	function applyInput(\JitFilter $input)
21	{
22		$this->value = $input->{$this->fieldName}->text();
23	}
24
25	function getQueryArguments()
26	{
27		if ($this->value) {
28			return [$this->fieldName => $this->value];
29		} else {
30			return [];
31		}
32	}
33
34	function getDescription()
35	{
36		return $this->value ?: null;
37	}
38
39	function getId()
40	{
41		return $this->fieldName;
42	}
43
44	function isUsable()
45	{
46		return true;
47	}
48
49	function hasValue()
50	{
51		return ! empty($this->value);
52	}
53
54	function getValue()
55	{
56		return $this->value;
57	}
58
59	function __toString()
60	{
61		$smarty = \TikiLib::lib('smarty');
62		$smarty->assign('control', [
63			'field' => $this->fieldName,
64			'value' => $this->value,
65		]);
66		return $smarty->fetch('filter_control/text_field.tpl');
67	}
68}
69