ServerGroveLiveChat /src/ServerGrove/SGLiveChatBundle/Document/VisitorRepository.php

Language PHP Lines 52
MD5 Hash af4a3b7f108a7383a90c05e7747e0bec
Repository https://github.com/casoetan/ServerGroveLiveChat.git View Raw File
 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
52
<?php

namespace ServerGrove\SGLiveChatBundle\Document;

use Doctrine\ODM\MongoDB\DocumentRepository;

/**
 * Description of VisitRepository
 *
 * @author Ismael Ambrosi<ismael@servergrove.com>
 */
class VisitorRepository extends DocumentRepository
{

    const REPOSITORY_NAME = 'SGLiveChatBundle:Visitor';

    public function create(array $args)
    {
        $visitor = new Visitor();
        foreach ($args as $k => $v) {
            $methodName = 'set' . ucfirst($k);
            if (method_exists($visitor, $methodName)) {
                call_user_func(array(
                    $visitor,
                    $methodName), $v);
            }
        }
        $visitor->setKey(md5(time() . $visitor->getAgent() . rand(0, 100)));

        return $visitor;
    }

    public function persist(Visitor $visitor)
    {
        $this->getDocumentManager()->persist($visitor);
        $this->getDocumentManager()->flush();
    }

    /**
     * @return ServerGrove\SGLiveChatBundle\Document\Visitor
     */
    public function getByKey($key)
    {
        $visitor = null;
        if (!is_null($key)) {
            $visitor = $this->findOneBy(array(
                'key' => $key));
        }
        return $visitor;
    }

}
Back to Top