/src/ServerGrove/SGLiveChatBundle/Document/VisitorRepository.php
PHP | 52 lines | 35 code | 9 blank | 8 comment | 2 complexity | af4a3b7f108a7383a90c05e7747e0bec MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, ISC, BSD-3-Clause
- <?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;
- }
- }