Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Validator;
6
 
7
use Laminas\Validator\Db\NoRecordExists;
8
use Laminas\Db\Sql\Select;
9
use Laminas\Db\Sql\TableIdentifier;
10
 
11
class NoRecordExistsMultiFields extends NoRecordExists
12
{
13
 
14
 	public function __construct($options = null)
15
    {
16
        parent::__construct($options);
17
	}
18
 
19
    public function isValid($value)
20
    {
21
        /*
22
         * Check for an adapter being defined. If not, throw an exception.
23
         */
24
        if (null === $this->adapter) {
25
            throw new \Exception('No database adapter present');
26
        }
27
 
28
        $select          = new Select();
29
        $tableIdentifier = new TableIdentifier($this->getTable(), $this->getSchema());
30
        $select->from($this->getTable())->columns(array($this->getField()));
31
        $select->where->equalTo($this->getField(), null);
32
 
33
        $custom_fields = $this->getOption('custom_fields');
34
 
35
        if(is_array($custom_fields)) {
36
            foreach($custom_fields as $key_custom => $value_custom)
37
            {
38
                if(!is_null($value_custom)) {
39
                    $select->where->equalTo($key_custom, $value_custom);
40
                }
41
            }
42
        }
43
 
44
        if ($this->exclude !== null)
45
        {
46
        	if (is_array($this->exclude))
47
        	{
48
        		$select->where->notEqualTo(
49
        				$this->exclude['field'],
50
        				$this->exclude['value']
51
        		);
52
        	}
53
        	else
54
        	{
55
        		$select->where($this->exclude);
56
        	}
57
        }
58
 
59
 
60
        $this->setSelect($select);
61
 
62
        $valid = true;
63
        $this->setValue($value);
64
 
65
        $result = $this->query($value);
66
 
67
 
68
        if ($result)
69
        {
70
            $valid = false;
71
            $this->error(self::ERROR_RECORD_FOUND);
72
        }
73
 
74
        return $valid;
75
    }
76
}