This repository was archived by the owner on Apr 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchHelper.php
More file actions
84 lines (74 loc) · 2.44 KB
/
Copy pathSearchHelper.php
File metadata and controls
84 lines (74 loc) · 2.44 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Copyright Zikula - https://ziku.la/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zikula\Module\CoreManagerModule\Helper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Zikula\Module\CoreManagerModule\Entity\CoreReleaseEntity;
use Zikula\Core\RouteUrl;
use Zikula\SearchModule\Entity\SearchResultEntity;
use Zikula\SearchModule\SearchableInterface;
class SearchHelper implements SearchableInterface
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var SessionInterface
*/
private $session;
/**
* @param EntityManagerInterface $entityManager
* @param SessionInterface $session
*/
public function __construct(
EntityManagerInterface $entityManager,
SessionInterface $session
) {
$this->entityManager = $entityManager;
$this->session = $session;
}
/**
* {@inheritdoc}
*/
public function amendForm(FormBuilderInterface $form)
{
// not needed because `active` child object is already added and that is all that is needed.
}
/**
* Get the search results
*
* @param array $words array of words to search for
* @param string $searchType AND|OR|EXACT
* @param array|null $modVars module form vars passed though
* @return array
*/
public function getResults(array $words, $searchType = 'AND', $modVars = null)
{
// this is an 'eager' search - it doesn't compensate for search type indicated in search UI
$results = $this->entityManager->getRepository(CoreReleaseEntity::class)->getByFragment($words);
$records = array();
foreach ($results as $result) {
/** @var $result CoreReleaseEntity */
$result = new SearchResultEntity();
$result->setTitle($result->getName())
->setText($result->getDescription())
->setModule('ZikulaCoreManagerModule')
->setCreated(new \DateTime())
->setUrl(RouteUrl::createFromRoute('zikulacoremanagermodule_user_viewcorereleases'))
->setSesid($this->session->getId());
$records[] = $result;
}
return $records;
}
public function getErrors()
{
return [];
}
}