Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 4b592357

Přidáno uživatelem Jan Šedivý před více než 5 roky(ů)

Re #7328 Zobrazování okolních řádek ve výsledcích vyhledávání

Zobrazit rozdíly:

app/FrontModule/component/Transliteration/TransliterationSearchResultList.latte
58 58
    {foreach $resultRows as $result}
59 59
        <hr>
60 60

  
61
        <a href="{plink Transliteration:view $result->id}">
61
        <a href="{plink Transliteration:view $result->id}" class="transliteration-link">
62 62
            {$result->book_abrev}, {$result->chapter}
63 63
        </a>
64
        {ifset $result['adjacentLines']['linesBefore']}
65
            {foreach $result['adjacentLines']['linesBefore'] as $lineBefore}
66
                <div>
67
                    <span>{$lineBefore->line_number}.</span>
68
                    <span>{$lineBefore->transliteration}</span>
69
                </div>
70
            {/foreach}
71
        {/ifset}
64 72
        <div>
65 73
            <span class="linefound">{$result->line_number}.</span>
66 74
            <span>{$result->transliteration|noescape}</span>
67 75
        </div>
76
        {ifset $result['adjacentLines']['linesAfter']}
77
            {foreach $result['adjacentLines']['linesAfter'] as $linesAfter}
78
                <div>
79
                    <span>{$linesAfter->line_number}.</span>
80
                    <span>{$linesAfter->transliteration}</span>
81
                </div>
82
            {/foreach}
83
        {/ifset}
68 84

  
69 85
    {/foreach}
70 86

  
app/FrontModule/component/Transliteration/TransliterationSearchResultList.php
5 5

  
6 6
use App\Enum\EAdjacentLines;
7 7
use App\Enum\EPageLimit;
8
use App\Enum\ESearchFormOperators;
9
use App\Model\Repository\LineRepository;
8 10
use App\Model\Repository\TransliterationRepository;
9 11
use App\Model\TransliterationSearchModel;
10 12
use App\Utils\Form;
......
19 21
    /** @var TransliterationRepository */
20 22
    private $transliterationRepository;
21 23

  
24
    /** @var LineRepository */
25
    private $lineRepository;
26

  
22 27
    /** @var Paginator */
23 28
    private $paginator;
24 29

  
......
31 36
    private $resultRows;
32 37
    private $totalCount;
33 38

  
34
    private $adjacentLines;
39
    /**
40
     * @persistent
41
     */
42
    public $adjacentLines;
43

  
44
    /**
45
     * @persistent
46
     */
47
    public $page;
48

  
49
    /**
50
     * @persistent
51
     */
52
    public $limit;
35 53

  
36 54
    /**
37 55
     * TransliterationSearchResultList constructor.
38 56
     * @param TransliterationSearchModel $transliterationSearchModel
39 57
     * @param TransliterationRepository $transliterationRepository
58
     * @param LineRepository $lineRepository
40 59
     * @throws \Nette\Application\AbortException
41 60
     */
42
    public function __construct(TransliterationSearchModel $transliterationSearchModel, TransliterationRepository $transliterationRepository)
61
    public function __construct(
62
        TransliterationSearchModel $transliterationSearchModel,
63
        TransliterationRepository $transliterationRepository,
64
        LineRepository $lineRepository
65
    )
43 66
    {
44 67
        parent::__construct();
45 68
        $this->transliterationSearchModel = $transliterationSearchModel;
46 69
        $this->transliterationRepository = $transliterationRepository;
47
        $this->paginator = new Paginator(1, 10);
70
        $this->lineRepository = $lineRepository;
71

  
72
        if(!$this->page)
73
        {
74
            $this->page = 1;
75
        }
76

  
77
        if(!$this->limit)
78
        {
79
            $this->limit = EPageLimit::$defaultLimit;
80
        }
81
        $this->paginator = new Paginator($this->page, $this->limit);
48 82

  
49 83
        $this->searchTerms = $this->transliterationSearchModel->getSearchTerms();
50 84
        $this->totalCount = $this->transliterationRepository->getTransliterationsFulltextSearchTotalCount($this->searchTerms);
......
67 101

  
68 102
        $this->resultRows = $this->transliterationRepository->transliterationsFulltextSearch($this->searchTerms, $this->paginator->getOffset(), $this->paginator->getPageSize())->fetchAll();
69 103
        $this->paginator->setPageCount($this->totalCount);
104

  
70 105
        $this->highlight();
106
        if(in_array($this->adjacentLines, EAdjacentLines::$lines) && $this->adjacentLines > 0)
107
        {
108
            foreach ($this->resultRows as &$row)
109
            {
110
                $row['adjacentLines'] = $this->lineRepository->getAdjacentLines($row['line_id'], $row['surface_id'], $this->adjacentLines);
111
            }
112
        }
71 113

  
72 114
        $this->template->resultRows = $this->resultRows;
73 115
        $this->template->paginator = $this->paginator;
......
78 120
    {
79 121
        foreach ($this->resultRows as $resultRow)
80 122
        {
81
            $resultRow->transliteration = str_replace("<", "&lt;", $resultRow->transliteration);
82
            $resultRow->transliteration = str_replace(">", "&gt;", $resultRow->transliteration);
123
            //nejprve escape html znaků, které chceme nechat zobrazovat,
124
            //jelikož následně přidáváme html tagy pro vyznačení a výstup v latte nemůže být escapovaný
125
            $resultRow->transliteration = htmlspecialchars($resultRow->transliteration);
83 126

  
84 127
            $resultRow->transliteration = preg_replace(
85 128
                "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word1']) . "/",
86 129
                "<span class='found'>$0</span>",
87 130
                $resultRow->transliteration);
88 131

  
89
            //TODO: dořešit označování slov, když se zadají slova co se překrývají tak se tagy mezi sebou ruší,
90
            // viz např. vyhledávání slov 'šu' a 'as'
91

  
92
//            if($this->searchTerms['word2_condition'] === ESearchFormOperators::AND || $this->searchTerms['word2_condition'] === ESearchFormOperators::OR )
93
//            {
94
//                $resultRow->transliteration = preg_replace(
95
//                    "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word2']) . "/",
96
//                    "<span class='found'>$0</span>",
97
//                    $resultRow->transliteration);
98
//            }
99
//
100
//            if($this->searchTerms['word3_condition'] === ESearchFormOperators::AND || $this->searchTerms['word3_condition'] === ESearchFormOperators::OR )
101
//            {
102
//                $resultRow->transliteration = preg_replace(
103
//                    "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word3']) . "/",
104
//                    "<span class='found'>$0</span>",
105
//                    $resultRow->transliteration);
106
//            }
132
            /**
133
             * TODO: dořešit označování slov, když se zadají slova co se překrývají tak se tagy mezi sebou ruší,
134
             * viz např. vyhledávání slov 'šu' a 'as'
135
             */
136
            if($this->searchTerms['word2_condition'] === ESearchFormOperators::AND || $this->searchTerms['word2_condition'] === ESearchFormOperators::OR )
137
            {
138
                $resultRow->transliteration = preg_replace(
139
                    "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word2']) . "/",
140
                    "<span class='found'>$0</span>",
141
                    $resultRow->transliteration);
142
            }
143

  
144
            if($this->searchTerms['word3_condition'] === ESearchFormOperators::AND || $this->searchTerms['word3_condition'] === ESearchFormOperators::OR )
145
            {
146
                $resultRow->transliteration = preg_replace(
147
                    "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word3']) . "/",
148
                    "<span class='found'>$0</span>",
149
                    $resultRow->transliteration);
150
            }
107 151
        }
108 152
    }
109 153

  
110 154
    public function handleChangePage($page, $limit)
111 155
    {
156
        $this->page = $page;
157
        $this->limit = $limit;
112 158
        $this->paginator = new Paginator($page, $limit);
113 159
        $this->redrawControl('resultList');
114 160
    }
......
149 195
            if($lines !== null)
150 196
            {
151 197
                $this->adjacentLines = $lines;
198
                $this->paginator = new Paginator($this->page, $this->limit);
199

  
152 200
                $this['searchSettingsForm']->setDefaults(array('lines' => $lines));
153 201
                $this->redrawControl('resultList');
154 202

  
app/model/repository/LineRepository.php
39 39
            $transliterationId
40 40
        );
41 41
    }
42

  
43
    /**
44
     * Returns lines of a surface adjacent to passed line by id
45
     * @param $lineId
46
     * @param $surfaceId
47
     * @param $numberOfLines number of adjacent lines
48
     * @return array of arrays of lines before and lines after
49
     */
50
    public function getAdjacentLines($lineId, $surfaceId, $numberOfLines)
51
    {
52
        $adjacentLines['linesBefore'] = [];
53
        $adjacentLines['linesAfter'] = [];
54
        if($numberOfLines < 1)
55
        {
56
            return $adjacentLines;
57
        }
58

  
59
        $linesBefore = $this->getTable()
60
            ->select('line_number, transliteration')
61
            ->where('id_surface = ? AND id_line < ?', $surfaceId, $lineId)
62
            ->limit($numberOfLines)
63
            ->order('id_line DESC')
64
            ->fetchAll();
65
        $adjacentLines['linesBefore'] = array_reverse($linesBefore);
66

  
67
        $linesAfter = $this->getTable()
68
            ->select('line_number, transliteration')
69
            ->where('id_surface = ? AND id_line > ?', $surfaceId, $lineId)
70
            ->limit($numberOfLines)
71
            ->order('id_line ASC')
72
            ->fetchAll();
73
        $adjacentLines['linesAfter'] = $linesAfter;
74

  
75
        return $adjacentLines;
76
    }
77

  
42 78
}
app/model/repository/TransliterationRepository.php
118 118
        }
119 119

  
120 120
        $query = "SELECT 
121
                    t.id_transliteration as id, 
121
                    t.id_transliteration as id,
122
                    s.id_surface as surface_id, 
122 123
                    b.book_abrev, 
123 124
                    t.chapter, 
124 125
                    l.transliteration, 
126
                    l.id_line as line_id,
125 127
                    l.line_number 
126 128
                  FROM transliteration t
127 129
                  LEFT JOIN surface s ON s.id_transliteration = t.id_transliteration
www/css/front/style.css
66 66
}
67 67

  
68 68
.linefound {
69
    color: #003dc7;
69 70
    font-weight: 600;
70 71
}
71 72

  
72 73
.found {
73 74
    font-weight: 600;
74
    color: #003366;
75
    color: #003dc7;
75 76
}
76 77

  
77 78
.search-settings-select {
......
84 85

  
85 86
.results-found {
86 87
    margin-bottom: 0.2em;
88
}
89

  
90
.page-link {
91
    color: #003dc7;
92
}
93

  
94
.page-item.active .page-link {
95
    background-color: #003366;
96
    border-color: #003366;
97
}
98

  
99
.transliteration-link {
100
    font-weight: 400;
101
}
102

  
103
a {
104
    color: #003dc7;
87 105
}

Také k dispozici: Unified diff