-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropNull.php
More file actions
85 lines (79 loc) · 2.4 KB
/
DropNull.php
File metadata and controls
85 lines (79 loc) · 2.4 KB
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
<?php
/**
* This file contains DropNull process
*
* @author KoolPHP Inc (support@koolphp.net)
* @link https://www.koolphp.net
* @copyright KoolPHP Inc
* @license https://www.koolreport.com/license
*/
namespace koolreport\cleandata;
use \koolreport\core\Process;
use \koolreport\core\Utility;
class DropNull extends Process
{
protected $targetValue;
protected $targetColumnType;
protected $targetColumns;
protected $excludedColumns;
protected $thresh;
protected $columns;
protected $strict;
protected function onInit()
{
$this->targetValue = Utility::get($this->params,"targetValue");
$this->targetColumnType = Utility::get($this->params,"targetColumnType");
$this->targetColumns = Utility::get($this->params,"targetColumns");
$this->excludedColumns = Utility::get($this->params,"excludedColumns");
$this->thresh = Utility::get($this->params,"thresh",1);
$this->strict = Utility::get($this->params,"strict",false);
}
protected function onMetaReceived($meta)
{
$columns = array();
foreach($meta["columns"] as $cName=>$cSetting)
{
$columnName = $cName;
if($this->targetColumns!==null && !in_array($cName,$this->targetColumns))
{
$columnName = null;
}
if($columnName!==null)
{
if($this->excludedColumns!==null && in_array($cName,$this->excludedColumns))
{
$columnName = null;
}
}
if($columnName!==null)
{
if($this->targetColumnType!==null && $this->targetColumnType!==Utility::get($cSetting,"type"))
{
$columnName = null;
}
}
if($columnName!==null)
{
array_push($columns,$columnName);
}
}
$this->columns = $columns;
return $meta;
}
protected function onInput($row)
{
$thresh=0;
foreach($this->columns as $cName)
{
if(($this->strict===false && $row[$cName]==$this->targetValue)||($this->strict===true && $row[$cName]===$this->targetValue))
{
$thresh++;
}
if($thresh>=$this->thresh)
{
return;
}
}
$this->next($row);
}
}