ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestRandomQuestionSetSourcePoolTaxonomiesDuplicator.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.ilTaxonomyTree.php';
5 require_once 'Services/Taxonomy/classes/class.ilTaxNodeAssignment.php';
6 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetDuplicatedTaxonomiesKeysMap.php';
7 
15 {
19  public $testOBJ = null;
20 
21  private $sourcePoolId = null;
22 
26  private $questionIdMapping = null;
27 
32 
34  {
35  $this->testOBJ = $testOBJ;
36  $this->sourcePoolId = $sourcePoolId;
37  $this->questionIdMapping = $questionIdMapping;
38 
39  $this->duplicatedTaxonomiesKeysMap = new ilTestRandomQuestionSetDuplicatedTaxonomiesKeysMap();
40  }
41 
42  public function setSourcePoolId($sourcePoolId)
43  {
44  $this->sourcePoolId = $sourcePoolId;
45  }
46 
47  public function getSourcePoolId()
48  {
49  return $this->sourcePoolId;
50  }
51 
53  {
54  $this->questionIdMapping = $questionIdMapping;
55  }
56 
57  public function getQuestionIdMapping()
58  {
60  }
61 
62  public function duplicate()
63  {
64  $poolTaxonomyIds = ilObjTaxonomy::getUsageOfObject($this->getSourcePoolId());
65 
66  foreach($poolTaxonomyIds as $poolTaxId)
67  {
68  $this->duplicateTaxonomyFromPoolToTest($poolTaxId);
69 
71  $poolTaxId, $this->duplicatedTaxonomiesKeysMap->getMappedTaxonomyId($poolTaxId)
72  );
73  }
74  }
75 
76  private function duplicateTaxonomyFromPoolToTest($poolTaxonomyId)
77  {
78  $testTaxonomy = new ilObjTaxonomy();
79  $testTaxonomy->create();
80 
81  $poolTaxonomy = new ilObjTaxonomy($poolTaxonomyId);
82  $poolTaxonomy->doCloneObject($testTaxonomy, null, null);
83 
84  $poolTaxonomy->getTree()->readRootId();
85  $testTaxonomy->getTree()->readRootId();
86 
87  $testTaxonomy->update();
88 
89  ilObjTaxonomy::saveUsage( $testTaxonomy->getId(), $this->testOBJ->getId() );
90 
91  $this->duplicatedTaxonomiesKeysMap->addDuplicatedTaxonomy($poolTaxonomy, $testTaxonomy);
92  }
93 
94  private function transferAssignmentsFromOriginalToDuplicatedTaxonomy($originalTaxonomyId, $mappedTaxonomyId)
95  {
96  $originalTaxAssignment = new ilTaxNodeAssignment('qpl', $this->getSourcePoolId(), 'quest', $originalTaxonomyId);
97 
98  $duplicatedTaxAssignment = new ilTaxNodeAssignment('tst', $this->testOBJ->getId(), 'quest', $mappedTaxonomyId);
99 
100  foreach($this->getQuestionIdMapping() as $originalQuestionId => $duplicatedQuestionId)
101  {
102  $assignments = $originalTaxAssignment->getAssignmentsOfItem($originalQuestionId);
103 
104  foreach($assignments as $assData)
105  {
106  $mappedNodeId = $this->duplicatedTaxonomiesKeysMap->getMappedTaxNodeId($assData['node_id']);
107 
108  $duplicatedTaxAssignment->addAssignment($mappedNodeId, $duplicatedQuestionId);
109  }
110  }
111  }
112 
117  {
119  }
120 }
getAssignmentsOfItem($a_item_id)
Get assignments for item.
Taxonomy node <-> item assignment.
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.