Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 7566bde2

Přidáno uživatelem Jan Šedivý před asi 6 roky(ů)

Re #7328 výsledky vyhledávání textů s pokročilými filtry

Zobrazit rozdíly:

app/FrontModule/component/Transliteration/TransliterationSearchForm.php
24 24
    /**
25 25
     * TransliterationSearchForm constructor.
26 26
     * @param TransliterationSearchModel $transliterationSearchModel
27
     * @param BookTypeRepository $bookTypeRepository
28
     * @param OriginRepository $originRepository
27 29
     */
28 30
    public function __construct(
29 31
        TransliterationSearchModel $transliterationSearchModel,
......
67 69
        $form->addSelect('type_condition', '', ESearchFormOperators::$selectEqualsOperatorLabels)
68 70
            ->setDefaultValue(ESearchFormOperators::IS);
69 71
        $form->addSelect('type', 'Type', $this->bookTypeRepository->getTypesForSelect());
70
//            ->setDefaultValue(ESearchFormOperators::IS);
71 72
        $form->addSelect('origin_condition', '', ESearchFormOperators::$selectEqualsOperatorLabels)
72 73
            ->setDefaultValue(ESearchFormOperators::IS);
73 74
        $form->addSelect('origin', 'Origin', $this->originRepository->getOriginsForSelect());
74 75

  
75

  
76 76
        $form->addSelect('registration_condition', '', ESearchFormOperators::$selectLikeOperatorLabels)
77 77
            ->setDefaultValue(ESearchFormOperators::CONTAINS);
78 78
        $form->addText('registration', 'Registration / Ex. number');
app/model/repository/TransliterationRepository.php
78 78
            }
79 79
        }
80 80

  
81
        if($queryParams['book'])
82
        {
83
            $where .= ' AND b.book_name' . ESearchFormOperators::$selectLikeOperatorQueryCondition[$queryParams['book_condition']];
84
            $whereArgs[] = $this->prepareQueryArgByOperator($queryParams['book'], $queryParams['book_condition']);
85
        }
86

  
87
        if($queryParams['museum'])
88
        {
89
            $where .= ' AND t.museum_no' . ESearchFormOperators::$selectLikeOperatorQueryCondition[$queryParams['museum_condition']];
90
            $whereArgs[] = $this->prepareQueryArgByOperator($queryParams['museum'], $queryParams['museum_condition']);
91
        }
92

  
93
        if($queryParams['type'])
94
        {
95
            $where .= ' AND t.id_book_type' . ESearchFormOperators::$selectEqualsOperatorQueryCondition[$queryParams['type_condition']];
96
            $whereArgs[] = $queryParams['type'];
97
        }
98

  
99
        if($queryParams['origin'])
100
        {
101
            $where .= ' AND t.id_origin' . ESearchFormOperators::$selectEqualsOperatorQueryCondition[$queryParams['origin_condition']];
102
            $whereArgs[] = $queryParams['origin'];
103
        }
104

  
105
        if($queryParams['registration'])
106
        {
107
            $where .= ' AND t.reg_no' . ESearchFormOperators::$selectLikeOperatorQueryCondition[$queryParams['registration_condition']];
108
            $whereArgs[] = $this->prepareQueryArgByOperator($queryParams['registration'], $queryParams['registration_condition']);
109
        }
110

  
111
        if($queryParams['date'])
112
        {
113
            $where .= ' AND t.date' . ESearchFormOperators::$selectLikeOperatorQueryCondition[$queryParams['date_condition']];
114
            $whereArgs[] = $this->prepareQueryArgByOperator($queryParams['date'], $queryParams['date_condition']);
115
        }
116

  
81 117
        $query = "SELECT 
82 118
                    t.id_transliteration as id, 
83 119
                    b.book_abrev, 
......
87 123
                  FROM transliteration t
88 124
                  LEFT JOIN surface s ON s.id_transliteration = t.id_transliteration
89 125
                  LEFT JOIN line l ON l.id_surface = s.id_surface
90
                  LEFT JOIN book b on t.id_book = b.id_book
126
                  LEFT JOIN book b ON t.id_book = b.id_book
91 127
                  WHERE " . $where;
92 128

  
93 129
        return $this->context->queryArgs($query, $whereArgs);
......
109 145
        return $regex;
110 146
    }
111 147

  
148
    /**
149
     * Připraví argument pro dotaz podle zvoleného operátoru
150
     * @param $word string
151
     * @param $op string operátor pro porovnání s ESearchFormOperators
152
     * @return string
153
     */
154
    private function prepareQueryArgByOperator($word, $op)
155
    {
156
        switch ($op)
157
        {
158
            case ESearchFormOperators::CONTAINS:
159
                return '%' . $word . '%';
160
            case ESearchFormOperators::BEGINS_WITH:
161
                return $word . '%';
162
            case ESearchFormOperators::ENDS_WITH:
163
                return '%' . $word;
164
            default:
165
                return $word;
166
        }
167
    }
168

  
112 169
    /**
113 170
     * @param int $id id transliterace
114 171
     * @return bool|\Nette\Database\IRow|\Nette\Database\Row

Také k dispozici: Unified diff