ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilQuestionPoolTaxonomiesDuplicator.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
5 require_once 'Services/Taxonomy/classes/class.ilTaxonomyTree.php';
6 require_once 'Services/Taxonomy/classes/class.ilTaxNodeAssignment.php';
7 require_once 'Modules/TestQuestionPool/classes/class.ilQuestionPoolDuplicatedTaxonomiesKeysMap.php';
8 
16 {
17  private $sourceObjId = null;
18 
19  private $sourceObjType = null;
20 
21  private $targetObjId = null;
22 
23  private $targetObjType = null;
24 
28  private $questionIdMapping = null;
29 
34 
35  public function __construct()
36  {
37  $this->duplicatedTaxonomiesKeysMap = new ilQuestionPoolDuplicatedTaxonomiesKeysMap();
38  }
39 
40  public function setSourceObjId($sourceObjId)
41  {
42  $this->sourceObjId = $sourceObjId;
43  }
44 
45  public function getSourceObjId()
46  {
47  return $this->sourceObjId;
48  }
49 
50  public function getSourceObjType()
51  {
52  return $this->sourceObjType;
53  }
54 
56  {
57  $this->sourceObjType = $sourceObjType;
58  }
59 
60  public function getTargetObjId()
61  {
62  return $this->targetObjId;
63  }
64 
65  public function setTargetObjId($targetObjId)
66  {
67  $this->targetObjId = $targetObjId;
68  }
69 
70  public function getTargetObjType()
71  {
72  return $this->targetObjType;
73  }
74 
76  {
77  $this->targetObjType = $targetObjType;
78  }
79 
81  {
82  $this->questionIdMapping = $questionIdMapping;
83  }
84 
85  public function getQuestionIdMapping()
86  {
88  }
89 
90  public function duplicate($poolTaxonomyIds)
91  {
92  foreach ($poolTaxonomyIds as $poolTaxId) {
93  $this->duplicateTaxonomyFromPoolToTest($poolTaxId);
94 
96  $poolTaxId,
97  $this->duplicatedTaxonomiesKeysMap->getMappedTaxonomyId($poolTaxId)
98  );
99  }
100  }
101 
102  private function duplicateTaxonomyFromPoolToTest($poolTaxonomyId)
103  {
104  $testTaxonomy = new ilObjTaxonomy();
105  $testTaxonomy->create();
106 
107  $poolTaxonomy = new ilObjTaxonomy($poolTaxonomyId);
108  $poolTaxonomy->doCloneObject($testTaxonomy, null, null);
109 
110  $poolTaxonomy->getTree()->readRootId();
111  $testTaxonomy->getTree()->readRootId();
112 
113  $testTaxonomy->update();
114 
115  ilObjTaxonomy::saveUsage($testTaxonomy->getId(), $this->getTargetObjId());
116 
117  $this->duplicatedTaxonomiesKeysMap->addDuplicatedTaxonomy($poolTaxonomy, $testTaxonomy);
118  }
119 
120  private function transferAssignmentsFromOriginalToDuplicatedTaxonomy($originalTaxonomyId, $mappedTaxonomyId)
121  {
122  $originalTaxAssignment = new ilTaxNodeAssignment($this->getSourceObjType(), $this->getSourceObjId(), 'quest', $originalTaxonomyId);
123 
124  $duplicatedTaxAssignment = new ilTaxNodeAssignment($this->getTargetObjType(), $this->getTargetObjId(), 'quest', $mappedTaxonomyId);
125 
126  foreach ($this->getQuestionIdMapping() as $originalQuestionId => $duplicatedQuestionId) {
127  $assignments = $originalTaxAssignment->getAssignmentsOfItem($originalQuestionId);
128 
129  foreach ($assignments as $assData) {
130  $mappedNodeId = $this->duplicatedTaxonomiesKeysMap->getMappedTaxNodeId($assData['node_id']);
131 
132  $duplicatedTaxAssignment->addAssignment($mappedNodeId, $duplicatedQuestionId);
133  }
134  }
135  }
136 
141  {
143  }
144 
146  {
148  }
149 }
Taxonomy node <-> item assignment.
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
transferAssignmentsFromOriginalToDuplicatedTaxonomy($originalTaxonomyId, $mappedTaxonomyId)
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.