19declare(strict_types=1);
34 private ?
int $id =
null;
131 $this->original_taxonomy_filter = $filter;
137 return empty($this->original_taxonomy_filter) ? null : serialize($this->original_taxonomy_filter);
143 $this->original_taxonomy_filter = empty($value) ? [] : unserialize($value);
161 $this->mapped_taxonomy_filter = array_filter(
163 static fn(mixed $value,
int|
string $key):
bool => (
int) $key > 0 || !is_array($value),
164 ARRAY_FILTER_USE_BOTH
170 return empty($this->mapped_taxonomy_filter) ? null : serialize($this->mapped_taxonomy_filter);
175 $this->mapped_taxonomy_filter = [];
176 if ($value ===
null || $value ===
'') {
180 $filter = unserialize($value, [
'allowed_classes' =>
false]);
181 if (!is_array($filter)) {
186 foreach ($filter as $tax_id => $node_ids) {
195 $this->mapped_taxonomy_filter = [];
196 foreach ($this->original_taxonomy_filter as $tax_id => $node_ids) {
197 $mapped_node_ids = [];
200 if ($mapped_taxonomy_id ===
null || $mapped_taxonomy_id < 1) {
204 foreach ($node_ids as $node_id) {
206 if ($mapped_node_id !==
null) {
207 $mapped_node_ids[] = $mapped_node_id;
210 $this->mapped_taxonomy_filter[$mapped_taxonomy_id] = $mapped_node_ids;
229 return empty($this->type_filter) ? null : serialize($this->type_filter);
237 $this->type_filter = empty($value) ? [] : unserialize($value);
252 return empty($this->lifecycle_filter) ? null : serialize($this->lifecycle_filter);
257 $this->lifecycle_filter = empty($db_value) ? [] : unserialize($db_value);
268 $map[$row[
'question_type_id']] = $row[
'type_tag'];
272 foreach ($this->type_filter as $type_id) {
273 if (isset($map[$type_id])) {
274 $tags[] = $map[$type_id];
289 $map[$row[
'type_tag']] = $row[
'question_type_id'];
292 $this->type_filter = [];
293 foreach ($tags as $type_tag) {
294 if (isset($map[$type_tag])) {
295 $this->type_filter[] = $map[$type_tag];
324 foreach ($data_array as $field => $value) {
327 $this->
setId($value);
341 case 'pool_quest_count':
344 case 'origin_tax_filter':
347 case 'mapped_tax_filter':
353 case 'lifecycle_filter':
369 $res = $this->db->queryF(
370 "SELECT * FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
375 while ($row = $this->db->fetchAssoc(
$res)) {
386 if ($this->
getId()) {
401 $this->db->manipulateF(
402 "DELETE FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
411 'tst_rnd_quest_set_qpls',
413 'test_fi' => [
'integer', $test_id],
414 'pool_fi' => [
'integer', $this->
getPoolId()],
427 'def_id' => [
'integer', $this->
getId()]
434 $next_id = $this->db->nextId(
'tst_rnd_quest_set_qpls');
436 $this->db->insert(
'tst_rnd_quest_set_qpls', [
437 'def_id' => [
'integer', $next_id],
438 'test_fi' => [
'integer', $test_id],
439 'pool_fi' => [
'integer', $this->
getPoolId()],
452 $this->
setId($next_id);
462 $path->enableTextOnly(
true);
466 $poolInfoLabel = sprintf(
467 $lng->txt(
'tst_random_question_set_source_questionpool_summary_string'),
468 $this->getPoolTitle(),
470 $this->getPoolQuestionCount()
473 return $poolInfoLabel;
482 ): array|float|bool|
int|string|null {
484 'id' => $transformations->normalize(new
Id($this->
getId(),
'rnd_src_pool_def')),
485 'pool_id' => $transformations->normalize(new
Id($this->
getPoolId(),
'qpl')),
493 'taxonomy_filter' => [],
494 'mapped_taxonomy_filter' => [],
498 $normalized[
'taxonomy_filter'][] = [
499 'tax_id' => $transformations->
normalize(
new Id($tax_id,
'tax')),
500 'node_ids' => array_map(
501 static fn($node_id): mixed => $transformations->
normalize(
new Id($node_id,
'tax_node')),
508 $normalized[
'mapped_taxonomy_filter'][] = [
509 'tax_id' => $transformations->
normalize(
new Id($tax_id,
'mapped_tax')),
510 'node_ids' => array_map(
511 static fn($node_id): mixed => $transformations->
normalize(
new Id($node_id,
'mapped_tax_node')),
525 $clone = clone $this;
526 $clone->setId($transformations->
denormalize($normalized[
'id'], Id::class)->getId());
527 $clone->setPoolId($transformations->
denormalize($normalized[
'pool_id'], Id::class)->getId());
528 $clone->setPoolTitle($transformations->
string($normalized[
'pool_title']));
529 $clone->setPoolPath($transformations->
string($normalized[
'pool_path']));
530 $clone->setQuestionAmount($transformations->
nullableInt($normalized[
'quest_amount']));
531 $clone->setPoolQuestionCount($transformations->
nullableInt($normalized[
'pool_quest_count']));
532 $clone->setSequencePosition($transformations->
int($normalized[
'position']));
533 $clone->setTypeFilterFromTypeTags($normalized[
'type_filter']);
534 $clone->setLifecycleFilter($normalized[
'lifecycle_filter']);
536 $taxonomy_filter = [];
537 foreach ($normalized[
'taxonomy_filter'] as $item) {
538 $tax_id = $transformations->
denormalize($item[
'tax_id'], Id::class)->getId();
539 $taxonomy_filter[$tax_id] = array_map(
540 static fn($node_id): mixed => $transformations->
denormalize($node_id, Id::class)->getId(),
544 $clone->setOriginalTaxonomyFilter($taxonomy_filter);
546 $mapped_taxonomy_filter = [];
547 foreach (($normalized[
'mapped_taxonomy_filter'] ?? []) as $item) {
548 $tax_id = $transformations->
denormalize($item[
'tax_id'], Id::class)->getId();
549 $mapped_taxonomy_filter[$tax_id] = array_map(
550 static fn($node_id): mixed => $transformations->
denormalize($node_id, Id::class)->getId(),
554 $clone->setMappedTaxonomyFilter($mapped_taxonomy_filter);
Wrapper object for an object identifier and an optional object type the identifier belongs to.
static _getQuestionTypes($all_tags=false, $fixOrder=false, $withDeprecatedTypes=true)
static _lookupObjId(int $ref_id)
getMappedTaxonomyId(int $original_taxonomy_id)
getMappedTaxNodeId(int $original_tax_node_id)
initFromArray(array $data_array)
getMappedTaxonomyFilter()
get the mapped taxonomy filter conditions
getOriginalTaxonomyFilterForDbValue()
cloneToDbForTestId(int $test_id)
setTypeFilterFromTypeTags(array $tags)
Set the type filter from a list of type tags.
setOriginalTaxonomyFilter(array $filter=[])
setOriginalTaxonomyFilterFromDbValue(?string $value)
updateDbRecord(int $test_id)
setMappedTaxonomyFilterFromDbValue(?string $value)
setTypeFilter(array $type_filter=[])
setLifecycleFilterFromDbValue(?string $db_value)
setPoolQuestionCount(?int $pool_question_count)
array $original_taxonomy_filter
setLifecycleFilter(array $lifecycle_filter)
array $mapped_taxonomy_filter
getMappedTaxonomyFilterForDbValue()
setMappedTaxonomyFilter(array $filter=[])
set the original taxonomy filter condition
getTypeFilterAsTypeTags()
Get the type filter as a list of type tags.
getPoolInfoLabel(ilLanguage $lng)
setPoolPath(string $pool_path)
getOriginalTaxonomyFilter()
setSequencePosition(int $sequence_position)
mapTaxonomyFilter(ilQuestionPoolDuplicatedTaxonomiesKeysMap $taxonomies_keys_map)
toNormalized(Transformations $transformations, array $context=[])
Convert the internal state of the implementing object into a language-neutral array structure.
__construct(protected ilDBInterface $db, protected ilObjTest $test_obj)
getTypeFilterForDbValue()
get the question type filter for insert into the database
setQuestionAmount(?int $question_amount)
fromNormalized(array $normalized, Transformations $transformations)
Restore the object from its normalized representation.
setTypeFilterFromDbValue(?string $value)
get the question type filter from database value
getLifecycleFilterForDbValue()
insertDbRecord(int $test_id)
setPoolTitle(string $pool_title)
setPoolRefId(?int $pool_ref_id)
foreach($_POST as $key=> $value) $res