ADoctrineCollection.class.php 999 Bytes
Newer Older
Яков's avatar
first  
Яков committed
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
<?php
/**
 * Created by IntelliJ IDEA.
 * User: victor
 * Date: 31.10.17
 * Time: 11:03
 */

class DoctrineCollectionHelper
{
    protected $collect;
    
    public static function make(Doctrine_Collection $collect)
    {
        return new self($collect);
    }
    
    public function __construct(Doctrine_Collection $collect)
    {
        $this->collect = clone $collect;
    }
    
    /**
     * @param array $arrFields array(fieldName => value)     *
     * @return Doctrine_Record|null
     */
    public function find($arrFields)
    {
        $result = null;
        /**@var Doctrine_Record $record*/
        foreach ($this->collect as $record) {
            $flag = true;
            foreach ($arrFields as $fieldName => $value) {
                if($record->get($fieldName))
                {
                
                }
            }
            if($flag) {
              $result = $record;
              break;
            }
        }
        return $result;
    }
    
    
}