17 public static function query($params = [])
19 [$select, $runtime, $filter] = self::processParams($params);
22 $entity = Index\Internals\PathIndexTable::getEntity();
23 foreach ($runtime as $field)
25 $entity->addField($field);
38 public static function getCount($filterIn):
int
40 [$select, $runtime, $filter] = self::processParams([
'filter' => $filterIn]);
43 $entity = Index\Internals\PathIndexTable::getEntity();
44 foreach ($runtime as $field)
46 $entity->addField($field);
55 $result = $query->exec()->fetch();
57 return (
int)$result[
'CNT'];
69 [$select, $runtime, $filter] = self::processParams($params);
72 'select' => \array_merge(
76 'IS_LANG' =>
'IS_LANG',
82 'runtime' => $runtime,
86 if (isset($params[
'order']))
88 $executeParams[
'order'] = $params[
'order'];
90 if (isset($params[
'offset']))
92 $executeParams[
'offset'] = $params[
'offset'];
94 if (isset($params[
'limit']))
96 $executeParams[
'limit'] = $params[
'limit'];
98 if (isset($params[
'count_total']))
100 $executeParams[
'count_total'] =
true;
103 return Index\Internals\PathIndexTable::getList($executeParams);
113 private static function processParams($params): array
115 $select = $runtime = $filterIn = $filterOut = [];
116 if (isset($params[
'filter']))
118 if (\is_object($params[
'filter']))
120 $filterIn = clone $params[
'filter'];
124 $filterIn = $params[
'filter'];
128 $enabledLanguages = Translate\Config::getEnabledLanguages();
129 $languageUpperKeys = \array_combine($enabledLanguages, \array_map(
'mb_strtoupper', $enabledLanguages));
131 $selectedLanguages = [];
132 foreach ($languageUpperKeys as $langId => $langUpper)
134 $alias =
"{$langUpper}_LANG";
135 if (isset($params[
'select']) && \in_array($alias, $params[
'select']))
137 $selectedLanguages[] = $langId;
139 elseif (isset($params[
'order'], $params[
'order'][$alias]))
141 $selectedLanguages[] = $langId;
143 elseif (isset($filterIn[
'LANGUAGE_ID']) && $filterIn[
'LANGUAGE_ID'] == $langId)
145 $selectedLanguages[] = $langId;
148 if (empty($selectedLanguages))
150 $selectedLanguages = $enabledLanguages;
154 if (!empty($filterIn[
'PATH']))
156 $topIndexPath = Index\PathIndex::loadByPath($filterIn[
'PATH']);
157 if ($topIndexPath instanceof Index\PathIndex)
159 $filterOut[
'=DESCENDANTS.PARENT_ID'] = $topIndexPath->getId();
162 unset($filterIn[
'PATH']);
164 foreach ($languageUpperKeys as $langId => $langUpper)
167 !\in_array($langId, $selectedLanguages) &&
174 $alias =
"{$langUpper}_LANG";
175 $tblAlias =
"File{$alias}";
177 $searchByLang =
false;
178 if (!empty($filterIn[
'LANGUAGE_ID']) && $langId == $filterIn[
'LANGUAGE_ID'])
180 $searchByLang =
true;
183 $runtime[] =
new Main\ORM\Fields\Relations\Reference(
185 Index\Internals\FileIndexTable::class,
186 Main\ORM\Query\Join::on(
'ref.PATH_ID',
'=',
'this.ID')->where(
'ref.LANG_ID',
'=', $langId),
187 [
'join_type' => $searchByLang ?
'INNER' :
'LEFT']
190 $select[$alias] =
"{$tblAlias}.PHRASE_COUNT";
192 unset($filterIn[
'LANGUAGE_ID']);
199 foreach ($languageUpperKeys as $langId => $langUpper)
203 $alias =
"{$langUpper}_LANG";
204 $fields[] =
"File{$alias}.ID";
205 $statement .=
' WHEN %s IS NOT NULL THEN 1 ';
208 unset($langId, $langUpper, $alias, $tblAlias, $fieldAlias);
211 new Main\ORM\Fields\ExpressionField(
213 "CASE {$statement} ELSE 0 END",
216 $select[] =
'IS_EXIST';
217 unset($statement, $fields);
237 $filterOut[
'=IS_DIR'] =
'N';
238 if (!empty($filterIn[
'FOLDER_NAME']))
240 $filterOut[
'%=PATH'] =
'%/'. $filterIn[
'FOLDER_NAME'].
'/%';
244 if (!empty($filterIn[
'FILE_NAME']))
246 $filterOut[
'%NAME'] = $filterIn[
'FILE_NAME'];
248 unset($filterIn[
'FILE_NAME'], $filterIn[
'FOLDER_NAME']);
250 $replaceLangId =
static function(&$val)
252 $val = Translate\IO\Path::replaceLangId($val,
'#LANG_ID#');
254 $trimSlash =
static function(&$val)
256 if (Translate\
IO\Path::isPhpFile($val))
258 $val =
'/'. \trim($val,
'/');
262 $val =
'/'. \trim($val,
'/').
'/%';
266 if (!empty($filterIn[
'INCLUDE_PATHS']))
268 $pathIncludes = \preg_split(
"/[\r\n\t,; ]+/".\BX_UTF_PCRE_MODIFIER, $filterIn[
'INCLUDE_PATHS']);
269 $pathIncludes = \array_filter($pathIncludes);
270 if (\count($pathIncludes) > 0)
272 $pathPathIncludes = [];
273 $pathNameIncludes = [];
274 foreach ($pathIncludes as $testPath)
276 if (!empty($testPath) && \trim($testPath) !==
'')
278 if (\mb_strpos($testPath,
'/') ===
false)
280 $pathNameIncludes[] = $testPath;
284 $pathPathIncludes[] = $testPath;
288 if (\count($pathNameIncludes) > 0 && \count($pathPathIncludes) > 0)
290 \array_walk($pathNameIncludes, $replaceLangId);
291 \array_walk($pathPathIncludes, $replaceLangId);
292 \array_walk($pathPathIncludes, $trimSlash);
295 '%=NAME' => $pathNameIncludes,
296 '%=PATH' => $pathPathIncludes,
299 elseif (\count($pathNameIncludes) > 0)
301 \array_walk($pathNameIncludes, $replaceLangId);
304 '%=NAME' => $pathNameIncludes,
305 '%=PATH' => $pathNameIncludes,
308 elseif (\count($pathPathIncludes) > 0)
310 \array_walk($pathPathIncludes, $replaceLangId);
311 \array_walk($pathPathIncludes, $trimSlash);
312 $filterOut[
'%=PATH'] = $pathPathIncludes;
315 unset($testPath, $pathIncludes, $pathNameIncludes, $pathPathIncludes);
317 if (!empty($filterIn[
'EXCLUDE_PATHS']))
319 $pathExcludes = \preg_split(
"/[\r\n\t,; ]+/".\BX_UTF_PCRE_MODIFIER, $filterIn[
'EXCLUDE_PATHS']);
320 $pathExcludes = \array_filter($pathExcludes);
321 if (\count($pathExcludes) > 0)
323 $pathPathExcludes = [];
324 $pathNameExcludes = [];
325 foreach ($pathExcludes as $testPath)
327 if (!empty($testPath) && \trim($testPath) !==
'')
329 if (\mb_strpos($testPath,
'/') ===
false)
331 $pathNameExcludes[] = $testPath;
335 $pathPathExcludes[] = $testPath;
339 if (\count($pathNameExcludes) > 0 && \count($pathPathExcludes) > 0)
341 \array_walk($pathNameExcludes, $replaceLangId);
342 \array_walk($pathPathExcludes, $replaceLangId);
343 \array_walk($pathPathExcludes, $trimSlash);
346 '!=%NAME' => $pathNameExcludes,
347 '!=%PATH' => $pathPathExcludes,
350 elseif (\count($pathNameExcludes) > 0)
352 \array_walk($pathNameExcludes, $replaceLangId);
355 '!=%NAME' => $pathNameExcludes,
356 '!=%PATH' => $pathNameExcludes,
359 elseif (\count($pathPathExcludes) > 0)
361 \array_walk($pathPathExcludes, $replaceLangId);
362 \array_walk($pathPathExcludes, $trimSlash);
363 $filterOut[
"!=%PATH"] = $pathPathExcludes;
366 unset($testPath, $pathExcludes, $pathPathExcludes, $pathNameExcludes);
368 unset($filterIn[
'INCLUDE_PATHS'], $filterIn[
'EXCLUDE_PATHS']);
388 foreach ($filterIn as $key => $value)
390 if (\in_array($key, [
'tabId',
'FILTER_ID',
'PRESET_ID',
'FILTER_APPLIED',
'FIND']))
394 $filterOut[$key] = $value;
397 return [$select, $runtime, $filterOut];