19declare(strict_types=1);
23use PHPUnit\Framework\TestCase;
50 [
'rbac_id' => 37,
'obj_id' => 55,
'obj_type' =>
'type1'],
51 [
'rbac_id' => 123,
'obj_id' => 85,
'obj_type' =>
'type2'],
52 [
'rbac_id' => 98,
'obj_id' => 4,
'obj_type' =>
'type3']
60 foreach ($ressource_ids as $ressource_id) {
62 'rbac_id' => $ressource_id->obj_id,
63 'obj_id' => $ressource_id->sub_id,
64 'obj_type' => $ressource_id->type
68 return $array ===
$data;
91 protected array $paths = [];
92 protected bool $force_join_to_base_table =
false;
94 public function addPathAndGetColumn(
96 bool $force_join_to_base_table
98 if (!$this->force_join_to_base_table) {
99 $this->force_join_to_base_table = $force_join_to_base_table;
101 $path_string =
$path->toString();
102 $this->paths[] = $path_string;
103 return $path_string .
'_column';
106 public function getSelectForQuery():
string
108 if (empty($this->paths)) {
109 throw new \ilMDRepositoryException(
'no paths!');
111 return 'selected paths' . ($this->force_join_to_base_table ?
' (join forced)' :
'') .
112 ':[' . implode(
'~', $this->paths) .
']';
115 public function getTableAliasForFilters():
string
117 if (empty($this->paths)) {
118 throw new \ilMDRepositoryException(
'no paths!');
128 $paths_parser_factory,
131 public string $exposed_last_query;
136 protected array $db_result
138 $this->ressource_factory = $ressource_factory;
139 $this->paths_parser_factory = $paths_parser_factory;
142 protected function queryDB(
string $query): \Generator
144 $this->exposed_last_query = $query;
145 yield
from $this->db_result;
148 protected function quoteIdentifier(
string $identifier):
string
150 return '~identifier:' . $identifier .
'~';
153 protected function quoteText(
string $text):
string
155 return '~text:' . $text .
'~';
158 protected function quoteInteger(
int $integer):
string
160 return '~int:' . $integer .
'~';
174 protected bool $negated,
175 protected string
$path,
176 protected
Mode $mode,
177 protected string $value,
178 protected bool $mode_negated
182 public function isNegated(): bool
184 return $this->negated;
187 public function isJoin(): bool
192 public function basicProperties(): ?BasicPropertiesInterface
199 ) extends NullBasicProperties {
201 protected string $path,
202 protected Mode $mode,
203 protected string $value,
204 protected bool $mode_negated
208 public function path(): PathInterface
222 public function isModeNegated(): bool
224 return $this->mode_negated;
227 public function mode():
Mode
232 public function value(): string
239 public function joinProperties(): ?JoinPropertiesInterface
253 protected bool $negated,
255 protected array $clauses
259 public function isNegated(): bool
261 return $this->negated;
264 public function isJoin(): bool
269 public function basicProperties(): ?BasicPropertiesInterface
274 public function joinProperties(): ?JoinPropertiesInterface
276 return new class ($this->operator, $this->clauses) extends NullJoinProperties {
279 protected array $clauses
283 public function operator():
Operator
285 return $this->operator;
288 public function subClauses(): \Generator
290 yield
from $this->clauses;
312 return $this->obj_id;
317 return $this->sub_id;
329 $searcher = $this->getDatabaseSearcher([]);
330 $clause = $this->getBasicClause(
338 $result = $searcher->search($clause,
null,
null);
339 $this->assertNull($result->current());
344 $searcher = $this->getDatabaseSearcher(self::RESULT);
345 $clause = $this->getBasicClause(
353 $result = $searcher->search($clause,
null,
null);
355 $this->mockRessourceIDsMatchArrayData(self::RESULT, ...$result)
361 $searcher = $this->getDatabaseSearcher(self::RESULT);
362 $clause = $this->getBasicClause(
370 $result = iterator_to_array($searcher->search($clause,
null,
null));
372 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
373 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
374 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
375 'ORDER BY rbac_id, obj_id, obj_type',
376 $searcher->exposed_last_query
382 $searcher = $this->getDatabaseSearcher(self::RESULT);
383 $clause = $this->getBasicClause(
391 $result = iterator_to_array($searcher->search($clause,
null,
null));
393 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
394 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
395 'HAVING COUNT(CASE WHEN path_column LIKE ~text:%value%~ THEN 1 END) > 0 ' .
396 'ORDER BY rbac_id, obj_id, obj_type',
397 $searcher->exposed_last_query
403 $searcher = $this->getDatabaseSearcher(self::RESULT);
404 $clause = $this->getBasicClause(
412 $result = iterator_to_array($searcher->search($clause,
null,
null));
414 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
415 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
416 'HAVING COUNT(CASE WHEN path_column LIKE ~text:value%~ THEN 1 END) > 0 ' .
417 'ORDER BY rbac_id, obj_id, obj_type',
418 $searcher->exposed_last_query
424 $searcher = $this->getDatabaseSearcher(self::RESULT);
425 $clause = $this->getBasicClause(
433 $result = iterator_to_array($searcher->search($clause,
null,
null));
435 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
436 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
437 'HAVING COUNT(CASE WHEN path_column LIKE ~text:%value~ THEN 1 END) > 0 ' .
438 'ORDER BY rbac_id, obj_id, obj_type',
439 $searcher->exposed_last_query
445 $searcher = $this->getDatabaseSearcher(self::RESULT);
446 $clause = $this->getBasicClause(
454 $result = iterator_to_array($searcher->search($clause,
null,
null));
456 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
457 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
458 'HAVING COUNT(CASE WHEN NOT path_column = ~text:value~ THEN 1 END) > 0 ' .
459 'ORDER BY rbac_id, obj_id, obj_type',
460 $searcher->exposed_last_query
466 $searcher = $this->getDatabaseSearcher(self::RESULT);
467 $clause = $this->getBasicClause(
475 $result = iterator_to_array($searcher->search($clause,
null,
null));
477 'selected paths (join forced):[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
478 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
479 'HAVING NOT COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
480 'ORDER BY rbac_id, obj_id, obj_type',
481 $searcher->exposed_last_query
489 $searcher = $this->getDatabaseSearcher(self::RESULT);
490 $clause = $this->getBasicClause(
498 $result = iterator_to_array($searcher->search($clause,
null,
null));
500 'selected paths (join forced):[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
501 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
502 'HAVING COUNT(CASE WHEN path_column = ~text:~ THEN 1 END) > 0 ' .
503 'ORDER BY rbac_id, obj_id, obj_type',
504 $searcher->exposed_last_query
510 $searcher = $this->getDatabaseSearcher(self::RESULT);
511 $clause1 = $this->getBasicClause(
518 $clause2 = $this->getBasicClause(
525 $joined_clause = $this->getJoinedClause(
false,
Operator::OR, $clause1, $clause2);
527 $result = iterator_to_array($searcher->search($joined_clause,
null,
null));
529 'selected paths:[path1~path2] GROUP BY ~identifier:base_table~.rbac_id, ' .
530 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
531 'HAVING (COUNT(CASE WHEN path1_column = ~text:value1~ THEN 1 END) > 0 ' .
532 'OR COUNT(CASE WHEN path2_column LIKE ~text:value2%~ THEN 1 END) > 0) ' .
533 'ORDER BY rbac_id, obj_id, obj_type',
534 $searcher->exposed_last_query
540 $searcher = $this->getDatabaseSearcher(self::RESULT);
541 $clause1 = $this->getBasicClause(
548 $clause2 = $this->getBasicClause(
555 $joined_clause = $this->getJoinedClause(
false, Operator::AND, $clause1, $clause2);
557 $result = iterator_to_array($searcher->search($joined_clause,
null,
null));
559 'selected paths:[path1~path2] GROUP BY ~identifier:base_table~.rbac_id, ' .
560 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
561 'HAVING (COUNT(CASE WHEN path1_column LIKE ~text:%value1%~ THEN 1 END) > 0 ' .
562 'AND COUNT(CASE WHEN path2_column LIKE ~text:value2%~ THEN 1 END) > 0) ' .
563 'ORDER BY rbac_id, obj_id, obj_type',
564 $searcher->exposed_last_query
570 $searcher = $this->getDatabaseSearcher(self::RESULT);
571 $clause1 = $this->getBasicClause(
578 $clause2 = $this->getBasicClause(
585 $joined_clause = $this->getJoinedClause(
true, Operator::AND, $clause1, $clause2);
587 $result = iterator_to_array($searcher->search($joined_clause,
null,
null));
589 'selected paths:[path1~path2] GROUP BY ~identifier:base_table~.rbac_id, ' .
590 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
591 'HAVING NOT (COUNT(CASE WHEN path1_column LIKE ~text:%value1%~ THEN 1 END) > 0 ' .
592 'AND COUNT(CASE WHEN path2_column = ~text:value2~ THEN 1 END) > 0) ' .
593 'ORDER BY rbac_id, obj_id, obj_type',
594 $searcher->exposed_last_query
600 $searcher = $this->getDatabaseSearcher(self::RESULT);
601 $clause1 = $this->getBasicClause(
608 $clause2 = $this->getBasicClause(
615 $clause3 = $this->getBasicClause(
622 $joined_clause = $this->getJoinedClause(
626 $this->getJoinedClause(
634 $result = iterator_to_array($searcher->search($joined_clause,
null,
null));
636 'selected paths:[path1~path2~path3] GROUP BY ~identifier:base_table~.rbac_id, ' .
637 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
638 'HAVING (COUNT(CASE WHEN path1_column LIKE ~text:%value1%~ THEN 1 END) > 0 ' .
639 'AND NOT (COUNT(CASE WHEN path2_column = ~text:value2~ THEN 1 END) > 0 OR ' .
640 'COUNT(CASE WHEN path3_column LIKE ~text:%value3~ THEN 1 END) > 0)) ' .
641 'ORDER BY rbac_id, obj_id, obj_type',
642 $searcher->exposed_last_query
648 $searcher = $this->getDatabaseSearcher(self::RESULT);
649 $clause = $this->getBasicClause(
657 $result = iterator_to_array($searcher->search($clause, 37,
null));
659 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
660 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
661 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
662 'ORDER BY rbac_id, obj_id, obj_type LIMIT ~int:37~',
663 $searcher->exposed_last_query
669 $searcher = $this->getDatabaseSearcher(self::RESULT);
670 $clause = $this->getBasicClause(
678 $result = iterator_to_array($searcher->search($clause,
null, 16));
680 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
681 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
682 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
683 'ORDER BY rbac_id, obj_id, obj_type LIMIT ~int:' . PHP_INT_MAX .
'~ OFFSET ~int:16~',
684 $searcher->exposed_last_query
690 $searcher = $this->getDatabaseSearcher(self::RESULT);
691 $clause = $this->getBasicClause(
699 $result = iterator_to_array($searcher->search($clause, 37, 16));
701 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
702 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
703 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
704 'ORDER BY rbac_id, obj_id, obj_type LIMIT ~int:37~ OFFSET ~int:16~',
705 $searcher->exposed_last_query
711 $searcher = $this->getDatabaseSearcher(self::RESULT);
712 $clause = $this->getBasicClause(
721 $result = iterator_to_array($searcher->search($clause,
null,
null, $filter));
723 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
724 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
725 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
726 'ORDER BY rbac_id, obj_id, obj_type',
727 $searcher->exposed_last_query
733 $searcher = $this->getDatabaseSearcher(self::RESULT);
734 $clause = $this->getBasicClause(
743 $result = iterator_to_array($searcher->search($clause,
null,
null, $filter));
745 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
746 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
747 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
748 'AND ((~identifier:base_table~.rbac_id = ~int:37~)) ' .
749 'ORDER BY rbac_id, obj_id, obj_type',
750 $searcher->exposed_last_query
756 $searcher = $this->getDatabaseSearcher(self::RESULT);
757 $clause = $this->getBasicClause(
766 $result = iterator_to_array($searcher->search($clause,
null,
null, $filter));
768 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
769 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
770 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
771 'AND ((~identifier:base_table~.obj_id = ~int:15~)) ' .
772 'ORDER BY rbac_id, obj_id, obj_type',
773 $searcher->exposed_last_query
779 $searcher = $this->getDatabaseSearcher(self::RESULT);
780 $clause = $this->getBasicClause(
789 $result = iterator_to_array($searcher->search($clause,
null,
null, $filter));
791 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
792 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
793 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
794 'AND ((~identifier:base_table~.obj_type = ~text:some type~)) ' .
795 'ORDER BY rbac_id, obj_id, obj_type',
796 $searcher->exposed_last_query
802 $searcher = $this->getDatabaseSearcher(self::RESULT);
803 $clause = $this->getBasicClause(
810 $filter = $this->getFilter(37, 15,
'some type');
812 $result = iterator_to_array($searcher->search($clause,
null,
null, $filter));
814 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
815 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
816 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
817 'AND ((~identifier:base_table~.rbac_id = ~int:37~ AND ' .
818 '~identifier:base_table~.obj_id = ~int:15~ AND ' .
819 '~identifier:base_table~.obj_type = ~text:some type~)) ' .
820 'ORDER BY rbac_id, obj_id, obj_type',
821 $searcher->exposed_last_query
827 $searcher = $this->getDatabaseSearcher(self::RESULT);
828 $clause = $this->getBasicClause(
839 $result = iterator_to_array($searcher->search(
848 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
849 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
850 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
851 'AND ((~identifier:base_table~.rbac_id = ~int:37~ AND ~identifier:base_table~.obj_id = ~int:15~) ' .
852 'OR (~identifier:base_table~.obj_id = ~int:15~ AND ~identifier:base_table~.obj_type = ~text:some type~) ' .
853 'OR (~identifier:base_table~.rbac_id = ~int:37~ AND ~identifier:base_table~.obj_type = ~text:some type~)) ' .
854 'ORDER BY rbac_id, obj_id, obj_type',
855 $searcher->exposed_last_query
861 $searcher = $this->getDatabaseSearcher(self::RESULT);
862 $clause = $this->getBasicClause(
871 $result = iterator_to_array($searcher->search($clause,
null,
null, $filter));
873 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
874 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
875 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
876 'AND ((~identifier:base_table~.obj_id = ~identifier:base_table~.rbac_id)) ' .
877 'ORDER BY rbac_id, obj_id, obj_type',
878 $searcher->exposed_last_query
884 $searcher = $this->getDatabaseSearcher(self::RESULT);
885 $clause = $this->getBasicClause(
894 $result = iterator_to_array($searcher->search($clause,
null,
null, $filter));
896 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
897 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
898 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
899 'AND ((~identifier:base_table~.rbac_id = ~identifier:base_table~.obj_id)) ' .
900 'ORDER BY rbac_id, obj_id, obj_type',
901 $searcher->exposed_last_query
907 $searcher = $this->getDatabaseSearcher(self::RESULT);
908 $clause = $this->getBasicClause(
917 $result = iterator_to_array($searcher->search($clause,
null,
null, $filter));
919 'selected paths:[path] GROUP BY ~identifier:base_table~.rbac_id, ' .
920 '~identifier:base_table~.obj_id, ~identifier:base_table~.obj_type ' .
921 'HAVING COUNT(CASE WHEN path_column = ~text:value~ THEN 1 END) > 0 ' .
922 'AND ((~identifier:base_table~.rbac_id = ~identifier:base_table~.obj_type)) ' .
923 'ORDER BY rbac_id, obj_id, obj_type',
924 $searcher->exposed_last_query
__construct()
Constructor setup ILIAS global object @access public.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc