File size: 1,401 Bytes
d2897cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php

namespace Mautic\CoreBundle\Event;

use Mautic\CoreBundle\Translation\Translator;
use Symfony\Contracts\EventDispatcher\Event;

class GlobalSearchEvent extends Event
{
    /**
     * @var array
     */
    protected $results = [];

    protected string $searchString;

    /**
     * @param string     $searchString
     * @param Translator $translator
     */
    public function __construct(
        $searchString,
        protected $translator
    ) {
        $this->searchString = strtolower(trim(strip_tags($searchString)));
    }

    /**
     * Returns the string to be searched.
     */
    public function getSearchString(): string
    {
        return $this->searchString;
    }

    /**
     * Add an array of results from a search query to be listed in right side panel
     * Each result should be the ENTIRE html to be rendered.
     *
     * @param string $header  String name for section header
     * @param array  $results Array of HTML output that will be wrapped in <li /> elements
     */
    public function addResults($header, array $results): void
    {
        $header                 = $this->translator->trans($header);
        $this->results[$header] = $results;
    }

    /**
     * Returns the results.
     *
     * @return array
     */
    public function getResults()
    {
        uksort($this->results, 'strnatcmp');

        return $this->results;
    }
}