Proyectos de Subversion LeadersLinked - Antes de SPA

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\RecordExists;
8
use Laminas\Db\Sql\Select;
9
use Laminas\Db\Sql\TableIdentifier;
10
 
11
class RecordExistsMultiFields extends RecordExists
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
        if(is_array($custom_fields)) {
35
            foreach($custom_fields as $key_custom => $value_custom)
36
            {
37
                if(!is_null($value_custom)) {
38
                    $select->where->equalTo($key_custom, $value_custom);
39
                }
40
            }
41
        }
42
 
43
        if ($this->exclude !== null)
44
        {
45
        	if (is_array($this->exclude))
46
        	{
47
        		$select->where->notEqualTo(
48
        				$this->exclude['field'],
49
        				$this->exclude['value']
50
        		);
51
        	}
52
        	else
53
        	{
54
        		$select->where($this->exclude);
55
        	}
56
        }
57
 
58
        $this->setSelect($select);
59
 
60
        $valid = true;
61
        $this->setValue($value);
62
 
63
        $result = $this->query($value);
64
        if (!$result)
65
        {
66
            $valid = false;
67
            $this->error(self::ERROR_NO_RECORD_FOUND);
68
        }
69
 
70
        return $valid;
71
    }
72
}