summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.php
blob: a47a1a47948b5776e14a7d7d7015e6683ec571d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');

class TScaffoldSearch extends TScaffoldBase
{
	private $_list;

	public function getListView()
	{
		if($this->_list===null && ($id = $this->getListViewID()) !== null)
		{
			$this->_list = $this->getParent()->findControl($id);
			if($this->_list ===null)
				throw new TConfigurationException('scaffold_unable_to_find_list_view', $id);
		}
		return $this->_list;
	}

	public function setListView($value)
	{
		$this->_list = $value;
	}

	public function setListViewID($value)
	{
		$this->setViewState('ListViewID', $value);
	}

	public function getListViewID()
	{
		return $this->getViewState('ListViewID');
	}

	public function bubbleEvent($sender, $param)
	{
		if(strtolower($param->getCommandName())==='search')
		{
			if(($list = $this->getListView()) !== null)
			{
				$list->setSearchCondition($this->createSearchCondition());
				$list->setSearchParameters(array());
				return false;
			}
		}
		$this->raiseBubbleEvent($this, $param);
		return true;
	}

	protected function createSearchCondition()
	{
		$table = $this->getTableMetaData();
		if(strlen($str=$this->getSearchText()->getText()) > 0)
			return $table->getSearchRegExpCriteria($this->getFields(), $str);
	}

	protected function getFields()
	{
		if(strlen(trim($str=$this->getSearchableFields()))>0)
			$fields = preg_split('/\s*,\s*/', $str);
		else
			$fields = array_keys($this->getTableMetaData()->getColumns());
		return $fields;
	}

	public function getSearchableFields()
	{
		return $this->getViewState('SearchableFields','');
	}

	public function setSearchableFields($value)
	{
		$this->setViewState('SearchableFields', $value, '');
	}

	public function getSearchButton()
	{
		$this->ensureChildControls();
		return $this->getRegisteredObject('_search');
	}

	public function getSearchText()
	{
		$this->ensureChildControls();
		return $this->getRegisteredObject('_textbox');
	}
}

?>