28 if (empty($params[
'GROUP_BY']))
35 $query->addSelect($params[
'GROUP_BY']);
36 $query->addGroup($params[
'GROUP_BY']);
38 if (empty($params[
'CURRENT_LANG']))
42 $currentLanguage = $params[
'CURRENT_LANG'];
44 if (empty($params[
'LANGUAGES']))
46 $languages = Translate\Config::getEnabledLanguages();
50 $languages = $params[
'LANGUAGES'];
52 \usort($languages,
function ($langId) use ($currentLanguage) {
53 return $langId === $currentLanguage ? 0 : 1;
55 $languageUpperKeys = \array_combine($languages, \array_map(
'mb_strtoupper', $languages));
57 foreach ($languageUpperKeys as $langId => $alias)
60 $query->addSelect(
new Main\ORM\Fields\
ExpressionField(
"{$alias}_CNT",
"SUM({$alias}_CNT)"));
63 $query->addSelect(
new Main\ORM\Fields\
ExpressionField(
"{$alias}_FILE_CNT",
"SUM({$alias}_FILE_CNT)"));
65 $query->addSelect(
new Main\ORM\Fields\
ExpressionField(
"{$alias}_FILE_EXCESS",
"SUM({$alias}_FILE_EXCESS)"));
67 $query->addSelect(
new Main\ORM\Fields\
ExpressionField(
"{$alias}_EXCESS",
"SUM({$alias}_EXCESS)"));
69 if ($langId != $currentLanguage)
72 $query->addSelect(
new Main\ORM\Fields\
ExpressionField(
"{$alias}_FILE_DEFICIENCY",
"SUM({$alias}_FILE_DEFICIENCY)"));
74 $query->addSelect(
new Main\ORM\Fields\
ExpressionField(
"{$alias}_DEFICIENCY",
"SUM({$alias}_DEFICIENCY)"));
96 if (empty($params[
'PARENT_ID']))
100 $topIndexPathId = (int)$params[
'PARENT_ID'];
102 if (empty($params[
'CURRENT_LANG']))
106 $currentLanguage = $params[
'CURRENT_LANG'];
108 $className =
"Aggregate_{$topIndexPathId}_{$currentLanguage}";
110 if (empty($params[
'LANGUAGES']))
112 $languages = Translate\Config::getEnabledLanguages();
116 $languages = $params[
'LANGUAGES'];
118 \usort($languages,
function ($langId) use ($currentLanguage) {
119 return $langId === $currentLanguage ? 0 : 1;
122 $className .=
"_". \implode(
'', $languages);
124 if (!empty($params[
'PATH_LIST']))
126 $className .=
"_". \md5(\implode(
'', $params[
'PATH_LIST']));
129 $languageUpperKeys = \array_combine($languages, \array_map(
'mb_strtoupper', $languages));
131 if (!isset(self::$entities[$className]))
133 $entity = Index\Internals\PathTreeTable::getEntity();
136 $query->registerRuntimeField(
new Main\ORM\Fields\Relations\
Reference(
138 Translate\Index\Internals\PathIndexTable::class,
139 Main\ORM\
Query\Join::on(
'ref.ID',
'=',
'this.PATH_ID')->where(
'ref.IS_DIR',
'=',
'Y'),
140 [
'join_type' =>
'INNER']
144 $query->registerRuntimeField(
new Main\ORM\Fields\Relations\
Reference(
146 Translate\Index\Internals\PathTreeTable::class,
147 Main\ORM\
Query\Join::on(
'ref.PARENT_ID',
'=',
'this.PATH_ID'),
148 [
'join_type' =>
'INNER']
150 $query->registerRuntimeField(
new Main\ORM\Fields\Relations\
Reference(
152 Translate\Index\Internals\PathIndexTable::class,
153 Main\ORM\
Query\Join::on(
'ref.ID',
'=',
'this.FILE_LIST.PATH_ID')->where(
'ref.IS_DIR',
'=',
'N'),
154 [
'join_type' =>
'INNER']
158 $query->addSelect(
'FOLDER_NODE.PATH',
'PARENT_PATH');
159 $query->addSelect(
'FILE_NODE.OBLIGATORY_LANGS',
'OBLIGATORY_LANGS');
160 $query->addSelect(
'FILE_NODE.PATH',
'FILE_PATH');
163 foreach ($languageUpperKeys as $langId => $alias)
165 $tblAlias =
"File{$alias}";
167 $query->registerRuntimeField(
new Main\ORM\Fields\Relations\
Reference(
169 Translate\Index\Internals\FileIndexTable::class,
170 Main\ORM\
Query\Join::on(
'ref.PATH_ID',
'=',
'this.FILE_NODE.ID')->where(
'ref.LANG_ID',
'=', $langId),
171 [
'join_type' =>
'LEFT']
176 "@{$alias}_OBLI := case when (INSTR(IFNULL(%s, '{$langId}'), '{$langId}') > 0) then 1 else 0 end",
177 'FILE_NODE.OBLIGATORY_LANGS'
181 if ($langId == $currentLanguage)
186 '@ETHALON_CNT := IFNULL(%s, 0)',
187 "{$tblAlias}.PHRASE_COUNT"
192 "case when (@ETHALON_CNT > 0) then 1 else 0 end"
196 "{$alias}_FILE_EXCESS",
197 "case when (@ETHALON_CNT > 0) and (@{$alias}_OBLI = 0) then 1 else 0 end"
202 "case when (@ETHALON_CNT > 0) and (@{$alias}_OBLI = 0) then @ETHALON_CNT else 0 end"
210 "@{$alias}_CNT := IFNULL(%s, 0)",
211 [
"{$tblAlias}.PHRASE_COUNT"]
216 "@{$alias}_DIFF := @{$alias}_CNT - @ETHALON_CNT"
221 "case when (@{$alias}_CNT > 0) then 1 else 0 end"
225 "{$alias}_FILE_DEFICIENCY",
226 "case when (@{$alias}_CNT = 0) and (@ETHALON_CNT > 0) AND (@{$alias}_OBLI = 1) then 1 else 0 end"
230 "{$alias}_FILE_EXCESS",
231 "case when (@{$alias}_CNT > 0) and (@ETHALON_CNT = 0) then 1 ".
232 "when (@{$alias}_CNT > 0) and (@ETHALON_CNT > 0) AND (@{$alias}_OBLI = 0) then 1 ".
238 "case when (@{$alias}_CNT > 0) and (@ETHALON_CNT = 0) then @{$alias}_CNT ".
239 "when (@{$alias}_CNT > 0) and (@ETHALON_CNT > 0) AND (@{$alias}_DIFF > 0) and (@{$alias}_OBLI = 1) then @{$alias}_DIFF ".
240 "when (@{$alias}_CNT > 0) and (@ETHALON_CNT > 0) and (@{$alias}_OBLI = 0) then @{$alias}_CNT ".
245 "{$alias}_DEFICIENCY",
246 "case when (@{$alias}_CNT = 0) and (@ETHALON_CNT > 0) AND (@{$alias}_OBLI = 1) then @ETHALON_CNT ".
247 "when (@{$alias}_CNT > 0) and (@ETHALON_CNT > 0) AND (@{$alias}_DIFF < 0) and (@{$alias}_OBLI = 1) then - @{$alias}_DIFF ".
252 unset($langId, $langUpper, $alias, $tblAlias);
254 $query->addFilter(
'=PARENT_ID', $topIndexPathId);
255 $query->addFilter(
'=DEPTH_LEVEL',
'1');
257 if (!empty($params[
'PATH_LIST']))
259 $query->addFilter(
'=FOLDER_NODE.PATH', $params[
'PATH_LIST']);
263 'PARENT_ID' => [
'data_type' =>
'integer'],
264 'PARENT_PATH' => [
'data_type' =>
'string'],
265 'FILE_PATH' => [
'data_type' =>
'string'],
266 'OBLIGATORY_LANGS' => [
'data_type' =>
'string'],
269 foreach ($languageUpperKeys as $langId => $alias)
271 $query->addSelect(
"{$alias}_CNT");
272 $query->addSelect(
"{$alias}_FILE_CNT");
273 $query->addSelect(
"{$alias}_FILE_EXCESS");
274 $query->addSelect(
"{$alias}_EXCESS");
276 $fields[
"{$alias}_CNT"] = [
'data_type' =>
'integer'];
277 $fields[
"{$alias}_FILE_CNT"] = [
'data_type' =>
'integer'];
278 $fields[
"{$alias}_FILE_EXCESS"] = [
'data_type' =>
'integer'];
279 $fields[
"{$alias}_EXCESS"] = [
'data_type' =>
'integer'];
281 if ($langId != $currentLanguage)
283 $query->addSelect(
"{$alias}_DIFF");
284 $query->addSelect(
"{$alias}_FILE_DEFICIENCY");
285 $query->addSelect(
"{$alias}_DEFICIENCY");
287 $fields[
"{$alias}_DIFF"] = [
'data_type' =>
'integer'];
288 $fields[
"{$alias}_FILE_DEFICIENCY"] = [
'data_type' =>
'integer'];
289 $fields[
"{$alias}_DEFICIENCY"] = [
'data_type' =>
'integer'];
293 self::$entities[$className] = Main\ORM\Entity::compileEntity(
297 'table_name' =>
'('.$query->getQuery().
')',
298 'namespace' => __NAMESPACE__,