Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ExactMatch.php « Filter « DataTable « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3f68658d61dc8fdaf7aaacdb777ec08521bbd913 (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
<?php
/**
 * Piwik - Open source web analytics
 * 
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
 * @version $Id$
 * 
 * @package Piwik_DataTable
 */

/**
 * Delete all rows for which the given $columnToFilter do not equal $patternToSearch
 * This filter can be used on both integer and string columns. 
 * You can pass an array of integers in $patternToSearch parameter.
 * 
 * @package Piwik_DataTable
 * @subpackage Piwik_DataTable_Filter 
 */
class Piwik_DataTable_Filter_ExactMatch extends Piwik_DataTable_Filter
{
	private $columnToFilter;
	private $patternToSearch;
	
	public function __construct( $table, $columnToFilter, $patternToSearch )
	{
		parent::__construct($table);
		$this->patternToSearch = $patternToSearch;
		$this->columnToFilter = $columnToFilter;
		$this->filter();
	}
	
	protected function filter()
	{
		foreach($this->table->getRows() as $key => $row)
		{
			if( is_array($this->patternToSearch) )
			{
				if( in_array($row->getColumn($this->columnToFilter), $this->patternToSearch) == false )
				{
					$this->table->deleteRow($key);
				}
			}
			else if( $row->getColumn($this->columnToFilter) != $this->patternToSearch )
			{
				$k = $row->getColumn($this->columnToFilter);
				$this->table->deleteRow($key);
			}
		}
	}
}