1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stinger Entity Search package. |
5
|
|
|
* |
6
|
|
|
* (c) Oliver Kotte <[email protected]> |
7
|
|
|
* (c) Florian Meyer <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
namespace StingerSoft\EntitySearchBundle\Services; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
15
|
|
|
use Doctrine\Common\Util\ClassUtils; |
16
|
|
|
use StingerSoft\EntitySearchBundle\Model\Document; |
17
|
|
|
use StingerSoft\EntitySearchBundle\Model\DocumentAdapter; |
18
|
|
|
|
19
|
|
|
abstract class AbstractSearchService implements SearchService { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* |
23
|
|
|
* @var ObjectManager |
24
|
|
|
*/ |
25
|
|
|
protected $objectManager; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
* |
31
|
|
|
* @see \StingerSoft\EntitySearchBundle\Services\SearchService::setObjectManager() |
32
|
|
|
*/ |
33
|
|
|
public function setObjectManager(ObjectManager $om) { |
34
|
|
|
if($this->objectManager) |
35
|
|
|
return; |
36
|
|
|
$this->objectManager = $om; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
* |
43
|
|
|
* @see \StingerSoft\EntitySearchBundle\Services\SearchService::getObjectManager() |
44
|
|
|
*/ |
45
|
|
|
public function getObjectManager() { |
46
|
|
|
return $this->objectManager; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
* |
53
|
|
|
* @see \StingerSoft\EntitySearchBundle\Services\SearchService::createEmptyDocumentFromEntity() |
54
|
|
|
*/ |
55
|
|
|
public function createEmptyDocumentFromEntity($entity) { |
56
|
|
|
$document = $this->newDocumentInstance(); |
57
|
|
|
$clazz = $this->getClass($entity); |
58
|
|
|
$cmd = $this->getObjectManager()->getClassMetadata($clazz); |
59
|
|
|
$id = $cmd->getIdentifierValues($entity); |
60
|
|
|
|
61
|
|
|
$document->setEntityClass($clazz); |
62
|
|
|
$document->setEntityId(count($id) == 1 ? current($id) : $id); |
63
|
|
|
return $document; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function getClass($entity) { |
67
|
|
|
$clazz = ClassUtils::getClass($entity); |
68
|
|
|
return $clazz; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
* |
75
|
|
|
* @see \StingerSoft\EntitySearchBundle\Services\SearchService::getOnlineHelp() |
76
|
|
|
*/ |
77
|
|
|
public function getOnlineHelp($locale, $defaultLocale = 'en') { |
78
|
|
|
return null; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Creates a new document instance |
83
|
|
|
* |
84
|
|
|
* @return Document |
85
|
|
|
*/ |
86
|
|
|
protected function newDocumentInstance() { |
87
|
|
|
return new DocumentAdapter(); |
88
|
|
|
} |
89
|
|
|
} |