1 | <?php |
||
13 | class IdLookup implements EntityIdLookup { |
||
14 | |||
15 | private $labelTable; |
||
16 | private $aliasesTable; |
||
17 | |||
18 | 16 | public function __construct( TableQueryExecutor $labelTable, TableQueryExecutor $aliasesTable ) { |
|
22 | |||
23 | /** |
||
24 | * Returns the first matching entity id. Case insensitive. |
||
25 | * |
||
26 | * @param string $labelLanguageCode |
||
27 | * @param string $labelText |
||
28 | * |
||
29 | * @return string|null |
||
30 | * @throws TermStoreException |
||
31 | */ |
||
32 | 2 | public function getIdByLabel( $labelLanguageCode, $labelText ) { |
|
35 | |||
36 | /** |
||
37 | * Returns the first matching item id. Case insensitive. |
||
38 | * |
||
39 | * @param string $labelLanguageCode |
||
40 | * @param string $labelText |
||
41 | * |
||
42 | * @return string|null |
||
43 | * @throws TermStoreException |
||
44 | */ |
||
45 | 2 | public function getItemIdByLabel( $labelLanguageCode, $labelText ) { |
|
48 | |||
49 | /** |
||
50 | * Returns the first matching property id. Case insensitive. |
||
51 | * |
||
52 | * @param string $labelLanguageCode |
||
53 | * @param string $labelText |
||
54 | * |
||
55 | * @return string|null |
||
56 | * @throws TermStoreException |
||
57 | */ |
||
58 | 2 | public function getPropertyIdByLabel( $labelLanguageCode, $labelText ) { |
|
61 | |||
62 | /** |
||
63 | * @param string $labelLanguageCode |
||
64 | * @param string $labelText |
||
65 | * @param string|null $entityTypeFilter |
||
66 | * |
||
67 | * @return string|null |
||
68 | * @throws TermStoreException |
||
69 | */ |
||
70 | 12 | private function getEntityIdByLabel( $labelLanguageCode, $labelText, $entityTypeFilter = null ) { |
|
71 | $conditions = [ |
||
72 | 12 | 'text_lowercase' => strtolower( $labelText ), |
|
73 | 12 | 'language' => $labelLanguageCode, |
|
74 | ]; |
||
75 | |||
76 | 12 | if ( $entityTypeFilter !== null ) { |
|
77 | 8 | $conditions['entity_type'] = $entityTypeFilter; |
|
78 | } |
||
79 | |||
80 | try { |
||
81 | 12 | return $this->labelTable->selectOneField( |
|
82 | 12 | 'entity_id', |
|
83 | 12 | $conditions |
|
84 | ); |
||
85 | } |
||
86 | catch ( DBALException $ex ) { |
||
87 | throw new TermStoreException( $ex->getMessage(), $ex ); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Returns the first matching entity id. Case insensitive. |
||
93 | * |
||
94 | * @param string $languageCode |
||
95 | * @param string $termText |
||
96 | * |
||
97 | * @return string|null |
||
98 | * @throws TermStoreException |
||
99 | */ |
||
100 | 2 | public function getIdByText( $languageCode, $termText ) { |
|
103 | |||
104 | /** |
||
105 | * Returns the first matching item id. Case insensitive. |
||
106 | * |
||
107 | * @param string $languageCode |
||
108 | * @param string $termText |
||
109 | * |
||
110 | * @return string|null |
||
111 | * @throws TermStoreException |
||
112 | */ |
||
113 | 2 | public function getItemIdByText( $languageCode, $termText ) { |
|
116 | |||
117 | /** |
||
118 | * Returns the first matching property id. Case insensitive. |
||
119 | * |
||
120 | * @param string $languageCode |
||
121 | * @param string $termText |
||
122 | * |
||
123 | * @return string|null |
||
124 | * @throws TermStoreException |
||
125 | */ |
||
126 | 2 | public function getPropertyIdByText( $languageCode, $termText ) { |
|
129 | |||
130 | /** |
||
131 | * @param string $languageCode |
||
132 | * @param string $termText |
||
133 | * @param string|null $entityTypeFilter |
||
134 | * |
||
135 | * @return string|null |
||
136 | * @throws TermStoreException |
||
137 | */ |
||
138 | 6 | private function getEntityIdByText( $languageCode, $termText, $entityTypeFilter = null ) { |
|
147 | |||
148 | /** |
||
149 | * @param string $aliasLanguageCode |
||
150 | * @param string $aliasText |
||
151 | * @param string|null $entityTypeFilter |
||
152 | * |
||
153 | * @return string|null |
||
154 | * @throws TermStoreException |
||
155 | */ |
||
156 | 3 | private function getIdByAlias( $aliasLanguageCode, $aliasText, $entityTypeFilter = null ) { |
|
176 | |||
177 | } |