ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilQuestionPoolTaxonomiesDuplicator.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
28 {
29  private $sourceObjId = null;
30 
31  private $sourceObjType = null;
32 
33  private $targetObjId = null;
34 
35  private $targetObjType = null;
36 
40  private $questionIdMapping = null;
41 
46 
47  public function __construct()
48  {
49  $this->duplicatedTaxonomiesKeysMap = new ilQuestionPoolDuplicatedTaxonomiesKeysMap();
50  }
51 
52  public function setSourceObjId($sourceObjId): void
53  {
54  $this->sourceObjId = $sourceObjId;
55  }
56 
57  public function getSourceObjId()
58  {
59  return $this->sourceObjId;
60  }
61 
62  public function getSourceObjType()
63  {
64  return $this->sourceObjType;
65  }
66 
67  public function setSourceObjType($sourceObjType): void
68  {
69  $this->sourceObjType = $sourceObjType;
70  }
71 
72  public function getTargetObjId()
73  {
74  return $this->targetObjId;
75  }
76 
77  public function setTargetObjId($targetObjId): void
78  {
79  $this->targetObjId = $targetObjId;
80  }
81 
82  public function getTargetObjType()
83  {
84  return $this->targetObjType;
85  }
86 
87  public function setTargetObjType($targetObjType): void
88  {
89  $this->targetObjType = $targetObjType;
90  }
91 
93  {
94  $this->questionIdMapping = $questionIdMapping;
95  }
96 
97  public function getQuestionIdMapping()
98  {
100  }
101 
102  public function duplicate($poolTaxonomyIds): void
103  {
104  foreach ($poolTaxonomyIds as $poolTaxId) {
105  $this->duplicateTaxonomyFromPoolToTest($poolTaxId);
106 
108  $poolTaxId,
109  $this->duplicatedTaxonomiesKeysMap->getMappedTaxonomyId($poolTaxId)
110  );
111  }
112  }
113 
114  private function duplicateTaxonomyFromPoolToTest($poolTaxonomyId): void
115  {
116  $poolTaxonomy = new ilObjTaxonomy($poolTaxonomyId);
117  $testTaxonomy = new ilObjTaxonomy();
118  $testTaxonomy->create();
119  $testTaxonomy->setTitle($poolTaxonomy->getTitle());
120  $testTaxonomy->setDescription($poolTaxonomy->getDescription());
121  $testTaxonomy->setSortingMode($poolTaxonomy->getSortingMode());
122 
123  $this->node_mapping = array();
124 
125  $poolTaxonomy->cloneNodes(
126  $testTaxonomy,
127  $testTaxonomy->getTree()->readRootId(),
128  $poolTaxonomy->getTree()->readRootId()
129  );
130 
131  $testTaxonomy->update();
132 
133  ilObjTaxonomy::saveUsage($testTaxonomy->getId(), $this->getTargetObjId());
134 
135  $this->duplicatedTaxonomiesKeysMap->addDuplicatedTaxonomy($poolTaxonomy, $testTaxonomy);
136  }
137 
138  private function transferAssignmentsFromOriginalToDuplicatedTaxonomy($originalTaxonomyId, $mappedTaxonomyId): void
139  {
140  $originalTaxAssignment = new ilTaxNodeAssignment($this->getSourceObjType(), $this->getSourceObjId(), 'quest', $originalTaxonomyId);
141 
142  $duplicatedTaxAssignment = new ilTaxNodeAssignment($this->getTargetObjType(), $this->getTargetObjId(), 'quest', $mappedTaxonomyId);
143 
144  foreach ($this->getQuestionIdMapping() as $originalQuestionId => $duplicatedQuestionId) {
145  $assignments = $originalTaxAssignment->getAssignmentsOfItem($originalQuestionId);
146 
147  foreach ($assignments as $assData) {
148  $mappedNodeId = $this->duplicatedTaxonomiesKeysMap->getMappedTaxNodeId($assData['node_id']);
149 
150  $duplicatedTaxAssignment->addAssignment($mappedNodeId, $duplicatedQuestionId);
151  }
152  }
153  }
154 
159  {
161  }
162 
163  public function getAllTaxonomiesForSourceObject(): array
164  {
166  }
167 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
transferAssignmentsFromOriginalToDuplicatedTaxonomy($originalTaxonomyId, $mappedTaxonomyId)
static saveUsage(int $a_tax_id, int $a_obj_id)