Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 1 | | Comparar con el anterior | 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
 
15449 efrain 28
 
29
 
1 www 30
        $select          = new Select();
31
        $tableIdentifier = new TableIdentifier($this->getTable(), $this->getSchema());
32
        $select->from($this->getTable())->columns(array($this->getField()));
33
        $select->where->equalTo($this->getField(), null);
15449 efrain 34
 
1 www 35
        $custom_fields = $this->getOption('custom_fields');
36
        if(is_array($custom_fields)) {
37
            foreach($custom_fields as $key_custom => $value_custom)
38
            {
39
                if(!is_null($value_custom)) {
40
                    $select->where->equalTo($key_custom, $value_custom);
41
                }
42
            }
43
        }
44
 
45
        if ($this->exclude !== null)
46
        {
47
        	if (is_array($this->exclude))
48
        	{
49
        		$select->where->notEqualTo(
50
        				$this->exclude['field'],
51
        				$this->exclude['value']
52
        		);
53
        	}
54
        	else
55
        	{
56
        		$select->where($this->exclude);
57
        	}
58
        }
59
 
60
        $this->setSelect($select);
15449 efrain 61
 
1 www 62
 
15449 efrain 63
       // echo $select->getSqlString($this->adapter->platform); exit;
64
 
1 www 65
        $valid = true;
66
        $this->setValue($value);
67
 
68
        $result = $this->query($value);
69
        if (!$result)
70
        {
71
            $valid = false;
72
            $this->error(self::ERROR_NO_RECORD_FOUND);
73
        }
74
 
75
        return $valid;
76
    }
77
}