/
bsdImportValidator.class.php
51 lines (36 loc) · 1.16 KB
/
bsdImportValidator.class.php
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
<?PHP
class bsdImportRowValidator extends sfValidatorBase
{
protected function configure($options = array(), $messages = array())
{
$this->addMessage('reqdFields', 'Required Field (%reqdField%) is not present on line: %line%.');
$this->addMessage('NotMultiDemArray', 'bsdImportRowValidator expected a multidemensional array but found only a single array was found. Possibly bsdImportRowValidator was given a single row?');
$this->addOption('reqdFields');
}
public function is_array_multi($array)
{
return (bool) (count($array) != count($array, COUNT_RECURSIVE));
}
public function clean($value)
{
$this->doClean($value);
}
protected function doClean($value)
{
$clean = $value;
if(!$this->is_array_multi($clean))
{
throw new sfValidatorError($this, 'NotMultiDemArray', array());
}
foreach($clean as $line => $row)
{
foreach($this->getOption("reqdFields") as $reqdField)
{
if(is_null($row[$reqdField]) || $row[$reqdField] == "")
{
throw new sfValidatorError($this, 'reqdFields', array('reqdField' => $reqdField, 'lineNo' => $line));
}
}
}
}
}